17b3d36e5SAxel Dörfler/*
2173f54f1SMatt Madia * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
37b3d36e5SAxel Dörfler * Distributed under the terms of the MIT License.
47b3d36e5SAxel Dörfler */
5f41c281fSDavid Reid#ifndef _SYS_STAT_H_
6ae372703SAxel Dörfler#define _SYS_STAT_H_
7f41c281fSDavid Reid
87b3d36e5SAxel Dörfler
910567eebSAxel Dörfler#include <sys/types.h>
10bcfe344cSIngo Weinhold#include <time.h>
11f41c281fSDavid Reid
12f41c281fSDavid Reid
13f41c281fSDavid Reidstruct stat {
14b2ec044cSAxel Dörfler	dev_t			st_dev;			/* device ID that this file resides on */
15b2ec044cSAxel Dörfler	ino_t			st_ino;			/* this file's serial inode ID */
16b2ec044cSAxel Dörfler	mode_t			st_mode;		/* file mode (rwx for user, group, etc) */
1710567eebSAxel Dörfler	nlink_t			st_nlink;		/* number of hard links to this file */
18b2ec044cSAxel Dörfler	uid_t			st_uid;			/* user ID of the owner of this file */
19b2ec044cSAxel Dörfler	gid_t			st_gid;			/* group ID of the owner of this file */
2010567eebSAxel Dörfler	off_t			st_size;		/* size in bytes of this file */
2194e11a83SAxel Dörfler	dev_t			st_rdev;		/* device type (not used) */
22b2ec044cSAxel Dörfler	blksize_t		st_blksize;		/* preferred block size for I/O */
23bcfe344cSIngo Weinhold	struct timespec	st_atim;		/* last access time */
24bcfe344cSIngo Weinhold	struct timespec	st_mtim;		/* last modification time */
25bcfe344cSIngo Weinhold	struct timespec	st_ctim;		/* last change time, not creation time */
26bcfe344cSIngo Weinhold	struct timespec	st_crtim;		/* creation time */
272222d055SIngo Weinhold	__haiku_uint32	st_type;		/* attribute/index type */
28b2ec044cSAxel Dörfler	blkcnt_t		st_blocks;		/* number of blocks allocated for object */
29f41c281fSDavid Reid};
30f41c281fSDavid Reid
31bcfe344cSIngo Weinhold/* source compatibility with old stat structure */
32bcfe344cSIngo Weinhold#define st_atime	st_atim.tv_sec
33bcfe344cSIngo Weinhold#define st_mtime	st_mtim.tv_sec
34bcfe344cSIngo Weinhold#define st_ctime	st_ctim.tv_sec
35bcfe344cSIngo Weinhold#define st_crtime	st_crtim.tv_sec
36bcfe344cSIngo Weinhold
37bcfe344cSIngo Weinhold
38ae372703SAxel Dörfler/* extended file types */
392311f9f7SAxel Dörfler#define S_ATTR_DIR			01000000000	/* attribute directory */
402311f9f7SAxel Dörfler#define S_ATTR				02000000000	/* attribute */
412311f9f7SAxel Dörfler#define S_INDEX_DIR			04000000000	/* index (or index directory) */
422311f9f7SAxel Dörfler#define S_STR_INDEX			00100000000	/* string index */
432311f9f7SAxel Dörfler#define S_INT_INDEX			00200000000	/* int32 index */
442311f9f7SAxel Dörfler#define S_UINT_INDEX		00400000000	/* uint32 index */
452311f9f7SAxel Dörfler#define S_LONG_LONG_INDEX	00010000000	/* int64 index */
462311f9f7SAxel Dörfler#define S_ULONG_LONG_INDEX	00020000000	/* uint64 index */
472311f9f7SAxel Dörfler#define S_FLOAT_INDEX		00040000000	/* float index */
482311f9f7SAxel Dörfler#define S_DOUBLE_INDEX		00001000000	/* double index */
492311f9f7SAxel Dörfler#define S_ALLOW_DUPS		00002000000	/* allow duplicate entries (currently unused) */
502311f9f7SAxel Dörfler
512311f9f7SAxel Dörfler/* link types */
522311f9f7SAxel Dörfler#define	S_LINK_SELF_HEALING	00001000000	/* link will be updated if you move its target */
532311f9f7SAxel Dörfler#define S_LINK_AUTO_DELETE	00002000000	/* link will be deleted if you delete its target */
54ae372703SAxel Dörfler
55ae372703SAxel Dörfler/* standard file types */
562311f9f7SAxel Dörfler#define S_IFMT				00000170000 /* type of file */
5764cd0336SIngo Weinhold#define	S_IFSOCK			00000140000 /* socket */
582311f9f7SAxel Dörfler#define	S_IFLNK				00000120000 /* symbolic link */
592311f9f7SAxel Dörfler#define S_IFREG 			00000100000 /* regular */
602311f9f7SAxel Dörfler#define S_IFBLK 			00000060000 /* block special */
612311f9f7SAxel Dörfler#define S_IFDIR 			00000040000 /* directory */
622311f9f7SAxel Dörfler#define S_IFCHR 			00000020000 /* character special */
632311f9f7SAxel Dörfler#define S_IFIFO 			00000010000 /* fifo */
64ae372703SAxel Dörfler
657b3d36e5SAxel Dörfler#define S_ISREG(mode)		(((mode) & S_IFMT) == S_IFREG)
667b3d36e5SAxel Dörfler#define S_ISLNK(mode)		(((mode) & S_IFMT) == S_IFLNK)
677b3d36e5SAxel Dörfler#define S_ISBLK(mode)		(((mode) & S_IFMT) == S_IFBLK)
687b3d36e5SAxel Dörfler#define S_ISDIR(mode)		(((mode) & S_IFMT) == S_IFDIR)
697b3d36e5SAxel Dörfler#define S_ISCHR(mode)		(((mode) & S_IFMT) == S_IFCHR)
707b3d36e5SAxel Dörfler#define S_ISFIFO(mode)		(((mode) & S_IFMT) == S_IFIFO)
7164cd0336SIngo Weinhold#define S_ISSOCK(mode)		(((mode) & S_IFMT) == S_IFSOCK)
727b3d36e5SAxel Dörfler#define S_ISINDEX(mode)		(((mode) & S_INDEX_DIR) == S_INDEX_DIR)
73ae372703SAxel Dörfler
74ae372703SAxel Dörfler#define	S_IUMSK 07777		/* user settable bits */
75ae372703SAxel Dörfler
76ae372703SAxel Dörfler#define S_ISUID 04000       /* set user id on execution */
77ae372703SAxel Dörfler#define S_ISGID 02000       /* set group id on execution */
78ae372703SAxel Dörfler
796449b66eSAxel Dörfler#define S_ISVTX 01000       /* save swapped text even after use (sticky bit) */
80ae372703SAxel Dörfler
81ae372703SAxel Dörfler#define S_IRWXU 00700       /* read, write, execute: owner */
82ae372703SAxel Dörfler#define S_IRUSR 00400       /* read permission: owner */
83ae372703SAxel Dörfler#define S_IWUSR 00200       /* write permission: owner */
84ae372703SAxel Dörfler#define S_IXUSR 00100       /* execute permission: owner */
85ae372703SAxel Dörfler#define S_IRWXG 00070       /* read, write, execute: group */
86ae372703SAxel Dörfler#define S_IRGRP 00040       /* read permission: group */
87ae372703SAxel Dörfler#define S_IWGRP 00020       /* write permission: group */
88ae372703SAxel Dörfler#define S_IXGRP 00010       /* execute permission: group */
89ae372703SAxel Dörfler#define S_IRWXO 00007       /* read, write, execute: other */
90ae372703SAxel Dörfler#define S_IROTH 00004       /* read permission: other */
91ae372703SAxel Dörfler#define S_IWOTH 00002       /* write permission: other */
92ae372703SAxel Dörfler#define S_IXOTH 00001       /* execute permission: other */
93f41c281fSDavid Reid
94a32a4683SAxel Dörfler/* BSD extensions */
95a32a4683SAxel Dörfler#define S_IREAD		S_IRUSR
96a32a4683SAxel Dörfler#define S_IWRITE	S_IWUSR
97a32a4683SAxel Dörfler#define S_IEXEC		S_IXUSR
98a32a4683SAxel Dörfler
99f41c281fSDavid Reid#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
1006449b66eSAxel Dörfler#define ALLPERMS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
1017b3d36e5SAxel Dörfler#define	DEFFILEMODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
1027b3d36e5SAxel Dörfler	/* default file mode, everyone can read/write */
103f41c281fSDavid Reid
1046c00aabcSIngo Weinhold/* special values for timespec::tv_nsec passed to utimensat(), futimens() */
1056c00aabcSIngo Weinhold#define UTIME_NOW	1000000000
1066c00aabcSIngo Weinhold#define UTIME_OMIT	1000000001
1076c00aabcSIngo Weinhold
108ae372703SAxel Dörfler#ifdef __cplusplus
109ae372703SAxel Dörflerextern "C" {
110f41c281fSDavid Reid#endif
111f41c281fSDavid Reid
112a6147679SIngo Weinholdextern int		chmod(const char *path, mode_t mode);
113a6147679SIngo Weinholdextern int		fchmod(int fd, mode_t mode);
114fb2500daSAxel Dörflerextern int		fchmodat(int fd, const char *path, mode_t mode, int flag);
115a6147679SIngo Weinholdextern int		stat(const char *path, struct stat *st);
116a6147679SIngo Weinholdextern int		fstat(int fd, struct stat *st);
117a6147679SIngo Weinholdextern int		lstat(const char *path, struct stat *st);
118a6147679SIngo Weinholdextern int		fstatat(int fd, const char *path, struct stat *st, int flag);
119a6147679SIngo Weinholdextern int		mkdir(const char *path, mode_t mode);
1206c00aabcSIngo Weinholdextern int		mkdirat(int fd, const char *path, mode_t mode);
121a6147679SIngo Weinholdextern int		mkfifo(const char *path, mode_t mode);
122fb2500daSAxel Dörflerextern int		mkfifoat(int fd, const char *path, mode_t mode);
1234dc5ce8fSJérôme Duvalextern int		mknod(const char *name, mode_t mode, dev_t dev);
1244dc5ce8fSJérôme Duvalextern int		mknodat(int fd, const char *name, mode_t mode, dev_t dev);
125a6147679SIngo Weinholdextern mode_t	umask(mode_t cmask);
12694e11a83SAxel Dörfler
1276c00aabcSIngo Weinholdextern int		utimensat(int fd, const char *path,
1286c00aabcSIngo Weinhold					const struct timespec times[2], int flag);
1296c00aabcSIngo Weinholdextern int		futimens(int fd, const struct timespec times[2]);
1306c00aabcSIngo Weinhold
131ae372703SAxel Dörfler#ifdef __cplusplus
132ae372703SAxel Dörfler}
133ae372703SAxel Dörfler#endif
134f41c281fSDavid Reid
1357b3d36e5SAxel Dörfler#endif	/* _SYS_STAT_H_ */