filefrag

filefrag.device

Device Objects

class Device()

Represents a device; the backing store of a filesystem.

filefrag.filemap

FileMap Objects

class FileMap()

Contains a mapping of a file to physical locations on the storage device.

update

def update()

(re)read the data, updating the internal state.

check_stale

def check_stale() -> bool

Returns true is the data the path points to is different to when it was loaded.

__iter__

def __iter__()

Iterates over the extents in the file.

filefrag.filefrag

main

def main()

Entrypoint for command line app.

filefrag.extent

Extent Objects

class Extent()

Represents a range of data inside a file.

These have a logical position in the file, and a physical position on the device. The length of an extent can’t be smaller than the block size of the filesystem holding it, so the length of all extents might be a bit longer than the file it represents.

is_last

@property
def is_last() -> bool

True if this is the last extent in the file map.

is_unknown

@property
def is_unknown() -> bool

If the extent is unknown, the physical location and other details returned are unreliable.

is_delayed_allocation

@property
def is_delayed_allocation() -> bool

True if the extent is in the process of being allocated, so the physical location will be set to 0 for the moment. Check again later

is_encoded

@property
def is_encoded() -> bool

An extent may be encoded in some way, like being compressed or stored in a way where it’ll need to be decoded before it can be read.

is_encrypted

@property
def is_encrypted() -> bool

If so, the extent contains encrypted data, you’ll need to decrypt it if you want the data inside.

is_not_aligned

@property
def is_not_aligned() -> bool

True if the extent is misaligned with the filesystem’s block or cluster sizes, if True then expect degraded performance.

is_inline

@property
def is_inline() -> bool

True if the extent is stored with the filesystem’s metadata rather than in the data section.

is_tail_packed

@property
def is_tail_packed() -> bool

True if the extent is the leftover bits at the end of a file that have been packed together with other extents to save space. If this is true, it’s likely not_aligned too.

is_unwritten

@property
def is_unwritten() -> bool

True if the data was allocated, but not yet written to the device.

is_merged

@property
def is_merged() -> bool

If so, the extent is merged with other extents for reporting purposes. How this is done is filesystem-dependent.

is_shared

@property
def is_shared() -> bool

This extent might share a physical location with other extents. Seen in copy-on-write filesystems with deduplication or snapshots (btrfs, zfs)

filefrag.fie

get_extents

def get_extents(fd)

This function retrieves all extents for a given file descriptor

filefrag.__main__

Entry point for the package