1fb7df12dSIngo Molnar/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
267ef2879SArnaldo Carvalho de Melo#ifndef _UAPI_LINUX_STAT_H
367ef2879SArnaldo Carvalho de Melo#define _UAPI_LINUX_STAT_H
467ef2879SArnaldo Carvalho de Melo
567ef2879SArnaldo Carvalho de Melo#include <linux/types.h>
667ef2879SArnaldo Carvalho de Melo
767ef2879SArnaldo Carvalho de Melo#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
867ef2879SArnaldo Carvalho de Melo
967ef2879SArnaldo Carvalho de Melo#define S_IFMT  00170000
1067ef2879SArnaldo Carvalho de Melo#define S_IFSOCK 0140000
1167ef2879SArnaldo Carvalho de Melo#define S_IFLNK	 0120000
1267ef2879SArnaldo Carvalho de Melo#define S_IFREG  0100000
1367ef2879SArnaldo Carvalho de Melo#define S_IFBLK  0060000
1467ef2879SArnaldo Carvalho de Melo#define S_IFDIR  0040000
1567ef2879SArnaldo Carvalho de Melo#define S_IFCHR  0020000
1667ef2879SArnaldo Carvalho de Melo#define S_IFIFO  0010000
1767ef2879SArnaldo Carvalho de Melo#define S_ISUID  0004000
1867ef2879SArnaldo Carvalho de Melo#define S_ISGID  0002000
1967ef2879SArnaldo Carvalho de Melo#define S_ISVTX  0001000
2067ef2879SArnaldo Carvalho de Melo
2167ef2879SArnaldo Carvalho de Melo#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
2267ef2879SArnaldo Carvalho de Melo#define S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
2367ef2879SArnaldo Carvalho de Melo#define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
2467ef2879SArnaldo Carvalho de Melo#define S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
2567ef2879SArnaldo Carvalho de Melo#define S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
2667ef2879SArnaldo Carvalho de Melo#define S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
2767ef2879SArnaldo Carvalho de Melo#define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)
2867ef2879SArnaldo Carvalho de Melo
2967ef2879SArnaldo Carvalho de Melo#define S_IRWXU 00700
3067ef2879SArnaldo Carvalho de Melo#define S_IRUSR 00400
3167ef2879SArnaldo Carvalho de Melo#define S_IWUSR 00200
3267ef2879SArnaldo Carvalho de Melo#define S_IXUSR 00100
3367ef2879SArnaldo Carvalho de Melo
3467ef2879SArnaldo Carvalho de Melo#define S_IRWXG 00070
3567ef2879SArnaldo Carvalho de Melo#define S_IRGRP 00040
3667ef2879SArnaldo Carvalho de Melo#define S_IWGRP 00020
3767ef2879SArnaldo Carvalho de Melo#define S_IXGRP 00010
3867ef2879SArnaldo Carvalho de Melo
3967ef2879SArnaldo Carvalho de Melo#define S_IRWXO 00007
4067ef2879SArnaldo Carvalho de Melo#define S_IROTH 00004
4167ef2879SArnaldo Carvalho de Melo#define S_IWOTH 00002
4267ef2879SArnaldo Carvalho de Melo#define S_IXOTH 00001
4367ef2879SArnaldo Carvalho de Melo
4467ef2879SArnaldo Carvalho de Melo#endif
4567ef2879SArnaldo Carvalho de Melo
4667ef2879SArnaldo Carvalho de Melo/*
4767ef2879SArnaldo Carvalho de Melo * Timestamp structure for the timestamps in struct statx.
4867ef2879SArnaldo Carvalho de Melo *
4967ef2879SArnaldo Carvalho de Melo * tv_sec holds the number of seconds before (negative) or after (positive)
5067ef2879SArnaldo Carvalho de Melo * 00:00:00 1st January 1970 UTC.
5167ef2879SArnaldo Carvalho de Melo *
526e30437bSIngo Molnar * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec time.
5367ef2879SArnaldo Carvalho de Melo *
5467ef2879SArnaldo Carvalho de Melo * __reserved is held in case we need a yet finer resolution.
5567ef2879SArnaldo Carvalho de Melo */
5667ef2879SArnaldo Carvalho de Melostruct statx_timestamp {
5767ef2879SArnaldo Carvalho de Melo	__s64	tv_sec;
586e30437bSIngo Molnar	__u32	tv_nsec;
5967ef2879SArnaldo Carvalho de Melo	__s32	__reserved;
6067ef2879SArnaldo Carvalho de Melo};
6167ef2879SArnaldo Carvalho de Melo
6267ef2879SArnaldo Carvalho de Melo/*
6367ef2879SArnaldo Carvalho de Melo * Structures for the extended file attribute retrieval system call
6467ef2879SArnaldo Carvalho de Melo * (statx()).
6567ef2879SArnaldo Carvalho de Melo *
6667ef2879SArnaldo Carvalho de Melo * The caller passes a mask of what they're specifically interested in as a
6767ef2879SArnaldo Carvalho de Melo * parameter to statx().  What statx() actually got will be indicated in
6867ef2879SArnaldo Carvalho de Melo * st_mask upon return.
6967ef2879SArnaldo Carvalho de Melo *
7067ef2879SArnaldo Carvalho de Melo * For each bit in the mask argument:
7167ef2879SArnaldo Carvalho de Melo *
7267ef2879SArnaldo Carvalho de Melo * - if the datum is not supported:
7367ef2879SArnaldo Carvalho de Melo *
7467ef2879SArnaldo Carvalho de Melo *   - the bit will be cleared, and
7567ef2879SArnaldo Carvalho de Melo *
7667ef2879SArnaldo Carvalho de Melo *   - the datum will be set to an appropriate fabricated value if one is
7767ef2879SArnaldo Carvalho de Melo *     available (eg. CIFS can take a default uid and gid), otherwise
7867ef2879SArnaldo Carvalho de Melo *
7967ef2879SArnaldo Carvalho de Melo *   - the field will be cleared;
8067ef2879SArnaldo Carvalho de Melo *
8167ef2879SArnaldo Carvalho de Melo * - otherwise, if explicitly requested:
8267ef2879SArnaldo Carvalho de Melo *
8367ef2879SArnaldo Carvalho de Melo *   - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
8467ef2879SArnaldo Carvalho de Melo *     set or if the datum is considered out of date, and
8567ef2879SArnaldo Carvalho de Melo *
8667ef2879SArnaldo Carvalho de Melo *   - the field will be filled in and the bit will be set;
8767ef2879SArnaldo Carvalho de Melo *
8867ef2879SArnaldo Carvalho de Melo * - otherwise, if not requested, but available in approximate form without any
8967ef2879SArnaldo Carvalho de Melo *   effort, it will be filled in anyway, and the bit will be set upon return
9067ef2879SArnaldo Carvalho de Melo *   (it might not be up to date, however, and no attempt will be made to
9167ef2879SArnaldo Carvalho de Melo *   synchronise the internal state first);
9267ef2879SArnaldo Carvalho de Melo *
9367ef2879SArnaldo Carvalho de Melo * - otherwise the field and the bit will be cleared before returning.
9467ef2879SArnaldo Carvalho de Melo *
9567ef2879SArnaldo Carvalho de Melo * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
9667ef2879SArnaldo Carvalho de Melo * will have values installed for compatibility purposes so that stat() and
9767ef2879SArnaldo Carvalho de Melo * co. can be emulated in userspace.
9867ef2879SArnaldo Carvalho de Melo */
9967ef2879SArnaldo Carvalho de Melostruct statx {
10067ef2879SArnaldo Carvalho de Melo	/* 0x00 */
10167ef2879SArnaldo Carvalho de Melo	__u32	stx_mask;	/* What results were written [uncond] */
10267ef2879SArnaldo Carvalho de Melo	__u32	stx_blksize;	/* Preferred general I/O size [uncond] */
10367ef2879SArnaldo Carvalho de Melo	__u64	stx_attributes;	/* Flags conveying information about the file [uncond] */
10467ef2879SArnaldo Carvalho de Melo	/* 0x10 */
10567ef2879SArnaldo Carvalho de Melo	__u32	stx_nlink;	/* Number of hard links */
10667ef2879SArnaldo Carvalho de Melo	__u32	stx_uid;	/* User ID of owner */
10767ef2879SArnaldo Carvalho de Melo	__u32	stx_gid;	/* Group ID of owner */
10867ef2879SArnaldo Carvalho de Melo	__u16	stx_mode;	/* File mode */
10967ef2879SArnaldo Carvalho de Melo	__u16	__spare0[1];
11067ef2879SArnaldo Carvalho de Melo	/* 0x20 */
11167ef2879SArnaldo Carvalho de Melo	__u64	stx_ino;	/* Inode number */
11267ef2879SArnaldo Carvalho de Melo	__u64	stx_size;	/* File size */
11367ef2879SArnaldo Carvalho de Melo	__u64	stx_blocks;	/* Number of 512-byte blocks allocated */
11404ec75e0SArnaldo Carvalho de Melo	__u64	stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
11567ef2879SArnaldo Carvalho de Melo	/* 0x40 */
11667ef2879SArnaldo Carvalho de Melo	struct statx_timestamp	stx_atime;	/* Last access time */
11767ef2879SArnaldo Carvalho de Melo	struct statx_timestamp	stx_btime;	/* File creation time */
11867ef2879SArnaldo Carvalho de Melo	struct statx_timestamp	stx_ctime;	/* Last attribute change time */
11967ef2879SArnaldo Carvalho de Melo	struct statx_timestamp	stx_mtime;	/* Last data modification time */
12067ef2879SArnaldo Carvalho de Melo	/* 0x80 */
12167ef2879SArnaldo Carvalho de Melo	__u32	stx_rdev_major;	/* Device ID of special file [if bdev/cdev] */
12267ef2879SArnaldo Carvalho de Melo	__u32	stx_rdev_minor;
12367ef2879SArnaldo Carvalho de Melo	__u32	stx_dev_major;	/* ID of device containing file [uncond] */
12467ef2879SArnaldo Carvalho de Melo	__u32	stx_dev_minor;
12567ef2879SArnaldo Carvalho de Melo	/* 0x90 */
12693dc627fSArnaldo Carvalho de Melo	__u64	stx_mnt_id;
12793dc627fSArnaldo Carvalho de Melo	__u64	__spare2;
12893dc627fSArnaldo Carvalho de Melo	/* 0xa0 */
12993dc627fSArnaldo Carvalho de Melo	__u64	__spare3[12];	/* Spare space for future expansion */
13067ef2879SArnaldo Carvalho de Melo	/* 0x100 */
13167ef2879SArnaldo Carvalho de Melo};
13267ef2879SArnaldo Carvalho de Melo
13367ef2879SArnaldo Carvalho de Melo/*
13467ef2879SArnaldo Carvalho de Melo * Flags to be stx_mask
13567ef2879SArnaldo Carvalho de Melo *
13667ef2879SArnaldo Carvalho de Melo * Query request/result mask for statx() and struct statx::stx_mask.
13767ef2879SArnaldo Carvalho de Melo *
13867ef2879SArnaldo Carvalho de Melo * These bits should be set in the mask argument of statx() to request
13967ef2879SArnaldo Carvalho de Melo * particular items when calling statx().
14067ef2879SArnaldo Carvalho de Melo */
14167ef2879SArnaldo Carvalho de Melo#define STATX_TYPE		0x00000001U	/* Want/got stx_mode & S_IFMT */
14267ef2879SArnaldo Carvalho de Melo#define STATX_MODE		0x00000002U	/* Want/got stx_mode & ~S_IFMT */
14367ef2879SArnaldo Carvalho de Melo#define STATX_NLINK		0x00000004U	/* Want/got stx_nlink */
14467ef2879SArnaldo Carvalho de Melo#define STATX_UID		0x00000008U	/* Want/got stx_uid */
14567ef2879SArnaldo Carvalho de Melo#define STATX_GID		0x00000010U	/* Want/got stx_gid */
14667ef2879SArnaldo Carvalho de Melo#define STATX_ATIME		0x00000020U	/* Want/got stx_atime */
14767ef2879SArnaldo Carvalho de Melo#define STATX_MTIME		0x00000040U	/* Want/got stx_mtime */
14867ef2879SArnaldo Carvalho de Melo#define STATX_CTIME		0x00000080U	/* Want/got stx_ctime */
14967ef2879SArnaldo Carvalho de Melo#define STATX_INO		0x00000100U	/* Want/got stx_ino */
15067ef2879SArnaldo Carvalho de Melo#define STATX_SIZE		0x00000200U	/* Want/got stx_size */
15167ef2879SArnaldo Carvalho de Melo#define STATX_BLOCKS		0x00000400U	/* Want/got stx_blocks */
15267ef2879SArnaldo Carvalho de Melo#define STATX_BASIC_STATS	0x000007ffU	/* The stuff in the normal stat struct */
15367ef2879SArnaldo Carvalho de Melo#define STATX_BTIME		0x00000800U	/* Want/got stx_btime */
15493dc627fSArnaldo Carvalho de Melo#define STATX_MNT_ID		0x00001000U	/* Got stx_mnt_id */
155581701b7SMiklos Szeredi
15604ec75e0SArnaldo Carvalho de Melo#define STATX__RESERVED		0x80000000U	/* Reserved for future struct statx expansion */
15767ef2879SArnaldo Carvalho de Melo
158581701b7SMiklos Szeredi#ifndef __KERNEL__
159581701b7SMiklos Szeredi/*
160581701b7SMiklos Szeredi * This is deprecated, and shall remain the same value in the future.  To avoid
161581701b7SMiklos Szeredi * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME)
162581701b7SMiklos Szeredi * instead.
163581701b7SMiklos Szeredi */
164581701b7SMiklos Szeredi#define STATX_ALL		0x00000fffU
165581701b7SMiklos Szeredi#endif
166581701b7SMiklos Szeredi
16767ef2879SArnaldo Carvalho de Melo/*
16804ec75e0SArnaldo Carvalho de Melo * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
16967ef2879SArnaldo Carvalho de Melo *
17067ef2879SArnaldo Carvalho de Melo * These give information about the features or the state of a file that might
17167ef2879SArnaldo Carvalho de Melo * be of use to ordinary userspace programs such as GUIs or ls rather than
17267ef2879SArnaldo Carvalho de Melo * specialised tools.
17367ef2879SArnaldo Carvalho de Melo *
1741c28a05dSArnaldo Carvalho de Melo * Note that the flags marked [I] correspond to the FS_IOC_SETFLAGS flags
17567ef2879SArnaldo Carvalho de Melo * semantically.  Where possible, the numerical value is picked to correspond
1761c28a05dSArnaldo Carvalho de Melo * also.  Note that the DAX attribute indicates that the file is in the CPU
1771c28a05dSArnaldo Carvalho de Melo * direct access state.  It does not correspond to the per-inode flag that
1781c28a05dSArnaldo Carvalho de Melo * some filesystems support.
1791c28a05dSArnaldo Carvalho de Melo *
18067ef2879SArnaldo Carvalho de Melo */
18167ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_COMPRESSED		0x00000004 /* [I] File is compressed by the fs */
18267ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_IMMUTABLE		0x00000010 /* [I] File is marked immutable */
18367ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_APPEND		0x00000020 /* [I] File is append-only */
18467ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_NODUMP		0x00000040 /* [I] File is not to be dumped */
18567ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_ENCRYPTED		0x00000800 /* [I] File requires key to decrypt in fs */
18667ef2879SArnaldo Carvalho de Melo#define STATX_ATTR_AUTOMOUNT		0x00001000 /* Dir: Automount trigger */
18793dc627fSArnaldo Carvalho de Melo#define STATX_ATTR_MOUNT_ROOT		0x00002000 /* Root of a mount */
188c66f2566SArnaldo Carvalho de Melo#define STATX_ATTR_VERITY		0x00100000 /* [I] Verity protected file */
1891c28a05dSArnaldo Carvalho de Melo#define STATX_ATTR_DAX			0x00200000 /* File is currently in DAX state */
19067ef2879SArnaldo Carvalho de Melo
19167ef2879SArnaldo Carvalho de Melo
19267ef2879SArnaldo Carvalho de Melo#endif /* _UAPI_LINUX_STAT_H */
193