fprop.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <syscall.h>
  2. #include <bits/fcntl.h>
  3. #include <bits/time.h>
  4. /* File properties (mode and times). The opposite of *stat(). */
  5. #define R_OK 4
  6. #define W_OK 2
  7. #define X_OK 1
  8. #define F_OK 0
  9. #define UTIME_NOW ((1l << 30) - 1l)
  10. #define UTIME_OMIT ((1l << 30) - 2l)
  11. inline static long sys_access(const char* path, int mode)
  12. {
  13. return syscall4(NR_faccessat, AT_FDCWD, (long)path, mode, 0);
  14. }
  15. inline static long sys_faccessat(int at, const char* path, int mode, int flags)
  16. {
  17. return syscall4(NR_faccessat, at, (long)path, mode, flags);
  18. }
  19. inline static long sys_chmod(const char* path, int mode)
  20. {
  21. #ifdef NR_fchmodat
  22. return syscall4(NR_fchmodat, AT_FDCWD, (long)path, mode, 0);
  23. #else
  24. return syscall2(NR_chmod, (long)path, mode);
  25. #endif
  26. }
  27. inline static long sys_fchmod(int fd, int mode)
  28. {
  29. return syscall2(NR_fchmod, fd, mode);
  30. }
  31. inline static long sys_fchmodat(int at, char* path, int mode, int flags)
  32. {
  33. return syscall4(NR_fchmodat, at, (long)path, mode, flags);
  34. }
  35. inline static long sys_chown(const char* path, int uid, int gid)
  36. {
  37. #ifdef NR_fchownat
  38. return syscall5(NR_fchownat, AT_FDCWD, (long)path, uid, gid, 0);
  39. #else
  40. return syscall3(NR_chown, (long)path, uid, gid);
  41. #endif
  42. }
  43. inline static long sys_fchown(int fd, int uid, int gid)
  44. {
  45. #ifdef NR_fchownat
  46. char* empty = "";
  47. int flags = AT_EMPTY_PATH;
  48. return syscall5(NR_fchownat, fd, (long)empty, uid, gid, flags);
  49. #else
  50. return syscall3(NR_fchown, fd, uid, gid);
  51. #endif
  52. }
  53. inline static long sys_fchownat(int at, char* name, int uid, int gid, int flags)
  54. {
  55. return syscall5(NR_fchownat, at, (long)name, uid, gid, flags);
  56. }
  57. inline static long sys_utimensat(int at, char* path,
  58. const struct timespec times[2], int flags)
  59. {
  60. return syscall4(NR_utimensat, at, (long)path, (long)times, flags);
  61. }
  62. inline static long sys_utimes(int fd, const struct timespec times[2])
  63. {
  64. return syscall4(NR_utimensat, fd, 0, (long)times, 0);
  65. }
  66. #define FALLOC_FL_KEEP_SIZE 1
  67. #define FALLOC_FL_PUNCH_HOLE 2
  68. #define FALLOC_FL_COLLAPSE_RANGE 8
  69. #define FALLOC_FL_ZERO_RANGE 16
  70. inline static long sys_fallocate(int fd, int mode, uint64_t offset, uint64_t len)
  71. {
  72. return syscall4(NR_fallocate, fd, mode, offset, len);
  73. }
  74. inline static long sys_truncate(const char* path, uint64_t size)
  75. {
  76. return syscall2(NR_truncate, (long)path, size);
  77. }
  78. inline static long sys_ftruncate(int fd, uint64_t size)
  79. {
  80. return syscall2(NR_ftruncate, fd, size);
  81. }