btrfs-0.2.0.0: Bindings to the btrfs API

Stabilityprovisional
Portabilitynon-portable (requires Linux)
Safe HaskellNone
LanguageHaskell2010

System.Linux.Btrfs.ByteString

Contents

Description

Deprecated: This module is deprecated and will be removed in a future version of this library. Please leave a comment on https://github.com/redneb/hs-btrfs/issues/5 if you think that is should not be removed.

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/deduplication

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/FICLONE 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/FICLONE 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 (the block size can be obtained using getFSInfo and fsiCloneAlignment).

Note: calls the BTRFS_IOC_CLONE_RANGE/FICLONERANGE 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/FIDEDUPERANGE 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. The directory that corresponds to the subvolume is removed asynchronously. As a result, the subvolume may appear again after a crash. If this is not acceptable, call startSync followed by a waitSync, after the destroySubvol call.

Note: calls the BTRFS_IOC_SNAP_DESTROY ioctl.

snapshot Source #

Arguments

:: RawFilePath

The source subvolume.

-> RawFilePath

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.

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

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. This is a wrapper around treeSearch.

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. This is a wrapper around treeSearch.

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. This is a wrapper around treeSearch.

Requires Linux 3.12 or later.

getDefaultSubvol Source #

Arguments

:: RawFilePath

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

-> IO SubvolId 

Find the id of the default subvolume. This is a wrapper around treeSearch.

setDefaultSubvol Source #

Arguments

:: RawFilePath

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

-> SubvolId

The id of the new default subvolume.

-> IO () 

Set the default subvolume.

Note: calls the BTRFS_IOC_DEFAULT_SUBVOL ioctl.

Defrag

There is a limitation in the kernel whereby a defrag operation will be silently aborted when the calling process receives any signal. This does not play well with GHC's rts which in some cases uses signals as a way to preempt haskell threads. So in order to use defrag or defragRange, you must compile your program with GHC >=8.2 and the use the threaded runtime which does not use signals anymore. Alternatively, for older versions of GHC, you can use something like the withRTSSignalsBlocked function from here.

defragFd :: Fd -> IO () Source #

defrag :: RawFilePath -> IO () Source #

Defrag a single file.

Note: calls the BTRFS_IOC_DEFRAG ioctl.

data DefragRangeArgs Source #

Argument to the defragRange operation.

Constructors

DefragRangeArgs 

Fields

defaultDefragRangeArgs :: DefragRangeArgs Source #

Defaults for defragRange. Selects the entire file, no compression, and no flushing.

defragRange :: RawFilePath -> DefragRangeArgs -> IO () Source #

Defrag a range within a single file.

Note: calls the BTRFS_IOC_DEFRAG_RANGE ioctl.

File system info

data FSInfo Source #

Information about a btrfs file system.

Instances
Eq FSInfo Source # 
Instance details

Defined in System.Linux.Btrfs.ByteString

Methods

(==) :: FSInfo -> FSInfo -> Bool #

(/=) :: FSInfo -> FSInfo -> Bool #

Show FSInfo Source # 
Instance details

Defined in System.Linux.Btrfs.ByteString

fsiDeviceCount :: FSInfo -> Word64 Source #

The number of devices in the file system.

fsiUuid :: FSInfo -> UUID Source #

The UUID of the file system.

fsiNodeSize :: FSInfo -> FileSize Source #

The tree block size in which metadata is stored.

fsiSectorSize :: FSInfo -> FileSize Source #

The minimum data block allocation unit.

fsiCloneAlignment :: FSInfo -> FileSize Source #

The size that is used for the alignment constraints of clone range operations.

getFSInfo Source #

Arguments

:: RawFilePath

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

-> IO FSInfo 

Retrieve information about a btrfs file system.

Note: calls the BTRFS_IOC_FS_INFO ioctl.

File system label

getFSLabel Source #

Arguments

:: RawFilePath

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

-> IO RawFilePath 

Retrieve the label of a btrfs file system.

Note: calls the BTRFS_IOC_GET_FSLABEL ioctl.

setFSLabel Source #

Arguments

:: RawFilePath

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

-> RawFilePath

The new label.

-> IO () 

Set the label of a btrfs file system. Note that a label can be up to 255 bytes long. If the provided label is longer, it will be silently truncated.

Note: calls the BTRFS_IOC_SET_FSLABEL 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 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.

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 #