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