Bcachefs

bcachefs.bcachefs.mount(file) → bcachefs.bcachefs.Bcachefs[source]

Virtually mount a disk image to access its files

file: str
path to the disk image

This in fact opens the disk image file for reading operations.

>>> with mount(path_to_file) as image:
...     with image.open('dir/subdir/file2', 'rb') as f:
...         data = f.read()
...         print(data.decode('utf-8'))
File content 2
class bcachefs.bcachefs.Bcachefs(path: str, mode: str = 'rb')[source]

Bases: bcachefs.bcachefs.ZipFileLikeMixin

cache_dir(path: Union[str, bcachefs.bcachefs.DirEnt])

Open a cursor to specified directory and cache its content

path: str, DirEnt
Path or DirEnt of a file or directory
cd(path: str = '')[source]

Open a cursor to specified directory and cache its content

path: str, DirEnt
Path or DirEnt of a file or directory
close()

Close the disk image. This invalidates all open files objects

closed

Is current disk image closed

dirents()[source]
extents()[source]
filename

Path of the current disk image

inodes()[source]
namelist()

Returns a list of files contained by this archive

Added for parity with Zipfile interface

>>> with Bcachefs(path_to_file, 'r') as image:
...     print(image.namelist())
['file1', 'n09332890/n09332890_29876.JPEG', 'dir/subdir/file2', 'n04467665/n04467665_63788.JPEG', 'n02033041/n02033041_3834.JPEG', 'n02445715/n02445715_16523.JPEG', 'n04584207/n04584207_7936.JPEG']
open(name: Union[str, int], mode: str = 'rb', encoding: str = 'utf-8')

Open a file and return the corresponding file object

name: str, int
Path or inode integer of a file
mode: str
reading mode rb (bytes)
encoding: str
string encoding to use, defaults to utf-8

FileNotFoundError when opening an file that does not exist

read(inode: Union[str, int]) → memoryview

Read and return all the bytes from the file

inode: str, int
Path or inode integer of a file
readinto(inode: Union[str, int], buffer: memoryview) → memoryview

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read

inode: str, int
Path or inode integer of a file
scandir(path: Union[str, bcachefs.bcachefs.DirEnt] = None) → Generator[bcachefs.bcachefs.DirEnt, NoneType, NoneType]

Return an iterator of DirEnt objects corresponding to the entries in the directory given by path

path: str, DirEnt
Path or DirEnt of a directory
umount()[source]

Unmount of the disk image. This invalidates all open files objects

This in fact closes the disk image file.

unmounted

Is current disk image unmounted

walk(top: str = None)

Generate the dirents in a directory tree by walking the tree either top-down. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirs, files)

top: str, int
Path or DirEnt of a file
class bcachefs.bcachefs.Cursor(filesystem: Union[str, bcachefs.bcachefs.FilesystemMixin], path: str, extents_map=None, inodes_ls=None, inodes_tree=None, inode_map=None)[source]

Bases: bcachefs.bcachefs.ZipFileLikeMixin

Cursor of a filesystem opened at a specific directory. Calls will be made relative to that directory and its recursive content will be cached

cache_dir(path: Union[str, bcachefs.bcachefs.DirEnt])

Open a cursor to specified directory and cache its content

path: str, DirEnt
Path or DirEnt of a file or directory
cd(path: Union[str, int] = '')[source]

Open a cursor to specified directory and cache its content

path: str, DirEnt
Path or DirEnt of a file or directory
close()[source]

Close the disk image. This invalidates all open files objects

closed

Is current disk image closed

filename

Path of the current disk image

namelist()

Returns a list of files contained by this archive

Added for parity with Zipfile interface

>>> with Bcachefs(path_to_file, 'r') as image:
...     print(image.namelist())
['file1', 'n09332890/n09332890_29876.JPEG', 'dir/subdir/file2', 'n04467665/n04467665_63788.JPEG', 'n02033041/n02033041_3834.JPEG', 'n02445715/n02445715_16523.JPEG', 'n04584207/n04584207_7936.JPEG']
open(name: Union[str, int], mode: str = 'rb', encoding: str = 'utf-8')

Open a file and return the corresponding file object

name: str, int
Path or inode integer of a file
mode: str
reading mode rb (bytes)
encoding: str
string encoding to use, defaults to utf-8

FileNotFoundError when opening an file that does not exist

pwd
read(inode: Union[str, int]) → memoryview

Read and return all the bytes from the file

inode: str, int
Path or inode integer of a file
readinto(inode: Union[str, int], buffer: memoryview) → memoryview

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read

inode: str, int
Path or inode integer of a file
scandir(path: Union[str, bcachefs.bcachefs.DirEnt] = None) → Generator[bcachefs.bcachefs.DirEnt, NoneType, NoneType]

Return an iterator of DirEnt objects corresponding to the entries in the directory given by path

path: str, DirEnt
Path or DirEnt of a directory
umount()

Unmount of the disk image. This invalidates all open files objects

This in fact closes the disk image file.

unmounted

Is current disk image unmounted

walk(top: str = None)

Generate the dirents in a directory tree by walking the tree either top-down. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirs, files)

top: str, int
Path or DirEnt of a file
class bcachefs.bcachefs.Extent(inode: int = 0, file_offset: int = 0, offset: int = 0, size: int = 0) → None[source]

Bases: object

Specify the location of an extent of a file inside the disk image

inode: int
inode of the file
file_offset: int
position of the extent in the logical file
offset: int
position inside the disk image where the extent starts
size: int
size of the extent
file_offset = 0
inode = 0
offset = 0
size = 0
class bcachefs.bcachefs.Inode(inode: int = 0, size: int = 0, hash_seed: int = 0) → None[source]

Bases: object

Bcachefs Inode Attributes

inode: int
inode the attributes belongs to
size: int
file size
hash_seed = 0
inode = 0
size = 0
class bcachefs.bcachefs.DirEnt(parent_inode: int = 0, inode: int = 0, type: int = 0, name: str = '') → None[source]

Bases: object

Bcachefs directory entry

parent_inode: int
inode of the parent entry (directory)
inode: int
inode of the current entry
type: int
file (8) or directory (4)
name: str
name of current entry (file or directory)
inode = 0
is_dir
is_file
name = ''
parent_inode = 0
type = 0