stat 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. .TH STAT 5
  2. .SH NAME
  3. stat, wstat \- inquire or change file attributes
  4. .SH SYNOPSIS
  5. .ta \w'\fLTwstat 'u
  6. .IR size [4]
  7. .B Tstat
  8. .IR tag [2]
  9. .IR fid [4]
  10. .br
  11. .IR size [4]
  12. .B Rstat
  13. .IR tag [2]
  14. .IR stat [ n ]
  15. .PP
  16. .IR size [4]
  17. .B Twstat
  18. .IR tag [2]
  19. .IR fid [4]
  20. .IR stat [ n ]
  21. .br
  22. .IR size [4]
  23. .B Rwstat
  24. .IR tag [2]
  25. .SH DESCRIPTION
  26. The
  27. .B stat
  28. transaction inquires about the file
  29. identified by
  30. .IR fid .
  31. The reply will contain a
  32. machine-independent
  33. .I directory
  34. .IR entry ,
  35. .IR stat ,
  36. laid out as follows:
  37. .TF \fIqid.path[8]
  38. .PD
  39. .TP
  40. .I size\f1[2]\fP
  41. total byte count of the following data
  42. .TP
  43. .I type\f1[2]\fP
  44. for kernel use
  45. .TP
  46. .I dev\f1[4]\fP
  47. for kernel use
  48. .TP
  49. .I qid.type\f1[1]\fP
  50. the type of the file (directory, etc.), represented as a bit vector
  51. corresponding to the high 8 bits of the file's mode word.
  52. .TP
  53. .I qid.vers\f1[4]\fP
  54. version number for given path
  55. .TP
  56. .I qid.path\f1[8]\fP
  57. the file server's unique identification for the file
  58. .TP
  59. .I mode\f1[4]\fP
  60. permissions and flags
  61. .TP
  62. .I atime\f1[4]\fP
  63. last access time
  64. .TP
  65. .I mtime\f1[4]\fP
  66. last modification time
  67. .TP
  68. .I length\f1[8]\fP
  69. length of file in bytes
  70. .TP
  71. .I name\f1[ s ]\fP
  72. file name; must be
  73. .B /
  74. if the file is the root directory of the server
  75. .TP
  76. .I uid\f1[ s ]\fP
  77. owner name
  78. .TP
  79. .I gid\f1[ s ]\fP
  80. group name
  81. .TP
  82. .I muid\f1[ s ]\fP
  83. name of the user who last modified the file
  84. .PD
  85. .PP
  86. Integers in this encoding are in little-endian order (least
  87. significant byte first).
  88. The
  89. .I convM2D
  90. and
  91. .I convD2M
  92. routines (see
  93. .IR fcall (2))
  94. convert between directory entries and a C structure called a
  95. .BR Dir .
  96. .PP
  97. The
  98. .I mode
  99. contains permission bits as described in
  100. .IR intro (5)
  101. and the following:
  102. .B 0x80000000
  103. .RB ( DMDIR ,
  104. this file is a directory),
  105. .B 0x40000000
  106. .RB ( DMAPPEND ,
  107. append only),
  108. .B 0x20000000
  109. .RB ( DMEXCL ,
  110. exclusive use),
  111. .B 0x04000000
  112. .RB ( DMTMP ,
  113. temporary);
  114. these are echoed in
  115. .BR Qid.type .
  116. Writes to append-only files always place their data at the
  117. end of the file; the
  118. .I offset
  119. in the
  120. .B write
  121. message is ignored, as is the
  122. .B OTRUNC
  123. bit in an open.
  124. Exclusive use files may be open for I/O by only one fid at a time
  125. across all clients of the server. If a second open is attempted,
  126. it draws an error. Servers may implement a timeout on the lock
  127. on an exclusive use file: if the fid holding the file open has
  128. been unused for an extended period (of order at least minutes),
  129. it is reasonable to break the lock and deny the initial fid
  130. further I/O.
  131. Temporary files are not included in nightly archives
  132. (see
  133. .IR fossil (4)).
  134. .PP
  135. The two time fields are measured in seconds since the epoch
  136. (Jan 1 00:00 1970 GMT).
  137. The
  138. .I mtime
  139. field reflects the time of the last change of content (except when later changed by
  140. .BR wstat ).
  141. For a plain file,
  142. .I mtime
  143. is the time of the most recent
  144. .BR create ,
  145. .B open
  146. with truncation,
  147. or
  148. .BR write ;
  149. for a directory it is the time of the most recent
  150. .BR remove ,
  151. .BR create ,
  152. or
  153. .B wstat
  154. of a file in the directory.
  155. Similarly, the
  156. .I atime
  157. field records the last
  158. .B read
  159. of the contents;
  160. also it is set whenever
  161. .I mtime
  162. is set.
  163. In addition, for a directory, it is set by
  164. an
  165. .BR attach ,
  166. .BR walk ,
  167. or
  168. .BR create ,
  169. all whether successful or not.
  170. .PP
  171. The
  172. .I muid
  173. field names the user whose actions most recently changed the
  174. .I mtime
  175. of the file.
  176. .PP
  177. The
  178. .I length
  179. records the number of bytes in the file.
  180. Directories and most files representing devices have a conventional
  181. length of 0.
  182. .PP
  183. The
  184. .B stat
  185. request requires no special permissions.
  186. .PP
  187. The
  188. .B wstat
  189. request can change some of the file status information.
  190. The
  191. .I name
  192. can be changed by anyone with write permission in the parent directory;
  193. it is an error to change the name to that of an existing file.
  194. The
  195. .I length
  196. can be changed (affecting the actual length of the file) by anyone with
  197. write permission on the file.
  198. It is an error to attempt to set the length of a directory to a non-zero value,
  199. and servers may decide to reject length changes for other reasons.
  200. The
  201. .I mode
  202. and
  203. .I mtime
  204. can be changed by the owner of the file or the group leader of the file's current
  205. group.
  206. The directory bit cannot be changed by a
  207. .BR wstat ;
  208. the other defined permission and mode bits can.
  209. The
  210. .I gid
  211. can be changed: by the owner if also a member of the new group; or
  212. by the group leader of the file's current group
  213. if also leader of the new group
  214. (see
  215. .IR intro (5)
  216. for more information about permissions and
  217. .IR users (6)
  218. for users and groups).
  219. None of the other data can be altered by a
  220. .B wstat
  221. and attempts to change them will trigger an error.
  222. In particular,
  223. it is illegal to attempt to change the owner of a file.
  224. (These conditions may be
  225. relaxed when establishing the initial state of a file server; see
  226. .IR fsconfig (8).)
  227. .PP
  228. Either all the changes in
  229. .B wstat
  230. request happen, or none of them does: if the request succeeds,
  231. all changes were made; if it fails, none were.
  232. .PP
  233. A
  234. .B wstat
  235. request can avoid modifying some properties of the file
  236. by providing explicit ``don't touch'' values in the
  237. .B stat
  238. data that is sent: zero-length strings for text values and
  239. the maximum unsigned value of appropriate size
  240. for integral values.
  241. As a special case, if
  242. .I all
  243. the elements of the directory entry in a
  244. .B Twstat
  245. message are ``don't touch'' values, the server may interpret it
  246. as a request to guarantee that the contents of the associated
  247. file are committed to stable storage before the
  248. .B Rwstat
  249. message is returned.
  250. (Consider the message to mean, ``make the state of the file
  251. exactly what it claims to be.'')
  252. .PP
  253. A
  254. .I read
  255. of a directory yields an integral number of directory entries in
  256. the machine independent encoding given above
  257. (see
  258. .IR read (5)).
  259. .PP
  260. Note that since the
  261. .B stat
  262. information is sent as a 9P variable-length datum, it is limited to a maximum of
  263. 65535 bytes.
  264. .SH ENTRY POINTS
  265. .B Stat
  266. messages are generated by
  267. .I fstat
  268. and
  269. .IR stat .
  270. .PP
  271. .B Wstat
  272. messages are generated by
  273. .I fwstat
  274. and
  275. .IR wstat .
  276. .SH BUGS
  277. To make the contents of a directory, such as returned by
  278. .IR read (5),
  279. easy to parse, each
  280. directory entry begins with a size field.
  281. For consistency, the entries in
  282. .B Twstat
  283. and
  284. .B Rstat
  285. messages also contain
  286. their size, which means the size appears twice.
  287. For example, the
  288. .B Rstat
  289. message is formatted as
  290. .RI ``(4+1+2+2+ n )[4]
  291. .B Rstat
  292. .IR tag [2]
  293. .IR n [2]
  294. .RI ( n -2)[2]
  295. .IR type [2]
  296. .IR dev [4]...,''
  297. where
  298. .I n
  299. is the value returned by
  300. .BR convD2M .