stat.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <sys/cdefs.h>
  28. #include <sys/types.h>
  29. __BEGIN_DECLS
  30. #define S_IFMT 0170000
  31. #define S_IFDIR 0040000
  32. #define S_IFCHR 0020000
  33. #define S_IFBLK 0060000
  34. #define S_IFREG 0100000
  35. #define S_IFIFO 0010000
  36. #define S_IFLNK 0120000
  37. #define S_IFSOCK 0140000
  38. #define S_ISUID 04000
  39. #define S_ISGID 02000
  40. #define S_ISVTX 01000
  41. #define S_IRUSR 0400
  42. #define S_IWUSR 0200
  43. #define S_IXUSR 0100
  44. #define S_IREAD S_IRUSR
  45. #define S_IWRITE S_IWUSR
  46. #define S_IEXEC S_IXUSR
  47. #define S_IRGRP 0040
  48. #define S_IWGRP 0020
  49. #define S_IXGRP 0010
  50. #define S_IROTH 0004
  51. #define S_IWOTH 0002
  52. #define S_IXOTH 0001
  53. #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
  54. #define S_IRWXG (S_IRWXU >> 3)
  55. #define S_IRWXO (S_IRWXG >> 3)
  56. #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
  57. #define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
  58. #define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
  59. #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
  60. #define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
  61. #define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
  62. #define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK)
  63. struct stat {
  64. dev_t st_dev; /* ID of device containing file */
  65. ino_t st_ino; /* inode number */
  66. mode_t st_mode; /* protection */
  67. nlink_t st_nlink; /* number of hard links */
  68. uid_t st_uid; /* user ID of owner */
  69. gid_t st_gid; /* group ID of owner */
  70. dev_t st_rdev; /* device ID (if special file) */
  71. off_t st_size; /* total size, in bytes */
  72. blksize_t st_blksize; /* blocksize for file system I/O */
  73. blkcnt_t st_blocks; /* number of 512B blocks allocated */
  74. time_t st_atime; /* time of last access */
  75. time_t st_mtime; /* time of last modification */
  76. time_t st_ctime; /* time of last status change */
  77. };
  78. mode_t umask(mode_t);
  79. int chmod(const char* pathname, mode_t);
  80. int fchmod(int fd, mode_t);
  81. int mkdir(const char* pathname, mode_t);
  82. int mkfifo(const char* pathname, mode_t);
  83. int fstat(int fd, struct stat* statbuf);
  84. int lstat(const char* path, struct stat* statbuf);
  85. int stat(const char* path, struct stat* statbuf);
  86. inline dev_t makedev(unsigned int major, unsigned int minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
  87. inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
  88. inline unsigned int minor(dev_t dev) { return (dev & 0xffu) | ((dev >> 12u) & 0xfff00u); }
  89. __END_DECLS