-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | HFuse is a binding for the Linux FUSE library.
--   
--   Bindings for the FUSE library, compatible with OSXFUSE.
@package HFuse
@version 0.2.4.1

-- | A binding for the FUSE (Filesystem in USErspace) library
--   (http://fuse.sourceforge.net/), which allows filesystems to be
--   implemented as userspace processes.
--   
--   The binding tries to follow as much as possible current Haskell POSIX
--   interface in System.Posix.Files and
--   System.Posix.Directory.
--   
--   FUSE uses POSIX threads, so any Haskell application using this library
--   must be linked against a threaded runtime system (eg. using the
--   threaded GHC option).
module System.Fuse

-- | This record, given to fuseMain, binds each required file system
--   operations.
--   
--   Each field is named against Posix names. Matching Linux system
--   calls are also given as a reference.
--   
--   fh is the file handle type returned by fuseOpen and
--   subsequently passed to all other file operations.
data FuseOperations fh
FuseOperations :: (FilePath -> IO (Either Errno FileStat)) -> (FilePath -> IO (Either Errno FilePath)) -> (FilePath -> EntryType -> FileMode -> DeviceID -> IO Errno) -> (FilePath -> FileMode -> IO Errno) -> (FilePath -> IO Errno) -> (FilePath -> IO Errno) -> (FilePath -> FilePath -> IO Errno) -> (FilePath -> FilePath -> IO Errno) -> (FilePath -> FilePath -> IO Errno) -> (FilePath -> FileMode -> IO Errno) -> (FilePath -> UserID -> GroupID -> IO Errno) -> (FilePath -> FileOffset -> IO Errno) -> (FilePath -> EpochTime -> EpochTime -> IO Errno) -> (FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)) -> (FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno ByteString)) -> (FilePath -> fh -> ByteString -> FileOffset -> IO (Either Errno ByteCount)) -> (String -> IO (Either Errno FileSystemStats)) -> (FilePath -> fh -> IO Errno) -> (FilePath -> fh -> IO ()) -> (FilePath -> SyncType -> IO Errno) -> (FilePath -> IO Errno) -> (FilePath -> IO (Either Errno [(FilePath, FileStat)])) -> (FilePath -> IO Errno) -> (FilePath -> SyncType -> IO Errno) -> (FilePath -> Int -> IO Errno) -> IO () -> IO () -> FuseOperations fh

-- | Implements getSymbolicLinkStatus operation (POSIX
--   lstat(2)).
fuseGetFileStat :: FuseOperations fh -> FilePath -> IO (Either Errno FileStat)

-- | Implements readSymbolicLink operation (POSIX
--   readlink(2)). The returned FilePath might be truncated
--   depending on caller buffer size.
fuseReadSymbolicLink :: FuseOperations fh -> FilePath -> IO (Either Errno FilePath)

-- | Implements createDevice (POSIX mknod(2)). This
--   function will also be called for regular file creation.
fuseCreateDevice :: FuseOperations fh -> FilePath -> EntryType -> FileMode -> DeviceID -> IO Errno

-- | Implements createDirectory (POSIX mkdir(2)).
fuseCreateDirectory :: FuseOperations fh -> FilePath -> FileMode -> IO Errno

-- | Implements removeLink (POSIX unlink(2)).
fuseRemoveLink :: FuseOperations fh -> FilePath -> IO Errno

-- | Implements removeDirectory (POSIX rmdir(2)).
fuseRemoveDirectory :: FuseOperations fh -> FilePath -> IO Errno

-- | Implements createSymbolicLink (POSIX symlink(2)).
fuseCreateSymbolicLink :: FuseOperations fh -> FilePath -> FilePath -> IO Errno

-- | Implements rename (POSIX rename(2)).
fuseRename :: FuseOperations fh -> FilePath -> FilePath -> IO Errno

-- | Implements createLink (POSIX link(2)).
fuseCreateLink :: FuseOperations fh -> FilePath -> FilePath -> IO Errno

-- | Implements setFileMode (POSIX chmod(2)).
fuseSetFileMode :: FuseOperations fh -> FilePath -> FileMode -> IO Errno

-- | Implements setOwnerAndGroup (POSIX chown(2)).
fuseSetOwnerAndGroup :: FuseOperations fh -> FilePath -> UserID -> GroupID -> IO Errno

-- | Implements setFileSize (POSIX truncate(2)).
fuseSetFileSize :: FuseOperations fh -> FilePath -> FileOffset -> IO Errno

-- | Implements setFileTimes (POSIX utime(2)).
fuseSetFileTimes :: FuseOperations fh -> FilePath -> EpochTime -> EpochTime -> IO Errno

-- | Implements openFd (POSIX open(2)). On success, returns
--   Right of a filehandle-like value that will be passed to future
--   file operations; on failure, returns Left of the appropriate
--   Errno.
--   
--   No creation, exclusive access or truncating flags will be passed. This
--   should check that the operation is permitted for the given flags.
fuseOpen :: FuseOperations fh -> FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)

-- | Implements Unix98 pread(2). It differs from fdRead by
--   the explicit FileOffset argument. The fuse.h
--   documentation stipulates that this "should return exactly the number
--   of bytes requested except on EOF or error, otherwise the rest of the
--   data will be substituted with zeroes."
fuseRead :: FuseOperations fh -> FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno ByteString)

-- | Implements Unix98 pwrite(2). It differs from fdWrite
--   by the explicit FileOffset argument.
fuseWrite :: FuseOperations fh -> FilePath -> fh -> ByteString -> FileOffset -> IO (Either Errno ByteCount)

-- | Implements statfs(2).
fuseGetFileSystemStats :: FuseOperations fh -> String -> IO (Either Errno FileSystemStats)

-- | Called when close(2) has been called on an open file. Note:
--   this does not mean that the file is released. This function may be
--   called more than once for each open(2). The return value is
--   passed on to the close(2) system call.
fuseFlush :: FuseOperations fh -> FilePath -> fh -> IO Errno

-- | Called when an open file has all file descriptors closed and all
--   memory mappings unmapped. For every open call there will be
--   exactly one release call with the same flags. It is possible
--   to have a file opened more than once, in which case only the last
--   release will mean that no more reads or writes will happen on the
--   file.
fuseRelease :: FuseOperations fh -> FilePath -> fh -> IO ()

-- | Implements fsync(2).
fuseSynchronizeFile :: FuseOperations fh -> FilePath -> SyncType -> IO Errno

-- | Implements opendir(3). This method should check if the open
--   operation is permitted for this directory.
fuseOpenDirectory :: FuseOperations fh -> FilePath -> IO Errno

-- | Implements readdir(3). The entire contents of the directory
--   should be returned as a list of tuples (corresponding to the first
--   mode of operation documented in fuse.h).
fuseReadDirectory :: FuseOperations fh -> FilePath -> IO (Either Errno [(FilePath, FileStat)])

-- | Implements closedir(3).
fuseReleaseDirectory :: FuseOperations fh -> FilePath -> IO Errno

-- | Synchronize the directory's contents; analogous to
--   fuseSynchronizeFile.
fuseSynchronizeDirectory :: FuseOperations fh -> FilePath -> SyncType -> IO Errno

-- | 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 also not called under
--   Linux kernel versions 2.4.x
fuseAccess :: FuseOperations fh -> FilePath -> Int -> IO Errno

-- | Initializes the filesystem. This is called before all other
--   operations.
fuseInit :: FuseOperations fh -> IO ()

-- | Called on filesystem exit to allow cleanup.
fuseDestroy :: FuseOperations fh -> IO ()

-- | Empty / default versions of the FUSE operations.
defaultFuseOps :: FuseOperations fh

-- | Main function of FUSE. This is all that has to be called from the
--   main function. On top of the FuseOperations record
--   with filesystem implementation, you must give an exception handler
--   converting Haskell exceptions to Errno.
--   
--   This function does the following:
--   
--   
--   
- parses command line options (-d, -s and
--   -h) ;
--   
- passes all options after -- to the fusermount program
--   ;
--   
- mounts the filesystem by calling fusermount ;
--   
- installs signal handlers for keyboardSignal,
--   lostConnection, softwareTermination and
--   openEndedPipe ;
--   
- registers an exit handler to unmount the filesystem on program
--   exit ;
--   
- registers the operations ;
--   
- calls FUSE event loop.
--   
fuseMain :: Exception e => FuseOperations fh -> (e -> IO Errno) -> IO ()
fuseRun :: String -> [String] -> Exception e => FuseOperations fh -> (e -> IO Errno) -> IO ()

-- | Default exception handler. Print the exception on error output and
--   returns eFAULT.
defaultExceptionHandler :: SomeException -> IO Errno

-- | Used by fuseGetFileStat. Corresponds to struct stat
--   from stat.h; st_dev, st_ino and
--   st_blksize are omitted, since (from the libfuse
--   documentation): "the st_dev and st_blksize fields
--   are ignored. The st_ino field is ignored except if the
--   use_ino mount option is given."
--   
--   TODO: at some point the inode field will probably be needed.
data FileStat
FileStat :: EntryType -> FileMode -> LinkCount -> UserID -> GroupID -> DeviceID -> FileOffset -> Integer -> EpochTime -> EpochTime -> EpochTime -> FileStat
statEntryType :: FileStat -> EntryType
statFileMode :: FileStat -> FileMode
statLinkCount :: FileStat -> LinkCount
statFileOwner :: FileStat -> UserID
statFileGroup :: FileStat -> GroupID
statSpecialDeviceID :: FileStat -> DeviceID
statFileSize :: FileStat -> FileOffset
statBlocks :: FileStat -> Integer
statAccessTime :: FileStat -> EpochTime
statModificationTime :: FileStat -> EpochTime
statStatusChangeTime :: FileStat -> EpochTime

-- | The Unix type of a node in the filesystem.
data EntryType

-- | Unknown entry type
Unknown :: EntryType
NamedPipe :: EntryType
CharacterSpecial :: EntryType
Directory :: EntryType
BlockSpecial :: EntryType
RegularFile :: EntryType
SymbolicLink :: EntryType
Socket :: EntryType

-- | Type used by the fuseGetFileSystemStats.
data FileSystemStats
FileSystemStats :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> FileSystemStats

-- | Optimal transfer block size. FUSE default is 512.
fsStatBlockSize :: FileSystemStats -> Integer

-- | Total data blocks in file system.
fsStatBlockCount :: FileSystemStats -> Integer

-- | Free blocks in file system.
fsStatBlocksFree :: FileSystemStats -> Integer

-- | Free blocks available to non-superusers.
fsStatBlocksAvailable :: FileSystemStats -> Integer

-- | Total file nodes in file system.
fsStatFileCount :: FileSystemStats -> Integer

-- | Free file nodes in file system.
fsStatFilesFree :: FileSystemStats -> Integer

-- | Maximum length of filenames. FUSE default is 255.
fsStatMaxNameLength :: FileSystemStats -> Integer

-- | Used by fuseSynchronizeFile and
--   fuseSynchronizeDirectory.
data SyncType

-- | Synchronize all in-core parts of a file to disk: file content and
--   metadata.
FullSync :: SyncType

-- | Synchronize only the file content.
DataSync :: SyncType

-- | Returns the context of the program doing the current FUSE call.
getFuseContext :: IO FuseContext

-- | Returned by getFuseContext.
data FuseContext

-- | Converts an EntryType into the corresponding POSIX
--   FileMode.
entryTypeToFileMode :: EntryType -> FileMode
fileModeToEntryType :: FileMode -> EntryType
data OpenMode :: *
ReadOnly :: OpenMode
WriteOnly :: OpenMode
ReadWrite :: OpenMode

-- | Correspond to some of the int flags from C's fcntl.h.
data OpenFileFlags :: *
OpenFileFlags :: Bool -> Bool -> Bool -> Bool -> Bool -> OpenFileFlags

-- | O_APPEND
append :: OpenFileFlags -> Bool

-- | O_EXCL
exclusive :: OpenFileFlags -> Bool

-- | O_NOCTTY
noctty :: OpenFileFlags -> Bool

-- | O_NONBLOCK
nonBlock :: OpenFileFlags -> Bool

-- | O_TRUNC
trunc :: OpenFileFlags -> Bool

-- | Combines two file modes into one that only contains modes that appear
--   in both.
intersectFileModes :: FileMode -> FileMode -> FileMode

-- | Combines the two file modes into one that contains modes that appear
--   in either.
unionFileModes :: FileMode -> FileMode -> FileMode
instance Show EntryType
instance Show FileStat
instance Eq SyncType
instance Enum SyncType
