stat.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) mlibc & plct lab
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023/06/16 bernard the first verison
  9. */
  10. #ifndef MLIBC_SYS_STAT_H__
  11. #define MLIBC_SYS_STAT_H__
  12. #include <stdint.h>
  13. #include <time.h>
  14. /* File types */
  15. #define S_IFMT 00170000
  16. #define S_IFSOCK 0140000
  17. #define S_IFLNK 0120000
  18. #define S_IFREG 0100000
  19. #define S_IFBLK 0060000
  20. #define S_IFDIR 0040000
  21. #define S_IFCHR 0020000
  22. #define S_IFIFO 0010000
  23. /* File permission */
  24. #define S_ISUID 0004000
  25. #define S_ISGID 0002000
  26. #define S_ISVTX 0001000
  27. #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  28. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  29. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  30. #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  31. #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  32. #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  33. #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  34. #define S_IRWXU 00700
  35. #define S_IRUSR 00400
  36. #define S_IWUSR 00200
  37. #define S_IXUSR 00100
  38. #define S_IRWXG 00070
  39. #define S_IRGRP 00040
  40. #define S_IWGRP 00020
  41. #define S_IXGRP 00010
  42. #define S_IRWXO 00007
  43. #define S_IROTH 00004
  44. #define S_IWOTH 00002
  45. #define S_IXOTH 00001
  46. /* stat structure */
  47. struct stat
  48. {
  49. dev_t st_dev;
  50. uint16_t st_ino;
  51. uint16_t st_mode;
  52. uint16_t st_nlink;
  53. uint16_t st_uid;
  54. uint16_t st_gid;
  55. dev_t st_rdev;
  56. uint32_t st_size;
  57. struct timespec st_atim;
  58. long st_spare1;
  59. struct timespec st_mtim;
  60. long st_spare2;
  61. struct timespec st_ctim;
  62. long st_spare3;
  63. uint32_t st_blksize;
  64. uint32_t st_blocks;
  65. long st_spare4[2];
  66. };
  67. #define st_atime st_atim.tv_sec
  68. #define st_mtime st_mtim.tv_sec
  69. #define st_ctime st_ctim.tv_sec
  70. int mkdir(const char *, mode_t);
  71. int stat(const char *__restrict, struct stat *__restrict);
  72. int fstat(int, struct stat *);
  73. int utimensat(int, const char *, const struct timespec [2], int);
  74. #endif /*MLIBC_SYS_STAT_H__*/