btrfs-0.1.0.1: Bindings to the btrfs API

Stabilityprovisional
Portabilitynon-portable (requires Linux)
Safe HaskellNone
LanguageHaskell2010

System.Linux.Btrfs.ByteString

Contents

Description

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.

Synopsis

Basic types

File cloning

cloneFd :: Fd -> Fd -> IO () Source

clone Source

Arguments

:: RawFilePath

The source file.

-> RawFilePath

The destination file.

-> IO () 

Clone an entire file to an existing file.

Note: calls the BTRFS_IOC_CLONE ioctl.

cloneNew :: RawFilePath -> RawFilePath -> 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.

cloneRange Source

Arguments

:: RawFilePath

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.

-> RawFilePath

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.

Constructors

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.

cloneRangeIfSame Source

Arguments

:: RawFilePath

The source file.

-> FileSize

The offset within the source file.

-> FileSize

The length of the range.

-> [(RawFilePath, 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 :: RawFilePath -> IO () Source

Create an (initially) empty new subvolume.

Note: calls the BTRFS_IOC_SUBVOL_CREATE ioctl.

destroySubvol :: RawFilePath -> IO () Source

Destroy (delete) a subvolume.

Note: calls the BTRFS_IOC_SNAP_DESTROY ioctl.

snapshot Source

Arguments

:: RawFilePath

The source subvolume.

-> RawFilePath

The destination subvolume (must not exist).

-> Bool

Make the subvolume read-only?

-> IO () 

Create a snapshot of an existing subvolume.

Note: calls the BTRFS_IOC_SNAP_CREATE_V2 ioctl.

getSubvolReadOnly :: RawFilePath -> IO Bool Source

Is the subvolume read-only?

Note: calls the BTRFS_IOC_SUBVOL_GETFLAGS ioctl.

setSubvolReadOnly :: RawFilePath -> Bool -> IO () Source

Make a subvolume read-only (or read-write).

Note: calls the BTRFS_IOC_SUBVOL_GETFLAGS and BTRFS_IOC_SUBVOL_SETFLAGS ioctls.

getSubvol :: RawFilePath -> IO SubvolId Source

Find the id of the subvolume where the given file resides. This is merely a wrapper around lookupInode provided for convenience.

lookupSubvol Source

Arguments

:: RawFilePath

The mount point of the volume (or any file in that volume).

-> SubvolId

The id of the subvolume.

-> IO (SubvolId, InodeNum, RawFilePath) 

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.

resolveSubvol Source

Arguments

:: RawFilePath

The mount point of the volume (or any file in that volume).

-> SubvolId

The id of the subvolume.

-> IO RawFilePath 

Given the id of a subvolume, find its path relative to the root of the volume. This function calls lookupSubvol recursively.

rootSubvol :: SubvolId Source

The id the root subvolume.

listSubvols :: RawFilePath -> IO [(SubvolId, SubvolId, InodeNum, RawFilePath)] 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 :: RawFilePath -> IO [(SubvolId, SubvolId, RawFilePath)] 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.

childSubvols Source

Arguments

:: RawFilePath

The mount point of the volume (or any file in that volume).

-> SubvolId

The id of the subvolume.

-> IO [(SubvolId, InodeNum, RawFilePath)] 

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.

childSubvolPaths Source

Arguments

:: RawFilePath

The mount point of the volume (or any file in that volume).

-> SubvolId

The id of the subvolume.

-> IO [(SubvolId, RawFilePath)] 

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.

Constructors

SubvolInfo 

Fields

siGeneration :: Word64

The generation when the subvolume was last modified.

siLastSnapshot :: Maybe Word64

The generation when the most recent snapshot of this subvolume was taken.

siParSnapGen :: Maybe Word64

The generation of the snapshot parent at the time when the snapshot was taken. Defined if only if this is a snapshot.

siReadOnly :: Bool

Is this a read-only subvolume?

siUuid :: Maybe UUID

The UUID of the subvolume.

siPUuid :: Maybe UUID

The UUID of the snapshot parent.

siReceivedUuid :: Maybe UUID

The UUID of the source subvolume that this subvolume was received from. This is always defined for received subvolumes.

siCTransId :: Maybe Word64

The generation when an inode was last modified.

siOTransId :: Maybe Word64

The generation when the subvolume was created.

siSTransId :: Maybe Word64

The generation of the source subvolume that this subvolume was received from. This is always defined for received subvolumes.

siRTransId :: Maybe Word64

The generation when the subvolume was received. This is always defined for received subvolumes.

siCTime :: Maybe UTCTime

The time when an inode was last modified.

siOTime :: Maybe UTCTime

The time when the subvolume was created.

siSTime :: Maybe UTCTime

The timestamp that corresponds to siSTransId.

siRTime :: Maybe UTCTime

The time when the subvolume was received. This is always defined for received subvolumes.

getSubvolInfo Source

Arguments

:: RawFilePath

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.

getSubvolByUuid Source

Arguments

:: RawFilePath

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

Arguments

:: RawFilePath

The mount point of the volume (or any file in that volume).

-> UUID

The siReceivedUuid of the subvolume.

-> IO SubvolId 

Find the id of a subvolume, given its siReceivedUuid.

Requires Linux 3.12 or later.

Defragging

defragFd :: Fd -> IO () Source

defrag :: RawFilePath -> IO () Source

Defrag a single file.

Note: calls the BTRFS_IOC_DEFRAG ioctl.

Sync

syncFd :: Fd -> IO () Source

sync :: RawFilePath -> 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.

startSync :: RawFilePath -> IO () Source

Initiate a sync for the file system identified by the supplied path.

Note: calls the BTRFS_IOC_START_SYNC ioctl.

waitSync :: RawFilePath -> IO () Source

Wait until the sync operation completes.

Note: calls the BTRFS_IOC_WAIT_SYNC ioctl.

Inspect internal

resolveLogical Source

Arguments

:: RawFilePath

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.

resolveInode Source

Arguments

:: RawFilePath

The path to the subvolume (or any file in that subvolume).

-> InodeNum

The inode number.

-> IO ([RawFilePath], Int) 

Find the file path(s) given an inode number. Returns a list of file paths and an integer indicating the number of path 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.

lookupInode Source

Arguments

:: RawFilePath

The path to any file in the volume. The subvolume where this file resides is ignored unless no SubvolId is provided (see below).

-> SubvolId

The id of the subvolume. Can be 0. In that case, the subvolume of the FilePath is used (see above).

-> InodeNum

The inode number.

-> IO (SubvolId, RawFilePath) 

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

getFileNoCOW :: RawFilePath -> IO Bool Source

Determine whether the NOCOW flag is enabled for the specified file.

Note: calls the FS_IOC_GETFLAGS ioctl.

setFileNoCOW :: RawFilePath -> 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 ioctls.

Tree search

Low-level API for tree search using the BTRFS_IOC_TREE_SEARCH ioctl.

treeSearchFd :: Fd -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO () Source

treeSearch :: RawFilePath -> SearchKey -> Int -> (SearchHeader -> Ptr i -> IO ()) -> IO () Source

treeSearchListFd :: Fd -> SearchKey -> (SearchHeader -> Ptr i -> IO (Maybe a)) -> IO [a] Source