dissect.cramfs.cramfs

Module Contents

Classes

CramFS

CramFS filesystem implementation.

INode

BlockStream

Basic buffered stream that provides aligned reads.

class dissect.cramfs.cramfs.CramFS(fh: BinaryIO)

CramFS filesystem implementation.

Parameters:

fh – A file-like object of the volume containing the filesystem.

fh
sb
root
inode(offset: int) INode
get(path: str | int, node: INode | None = None) INode

Return an inode for the given path or offset.

Parameters:
  • path – The path or offset of the inode.

  • node – An optional inode object to relatively resolve the path from.

class dissect.cramfs.cramfs.INode(fs: CramFS, offset: int)
fs
offset
__repr__() str
property inode: dissect.cramfs.c_cramfs.c_cramfs.cramfs_inode

Return the inode header.

property mode: int

Return the file mode.

property uid: int

Return the user ID.

property major: int

Return the major device ID for block and character devices.

property minor: int

Return the minor device ID for block and character devices.

property size: int

Return the file size.

property gid: int

Return the group ID.

property data_offset: int

Offset to the start of the data block or INode.

  • For files: this is the offset to the first data block.

  • For directories: this is the offset to the first INode.

  • For symlinks: this is the offset the data block holding the target name.

property name: str

Return the name of this inode.

Return the symlink target.

property blocks: list[tuple[int, int]]

Return a list containing pairs of starting offsets and byte lengths for each block of this inode.

is_dir() bool

Return whether this inode is a directory.

is_file() bool

Return whether this inode is a file.

Return whether this inode is a symlink.

is_block_device() bool

Return whether this inode is a block device.

is_character_device() bool

Return whether this inode is a character device.

is_device() bool

Return whether this inode is a device file.

is_fifo() bool

Return whether this inode is a FIFO (named pipe).

is_socket() bool

Return whether this inode is a socket.

is_ipc() bool

Return whether this inode is an IPC object (FIFO or socket).

listdir() dict[str, INode]

Return a directory listing.

dirlist
iterdir() collections.abc.Iterator[INode]

Iterate directory contents.

open() BlockStream | dissect.util.stream.RangeStream

Return a file-like object for reading.

class dissect.cramfs.cramfs.BlockStream(inode: INode)

Bases: dissect.util.stream.AlignedStream

Basic buffered stream that provides aligned reads.

Must be subclassed for various stream implementations. Subclasses can implement:
  • _read()

  • _seek()

The offset and length for _read are guaranteed to be aligned for streams of a known size. If your stream has an unknown size (i.e. size == None), reads of length -1 (i.e. read until EOF) will be passed through to your implementation of _read. The only time that overriding _seek would make sense is if there’s no known size of your stream, but still want to provide SEEK_END functionality.

Most subclasses of AlignedStream take one or more file-like objects as source. Operations on these subclasses, like reading, will modify the source file-like object as a side effect.

Parameters:
  • size – The size of the stream. This is used in read and seek operations. None if unknown.

  • align – The alignment size. Read operations are aligned on this boundary. Also determines buffer size.

_read(offset: int, length: int) bytes

Read method that backs this aligned stream.

_seek(pos: int, whence: int = 0) int

Calculate and return the new stream position after a seek.

inode
blocks
num_blocks