Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The core stuff
This is an internal module. It is exposed to allow fine-tuning and workarounds but its API is not stable.
Synopsis
- data EntryType
- entryTypeToFileMode :: EntryType -> FileMode
- fileModeToEntryType :: FileMode -> EntryType
- data SyncType
- data AccessMode
- data SetxattrFlag
- access :: FilePath -> AccessMode -> IO ()
- accessErrno :: FilePath -> AccessMode -> IO Errno
- data FuseOperations fh dh = FuseOperations {
- fuseGetattr :: Maybe (FilePath -> Maybe fh -> IO (Either Errno FileStat))
- fuseReadlink :: Maybe (FilePath -> IO (Either Errno FilePath))
- fuseMknod :: Maybe (FilePath -> FileMode -> DeviceID -> IO Errno)
- fuseMkdir :: Maybe (FilePath -> FileMode -> IO Errno)
- fuseUnlink :: Maybe (FilePath -> IO Errno)
- fuseRmdir :: Maybe (FilePath -> IO Errno)
- fuseSymlink :: Maybe (FilePath -> FilePath -> IO Errno)
- fuseRename :: Maybe (FilePath -> FilePath -> IO Errno)
- fuseLink :: Maybe (FilePath -> FilePath -> IO Errno)
- fuseChmod :: Maybe (FilePath -> Maybe fh -> FileMode -> IO Errno)
- fuseChown :: Maybe (FilePath -> Maybe fh -> UserID -> GroupID -> IO Errno)
- fuseTruncate :: Maybe (FilePath -> Maybe fh -> FileOffset -> IO Errno)
- fuseOpen :: Maybe (FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh))
- fuseRead :: Maybe (FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno ByteString))
- fuseWrite :: Maybe (FilePath -> fh -> ByteString -> FileOffset -> IO (Either Errno CInt))
- fuseStatfs :: Maybe (String -> IO (Either Errno FileSystemStats))
- fuseFlush :: Maybe (FilePath -> fh -> IO Errno)
- fuseRelease :: Maybe (FilePath -> fh -> IO ())
- fuseFsync :: Maybe (FilePath -> fh -> SyncType -> IO Errno)
- fuseSetxattr :: Maybe (FilePath -> String -> ByteString -> SetxattrFlag -> IO Errno)
- fuseGetxattr :: Maybe (FilePath -> String -> IO (Either Errno ByteString))
- fuseListxattr :: Maybe (FilePath -> IO (Either Errno [String]))
- fuseRemovexattr :: Maybe (FilePath -> String -> IO Errno)
- fuseOpendir :: Maybe (FilePath -> IO (Either Errno dh))
- fuseReaddir :: Maybe (FilePath -> dh -> IO (Either Errno [(String, Maybe FileStat)]))
- fuseReleasedir :: Maybe (FilePath -> dh -> IO Errno)
- fuseFsyncdir :: Maybe (FilePath -> dh -> SyncType -> IO Errno)
- fuseInit :: Maybe (FuseConfig -> IO FuseConfig)
- fuseDestroy :: Maybe (IO ())
- fuseAccess :: Maybe (FilePath -> AccessMode -> IO Errno)
- fuseCreate :: Maybe (FilePath -> OpenMode -> FileMode -> OpenFileFlags -> IO (Either Errno fh))
- fuseUtimens :: Maybe (FilePath -> Maybe fh -> TimeSpec -> TimeSpec -> IO Errno)
- fuseFallocate :: Maybe (FilePath -> fh -> CInt -> FileOffset -> FileOffset -> IO Errno)
- fuseCopyFileRange :: Maybe (FilePath -> fh -> FileOffset -> FilePath -> fh -> FileOffset -> ByteCount -> CInt -> IO (Either Errno CSsize))
- fuseLseek :: Maybe (FilePath -> fh -> FileOffset -> SeekMode -> IO (Either Errno FileOffset))
- defaultFuseOperations :: FuseOperations fh dh
- mergeLFuseOperations :: FuseOperations fh dh -> FuseOperations fh dh -> FuseOperations fh dh
- resCFuseOperations :: forall fh dh e. Exception e => FuseOperations fh dh -> ExceptionHandler e -> ResourceT IO (Ptr FuseOperations)
- resFuseArgs :: String -> [String] -> ResourceT IO (Ptr FuseArgs)
- fuseParseCommandLine :: Ptr FuseArgs -> IO (Either ExitCode FuseMainArgs)
- fuseParseCommandLineOrExit :: Ptr FuseArgs -> IO FuseMainArgs
- fuseDaemonize :: ResourceT IO a -> ResourceT IO b
- withSignalHandlers :: IO () -> IO a -> IO a
- type FuseMainArgs = (Bool, String, CInt)
- fuseMainReal :: Ptr StructFuse -> FuseMainArgs -> ResourceT IO a
- fuseRun :: Exception e => String -> [String] -> FuseOperations fh dh -> ExceptionHandler e -> IO a
- fuseMain :: Exception e => FuseOperations fh dh -> ExceptionHandler e -> IO ()
- type ExceptionHandler e = e -> IO Errno
- defaultExceptionHandler :: ExceptionHandler SomeException
- getFH :: Ptr FuseFileInfo -> IO (Maybe fh)
- getFHJust :: Ptr FuseFileInfo -> IO fh
- newFH :: Ptr FuseFileInfo -> fh -> IO ()
- delFH :: Ptr FuseFileInfo -> IO ()
- peekFuseFillDir :: FunPtr FuseFillDir -> FuseFillDir
Documentation
The Unix type of a node in the filesystem.
Unknown | Unknown entry type |
NamedPipe | |
CharacterSpecial | |
Directory | |
BlockSpecial | |
RegularFile | |
SymbolicLink | |
Socket |
data AccessMode Source #
The query type of access
. Passed to fuseAccess
.
FileOK | File existence ( |
PermOK Bool Bool Bool | Reading, writing and executing permissions ( |
Instances
Show AccessMode Source # | |
Defined in System.LibFuse3.Internal | |
Eq AccessMode Source # | |
Defined in System.LibFuse3.Internal (==) :: AccessMode -> AccessMode -> Bool Source # (/=) :: AccessMode -> AccessMode -> Bool Source # |
data SetxattrFlag Source #
Passed to fuseSetxattr
.
SetxattrDefault | Create a new attribute if it does not exist, or replace the value if it already exists ( |
SetxattrCreate | Perform a pure create, which fails if the named attribute exists already ( |
SetxattrReplace | Perform a pure replace operation, which fails if the named attribute does not already exist ( |
Instances
Show SetxattrFlag Source # | |
Defined in System.LibFuse3.Internal | |
Eq SetxattrFlag Source # | |
Defined in System.LibFuse3.Internal (==) :: SetxattrFlag -> SetxattrFlag -> Bool Source # (/=) :: SetxattrFlag -> SetxattrFlag -> Bool Source # |
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 #
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
.
FuseOperations | |
|
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 typeStablePtr fh
orStablePtr dh
, depending on operations. It is created withnewFH
, accessed withgetFH
and released withdelFH
. - Every methods handle Haskell exception with the supplied error handler. Any exceptions
not catched by it are catched, logged and returns
eIO
. This means thatexitSuccess
does not work insideFuseOperations
. - 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
itself or its FuseFileInfo
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
.