sys_statvfs.odin 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #+build linux, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // sys/statvfs.h - VFS File System information structure
  10. foreign lib {
  11. /*
  12. Obtains information about the file system containing the fildes.
  13. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/statvfs.html ]]
  14. */
  15. @(link_name=LFSTATVFS)
  16. fstatvfs :: proc(fildes: FD, buf: ^statvfs_t) -> result ---
  17. /*
  18. Obtains information about the file system containing the file named by path.
  19. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/statvfs.html ]]
  20. */
  21. @(link_name=LSTATVFS)
  22. statvfs :: proc(path: cstring, buf: ^statvfs_t) -> result ---
  23. }
  24. VFS_Flag_Bits :: enum c.ulong {
  25. // Read-only file system.
  26. RDONLY = log2(ST_RDONLY),
  27. // Does not support the semantics of the ST_ISUID and ST_ISGID file mode bits.
  28. NOSUID = log2(ST_NOSUID),
  29. }
  30. VFS_Flags :: bit_set[VFS_Flag_Bits; c.ulong]
  31. when ODIN_OS == .NetBSD {
  32. @(private) LFSTATVFS :: "__fstatvfs90"
  33. @(private) LSTATVFS :: "__statvfs90"
  34. } else {
  35. @(private) LFSTATVFS :: "fstatvfs"
  36. @(private) LSTATVFS :: "statvfs"
  37. }
  38. when ODIN_OS == .Darwin || ODIN_OS == .OpenBSD {
  39. fsblkcnt_t :: distinct c.uint
  40. statvfs_t :: struct {
  41. f_bsize: c.ulong, /* [PSX] file system block size */
  42. f_frsize: c.ulong, /* [PSX] fundamental file system block size */
  43. f_blocks: fsblkcnt_t, /* [PSX] total number of blocks on file system in units of f_frsize */
  44. f_bfree: fsblkcnt_t, /* [PSX] total number of free blocks */
  45. f_bavail: fsblkcnt_t, /* [PSX] number of free blocks available to non-privileged process */
  46. f_files: fsblkcnt_t, /* [PSX] total number of file serial numbers */
  47. f_ffree: fsblkcnt_t, /* [PSX] total number of free file serial numbers */
  48. f_favail: fsblkcnt_t, /* [PSX] number of file serial numbers available to non-privileged process */
  49. f_fsid: c.ulong, /* [PSX] file system ID */
  50. f_flag: VFS_Flags, /* [PSX] bit mask of f_flag values */
  51. f_namemax: c.ulong, /* [PSX] maximum filename length */
  52. }
  53. ST_RDONLY :: 0x00000001
  54. ST_NOSUID :: 0x00000002
  55. } else when ODIN_OS == .FreeBSD {
  56. fsblkcnt_t :: distinct c.uint64_t
  57. statvfs_t :: struct {
  58. f_bavail: fsblkcnt_t, /* [PSX] number of free blocks available to non-privileged process */
  59. f_bfree: fsblkcnt_t, /* [PSX] total number of free blocks */
  60. f_blocks: fsblkcnt_t, /* [PSX] total number of blocks on file system in units of f_frsize */
  61. f_favail: fsblkcnt_t, /* [PSX] number of file serial numbers available to non-privileged process */
  62. f_ffree: fsblkcnt_t, /* [PSX] total number of free file serial numbers */
  63. f_files: fsblkcnt_t, /* [PSX] total number of file serial numbers */
  64. f_bsize: c.ulong, /* [PSX] file system block size */
  65. f_flag: VFS_Flags, /* [PSX] bit mask of f_flag values */
  66. f_frsize: c.ulong, /* [PSX] fundamental file system block size */
  67. f_fsid: c.ulong, /* [PSX] file system ID */
  68. f_namemax: c.ulong, /* [PSX] maximum filename length */
  69. }
  70. ST_RDONLY :: 0x00000001
  71. ST_NOSUID :: 0x00000002
  72. } else when ODIN_OS == .NetBSD {
  73. fsblkcnt_t :: distinct c.uint64_t
  74. @(private)
  75. _VFS_NAMELEN :: 1024
  76. @(private)
  77. fsid_t :: struct {
  78. __fsid_val: [2]c.int,
  79. }
  80. statvfs_t :: struct {
  81. f_flag: VFS_Flags, /* [PSX] bit mask of f_flag values */
  82. f_bsize: c.ulong, /* [PSX] file system block size */
  83. f_frsize: c.ulong, /* [PSX] fundamental file system block size */
  84. f_iosize: c.ulong,
  85. f_blocks: fsblkcnt_t, /* [PSX] total number of blocks on file system in units of f_frsize */
  86. f_bfree: fsblkcnt_t, /* [PSX] total number of free blocks */
  87. f_bavail: fsblkcnt_t, /* [PSX] number of free blocks available to non-privileged process */
  88. f_bresvd: fsblkcnt_t,
  89. f_files: fsblkcnt_t, /* [PSX] total number of file serial numbers */
  90. f_ffree: fsblkcnt_t, /* [PSX] total number of free file serial numbers */
  91. f_favail: fsblkcnt_t, /* [PSX] number of file serial numbers available to non-privileged process */
  92. f_fresvd: fsblkcnt_t,
  93. f_syncreads: c.uint64_t,
  94. f_syncwrites: c.uint64_t,
  95. f_asyncreads: c.uint64_t,
  96. f_asyncwrites: c.uint64_t,
  97. f_fsidx: fsid_t,
  98. f_fsid: c.ulong, /* [PSX] file system ID */
  99. f_namemax: c.ulong, /* [PSX] maximum filename length */
  100. f_owner: uid_t,
  101. f_spare: [4]c.uint64_t,
  102. f_fstypename: [_VFS_NAMELEN]c.char `fmt:"s,0"`,
  103. f_mntonname: [_VFS_NAMELEN]c.char `fmt:"s,0"`,
  104. f_mntfromname: [_VFS_NAMELEN]c.char `fmt:"s,0"`,
  105. f_mntfromlabel: [_VFS_NAMELEN]c.char `fmt:"s,0"`,
  106. }
  107. ST_RDONLY :: 0x00000001
  108. ST_NOSUID :: 0x00000008
  109. } else when ODIN_OS == .Linux {
  110. fsblkcnt_t :: distinct c.uint64_t
  111. statvfs_t :: struct {
  112. f_bsize: c.ulong, /* [PSX] file system block size */
  113. f_frsize: c.ulong, /* [PSX] fundamental file system block size */
  114. f_blocks: fsblkcnt_t, /* [PSX] total number of blocks on file system in units of f_frsize */
  115. f_bfree: fsblkcnt_t, /* [PSX] total number of free blocks */
  116. f_bavail: fsblkcnt_t, /* [PSX] number of free blocks available to non-privileged process */
  117. f_files: fsblkcnt_t, /* [PSX] total number of file serial numbers */
  118. f_ffree: fsblkcnt_t, /* [PSX] total number of free file serial numbers */
  119. f_favail: fsblkcnt_t, /* [PSX] number of file serial numbers available to non-privileged process */
  120. f_fsid: c.ulong, /* [PSX] file system ID */
  121. _: [2*size_of(c.int)-size_of(c.long)]byte,
  122. f_flag: VFS_Flags, /* [PSX] bit mask of f_flag values */
  123. f_namemax: c.ulong, /* [PSX] maximum filename length */
  124. f_type: c.uint,
  125. __reserved: [5]c.int,
  126. }
  127. ST_RDONLY :: 0x00000001
  128. ST_NOSUID :: 0x00000002
  129. }