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