btrfs 0.1.1.0 → 0.1.1.1
raw patch · 4 files changed
+119/−13 lines, 4 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ System.Linux.Btrfs: getDefaultSubvol :: FilePath -> IO SubvolId
+ System.Linux.Btrfs: getDefaultSubvolFd :: Fd -> IO SubvolId
+ System.Linux.Btrfs: instance Eq DefragRangeArgs
+ System.Linux.Btrfs: instance Show DefragRangeArgs
+ System.Linux.Btrfs: setDefaultSubvol :: FilePath -> SubvolId -> IO ()
+ System.Linux.Btrfs: setDefaultSubvolFd :: Fd -> ObjectId -> IO ()
+ System.Linux.Btrfs.ByteString: getDefaultSubvol :: RawFilePath -> IO SubvolId
+ System.Linux.Btrfs.ByteString: getDefaultSubvolFd :: Fd -> IO SubvolId
+ System.Linux.Btrfs.ByteString: instance Eq DefragRangeArgs
+ System.Linux.Btrfs.ByteString: instance Show DefragRangeArgs
+ System.Linux.Btrfs.ByteString: setDefaultSubvol :: RawFilePath -> SubvolId -> IO ()
+ System.Linux.Btrfs.ByteString: setDefaultSubvolFd :: Fd -> ObjectId -> IO ()
Files
- ChangeLog +4/−0
- System/Linux/Btrfs.hsc +57/−6
- System/Linux/Btrfs/ByteString.hsc +57/−6
- btrfs.cabal +1/−1
ChangeLog view
@@ -1,3 +1,7 @@+v0.1.1.1++ * Support getting/setting the id of the default subvolume.+ v0.1.1.0 * Support defraging file ranges.
System/Linux/Btrfs.hsc view
@@ -46,6 +46,8 @@ , getSubvolInfoFd, getSubvolInfo , getSubvolByUuidFd, getSubvolByUuid , getSubvolByReceivedUuidFd, getSubvolByReceivedUuid+ , getDefaultSubvolFd, getDefaultSubvol+ , setDefaultSubvolFd, setDefaultSubvol -- * Defragging , defragFd, defrag , DefragRangeArgs(..), defaultDefragRangeArgs@@ -614,7 +616,7 @@ , siRTime = nothingIf (nv2 || rTransId == 0) rTime } --- | Retrieve information about a subvolume.+-- | Retrieve information about a subvolume. This is a wrapper around 'treeSearch'. getSubvolInfo :: FILEPATH -- ^ The mount point of the volume (or any file in that volume). -> SubvolId -- ^ The id of the subvolume.@@ -646,7 +648,8 @@ getSubvolByUuidFd = searchByUuidFd (#const BTRFS_UUID_KEY_SUBVOL) --- | Find the id of a subvolume, given its UUID.+-- | Find the id of a subvolume, given its UUID. This is a wrapper around+-- 'treeSearch'. -- -- /Requires Linux 3.12 or later./ getSubvolByUuid@@ -661,7 +664,8 @@ getSubvolByReceivedUuidFd = searchByUuidFd (#const BTRFS_UUID_KEY_RECEIVED_SUBVOL) --- | Find the id of a subvolume, given its 'siReceivedUuid'.+-- | Find the id of a subvolume, given its 'siReceivedUuid'. This is a+-- wrapper around 'treeSearch'. -- -- /Requires Linux 3.12 or later./ getSubvolByReceivedUuid@@ -672,6 +676,53 @@ withFd path ReadOnly $ \fd -> getSubvolByReceivedUuidFd fd uuid +getDefaultSubvolFd :: Fd -> IO SubvolId+getDefaultSubvolFd fd = do+ let sk = defaultSearchKey+ { skTreeId = (#const BTRFS_ROOT_TREE_OBJECTID)+ , skMinObjectId = (#const BTRFS_ROOT_TREE_DIR_OBJECTID)+ , skMaxObjectId = (#const BTRFS_ROOT_TREE_DIR_OBJECTID)+ , skMinType = (#const BTRFS_DIR_ITEM_KEY)+ , skMaxType = (#const BTRFS_DIR_ITEM_KEY)+ }+ l <- treeSearchListFd fd sk $ \_ ptr -> do+ LE16 nameLen <- (#peek struct btrfs_dir_item, name_len) ptr+ let cName = ptr `plusPtr` (#size struct btrfs_dir_item)+ name <- peekCStringLen (cName, fromIntegral nameLen)+ if name /= "default" then+ return Nothing+ else do+ let location = ptr `plusPtr` (#offset struct btrfs_dir_item, location)+ LE64 objectId <- (#peek struct btrfs_disk_key, objectid) location+ return (Just objectId)+ case l of+ [] -> ioError $ mkIOError doesNotExistErrorType "getDefaultSubvolFd" Nothing Nothing+ (objectId : _) -> return objectId++-- | Find the id of the default subvolume. This is a wrapper around+-- 'treeSearch'.+getDefaultSubvol+ :: FILEPATH -- ^ The mount point of the volume (or any file in that volume).+ -> IO SubvolId+getDefaultSubvol path = withFd path ReadOnly getDefaultSubvolFd++setDefaultSubvolFd :: Fd -> ObjectId -> IO ()+setDefaultSubvolFd fd objectId = do+ alloca $ \ptr -> do+ poke ptr objectId+ throwErrnoIfMinus1_ "setDefaultSubvolFd" $+ ioctl fd (#const BTRFS_IOC_DEFAULT_SUBVOL) ptr++-- | Set the default subvolume.+--+-- Note: calls the @BTRFS_IOC_DEFAULT_SUBVOL@ @ioctl@.+setDefaultSubvol+ :: FILEPATH -- ^ The mount point of the volume (or any file in that volume).+ -> SubvolId -- ^ The id of the new default subvolume.+ -> IO ()+setDefaultSubvol path subvolId =+ withFd path ReadOnly $ \fd -> setDefaultSubvolFd fd subvolId+ -------------------------------------------------------------------------------- defragFd :: Fd -> IO ()@@ -693,14 +744,14 @@ , draLength :: FileSize -- ^ Number of bytes to defrag, use 'maxBound' to say all. , draExtentThreshold :: Word32- -- ^ Any extent bigger than this size will be considered already- -- defragged. Use 0 to take the kernel default, use 1 to say every- -- single extent must be rewritten.+ -- ^ Any extent of size bigger or equal to this number will be+ -- considered already defragged. Use 0 for the kernel default. , draCompress :: Maybe CompressionType -- ^ Compress the file while defragmenting. , draFlush :: Bool -- ^ Flush data to disk immediately after defragmenting. }+ deriving (Show, Eq) -- | Defaults for 'defragRange'. Selects the entire file, no compression, -- and no flushing.
System/Linux/Btrfs/ByteString.hsc view
@@ -46,6 +46,8 @@ , getSubvolInfoFd, getSubvolInfo , getSubvolByUuidFd, getSubvolByUuid , getSubvolByReceivedUuidFd, getSubvolByReceivedUuid+ , getDefaultSubvolFd, getDefaultSubvol+ , setDefaultSubvolFd, setDefaultSubvol -- * Defragging , defragFd, defrag , DefragRangeArgs(..), defaultDefragRangeArgs@@ -614,7 +616,7 @@ , siRTime = nothingIf (nv2 || rTransId == 0) rTime } --- | Retrieve information about a subvolume.+-- | Retrieve information about a subvolume. This is a wrapper around 'treeSearch'. getSubvolInfo :: FILEPATH -- ^ The mount point of the volume (or any file in that volume). -> SubvolId -- ^ The id of the subvolume.@@ -646,7 +648,8 @@ getSubvolByUuidFd = searchByUuidFd (#const BTRFS_UUID_KEY_SUBVOL) --- | Find the id of a subvolume, given its UUID.+-- | Find the id of a subvolume, given its UUID. This is a wrapper around+-- 'treeSearch'. -- -- /Requires Linux 3.12 or later./ getSubvolByUuid@@ -661,7 +664,8 @@ getSubvolByReceivedUuidFd = searchByUuidFd (#const BTRFS_UUID_KEY_RECEIVED_SUBVOL) --- | Find the id of a subvolume, given its 'siReceivedUuid'.+-- | Find the id of a subvolume, given its 'siReceivedUuid'. This is a+-- wrapper around 'treeSearch'. -- -- /Requires Linux 3.12 or later./ getSubvolByReceivedUuid@@ -672,6 +676,53 @@ withFd path ReadOnly $ \fd -> getSubvolByReceivedUuidFd fd uuid +getDefaultSubvolFd :: Fd -> IO SubvolId+getDefaultSubvolFd fd = do+ let sk = defaultSearchKey+ { skTreeId = (#const BTRFS_ROOT_TREE_OBJECTID)+ , skMinObjectId = (#const BTRFS_ROOT_TREE_DIR_OBJECTID)+ , skMaxObjectId = (#const BTRFS_ROOT_TREE_DIR_OBJECTID)+ , skMinType = (#const BTRFS_DIR_ITEM_KEY)+ , skMaxType = (#const BTRFS_DIR_ITEM_KEY)+ }+ l <- treeSearchListFd fd sk $ \_ ptr -> do+ LE16 nameLen <- (#peek struct btrfs_dir_item, name_len) ptr+ let cName = ptr `plusPtr` (#size struct btrfs_dir_item)+ name <- peekCStringLen (cName, fromIntegral nameLen)+ if name /= "default" then+ return Nothing+ else do+ let location = ptr `plusPtr` (#offset struct btrfs_dir_item, location)+ LE64 objectId <- (#peek struct btrfs_disk_key, objectid) location+ return (Just objectId)+ case l of+ [] -> ioError $ mkIOError doesNotExistErrorType "getDefaultSubvolFd" Nothing Nothing+ (objectId : _) -> return objectId++-- | Find the id of the default subvolume. This is a wrapper around+-- 'treeSearch'.+getDefaultSubvol+ :: FILEPATH -- ^ The mount point of the volume (or any file in that volume).+ -> IO SubvolId+getDefaultSubvol path = withFd path ReadOnly getDefaultSubvolFd++setDefaultSubvolFd :: Fd -> ObjectId -> IO ()+setDefaultSubvolFd fd objectId = do+ alloca $ \ptr -> do+ poke ptr objectId+ throwErrnoIfMinus1_ "setDefaultSubvolFd" $+ ioctl fd (#const BTRFS_IOC_DEFAULT_SUBVOL) ptr++-- | Set the default subvolume.+--+-- Note: calls the @BTRFS_IOC_DEFAULT_SUBVOL@ @ioctl@.+setDefaultSubvol+ :: FILEPATH -- ^ The mount point of the volume (or any file in that volume).+ -> SubvolId -- ^ The id of the new default subvolume.+ -> IO ()+setDefaultSubvol path subvolId =+ withFd path ReadOnly $ \fd -> setDefaultSubvolFd fd subvolId+ -------------------------------------------------------------------------------- defragFd :: Fd -> IO ()@@ -693,14 +744,14 @@ , draLength :: FileSize -- ^ Number of bytes to defrag, use 'maxBound' to say all. , draExtentThreshold :: Word32- -- ^ Any extent bigger than this size will be considered already- -- defragged. Use 0 to take the kernel default, use 1 to say every- -- single extent must be rewritten.+ -- ^ Any extent of size bigger or equal to this number will be+ -- considered already defragged. Use 0 for the kernel default. , draCompress :: Maybe CompressionType -- ^ Compress the file while defragmenting. , draFlush :: Bool -- ^ Flush data to disk immediately after defragmenting. }+ deriving (Show, Eq) -- | Defaults for 'defragRange'. Selects the entire file, no compression, -- and no flushing.
btrfs.cabal view
@@ -1,5 +1,5 @@ name: btrfs-version: 0.1.1.0+version: 0.1.1.1 synopsis: Bindings to the btrfs API description: This package provides low-level bindings to the btrfs API (i.e. the