-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Retrieve file fragmentation information under Linux
--   
--   This package provides a simple wrapper around the Linux FIEMAP ioctl.
--   It can be used to retrieve the list of all the extents of any given
--   file, i.e. the area of the disk where the file is actually stored.
--   This is similar to the <tt>filefrag</tt> command line tool provided by
--   the <tt>e2fsprogs</tt> package.
@package linux-file-extents
@version 0.2.0.0


-- | 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
--   <tt>filesystems/fiemap.txt</tt> in the kernel documentation.
module System.Linux.FileExtents
type ExtentFlags = Word32

-- | Last extent in file.
efLast :: ExtentFlags

-- | Data location unknown.
efUnknown :: ExtentFlags

-- | Location still pending.
efDelalloc :: ExtentFlags

-- | Data cannot be read while fs is unmounted.
efEncoded :: ExtentFlags

-- | Data is encrypted by fs.
efDataEncrypted :: ExtentFlags

-- | Extent offsets may not be block aligned.
efNotAligned :: ExtentFlags

-- | Data mixed with metadata.
efDataInline :: ExtentFlags

-- | Multiple files in block.
efDataTail :: ExtentFlags

-- | Space allocated, but no data (i.e. zero).
efUnwritten :: ExtentFlags

-- | File does not natively support extents. Result merged for efficiency.
efMerged :: ExtentFlags

-- | Space shared with other files.
efShared :: ExtentFlags

-- | Description of a single extent. All offsets and lengths are in bytes.
data Extent
Extent :: Word64 -> Word64 -> Word64 -> ExtentFlags -> Extent

-- | Offset relative to the beginning of the file.
[extLogical] :: Extent -> Word64

-- | Offset relative to the beginning of the underlying block device.
[extPhysical] :: Extent -> Word64

-- | The length of the extent.
[extLength] :: Extent -> Word64

-- | Flags for this extent.
[extFlags] :: Extent -> ExtentFlags

-- | Flags the modify the behavior of extent information requests.
data ReqFlags
ReqFlags :: Bool -> Bool -> Bool -> ReqFlags

-- | Sync the file before requesting its extents.
[rfSync] :: ReqFlags -> Bool

-- | Retrieve the extents of the inode's extended attribute lookup tree,
--   instead of its data tree.
[rfXattr] :: ReqFlags -> Bool

-- | Request caching of the extents (not supported by older kernels).
[rfCache] :: ReqFlags -> Bool

-- | Default values for the request flags. All options are disabled.
defReqFlags :: ReqFlags

-- | 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: <a>getExtentsFd</a> 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.
getExtentsFd :: ReqFlags -> Fd -> Maybe (Word64, Word64) -> IO [Extent]

-- | Like <a>getExtentsFd</a> except that it operates on file paths instead
--   of file descriptors.
getExtents :: ReqFlags -> FilePath -> Maybe (Word64, Word64) -> IO [Extent]

-- | Like <a>getExtentsFd</a> except that it returns the number of extents
--   instead of a list.
getExtentCountFd :: ReqFlags -> Fd -> Maybe (Word64, Word64) -> IO Word32

-- | Like <a>getExtents</a> except that it returns the number of extents
--   instead of a list.
getExtentCount :: ReqFlags -> FilePath -> Maybe (Word64, Word64) -> IO Word32
instance GHC.Classes.Eq System.Linux.FileExtents.ReqFlags
instance GHC.Show.Show System.Linux.FileExtents.ReqFlags
instance GHC.Classes.Eq System.Linux.FileExtents.Extent
instance GHC.Show.Show System.Linux.FileExtents.Extent
instance Foreign.Storable.Storable System.Linux.FileExtents.Extent
