Stability | provisional |
---|---|
Portability | non-portable (requires Linux) |
Safe Haskell | None |
Language | Haskell2010 |
Most functions in this module come in two flavors: one that operates on
file descriptors and another one that operates on file paths. The former
can be distinguished by the Fd
suffix in their names.
- type FileSize = Word64
- type ObjectType = Word8
- type ObjectId = Word64
- type InodeNum = ObjectId
- type SubvolId = ObjectId
- data CompressionType
- cloneFd :: Fd -> Fd -> IO ()
- clone :: FilePath -> FilePath -> IO ()
- cloneNew :: FilePath -> FilePath -> IO ()
- cloneRangeFd :: Fd -> FileSize -> FileSize -> Fd -> FileSize -> IO ()
- cloneRange :: FilePath -> FileSize -> FileSize -> FilePath -> FileSize -> IO ()
- data CloneResult
- cloneRangeIfSameFd :: Fd -> FileSize -> FileSize -> [(Fd, FileSize)] -> IO [CloneResult]
- cloneRangeIfSame :: FilePath -> FileSize -> FileSize -> [(FilePath, FileSize)] -> IO [CloneResult]
- createSubvol :: FilePath -> IO ()
- destroySubvol :: FilePath -> IO ()
- snapshotFd :: Fd -> FilePath -> Bool -> IO ()
- snapshot :: FilePath -> FilePath -> Bool -> IO ()
- getSubvolReadOnlyFd :: Fd -> IO Bool
- getSubvolReadOnly :: FilePath -> IO Bool
- setSubvolReadOnlyFd :: Fd -> Bool -> IO ()
- setSubvolReadOnly :: FilePath -> Bool -> IO ()
- getSubvolFd :: Fd -> IO SubvolId
- getSubvol :: FilePath -> IO SubvolId
- lookupSubvolFd :: Fd -> SubvolId -> IO (SubvolId, InodeNum, FilePath)
- lookupSubvol :: FilePath -> SubvolId -> IO (SubvolId, InodeNum, FilePath)
- resolveSubvolFd :: Fd -> SubvolId -> IO FilePath
- resolveSubvol :: FilePath -> SubvolId -> IO FilePath
- rootSubvol :: SubvolId
- listSubvolsFd :: Fd -> IO [(SubvolId, SubvolId, InodeNum, FilePath)]
- listSubvols :: FilePath -> IO [(SubvolId, SubvolId, InodeNum, FilePath)]
- listSubvolPathsFd :: Fd -> IO [(SubvolId, SubvolId, FilePath)]
- listSubvolPaths :: FilePath -> IO [(SubvolId, SubvolId, FilePath)]
- childSubvolsFd :: Fd -> SubvolId -> IO [(SubvolId, InodeNum, FilePath)]
- childSubvols :: FilePath -> SubvolId -> IO [(SubvolId, InodeNum, FilePath)]
- childSubvolPathsFd :: Fd -> SubvolId -> IO [(SubvolId, FilePath)]
- childSubvolPaths :: FilePath -> SubvolId -> IO [(SubvolId, FilePath)]
- data SubvolInfo = SubvolInfo {
- siGeneration :: Word64
- siLastSnapshot :: Maybe Word64
- siParSnapGen :: Maybe Word64
- siReadOnly :: Bool
- siUuid :: Maybe UUID
- siPUuid :: Maybe UUID
- siReceivedUuid :: Maybe UUID
- siCTransId :: Maybe Word64
- siOTransId :: Maybe Word64
- siSTransId :: Maybe Word64
- siRTransId :: Maybe Word64
- siCTime :: Maybe UTCTime
- siOTime :: Maybe UTCTime
- siSTime :: Maybe UTCTime
- siRTime :: Maybe UTCTime
- getSubvolInfoFd :: Fd -> SubvolId -> IO SubvolInfo
- getSubvolInfo :: FilePath -> SubvolId -> IO SubvolInfo
- getSubvolByUuidFd :: Fd -> UUID -> IO SubvolId
- getSubvolByUuid :: FilePath -> UUID -> IO SubvolId
- getSubvolByReceivedUuidFd :: Fd -> UUID -> IO SubvolId
- getSubvolByReceivedUuid :: FilePath -> UUID -> IO SubvolId
- defragFd :: Fd -> IO ()
- defrag :: FilePath -> IO ()
- data DefragRangeArgs = DefragRangeArgs {}
- defaultDefragRangeArgs :: DefragRangeArgs
- defragRangeFd :: Fd -> DefragRangeArgs -> IO ()
- defragRange :: FilePath -> DefragRangeArgs -> IO ()
- syncFd :: Fd -> IO ()
- sync :: FilePath -> IO ()
- startSyncFd :: Fd -> IO ()
- startSync :: FilePath -> IO ()
- waitSyncFd :: Fd -> IO ()
- waitSync :: FilePath -> IO ()
- resolveLogicalFd :: Fd -> FileSize -> IO ([(InodeNum, FileSize, SubvolId)], Int)
- resolveLogical :: FilePath -> FileSize -> IO ([(InodeNum, FileSize, SubvolId)], Int)
- resolveInodeFd :: Fd -> InodeNum -> IO ([FilePath], Int)
- resolveInode :: FilePath -> InodeNum -> IO ([FilePath], Int)
- lookupInodeFd :: Fd -> SubvolId -> InodeNum -> IO (SubvolId, FilePath)
- lookupInode :: FilePath -> SubvolId -> InodeNum -> IO (SubvolId, FilePath)
- getFileNoCOWFd :: Fd -> IO Bool
- getFileNoCOW :: FilePath -> IO Bool
- setFileNoCOWFd :: Fd -> Bool -> IO ()
- setFileNoCOW :: FilePath -> Bool -> IO ()
- data SearchKey = SearchKey {}
- defaultSearchKey :: SearchKey
- data SearchHeader = SearchHeader {
- shTransId :: Word64
- shObjectId :: ObjectId
- shOffset :: Word64
- shType :: ObjectType
- shLen :: Word32
- treeSearchFd :: Fd -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO ()
- treeSearch :: FilePath -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO ()
- treeSearchListFd :: Fd -> SearchKey -> (SearchHeader -> Ptr i -> IO (Maybe a)) -> IO [a]
- treeSearchList :: FilePath -> SearchKey -> (SearchHeader -> Ptr i -> IO (Maybe a)) -> IO [a]
- findFirstItemFd :: Fd -> SearchKey -> (SearchHeader -> Ptr i -> IO a) -> IO a
- findFirstItem :: FilePath -> SearchKey -> (SearchHeader -> Ptr i -> IO a) -> IO a
Basic types
type ObjectType = Word8 Source
data CompressionType Source
File cloning
Clone an entire file to an existing file.
Note: calls the BTRFS_IOC_CLONE
ioctl
.
cloneNew :: FilePath -> FilePath -> IO () Source
Like clone
except that it will create or truncate the destination
file if necessary. This is similar to cp --reflink=always
.
Note: calls the BTRFS_IOC_CLONE
ioctl
.
:: FilePath | The source file. |
-> FileSize | The offset within the source file. |
-> FileSize | The length of the range. A length of 0 selects the range from the source offset to the end. |
-> FilePath | The destination file. |
-> FileSize | The offset within the destination file. |
-> IO () |
Clones a range of bytes from a file to another file. All ranges must be block-aligned.
Note: calls the BTRFS_IOC_CLONE_RANGE
ioctl
.
data CloneResult Source
The result of a cloneRangeIfSame
operation.
CRError IOError | Cloning failed because of an error. |
CRDataDiffers | No cloning was performed because the contents of the source and the destination file differ. |
CRSuccess FileSize | Cloning succeeded, the returned integer indicates the number of bytes that were deduped. |
cloneRangeIfSameFd :: Fd -> FileSize -> FileSize -> [(Fd, FileSize)] -> IO [CloneResult] Source
:: FilePath | The source file. |
-> FileSize | The offset within the source file. |
-> FileSize | The length of the range. |
-> [(FilePath, FileSize)] | The destination files and corresponding offsets. |
-> IO [CloneResult] |
Similar to cloneRange
except that it performs the cloning only if
the data ranges contain identical data.
Additionally, it accepts multiple destination files. The same thing can
be accomplished with cloneRange
in conjunction with file locking but
this function uses in-kernel locking to guarantee that the deduplicated
data is identical at the time of the operation. On the other hand, this
function will not clone arbitrarily large ranges; the kernel has an upper
limit for the length and if cloning bigger ranges is desired then it
has to be called multiple times. Note that cloning may succeed for some
of the destination files and fail for others. Because of that, this
function returns a list of outcomes, one for each destination file, and
no exceptions will be raised for the failed files.
Note: calls the BTRFS_IOC_FILE_EXTENT_SAME
ioctl
.
Requires Linux 3.12 or later.
Subvolumes and snapshots
createSubvol :: FilePath -> IO () Source
Create an (initially) empty new subvolume.
Note: calls the BTRFS_IOC_SUBVOL_CREATE
ioctl
.
destroySubvol :: FilePath -> IO () Source
Destroy (delete) a subvolume.
Note: calls the BTRFS_IOC_SNAP_DESTROY
ioctl
.
:: FilePath | The source subvolume. |
-> FilePath | The destination subvolume (must not exist). |
-> Bool | Create a read-only snapshot? |
-> IO () |
Create a snapshot of an existing subvolume.
Note: calls the BTRFS_IOC_SNAP_CREATE_V2
ioctl
.
getSubvolReadOnlyFd :: Fd -> IO Bool Source
getSubvolReadOnly :: FilePath -> IO Bool Source
Is the subvolume read-only?
Note: calls the BTRFS_IOC_SUBVOL_GETFLAGS
ioctl
.
setSubvolReadOnlyFd :: Fd -> Bool -> IO () Source
setSubvolReadOnly :: FilePath -> Bool -> IO () Source
Make a subvolume read-only (or read-write).
Note: calls the BTRFS_IOC_SUBVOL_GETFLAGS
and
BTRFS_IOC_SUBVOL_SETFLAGS
ioctl
s.
getSubvolFd :: Fd -> IO SubvolId Source
getSubvol :: FilePath -> IO SubvolId Source
Find the id of the subvolume where the given file resides. This is
merely a wrapper around lookupInode
provided for convenience.
:: FilePath | The mount point of the volume (or any file in that volume). |
-> SubvolId | The id of the subvolume. |
-> IO (SubvolId, InodeNum, FilePath) |
Given the id of a subvolume, find the id of the parent subvolume, the
inode number of the directory containing it, and its name. This is
a wrapper around treeSearch
.
:: FilePath | The mount point of the volume (or any file in that volume). |
-> SubvolId | The id of the subvolume. |
-> IO FilePath |
Given the id of a subvolume, find its path relative to the root of the
volume. This function calls lookupSubvol
recursively.
The id the root subvolume.
listSubvols :: FilePath -> IO [(SubvolId, SubvolId, InodeNum, FilePath)] Source
Find all subvolumes of the given volume. For each subvolume found, it
returns: its id, the id of its parent subvolume, the inode number of the
directory containing it, and its name. This is a wrapper around
treeSearch
.
listSubvolPaths :: FilePath -> IO [(SubvolId, SubvolId, FilePath)] Source
Find all subvolumes of the given volume. For each subvolume found, it
returns: its id, the id of its parent subvolume, and its path relative
to the root of the volume. This is a wrapper around treeSearch
and
resolveSubvol
.
:: FilePath | The mount point of the volume (or any file in that volume). |
-> SubvolId | The id of the subvolume. |
-> IO [(SubvolId, InodeNum, FilePath)] |
Find all child subvolumes of the given subvolume. For each child,
returns its id, the inode number of the directory containing it, and its
name. This is a wrapper around treeSearch
.
:: FilePath | The mount point of the volume (or any file in that volume). |
-> SubvolId | The id of the subvolume. |
-> IO [(SubvolId, FilePath)] |
Find all child subvolumes of the given subvolume. For each child,
returns its id and its path relative to the root of the parent.
This is a wrapper around treeSearch
and lookupInode
.
data SubvolInfo Source
Information about a subvolume.
SubvolInfo | |
|
getSubvolInfoFd :: Fd -> SubvolId -> IO SubvolInfo Source
:: FilePath | The mount point of the volume (or any file in that volume). |
-> SubvolId | The id of the subvolume. |
-> IO SubvolInfo |
Retrieve information about a subvolume.
:: FilePath | The mount point of the volume (or any file in that volume). |
-> UUID | The UUID of the subvolume. |
-> IO SubvolId |
Find the id of a subvolume, given its UUID.
Requires Linux 3.12 or later.
getSubvolByReceivedUuid Source
:: FilePath | The mount point of the volume (or any file in that volume). |
-> UUID | The |
-> IO SubvolId |
Find the id of a subvolume, given its siReceivedUuid
.
Requires Linux 3.12 or later.
Defragging
data DefragRangeArgs Source
Argument to the defragRange
operation.
DefragRangeArgs | |
|
defaultDefragRangeArgs :: DefragRangeArgs Source
Defaults for defragRange
. Selects the entire file, no compression,
and no flushing.
defragRangeFd :: Fd -> DefragRangeArgs -> IO () Source
defragRange :: FilePath -> DefragRangeArgs -> IO () Source
Defrag a range within a single file.
Note: calls the BTRFS_IOC_DEFRAG_RANGE
ioctl
.
Sync
sync :: FilePath -> IO () Source
Sync the file system identified by the supplied path.
The FilePath
can refer to any file in the file system.
Note: calls the BTRFS_IOC_SYNC
ioctl
.
startSyncFd :: Fd -> IO () Source
startSync :: FilePath -> IO () Source
Initiate a sync for the file system identified by the supplied path.
Note: calls the BTRFS_IOC_START_SYNC
ioctl
.
waitSyncFd :: Fd -> IO () Source
waitSync :: FilePath -> IO () Source
Wait until the sync operation completes.
Note: calls the BTRFS_IOC_WAIT_SYNC
ioctl
.
Inspect internal
:: FilePath | The mount point of the volume (or any file in that volume). |
-> FileSize | The physical byte offset in the underlying block device. |
-> IO ([(InodeNum, FileSize, SubvolId)], Int) |
Given a physical offset, look for any inodes that this byte belongs to. For each inode, it returns the inode number, the logical offset (i.e. the offset within the inode), and the subvolume id. If a large number of inodes is found, then not all of them will be returned by this function. This is due to a current limitation in the kernel. The integer returned along with list of inodes indicates the number of inodes found but not included in the list.
Note: calls the BTRFS_IOC_LOGICAL_INO
ioctl
.
:: FilePath | The path to the subvolume (or any file in that subvolume). |
-> InodeNum | The inode number. |
-> IO ([FilePath], Int) |
Find the file path(s) given an inode number. Returns a list of file paths and an integer indicating the number of paths found but not included in the resulting list. This is because of a limitation in the kernel (it will not return an arbitrarily large list). The paths returned are relative to the root of the subvolume.
Note: calls the BTRFS_IOC_INO_PATHS
ioctl
.
:: FilePath | The path to any file in the volume. The subvolume where
this file resides is ignored unless no |
-> SubvolId | The id of the subvolume. Can be 0. In that case, the
subvolume of the |
-> InodeNum | The inode number. |
-> IO (SubvolId, FilePath) |
Find the path of a file given its inode number and the id of the
subvolume. If multiple files share the same inode number, only one of
them is returned. The id of the subvolume is also returned. This is
useful when 0 is given for the SubvolId
argument (also see
getSubvol
for this case).
Note: calls the BTRFS_IOC_INO_LOOKUP
ioctl
.
Miscellaneous
getFileNoCOWFd :: Fd -> IO Bool Source
getFileNoCOW :: FilePath -> IO Bool Source
Determine whether the NOCOW flag is enabled for the specified file.
Note: calls the FS_IOC_GETFLAGS
ioctl
.
setFileNoCOWFd :: Fd -> Bool -> IO () Source
setFileNoCOW :: FilePath -> Bool -> IO () Source
Set or clear the NOCOW flag for the specified file. If the file is not empty, this has no effect and no error will be reported.
Note: calls the FS_IOC_GETFLAGS
and FS_IOC_GETFLAGS
ioctl
s.
Tree search
Low-level API for tree search using the BTRFS_IOC_TREE_SEARCH
ioctl
.
SearchKey | |
|
data SearchHeader Source
SearchHeader | |
|
treeSearchFd :: Fd -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO () Source
treeSearch :: FilePath -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO () Source
treeSearchListFd :: Fd -> SearchKey -> (SearchHeader -> Ptr i -> IO (Maybe a)) -> IO [a] Source
treeSearchList :: FilePath -> SearchKey -> (SearchHeader -> Ptr i -> IO (Maybe a)) -> IO [a] Source
findFirstItemFd :: Fd -> SearchKey -> (SearchHeader -> Ptr i -> IO a) -> IO a Source
findFirstItem :: FilePath -> SearchKey -> (SearchHeader -> Ptr i -> IO a) -> IO a Source