fuse_kernel.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // See the file LICENSE for copyright and licensing information.
  2. // Derived from FUSE's fuse_kernel.h, which carries this notice:
  3. /*
  4. This file defines the kernel interface of FUSE
  5. Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
  6. This -- and only this -- header file may also be distributed under
  7. the terms of the BSD Licence as follows:
  8. Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. 1. Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  21. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. SUCH DAMAGE.
  28. */
  29. package fuse
  30. import (
  31. "fmt"
  32. "syscall"
  33. "unsafe"
  34. )
  35. // The FUSE version implemented by the package.
  36. const (
  37. protoVersionMinMajor = 7
  38. protoVersionMinMinor = 8
  39. protoVersionMaxMajor = 7
  40. protoVersionMaxMinor = 12
  41. )
  42. const (
  43. rootID = 1
  44. )
  45. type kstatfs struct {
  46. Blocks uint64
  47. Bfree uint64
  48. Bavail uint64
  49. Files uint64
  50. Ffree uint64
  51. Bsize uint32
  52. Namelen uint32
  53. Frsize uint32
  54. _ uint32
  55. Spare [6]uint32
  56. }
  57. type fileLock struct {
  58. Start uint64
  59. End uint64
  60. Type uint32
  61. Pid uint32
  62. }
  63. // GetattrFlags are bit flags that can be seen in GetattrRequest.
  64. type GetattrFlags uint32
  65. const (
  66. // Indicates the handle is valid.
  67. GetattrFh GetattrFlags = 1 << 0
  68. )
  69. var getattrFlagsNames = []flagName{
  70. {uint32(GetattrFh), "GetattrFh"},
  71. }
  72. func (fl GetattrFlags) String() string {
  73. return flagString(uint32(fl), getattrFlagsNames)
  74. }
  75. // The SetattrValid are bit flags describing which fields in the SetattrRequest
  76. // are included in the change.
  77. type SetattrValid uint32
  78. const (
  79. SetattrMode SetattrValid = 1 << 0
  80. SetattrUid SetattrValid = 1 << 1
  81. SetattrGid SetattrValid = 1 << 2
  82. SetattrSize SetattrValid = 1 << 3
  83. SetattrAtime SetattrValid = 1 << 4
  84. SetattrMtime SetattrValid = 1 << 5
  85. SetattrHandle SetattrValid = 1 << 6
  86. // Linux only(?)
  87. SetattrAtimeNow SetattrValid = 1 << 7
  88. SetattrMtimeNow SetattrValid = 1 << 8
  89. SetattrLockOwner SetattrValid = 1 << 9 // http://www.mail-archive.com/git-commits-head@vger.kernel.org/msg27852.html
  90. // OS X only
  91. SetattrCrtime SetattrValid = 1 << 28
  92. SetattrChgtime SetattrValid = 1 << 29
  93. SetattrBkuptime SetattrValid = 1 << 30
  94. SetattrFlags SetattrValid = 1 << 31
  95. )
  96. func (fl SetattrValid) Mode() bool { return fl&SetattrMode != 0 }
  97. func (fl SetattrValid) Uid() bool { return fl&SetattrUid != 0 }
  98. func (fl SetattrValid) Gid() bool { return fl&SetattrGid != 0 }
  99. func (fl SetattrValid) Size() bool { return fl&SetattrSize != 0 }
  100. func (fl SetattrValid) Atime() bool { return fl&SetattrAtime != 0 }
  101. func (fl SetattrValid) Mtime() bool { return fl&SetattrMtime != 0 }
  102. func (fl SetattrValid) Handle() bool { return fl&SetattrHandle != 0 }
  103. func (fl SetattrValid) AtimeNow() bool { return fl&SetattrAtimeNow != 0 }
  104. func (fl SetattrValid) MtimeNow() bool { return fl&SetattrMtimeNow != 0 }
  105. func (fl SetattrValid) LockOwner() bool { return fl&SetattrLockOwner != 0 }
  106. func (fl SetattrValid) Crtime() bool { return fl&SetattrCrtime != 0 }
  107. func (fl SetattrValid) Chgtime() bool { return fl&SetattrChgtime != 0 }
  108. func (fl SetattrValid) Bkuptime() bool { return fl&SetattrBkuptime != 0 }
  109. func (fl SetattrValid) Flags() bool { return fl&SetattrFlags != 0 }
  110. func (fl SetattrValid) String() string {
  111. return flagString(uint32(fl), setattrValidNames)
  112. }
  113. var setattrValidNames = []flagName{
  114. {uint32(SetattrMode), "SetattrMode"},
  115. {uint32(SetattrUid), "SetattrUid"},
  116. {uint32(SetattrGid), "SetattrGid"},
  117. {uint32(SetattrSize), "SetattrSize"},
  118. {uint32(SetattrAtime), "SetattrAtime"},
  119. {uint32(SetattrMtime), "SetattrMtime"},
  120. {uint32(SetattrHandle), "SetattrHandle"},
  121. {uint32(SetattrAtimeNow), "SetattrAtimeNow"},
  122. {uint32(SetattrMtimeNow), "SetattrMtimeNow"},
  123. {uint32(SetattrLockOwner), "SetattrLockOwner"},
  124. {uint32(SetattrCrtime), "SetattrCrtime"},
  125. {uint32(SetattrChgtime), "SetattrChgtime"},
  126. {uint32(SetattrBkuptime), "SetattrBkuptime"},
  127. {uint32(SetattrFlags), "SetattrFlags"},
  128. }
  129. // Flags that can be seen in OpenRequest.Flags.
  130. const (
  131. // Access modes. These are not 1-bit flags, but alternatives where
  132. // only one can be chosen. See the IsReadOnly etc convenience
  133. // methods.
  134. OpenReadOnly OpenFlags = syscall.O_RDONLY
  135. OpenWriteOnly OpenFlags = syscall.O_WRONLY
  136. OpenReadWrite OpenFlags = syscall.O_RDWR
  137. // File was opened in append-only mode, all writes will go to end
  138. // of file. OS X does not provide this information.
  139. OpenAppend OpenFlags = syscall.O_APPEND
  140. OpenCreate OpenFlags = syscall.O_CREAT
  141. OpenDirectory OpenFlags = syscall.O_DIRECTORY
  142. OpenExclusive OpenFlags = syscall.O_EXCL
  143. OpenNonblock OpenFlags = syscall.O_NONBLOCK
  144. OpenSync OpenFlags = syscall.O_SYNC
  145. OpenTruncate OpenFlags = syscall.O_TRUNC
  146. )
  147. // OpenAccessModeMask is a bitmask that separates the access mode
  148. // from the other flags in OpenFlags.
  149. const OpenAccessModeMask OpenFlags = syscall.O_ACCMODE
  150. // OpenFlags are the O_FOO flags passed to open/create/etc calls. For
  151. // example, os.O_WRONLY | os.O_APPEND.
  152. type OpenFlags uint32
  153. func (fl OpenFlags) String() string {
  154. // O_RDONLY, O_RWONLY, O_RDWR are not flags
  155. s := accModeName(fl & OpenAccessModeMask)
  156. flags := uint32(fl &^ OpenAccessModeMask)
  157. if flags != 0 {
  158. s = s + "+" + flagString(flags, openFlagNames)
  159. }
  160. return s
  161. }
  162. // Return true if OpenReadOnly is set.
  163. func (fl OpenFlags) IsReadOnly() bool {
  164. return fl&OpenAccessModeMask == OpenReadOnly
  165. }
  166. // Return true if OpenWriteOnly is set.
  167. func (fl OpenFlags) IsWriteOnly() bool {
  168. return fl&OpenAccessModeMask == OpenWriteOnly
  169. }
  170. // Return true if OpenReadWrite is set.
  171. func (fl OpenFlags) IsReadWrite() bool {
  172. return fl&OpenAccessModeMask == OpenReadWrite
  173. }
  174. func accModeName(flags OpenFlags) string {
  175. switch flags {
  176. case OpenReadOnly:
  177. return "OpenReadOnly"
  178. case OpenWriteOnly:
  179. return "OpenWriteOnly"
  180. case OpenReadWrite:
  181. return "OpenReadWrite"
  182. default:
  183. return ""
  184. }
  185. }
  186. var openFlagNames = []flagName{
  187. {uint32(OpenAppend), "OpenAppend"},
  188. {uint32(OpenCreate), "OpenCreate"},
  189. {uint32(OpenDirectory), "OpenDirectory"},
  190. {uint32(OpenExclusive), "OpenExclusive"},
  191. {uint32(OpenNonblock), "OpenNonblock"},
  192. {uint32(OpenSync), "OpenSync"},
  193. {uint32(OpenTruncate), "OpenTruncate"},
  194. }
  195. // The OpenResponseFlags are returned in the OpenResponse.
  196. type OpenResponseFlags uint32
  197. const (
  198. OpenDirectIO OpenResponseFlags = 1 << 0 // bypass page cache for this open file
  199. OpenKeepCache OpenResponseFlags = 1 << 1 // don't invalidate the data cache on open
  200. OpenNonSeekable OpenResponseFlags = 1 << 2 // mark the file as non-seekable (not supported on OS X)
  201. OpenPurgeAttr OpenResponseFlags = 1 << 30 // OS X
  202. OpenPurgeUBC OpenResponseFlags = 1 << 31 // OS X
  203. )
  204. func (fl OpenResponseFlags) String() string {
  205. return flagString(uint32(fl), openResponseFlagNames)
  206. }
  207. var openResponseFlagNames = []flagName{
  208. {uint32(OpenDirectIO), "OpenDirectIO"},
  209. {uint32(OpenKeepCache), "OpenKeepCache"},
  210. {uint32(OpenNonSeekable), "OpenNonSeekable"},
  211. {uint32(OpenPurgeAttr), "OpenPurgeAttr"},
  212. {uint32(OpenPurgeUBC), "OpenPurgeUBC"},
  213. }
  214. // The InitFlags are used in the Init exchange.
  215. type InitFlags uint32
  216. const (
  217. InitAsyncRead InitFlags = 1 << 0
  218. InitPosixLocks InitFlags = 1 << 1
  219. InitFileOps InitFlags = 1 << 2
  220. InitAtomicTrunc InitFlags = 1 << 3
  221. InitExportSupport InitFlags = 1 << 4
  222. InitBigWrites InitFlags = 1 << 5
  223. // Do not mask file access modes with umask. Not supported on OS X.
  224. InitDontMask InitFlags = 1 << 6
  225. InitSpliceWrite InitFlags = 1 << 7
  226. InitSpliceMove InitFlags = 1 << 8
  227. InitSpliceRead InitFlags = 1 << 9
  228. InitFlockLocks InitFlags = 1 << 10
  229. InitHasIoctlDir InitFlags = 1 << 11
  230. InitAutoInvalData InitFlags = 1 << 12
  231. InitDoReaddirplus InitFlags = 1 << 13
  232. InitReaddirplusAuto InitFlags = 1 << 14
  233. InitAsyncDIO InitFlags = 1 << 15
  234. InitWritebackCache InitFlags = 1 << 16
  235. InitNoOpenSupport InitFlags = 1 << 17
  236. InitCaseSensitive InitFlags = 1 << 29 // OS X only
  237. InitVolRename InitFlags = 1 << 30 // OS X only
  238. InitXtimes InitFlags = 1 << 31 // OS X only
  239. )
  240. type flagName struct {
  241. bit uint32
  242. name string
  243. }
  244. var initFlagNames = []flagName{
  245. {uint32(InitAsyncRead), "InitAsyncRead"},
  246. {uint32(InitPosixLocks), "InitPosixLocks"},
  247. {uint32(InitFileOps), "InitFileOps"},
  248. {uint32(InitAtomicTrunc), "InitAtomicTrunc"},
  249. {uint32(InitExportSupport), "InitExportSupport"},
  250. {uint32(InitBigWrites), "InitBigWrites"},
  251. {uint32(InitDontMask), "InitDontMask"},
  252. {uint32(InitSpliceWrite), "InitSpliceWrite"},
  253. {uint32(InitSpliceMove), "InitSpliceMove"},
  254. {uint32(InitSpliceRead), "InitSpliceRead"},
  255. {uint32(InitFlockLocks), "InitFlockLocks"},
  256. {uint32(InitHasIoctlDir), "InitHasIoctlDir"},
  257. {uint32(InitAutoInvalData), "InitAutoInvalData"},
  258. {uint32(InitDoReaddirplus), "InitDoReaddirplus"},
  259. {uint32(InitReaddirplusAuto), "InitReaddirplusAuto"},
  260. {uint32(InitAsyncDIO), "InitAsyncDIO"},
  261. {uint32(InitWritebackCache), "InitWritebackCache"},
  262. {uint32(InitNoOpenSupport), "InitNoOpenSupport"},
  263. {uint32(InitCaseSensitive), "InitCaseSensitive"},
  264. {uint32(InitVolRename), "InitVolRename"},
  265. {uint32(InitXtimes), "InitXtimes"},
  266. }
  267. func (fl InitFlags) String() string {
  268. return flagString(uint32(fl), initFlagNames)
  269. }
  270. func flagString(f uint32, names []flagName) string {
  271. var s string
  272. if f == 0 {
  273. return "0"
  274. }
  275. for _, n := range names {
  276. if f&n.bit != 0 {
  277. s += "+" + n.name
  278. f &^= n.bit
  279. }
  280. }
  281. if f != 0 {
  282. s += fmt.Sprintf("%+#x", f)
  283. }
  284. return s[1:]
  285. }
  286. // The ReleaseFlags are used in the Release exchange.
  287. type ReleaseFlags uint32
  288. const (
  289. ReleaseFlush ReleaseFlags = 1 << 0
  290. )
  291. func (fl ReleaseFlags) String() string {
  292. return flagString(uint32(fl), releaseFlagNames)
  293. }
  294. var releaseFlagNames = []flagName{
  295. {uint32(ReleaseFlush), "ReleaseFlush"},
  296. }
  297. // Opcodes
  298. const (
  299. opLookup = 1
  300. opForget = 2 // no reply
  301. opGetattr = 3
  302. opSetattr = 4
  303. opReadlink = 5
  304. opSymlink = 6
  305. opMknod = 8
  306. opMkdir = 9
  307. opUnlink = 10
  308. opRmdir = 11
  309. opRename = 12
  310. opLink = 13
  311. opOpen = 14
  312. opRead = 15
  313. opWrite = 16
  314. opStatfs = 17
  315. opRelease = 18
  316. opFsync = 20
  317. opSetxattr = 21
  318. opGetxattr = 22
  319. opListxattr = 23
  320. opRemovexattr = 24
  321. opFlush = 25
  322. opInit = 26
  323. opOpendir = 27
  324. opReaddir = 28
  325. opReleasedir = 29
  326. opFsyncdir = 30
  327. opGetlk = 31
  328. opSetlk = 32
  329. opSetlkw = 33
  330. opAccess = 34
  331. opCreate = 35
  332. opInterrupt = 36
  333. opBmap = 37
  334. opDestroy = 38
  335. opIoctl = 39 // Linux?
  336. opPoll = 40 // Linux?
  337. // OS X
  338. opSetvolname = 61
  339. opGetxtimes = 62
  340. opExchange = 63
  341. )
  342. type entryOut struct {
  343. Nodeid uint64 // Inode ID
  344. Generation uint64 // Inode generation
  345. EntryValid uint64 // Cache timeout for the name
  346. AttrValid uint64 // Cache timeout for the attributes
  347. EntryValidNsec uint32
  348. AttrValidNsec uint32
  349. Attr attr
  350. }
  351. func entryOutSize(p Protocol) uintptr {
  352. switch {
  353. case p.LT(Protocol{7, 9}):
  354. return unsafe.Offsetof(entryOut{}.Attr) + unsafe.Offsetof(entryOut{}.Attr.Blksize)
  355. default:
  356. return unsafe.Sizeof(entryOut{})
  357. }
  358. }
  359. type forgetIn struct {
  360. Nlookup uint64
  361. }
  362. type getattrIn struct {
  363. GetattrFlags uint32
  364. _ uint32
  365. Fh uint64
  366. }
  367. type attrOut struct {
  368. AttrValid uint64 // Cache timeout for the attributes
  369. AttrValidNsec uint32
  370. _ uint32
  371. Attr attr
  372. }
  373. func attrOutSize(p Protocol) uintptr {
  374. switch {
  375. case p.LT(Protocol{7, 9}):
  376. return unsafe.Offsetof(attrOut{}.Attr) + unsafe.Offsetof(attrOut{}.Attr.Blksize)
  377. default:
  378. return unsafe.Sizeof(attrOut{})
  379. }
  380. }
  381. // OS X
  382. type getxtimesOut struct {
  383. Bkuptime uint64
  384. Crtime uint64
  385. BkuptimeNsec uint32
  386. CrtimeNsec uint32
  387. }
  388. type mknodIn struct {
  389. Mode uint32
  390. Rdev uint32
  391. Umask uint32
  392. _ uint32
  393. // "filename\x00" follows.
  394. }
  395. func mknodInSize(p Protocol) uintptr {
  396. switch {
  397. case p.LT(Protocol{7, 12}):
  398. return unsafe.Offsetof(mknodIn{}.Umask)
  399. default:
  400. return unsafe.Sizeof(mknodIn{})
  401. }
  402. }
  403. type mkdirIn struct {
  404. Mode uint32
  405. Umask uint32
  406. // filename follows
  407. }
  408. func mkdirInSize(p Protocol) uintptr {
  409. switch {
  410. case p.LT(Protocol{7, 12}):
  411. return unsafe.Offsetof(mkdirIn{}.Umask) + 4
  412. default:
  413. return unsafe.Sizeof(mkdirIn{})
  414. }
  415. }
  416. type renameIn struct {
  417. Newdir uint64
  418. // "oldname\x00newname\x00" follows
  419. }
  420. // OS X
  421. type exchangeIn struct {
  422. Olddir uint64
  423. Newdir uint64
  424. Options uint64
  425. // "oldname\x00newname\x00" follows
  426. }
  427. type linkIn struct {
  428. Oldnodeid uint64
  429. }
  430. type setattrInCommon struct {
  431. Valid uint32
  432. _ uint32
  433. Fh uint64
  434. Size uint64
  435. LockOwner uint64 // unused on OS X?
  436. Atime uint64
  437. Mtime uint64
  438. Unused2 uint64
  439. AtimeNsec uint32
  440. MtimeNsec uint32
  441. Unused3 uint32
  442. Mode uint32
  443. Unused4 uint32
  444. Uid uint32
  445. Gid uint32
  446. Unused5 uint32
  447. }
  448. type openIn struct {
  449. Flags uint32
  450. Unused uint32
  451. }
  452. type openOut struct {
  453. Fh uint64
  454. OpenFlags uint32
  455. _ uint32
  456. }
  457. type createIn struct {
  458. Flags uint32
  459. Mode uint32
  460. Umask uint32
  461. _ uint32
  462. }
  463. func createInSize(p Protocol) uintptr {
  464. switch {
  465. case p.LT(Protocol{7, 12}):
  466. return unsafe.Offsetof(createIn{}.Umask)
  467. default:
  468. return unsafe.Sizeof(createIn{})
  469. }
  470. }
  471. type releaseIn struct {
  472. Fh uint64
  473. Flags uint32
  474. ReleaseFlags uint32
  475. LockOwner uint32
  476. }
  477. type flushIn struct {
  478. Fh uint64
  479. FlushFlags uint32
  480. _ uint32
  481. LockOwner uint64
  482. }
  483. type readIn struct {
  484. Fh uint64
  485. Offset uint64
  486. Size uint32
  487. ReadFlags uint32
  488. LockOwner uint64
  489. Flags uint32
  490. _ uint32
  491. }
  492. func readInSize(p Protocol) uintptr {
  493. switch {
  494. case p.LT(Protocol{7, 9}):
  495. return unsafe.Offsetof(readIn{}.ReadFlags) + 4
  496. default:
  497. return unsafe.Sizeof(readIn{})
  498. }
  499. }
  500. // The ReadFlags are passed in ReadRequest.
  501. type ReadFlags uint32
  502. const (
  503. // LockOwner field is valid.
  504. ReadLockOwner ReadFlags = 1 << 1
  505. )
  506. var readFlagNames = []flagName{
  507. {uint32(ReadLockOwner), "ReadLockOwner"},
  508. }
  509. func (fl ReadFlags) String() string {
  510. return flagString(uint32(fl), readFlagNames)
  511. }
  512. type writeIn struct {
  513. Fh uint64
  514. Offset uint64
  515. Size uint32
  516. WriteFlags uint32
  517. LockOwner uint64
  518. Flags uint32
  519. _ uint32
  520. }
  521. func writeInSize(p Protocol) uintptr {
  522. switch {
  523. case p.LT(Protocol{7, 9}):
  524. return unsafe.Offsetof(writeIn{}.LockOwner)
  525. default:
  526. return unsafe.Sizeof(writeIn{})
  527. }
  528. }
  529. type writeOut struct {
  530. Size uint32
  531. _ uint32
  532. }
  533. // The WriteFlags are passed in WriteRequest.
  534. type WriteFlags uint32
  535. const (
  536. WriteCache WriteFlags = 1 << 0
  537. // LockOwner field is valid.
  538. WriteLockOwner WriteFlags = 1 << 1
  539. )
  540. var writeFlagNames = []flagName{
  541. {uint32(WriteCache), "WriteCache"},
  542. {uint32(WriteLockOwner), "WriteLockOwner"},
  543. }
  544. func (fl WriteFlags) String() string {
  545. return flagString(uint32(fl), writeFlagNames)
  546. }
  547. const compatStatfsSize = 48
  548. type statfsOut struct {
  549. St kstatfs
  550. }
  551. type fsyncIn struct {
  552. Fh uint64
  553. FsyncFlags uint32
  554. _ uint32
  555. }
  556. type setxattrInCommon struct {
  557. Size uint32
  558. Flags uint32
  559. }
  560. func (setxattrInCommon) position() uint32 {
  561. return 0
  562. }
  563. type getxattrInCommon struct {
  564. Size uint32
  565. _ uint32
  566. }
  567. func (getxattrInCommon) position() uint32 {
  568. return 0
  569. }
  570. type getxattrOut struct {
  571. Size uint32
  572. _ uint32
  573. }
  574. type lkIn struct {
  575. Fh uint64
  576. Owner uint64
  577. Lk fileLock
  578. LkFlags uint32
  579. _ uint32
  580. }
  581. func lkInSize(p Protocol) uintptr {
  582. switch {
  583. case p.LT(Protocol{7, 9}):
  584. return unsafe.Offsetof(lkIn{}.LkFlags)
  585. default:
  586. return unsafe.Sizeof(lkIn{})
  587. }
  588. }
  589. type lkOut struct {
  590. Lk fileLock
  591. }
  592. type accessIn struct {
  593. Mask uint32
  594. _ uint32
  595. }
  596. type initIn struct {
  597. Major uint32
  598. Minor uint32
  599. MaxReadahead uint32
  600. Flags uint32
  601. }
  602. const initInSize = int(unsafe.Sizeof(initIn{}))
  603. type initOut struct {
  604. Major uint32
  605. Minor uint32
  606. MaxReadahead uint32
  607. Flags uint32
  608. Unused uint32
  609. MaxWrite uint32
  610. }
  611. type interruptIn struct {
  612. Unique uint64
  613. }
  614. type bmapIn struct {
  615. Block uint64
  616. BlockSize uint32
  617. _ uint32
  618. }
  619. type bmapOut struct {
  620. Block uint64
  621. }
  622. type inHeader struct {
  623. Len uint32
  624. Opcode uint32
  625. Unique uint64
  626. Nodeid uint64
  627. Uid uint32
  628. Gid uint32
  629. Pid uint32
  630. _ uint32
  631. }
  632. const inHeaderSize = int(unsafe.Sizeof(inHeader{}))
  633. type outHeader struct {
  634. Len uint32
  635. Error int32
  636. Unique uint64
  637. }
  638. type dirent struct {
  639. Ino uint64
  640. Off uint64
  641. Namelen uint32
  642. Type uint32
  643. Name [0]byte
  644. }
  645. const direntSize = 8 + 8 + 4 + 4
  646. const (
  647. notifyCodePoll int32 = 1
  648. notifyCodeInvalInode int32 = 2
  649. notifyCodeInvalEntry int32 = 3
  650. )
  651. type notifyInvalInodeOut struct {
  652. Ino uint64
  653. Off int64
  654. Len int64
  655. }
  656. type notifyInvalEntryOut struct {
  657. Parent uint64
  658. Namelen uint32
  659. _ uint32
  660. }