libfuse3-0.2.0.1: A Haskell binding for libfuse-3.x
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.LibFuse3.Internal

Description

The core stuff

This is an internal module. It is exposed to allow fine-tuning and workarounds but its API is not stable.

Synopsis

Documentation

data EntryType Source #

The Unix type of a node in the filesystem.

Instances

Instances details
Show EntryType Source # 
Instance details

Defined in System.LibFuse3.Internal

Eq EntryType Source # 
Instance details

Defined in System.LibFuse3.Internal

entryTypeToFileMode :: EntryType -> FileMode Source #

Converts an EntryType into the corresponding POSIX FileMode.

data SyncType Source #

Passed to fuseFsync and fuseFsyncdir.

Constructors

FullSync

Synchronize both file content and metadata.

DataSync

Synchronize only the file content.

Instances

Instances details
Show SyncType Source # 
Instance details

Defined in System.LibFuse3.Internal

Eq SyncType Source # 
Instance details

Defined in System.LibFuse3.Internal

data AccessMode Source #

The query type of access. Passed to fuseAccess.

Constructors

FileOK

File existence (F_OK)

PermOK Bool Bool Bool

Reading, writing and executing permissions (R_OK, W_OK and X_OK, resp.)

Instances

Instances details
Show AccessMode Source # 
Instance details

Defined in System.LibFuse3.Internal

Eq AccessMode Source # 
Instance details

Defined in System.LibFuse3.Internal

data SetxattrFlag Source #

Passed to fuseSetxattr.

Constructors

SetxattrDefault

Create a new attribute if it does not exist, or replace the value if it already exists (0)

SetxattrCreate

Perform a pure create, which fails if the named attribute exists already (XATTR_CREATE)

SetxattrReplace

Perform a pure replace operation, which fails if the named attribute does not already exist (XATTR_REPLACE)

access :: FilePath -> AccessMode -> IO () Source #

Tests if access permissions to the file is granted or the file exists.

Calls access. Compared to fileAccess and fileExist, this function doesn't translate the errno and just returns () to indicate success, or throws an error to indicate failure.

accessErrno :: FilePath -> AccessMode -> IO Errno Source #

Same as access but returns the Errno instead of throwing an exception.

Returns eOK on success.

data FuseOperations fh dh Source #

The file system operations.

All operations are optional. Each field is named against struct fuse_operations in fuse.h.

fh is the file handle type returned by fuseOpen, and subsequently passed to all other file operations.

dh is the directory handle type returned by fuseOpendir, and subsequently passed to fuseReaddir and fuseReleasedir.

Constructors

FuseOperations 

Fields

defaultFuseOperations :: FuseOperations fh dh Source #

An empty set of operations whose fields are Nothing.

mergeLFuseOperations :: FuseOperations fh dh -> FuseOperations fh dh -> FuseOperations fh dh Source #

Merges two FuseOperations in a left-biased manner.

resCFuseOperations :: forall fh dh e. Exception e => FuseOperations fh dh -> ExceptionHandler e -> ResourceT IO (Ptr FuseOperations) Source #

Allocates a fuse_operations struct and pokes FuseOperations into it.

Each field of FuseOperations is converted into a C function pointer and is assigned to a corresponding field of struct fuse_operations.

The created FuseOperations has the following invariants:

  • The content of fuse_file_info.fh is a Haskell value of type StablePtr fh or StablePtr dh, depending on operations. It is created with newFH, accessed with getFH and released with delFH.
  • Every methods handle Haskell exception with the supplied error handler. Any exceptions not catched by it are catched, logged and returns eIO. This means that exitSuccess does not work inside FuseOperations.
  • NULL filepaths (passed from libfuse if nullpathOk is set) are translated to empty strings.

resFuseArgs :: String -> [String] -> ResourceT IO (Ptr FuseArgs) Source #

Allocates a fuse_args struct to hold commandline arguments.

fuseParseCommandLine :: Ptr FuseArgs -> IO (Either ExitCode FuseMainArgs) Source #

Calls fuse_parse_cmdline to parse the part of the commandline arguments that we care about.

fuse_parse_cmdline will modify the FuseArgs struct passed in to remove those arguments; the FuseArgs struct containing remaining arguments must be passed to fuse_mount/fuse_new.

The multithreaded runtime will be used regardless of the threading flag! See the comment in fuse_session_exit for why.

fuseParseCommandLineOrExit :: Ptr FuseArgs -> IO FuseMainArgs Source #

Parses the commandline arguments and exit if the args are bad or certain informational flag(s) are specified. See fuseParseCommandLine.

fuseDaemonize :: ResourceT IO a -> ResourceT IO b Source #

Haskell version of fuse_daemonize.

During the fork, transfers all of the resources in ResourceT (and its cleanup actions) to the forked process.

Mimics daemon()'s use of _exit() instead of exit(); we depend on this in fuseMainReal, because otherwise we'll unmount the filesystem when the foreground process exits.

withSignalHandlers :: IO () -> IO a -> IO a Source #

withSignalHandlers handler io installs signal handlers while io is executed.

type FuseMainArgs = (Bool, String, CInt) Source #

The parts of fuse_parse_cmdline we are interested in. Passed to fuseMainReal.

(foreground, mountpoint, clone_fd)

So far, we don't interpret the value of clone_fd at all so its type is CInt.

fuseMainReal :: Ptr StructFuse -> FuseMainArgs -> ResourceT IO a Source #

Mounts the filesystem, forks (if requested), and then starts fuse.

fuseRun :: Exception e => String -> [String] -> FuseOperations fh dh -> ExceptionHandler e -> IO a Source #

Parses the commandline arguments and runs fuse.

fuseMain :: Exception e => FuseOperations fh dh -> ExceptionHandler e -> IO () Source #

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.

type ExceptionHandler e = e -> IO Errno Source #

An exception handler which converts Haskell exceptions from FuseOperations methods to Errno.

defaultExceptionHandler :: ExceptionHandler SomeException Source #

Catches any exception, logs it to stderr, and returns eIO.

Suitable as a default exception handler.

NOTE 1 This differs from the one in the HFuse package which returns eFAULT.

NOTE 2 If the filesystem is daemonized (as default), the exceptions will not be logged because stderr is redirected to /dev/null.

getFH :: Ptr FuseFileInfo -> IO (Maybe fh) Source #

Gets a file handle from FuseFileInfo which is embedded with newFH.

If either the Ptr FuseFileInfo itself or its fh field is NULL, returns Nothing.

getFHJust :: Ptr FuseFileInfo -> IO fh Source #

Gets a file handle from FuseFileInfo.

getFHJust = fmap fromJust . getFH

This means you must make sure that getFH returns Just or you'll get a Haskell exception. However, it's deliberately made lazy so that calling getFHJust itself won't throw but trying to use the returned value will.

This function is implemented this way in order to take care of rare(?) cases in which fuseRead/fuseReaddir is implemented but not fuseOpen/fuseOpendir resp. In such a case, newFH would not be called but only getFH would be. Without some protection, we would be dereferencing a non-initialized StablePtr, which is undefined behavior. Throwing a Haskell exception in a pure code is much better than UB. See the comment in the source of getFH if you are interested in more explanation.

newFH :: Ptr FuseFileInfo -> fh -> IO () Source #

Embeds a file handle into FuseFileInfo. It should be freed with delFH when no longer required.

delFH :: Ptr FuseFileInfo -> IO () Source #

Frees a file handle in FuseFileInfo which is embedded with newFH.

peekFuseFillDir :: FunPtr FuseFillDir -> FuseFillDir Source #

Materializes the callback of readdir to marshal fuseReaddir.