Module fuse

Types

Option*[T] = object 
  case kind: OptionKind
  of kSome: v: T
  of kNone: nil
  
Buf* = ref object 
  data: seq[char]
  size*: int
  pos*: int
fuse_kstatfs* = object 
  blocks*: int64
  bfree*: int64
  bavail*: int64
  files*: int64
  ffree*: int64
  bsize*: int32
  namelen*: int32
  frsize*: int32
  padding: int32
  spare: array[6, int32]
fuse_file_lock* = object 
  start*: int64
  theEnd*: int64
  theType*: int32
  pid*: int32
fuse_open_out* = object 
  fh*: int64
  open_flags*: int32
  padding: int32
fuse_write_out* = object 
  size*: int32
  padding: int32
fuse_getxattr_out* = object 
  size*: int32
  padding: int32
request of in-kernel buffer size (byte)
fuse_bmap_out* = object 
  theBlock*: int64
fuse_in_header* = object 
  len*: int32
  opcode*: int32
  unique*: int64
  nodeid*: int64
  uid*: int32
  gid*: int32
  pid*: int32
  padding: int32
Timespec* = object 
  sec*: int64
  nsec*: int32
FileAttr* = ref object 
  ino*: int64
  size*: int64
  blocks*: int64
  atime*: Timespec
  mtime*: Timespec
  ctime*: Timespec
  crtime*: Timespec
  mode*: int32
  nlink*: int32
  uid*: int32
  gid*: int32
  rdev*: int32
  flags*: int32
number of hard links. TNlink?
TEntryOut* = ref object 
  generation*: int64
  entry_timeout*: Timespec    ## Validity timeout for the name.
  attr_timeout*: Timespec     ## Validity timeout for the attributes.
  attr*: FileAttr
(ino, generation) should be unique for the filesystem's lifetime.
Readdir* = ref object 
  raw: Raw
  data: Buf
Request* = ref object 
  header*: fuse_in_header
  data: Buf
FuseFs* = ref object of RootObj
  
Base class for FUSE filesystem User needs to implement a subclass These methods corrospond to fuse_lowlevel_ops in libfuse. Reasonable default implementations are provided here to get a mountable filesystem that does nothing.

Lets

FUSE_KERNEL_VERSION* = 7'i32
FUSE_KERNEL_MINOR_VERSION* = 8'i32
FUSE_ROOT_ID* = 1
FOPEN_DIRECT_IO* = 1 shl 0
FOPEN_KEEP_CACHE* = 1 shl 1
FOPEN_PURGE_ATTR* = 1 shl 30
FOPEN_PURGE_UBC* = 1 shl 31
FUSE_ASYNC_READ* = 1 shl 0
FUSE_POSIX_LOCKS* = 1 shl 1
FUSE_CASE_INSENSITIVE* = 1 shl 29
FUSE_VOL_RENAME* = 1 shl 30
FUSE_XTIMES* = 1 shl 31

Procs

proc `$`*[T](o: Option[T]): string
proc isSome*[T](o: Option[T]): bool
proc isNone*[T](o: Option[T]): bool
proc unwrap*[T](o: Option[T]): T
proc mkBuf*(size: int): Buf
Make a buf object of size bytes
proc extend*(self: Buf; size: int)
proc asPtr*(self: Buf; at: int): pointer
proc asPtr*(self: Buf): pointer
Get the current pos as the pointer
proc asBuf*(self: Buf): Buf
Get the [pos,] buffer like slicing
proc asTIOVec*(self: Buf): TIOVec
proc mkTIOVecT*[T](o: var T): TIOVec
proc mkTIOVecS*(s: var string): TIOVec
proc write*(self: Buf; p: pointer; size: int)
proc write*[T](self: Buf; obj: T)
proc nullTerminated*(s: string): string
Returns null terminated string of s The length is incremented e.g. mybuf.writeS("hoge".nullTerminated)
proc writeS*(self: Buf; s: string)
Write string s (Only the contents. Exclude null terminator)
proc parseS*(self: Buf): string
Parse a null-terminated string in the buffer
proc read*[T](self: Buf): T
Read a value of type T from the buffer
proc pop*[T](self: Buf): T
Read and advance the position
proc tryAdd*(self: Readdir; ino: int64; off: int64; st_mode: int32; name: string): bool
Try to add the entry If the buffer is too small for the entry then it returns false
proc ok*(self: Readdir)
Ack by the current buffer contents If nothing is in the buffer it notifies the end of the stream.
proc ok*(self: GetXAttrData; data: TIOVec)
proc ok*(self: ListXAttrData; keys: openArray[string])
proc mount*(fs: FuseFs; mountpoint: string; options: openArray[string])
Mount the given filesystem fs to the given mountpoint mountpoint

Methods

method init*(self: FuseFs; req: Request): int
Initialize filesystem Called before any other filesystem method.
method destroy*(self: FuseFs; req: Request)
Clean up filesystem Called on filesystem exit.
method lookup*(self: FuseFs; req: Request; parent: int64; name: string; 
               reply: Lookup)
Look up a directory entry by name and get its attributes.
method forget*(self: FuseFs; req: Request; ino: int64; nlookup: int64)
Forget about an inode The nlookup parameter indicates the number of lookups previously performed on this inode. If the filesystem implements inode lifetimes, it is recommended that inodes acquire a single reference on each lookup, and lose nlookup references on each forget. The filesystem may ignore forget calls, if the inodes don't need to have a limited lifetime. On unmount it is not guaranteed, that all referenced inodes will receive a forget message.
method getattr*(self: FuseFs; req: Request; ino: int64; reply: GetAttr)
Get file attributes
method setattr*(self: FuseFs; req: Request; ino: int64; mode: Option[int32]; 
                uid: Option[int32]; gid: Option[int32]; size: Option[int64]; 
                atime: Option[Timespec]; mtime: Option[Timespec]; 
                fh: Option[int64]; crtime: Option[Timespec]; 
                chgtime: Option[Timespec]; bkuptime: Option[Timespec]; 
                flags: Option[int32]; reply: SetAttr)
Set file attributes
Read symbolic link
method mknod*(self: FuseFs; req: Request; parent: int64; name: string; 
              mode: int32; rdev: int32; reply: Mknod)
Create file node Create a regular file, character device, block device, fifo or socket node.
method mkdir*(self: FuseFs; req: Request; parent: int64; name: string; 
              mode: int32; reply: Mkdir)
Create a directory
Remove a file
method rmdir*(self: FuseFs; req: Request; parent: int64; name: string; 
              reply: Rmdir)
Remove a directory
Create a symboilc link (parent, name) which, when evaluated, will lead to link ~= ln -s link (parent, name)
method rename*(self: FuseFs; req: Request; parent: int64; name: string; 
               newdir: int64; newname: string; reply: Rename)
Rename a file (parent, name) to (newdir, newname)
Create a hard link (newparent, newname) to ino ~= ln ino (newparent, newname) Hard links aren't required for a working filesystem, and many successful filesystems don't support them.
method open*(self: FuseFs; req: Request; ino: int64; flags: int32; reply: Open)
Open a file Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and O_TRUNC) are available in flags. Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other file operations (read, write, flush, release, fsync). Filesystem may also implement stateless file I/O and not store anything in fh. There are also some flags (direct_io, keep_cache) which the filesystem may set, to change the way the file is opened. See fuse_file_info structure in <fuse_common.h> for more details.
method read*(self: FuseFs; req: Request; ino: int64; fh: int64; offset: int64; 
             size: int32; reply: Read)
Read data Read should send exactly the number of bytes requested except on EOF or error, otherwise the rest of the data will be substituted with zeroes. An exception to this is when the file has been opened in 'direct_io' mode, in which case the return value of the read system call will reflect the return value of this operation. fh will contain the value set by the open method, or will be undefined if the open method didn't set any value.
method write*(self: FuseFs; req: Request; ino: int64; fh: int64; offset: int64; 
              data: Buf; flags: int32; reply: Write)
Write data Write should return exactly the number of bytes requested except on error. An exception to this is when the file has been opened in 'direct_io' mode, in which case the return value of the write system call will reflect the return value of this operation. fh will contain the value set by the open method, or will be undefined if the open method didn't set any value.
method flush*(self: FuseFs; req: Request; ino: int64; fh: int64; 
              lock_owner: int64; reply: Flush)
Flush method This is called on each close() of the opened file. Since file descriptors can be duplicated (dup, dup2, fork), for one open call there may be many flush calls. Filesystems shouldn't assume that flush will always be called after some writes, or that if will be called at all. fh will contain the value set by the open method, or will be undefined if the open method didn't set any value. NOTE: the name of the method is misleading, since (unlike fsync) the filesystem is not forced to flush pending writes. One reason to flush data, is if the filesystem wants to return write errors. If the filesystem supports file locking operations (setlk, getlk) it should remove all locks belonging to 'lock_owner'.
method release*(self: FuseFs; req: Request; ino: int64; fh: int64; flags: int32; 
                lock_owner: int64; flush: bool; reply: Release)
Release an open file Release is called when there are no more references to an open file: all file descriptors are closed and all memory mappings are unmapped. For every open call there will be exactly one release call. The filesystem may reply with an error, but error values are not returned to close() or munmap() which triggered the release. fh will contain the value set by the open method, or will be undefined if the open method didn't set any value. flags will contain the same flags as for open.
method fsync*(self: FuseFs; req: Request; ino: int64; fh: int64; datasync: bool; 
              reply: Fsync)
Synchronize file contents If the datasync parameter is non-zero, then only the user data should be flushed, not the meta data.
method opendir*(self: FuseFs; req: Request; ino: int64; flags: int32; 
                reply: Opendir)
Open a directory Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other directory stream operations (readdir, releasedir, fsyncdir). Filesystem may also implement stateless directory I/O and not store anything in fh, though that makes it impossible to implement standard conforming directory stream operations in case the contents of the directory can change between opendir and releasedir.
method readdir*(self: FuseFs; req: Request; ino: int64; fh: int64; 
                offset: int64; reply: Readdir)
Read directory Send a buffer filled using buffer.fill(), with size not exceeding the requested size. Send an empty buffer on end of stream. fh will contain the value set by the opendir method, or will be undefined if the opendir method didn't set any value.
method releasedir*(self: FuseFs; req: Request; fh: int64; flags: int32; 
                   reply: Releasedir)
Release an open directory For every opendir call there will be exactly one releasedir call. fh will contain the value set by the opendir method, or will be undefined if the opendir method didn't set any value.
method fsyncdir*(self: FuseFs; req: Request; ino: int64; fh: int64; 
                 datasync: bool; reply: Fsyncdir)
Synchronize directory contents If the datasync parameter is set, then only the directory contents should be flushed, not the meta data. fh will contain the value set by the opendir method, or will be undefined if the opendir method didn't set any value.
method statfs*(self: FuseFs; req: Request; ino: int64; reply: Statfs)
Get file system statistics
method setxattr*(self: FuseFs; req: Request; ino: int64; key: string; 
                 value: Buf; flags: int32; position: int32; reply: SetXAttr)
Set an extended attribute
method getxattr*(self: FuseFs; req: Request; ino: int64; key: string; 
                 reply: GetXAttr)
Get an extended attribute
method listxattr*(self: FuseFs; req: Request; ino: int64; reply: ListXAttr)
List extended attribute names
method removexattr*(self: FuseFs; req: Request; ino: int64; name: string; 
                    reply: RemoveXAttr)
Remove an extended attribute
method access*(self: FuseFs; req: Request; ino: int64; mask: int32; 
               reply: Access)
Check file access permissions This will be called for the access() system call. If the 'default_permissions' mount option is given, this method is not called. This method is not called under Linux kernel versions 2.4.x
method create*(self: FuseFs; req: Request; parent: int64; name: string; 
               mode: int32; flags: int32; reply: Create)
Create and open a file If the file does not exist, first create it with the specified mode, and then open it. Open flags (with the exception of O_NOCTTY) are available in flags. Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other file operations (read, write, flush, release, fsync). There are also some flags (direct_io, keep_cache) which the filesystem may set, to change the way the file is opened. See fuse_file_info structure in <fuse_common.h> for more details. If this method is not implemented or under Linux kernel versions earlier than 2.6.15, the mknod() and open() methods will be called instead.
method getlk*(self: FuseFs; req: Request; ino: int64; fh: int64; 
              lock_owner: int64; start: int64; theEnd: int64; theType: int64; 
              pid: int32; reply: Getlk)
Test for a POSIX file lock
method setlk*(self: FuseFs; req: Request; ino: int64; fh: int64; 
              lock_owner: int64; start: int64; theEnd: int64; theType: int64; 
              pid: int32; sleep: bool; reply: Setlk)
Acquire, modify or release a POSIX file lock For POSIX threads (NPTL) there's a 1-1 relation between pid and owner, but otherwise this is not always the case. For checking lock ownership, 'fi->owner' must be used. The l_pid field in 'struct flock' should only be used to fill in this field in getlk(). Note: if the locking methods are not implemented, the kernel will still allow file locking to work locally. Hence these are only interesting for network filesystems and similar.
method bmap*(self: FuseFs; req: Request; ino: int64; blocksize: int32; 
             idx: int64; reply: Bmap)
Map block index within file to block index within device Note: This makes sense only for block device backed filesystems mounted with the 'blkdev' option