linux-file-extents- Retrieve file fragmentation information under Linux

Portabilitynon-portable (requires Linux)
Safe HaskellNone




This module can be used to retrieve information about how a particular file is stored on disk (i.e. the file fragmentation). It accomplishes that by directly calling the FIEMAP ioctl provided by recent versions of the Linux kernel. This ioctl is specific to Linux and therefore this module is not portable.

For more information about the FIEMAP ioctl see filesystems/fiemap.txt in the kernel documentation.


Extent flags

See filesystems/fiemap.txt in the kernel documentation for a more detailed description of each of these flags.

efLast :: ExtentFlagsSource

Last extent in file.

efUnknown :: ExtentFlagsSource

Data location unknown.

efDelalloc :: ExtentFlagsSource

Location still pending.

efEncoded :: ExtentFlagsSource

Data cannot be read while fs is unmounted.

efDataEncrypted :: ExtentFlagsSource

Data is encrypted by fs.

efNotAligned :: ExtentFlagsSource

Extent offsets may not be block aligned.

efDataInline :: ExtentFlagsSource

Data mixed with metadata.

efDataTail :: ExtentFlagsSource

Multiple files in block.

efUnwritten :: ExtentFlagsSource

Space allocated, but no data (i.e. zero).

efMerged :: ExtentFlagsSource

File does not natively support extents. Result merged for efficiency.

efShared :: ExtentFlagsSource

Space shared with other files.


data Extent Source

Description of a single extent. All offsets and lengths are in bytes.




extLogical :: Word64

Offset relative to the beginning of the file.

extPhysical :: Word64

Offset relative to the beginning of the underlying block device.

extLength :: Word64

The length of the extent.

extFlags :: ExtentFlags

Flags for this extent.

Request flags

data ReqFlags Source

Flags the modify the behavior of extent information requests.




rfSync :: Bool

Sync the file before requesting its extents.

rfXattr :: Bool

Retrieve the extents of the inode's extended attribute lookup tree, instead of its data tree.

rfCache :: Bool

Request caching of the extents (not supported by older kernels).


defReqFlags :: ReqFlagsSource

Default values for the request flags. All options are disabled.

Getting extent information



:: ReqFlags 
-> Fd 
-> Maybe (Word64, Word64)

The range (offset and length) within the file to look extents for. Use Nothing for the entire file.

-> IO [Extent] 

Retrieve the list of all extents associated with the file referenced by the file descriptor. Extents returned mirror those on disk - that is, the logical offset of the first returned extent may start before the requested range, and the last returned extent may end after the end of the requested range.

Note: getExtentsFd might call the FIEMAP ioctl multiple times in order to retrieve all the extents of the file. This is necessary when the file has too many fragments. If the file is modified in the meantime, the returned list might be inconsistent.

getExtents :: ReqFlags -> FilePath -> Maybe (Word64, Word64) -> IO [Extent]Source

Like getExtentsFd except that it operates on file paths instead of file descriptors.

getExtentCountFd :: ReqFlags -> Fd -> Maybe (Word64, Word64) -> IO Word32Source

Like getExtentsFd except that it returns the number of extents instead of a list.

getExtentCount :: ReqFlags -> FilePath -> Maybe (Word64, Word64) -> IO Word32Source

Like getExtents except that it returns the number of extents instead of a list.