Skip to main content

Ext4

Struct Ext4 

pub struct Ext4 {
    pub block_device: Arc<dyn BlockDevice>,
    pub super_block: Ext4Superblock,
    pub system_zone_cache: Option<Vec<SystemZone>>,
}

Fields§

§block_device: Arc<dyn BlockDevice>§super_block: Ext4Superblock§system_zone_cache: Option<Vec<SystemZone>>

Implementations§

§

impl Ext4

pub fn find_extent( &self, inode_ref: &Ext4InodeRef, lblock: u32, ) -> Result<SearchPath, Ext4Error>

Find an extent in the extent tree.

Params: inode_ref: &Ext4InodeRef - inode reference lblock: Ext4Lblk - logical block id

Returns: Result<SearchPath> - search path

If depth > 0, search for the extent_index that corresponds to the target lblock. If depth = 0, directly search for the extent in the root node that corresponds to the target lblock.

pub fn insert_extent( &self, inode_ref: &mut Ext4InodeRef, newex: &mut Ext4Extent, ) -> Result<(), Ext4Error>

Insert an extent into the extent tree.

§

impl Ext4

pub fn extent_remove_space( &self, inode_ref: &mut Ext4InodeRef, from: u32, to: u32, ) -> Result<usize, Ext4Error>

pub fn ext_remove_leaf( &self, inode_ref: &mut Ext4InodeRef, path: &mut SearchPath, from: u32, to: u32, ) -> Result<usize, Ext4Error>

pub fn more_to_rm(&self, path: &ExtentPathNode, to: u32) -> bool

§

impl Ext4

pub fn get_system_zone(&self) -> Vec<SystemZone>

获取system zone缓存

pub fn open(block_device: Arc<dyn BlockDevice>) -> Ext4

Opens and loads an Ext4 from the block_device.

pub fn generic_open( &self, path: &str, parent_inode_num: &mut u32, create: bool, ftype: u16, name_off: &mut u32, ) -> Result<u32, Ext4Error>

pub fn dir_mk(&self, path: &str) -> Result<usize, Ext4Error>

§

impl Ext4

pub fn get_bgid_of_inode(&self, inode_num: u32) -> u32

pub fn inode_to_bgidx(&self, inode_num: u32) -> u32

pub fn inode_disk_pos(&self, inode_num: u32) -> usize

Get inode disk position.

pub fn get_inode_ref(&self, inode_num: u32) -> Ext4InodeRef

Load the inode reference from the disk.

pub fn write_back_inode(&self, inode_ref: &mut Ext4InodeRef)

write back inode with checksum

pub fn write_back_inode_without_csum(&self, inode_ref: &Ext4InodeRef)

write back inode with checksum

pub fn get_pblock_idx( &self, inode_ref: &Ext4InodeRef, lblock: u32, ) -> Result<u64, Ext4Error>

Get physical block id of a logical block.

Params: inode_ref: &Ext4InodeRef - inode reference lblock: Ext4Lblk - logical block id

Returns: Result<Ext4Fsblk> - physical block id

pub fn allocate_new_block( &self, inode_ref: &mut Ext4InodeRef, ) -> Result<u64, Ext4Error>

Allocate a new block

pub fn append_inode_pblk( &self, inode_ref: &mut Ext4InodeRef, ) -> Result<u64, Ext4Error>

Append a new block to the inode and update the extent tree.

Params: inode_ref: &mut Ext4InodeRef - inode reference iblock: Ext4Lblk - logical block id

Returns: Result<Ext4Fsblk> - physical block id of the new block

pub fn append_inode_pblk_from( &self, inode_ref: &mut Ext4InodeRef, start_bgid: &mut u32, ) -> Result<u64, Ext4Error>

Append a new block to the inode and update the extent tree.From a specific bgid

Params: inode_ref: &mut Ext4InodeRef - inode reference bgid: Start bgid of free block search

Returns: Result<Ext4Fsblk> - physical block id of the new block

pub fn alloc_inode(&self, is_dir: bool) -> Result<u32, Ext4Error>

Allocate a new inode

Params: inode_mode: u16 - inode mode

Returns: Result<u32> - inode number

pub fn correspond_inode_mode(&self, filetype: u8) -> u16

pub fn append_inode_pblk_batch( &self, inode_ref: &mut Ext4InodeRef, start_bgid: &mut u32, block_count: usize, ) -> Result<Vec<u64>, Ext4Error>

Append multiple blocks to the inode and update the extent tree.

Params: inode_ref: &mut Ext4InodeRef - inode reference start_bgid: &mut u32 - start block group id for allocation block_count: usize - number of blocks to allocate

Returns: Result<Vec<Ext4Fsblk>> - vector of physical block ids of the new blocks

§

impl Ext4

pub fn dir_find_entry( &self, parent_inode: u32, name: &str, result: &mut Ext4DirSearchResult, ) -> Result<usize, Ext4Error>

Find a directory entry in a directory

Params: parent_inode: u32 - inode number of the parent directory name: &str - name of the entry to find result: &mut Ext4DirSearchResult - result of the search

Returns: Result<usize> - status of the search

pub fn dir_find_in_block( &self, block: &Block, name: &str, result: &mut Ext4DirSearchResult, ) -> Result<Ext4DirEntry, Ext4Error>

Find a directory entry in a block

Params: block: &mut Block - block to search in name: &str - name of the entry to find

Returns: result: Ext4DirEntry - result of the search

pub fn dir_get_entries(&self, inode: u32) -> Vec<Ext4DirEntry>

Get dir entries of a inode

Params: inode: u32 - inode number of the directory

Returns: Vec<Ext4DirEntry> - list of directory entries

pub fn dir_set_csum(&self, dst_blk: &mut Block, ino_gen: u32)

pub fn dir_add_entry( &self, parent: &mut Ext4InodeRef, child: &Ext4InodeRef, name: &str, ) -> Result<usize, Ext4Error>

Add a new entry to a directory

Params: parent: &mut Ext4InodeRef - parent directory inode reference child: &mut Ext4InodeRef - child inode reference path: &str - path of the new entry

Returns: Result<usize> - status of the operation

pub fn try_insert_to_existing_block( &self, block: &mut Block, name: &str, child_inode: u32, ) -> Result<usize, Ext4Error>

Try to insert a new entry to an existing block

Params: block: &mut Block - block to insert the new entry name: &str - name of the new entry inode: u32 - inode number of the new entry

Returns: Result<usize> - status of the operation

pub fn insert_to_new_block( &self, block: &mut Block, inode: u32, name: &str, de_type: DirEntryType, )

Insert a new entry to a new block

Params: block: &mut Block - block to insert the new entry name: &str - name of the new entry inode: u32 - inode number of the new entry

pub fn dir_remove_entry( &self, parent: &mut Ext4InodeRef, path: &str, ) -> Result<usize, Ext4Error>

pub fn dir_has_entry(&self, dir_inode: u32) -> bool

pub fn dir_remove(&self, parent: u32, path: &str) -> Result<usize, Ext4Error>

§

impl Ext4

Link a child inode to a parent directory

Params: parent: &mut Ext4InodeRef - parent directory inode reference child: &mut Ext4InodeRef - child inode reference name: &str - name of the child inode

Returns: Result<usize> - status of the operation

pub fn create( &self, parent: u32, name: &str, inode_mode: u16, ) -> Result<Ext4InodeRef, Ext4Error>

create a new inode and link it to the parent directory

Params: parent: u32 - inode number of the parent directory name: &str - name of the new file mode: u16 - file mode

Returns:

pub fn create_inode(&self, inode_mode: u16) -> Result<Ext4InodeRef, Ext4Error>

pub fn create_with_attr( &self, parent: u32, name: &str, inode_mode: u16, uid: u16, gid: u16, ) -> Result<Ext4InodeRef, Ext4Error>

create a new inode and link it to the parent directory

Params: parent: u32 - inode number of the parent directory name: &str - name of the new file mode: u16 - file mode uid: u32 - user id gid: u32 - group id

Returns:

pub fn read_at( &self, inode: u32, offset: usize, read_buf: &mut [u8], ) -> Result<usize, Ext4Error>

Read data from a file at a given offset

Params: inode: u32 - inode number of the file offset: usize - offset from where to read read_buf: &mut u8 - buffer to read the data into

Returns: Result<usize> - number of bytes read

pub fn write_at( &self, inode: u32, offset: usize, write_buf: &[u8], ) -> Result<usize, Ext4Error>

Write data to a file at a given offset

Params: inode: u32 - inode number of the file offset: usize - offset from where to write write_buf: &u8 - buffer to write the data from

Returns: Result<usize> - number of bytes written

pub fn file_remove(&self, path: &str) -> Result<usize, Ext4Error>

File remove

Params: path: file path start from root

Returns: Result<usize> - status of the operation

pub fn truncate_inode( &self, inode_ref: &mut Ext4InodeRef, new_size: u64, ) -> Result<usize, Ext4Error>

File truncate

Params: inode_ref: &mut Ext4InodeRef - inode reference new_size: u64 - new size of the file

Returns: Result<usize> - status of the operation

§

impl Ext4

pub fn ialloc_alloc_inode(&self, is_dir: bool) -> Result<u32, Ext4Error>

pub fn ialloc_free_inode(&self, index: u32, is_dir: bool)

§

impl Ext4

pub fn get_bgid_of_block(&self, baddr: u64) -> u32

Compute number of block group from block address.

Params:

baddr - Absolute address of block.

§Returns

u32 - Block group index

pub fn get_block_of_bgid(&self, bgid: u32) -> u64

Compute the starting block address of a block group.

Params: bgid - Block group index

Returns: u64 - Block address

pub fn addr_to_idx_bg(&self, baddr: u64) -> u32

Convert block address to relative index in block group.

Params: baddr - Block number to convert.

Returns: u32 - Relative number of block.

pub fn bg_idx_to_addr(&self, index: u32, bgid: u32) -> u64

Convert relative block address in group to absolute address.

§Arguments
  • index - Relative block address.
  • bgid - Block group.
§Returns
  • Ext4Fsblk - Absolute block address.

pub fn balloc_alloc_block( &self, inode_ref: &mut Ext4InodeRef, goal: Option<u64>, ) -> Result<u64, Ext4Error>

Allocate a new block.

Params: inode_ref - Reference to the inode. goal - Absolute address of the block.

Returns: Result<Ext4Fsblk> - The physical block number allocated.

pub fn balloc_alloc_block_from( &self, inode_ref: &mut Ext4InodeRef, start_bgid: &mut u32, ) -> Result<u64, Ext4Error>

Allocate a new block start from a specific bgid

Params: inode_ref - Reference to the inode. start_bgid - Start bgid of free block search

Returns: Result<Ext4Fsblk> - The physical block number allocated.

pub fn balloc_free_blocks( &self, inode_ref: &mut Ext4InodeRef, start: u64, count: u32, )

pub fn is_system_reserved_block(&self, block_num: u64, _bgid: u32) -> bool

pub fn balloc_alloc_block_batch( &self, inode_ref: &mut Ext4InodeRef, start_bgid: &mut u32, count: usize, ) -> Result<Vec<u64>, Ext4Error>

Optimized block allocation inspired by lwext4

Params: inode_ref - Reference to the inode start_bgid - Starting block group ID, will be updated to the last used block group count - Number of blocks to allocate

Returns: Result<Vec<Ext4Fsblk>> - Vector of allocated physical block numbers

pub fn num_base_meta_blocks(&self, bgid: u32) -> u32

Returns the number of meta blocks for a given block group, like Linux ext4_num_base_meta_blocks.

pub fn ext4_bg_has_super(&self, group: u32) -> bool

判断group是否有superblock备份(与Linux ext4_bg_has_super一致)

pub fn ext4_has_feature_meta_bg(&self) -> bool

判断是否有meta_bg特性(与Linux ext4_has_feature_meta_bg一致)

pub fn ext4_bg_num_gdb(&self, group: u32) -> u32

返回该group的GDT blocks数(与Linux ext4_bg_num_gdb一致)

§

impl Ext4

simple interface for ext4

pub fn ext4_file_open(&self, path: &str, flags: &str) -> Result<u32, Ext4Error>

Open a file at the specified path and return the corresponding inode number.

Open a file by searching for the given path starting from the root directory (ROOT_INODE). If the file does not exist and the O_CREAT flag is specified, the file will be created.

§Arguments
  • path - The path of the file to open.
  • flags - The access flags (e.g., “r”, “w”, “a”, etc.).
§Returns
  • Result<u32> - Returns the inode number of the opened file if successful.

pub fn ext4_dir_mk(&self, path: &str) -> Result<u32, Ext4Error>

Create a new directory at the specified path.

Checks if the directory already exists by searching from the root directory (ROOT_INODE). If the directory does not exist, it creates the directory under the root directory and returns its inode number.

§Arguments
  • path - The path where the directory will be created.
§Returns
  • Result<u32> - The inode number of the newly created directory if successful, or an error (Errno::EEXIST) if the directory already exists.

pub fn ext4_dir_open(&self, path: &str) -> Result<u32, Ext4Error>

Open a directory at the specified path and return the corresponding inode number.

Opens a directory by searching for the given path starting from the root directory (ROOT_INODE).

§Arguments
  • path - The path of the directory to open.
§Returns
  • Result<u32> - Returns the inode number of the opened directory if successful.

pub fn ext4_dir_get_entries(&self, inode: u32) -> Vec<Ext4DirEntry>

Get dir entries of a inode

Params: inode: u32 - inode number of the directory assert!(inode.is_dir());

Returns: Vec<Ext4DirEntry> - list of directory entries

pub fn ext4_file_read( &self, ino: u64, size: u32, offset: i64, ) -> Result<Vec<u8>, Ext4Error>

Read data from a file starting from a given offset.

Reads data from the file starting at the specified inode (ino), with a given offset and size.

§Arguments
  • ino - The inode number of the file to read from.
  • size - The number of bytes to read.
  • offset - The offset from where to start reading.
§Returns
  • Result<Vec<u8>> - The data read from the file.

pub fn ext4_file_write( &self, ino: u64, offset: i64, data: &[u8], ) -> Result<usize, Ext4Error>

Write data to a file starting at a given offset.

Writes data to the file starting at the specified inode (ino) and offset.

§Arguments
  • ino - The inode number of the file to write to.
  • offset - The offset in the file where the data will be written.
  • data - The data to write to the file.
§Returns
  • Result<usize> - The number of bytes written to the file.
§

impl Ext4

fuser interface for ext4

pub fn fuse_lookup( &self, parent: u64, name: &str, ) -> Result<FileAttr, Ext4Error>

Look up a directory entry by name and get its attributes.

pub fn fuse_getattr(&self, ino: u64) -> Result<FileAttr, Ext4Error>

Get file attributes.

pub fn fuse_setattr( &self, ino: u64, mode: Option<u32>, uid: Option<u32>, gid: Option<u32>, size: Option<u64>, atime: Option<u32>, mtime: Option<u32>, ctime: Option<u32>, fh: Option<u64>, crtime: Option<u32>, chgtime: Option<u32>, bkuptime: Option<u32>, flags: Option<u32>, )

Set file attributes.

pub fn fuse_mknod( &self, parent: u64, name: &str, mode: u32, umask: u32, rdev: u32, ) -> Result<Ext4InodeRef, Ext4Error>

Create a regular file, character device, block device, fifo or socket node.

pub fn fuse_mknod_with_attr( &self, parent: u64, name: &str, mode: u32, umask: u32, rdev: u32, uid: u32, gid: u32, ) -> Result<Ext4InodeRef, Ext4Error>

Create a regular file, character device, block device, fifo or socket node.

pub fn fuse_mkdir( &mut self, parent: u64, name: &str, mode: u32, umask: u32, ) -> Result<usize, Ext4Error>

Create a directory.

pub fn fuse_mkdir_with_attr( &mut self, parent: u64, name: &str, mode: u32, umask: u32, uid: u32, gid: u32, ) -> Result<Ext4InodeRef, Ext4Error>

Create a directory.

Remove a file.

pub fn fuse_rmdir( &mut self, parent: u64, name: &str, ) -> Result<usize, Ext4Error>

Remove a directory.

Create a symbolic link.

Create a hard link. Params: ino: the inode number of the source file newparent: the inode number of the new parent directory newname: the name of the new file

pub fn fuse_open(&mut self, ino: u64, flags: i32) -> Result<usize, Ext4Error>

Open a file. Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and O_TRUNC) are available in flags. Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other file operations (read, write, flush, release, fsync). Filesystem may also implement stateless file I/O and not store anything in fh. There are also some flags (direct_io, keep_cache) which the filesystem may set, to change the way the file is opened. See fuse_file_info structure in <fuse_common.h> for more details.

pub fn fuse_read( &self, ino: u64, fh: u64, offset: i64, size: u32, flags: i32, lock_owner: Option<u64>, ) -> Result<Vec<u8>, Ext4Error>

Read data. Read should send exactly the number of bytes requested except on EOF or error, otherwise the rest of the data will be substituted with zeroes. An exception to this is when the file has been opened in ‘direct_io’ mode, in which case the return value of the read system call will reflect the return value of this operation. fh will contain the value set by the open method, or will be undefined if the open method didn’t set any value.

flags: these are the file flags, such as O_SYNC. Only supported with ABI >= 7.9 lock_owner: only supported with ABI >= 7.9

pub fn fuse_write( &self, ino: u64, fh: u64, offset: i64, data: &[u8], write_flags: u32, flags: i32, lock_owner: Option<u64>, ) -> Result<usize, Ext4Error>

Write data. Write should return exactly the number of bytes requested except on error. An exception to this is when the file has been opened in ‘direct_io’ mode, in which case the return value of the write system call will reflect the return value of this operation. fh will contain the value set by the open method, or will be undefined if the open method didn’t set any value.

write_flags: will contain FUSE_WRITE_CACHE, if this write is from the page cache. If set, the pid, uid, gid, and fh may not match the value that would have been sent if write cachin is disabled flags: these are the file flags, such as O_SYNC. Only supported with ABI >= 7.9 lock_owner: only supported with ABI >= 7.9

pub fn fuse_opendir(&mut self, ino: u64, flags: i32) -> Result<usize, Ext4Error>

Open a directory. Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other directory stream operations (readdir, releasedir, fsyncdir). Filesystem may also implement stateless directory I/O and not store anything in fh, though that makes it impossible to implement standard conforming directory stream operations in case the contents of the directory can change between opendir and releasedir.

pub fn fuse_readdir( &self, ino: u64, fh: u64, offset: i64, ) -> Result<Vec<Ext4DirEntry>, Ext4Error>

Read directory. Send a buffer filled using buffer.fill(), with size not exceeding the requested size. Send an empty buffer on end of stream. fh will contain the value set by the opendir method, or will be undefined if the opendir method didn’t set any value.

pub fn fuse_create( &mut self, parent: u64, name: &str, mode: u32, umask: u32, flags: i32, ) -> Result<usize, Ext4Error>

Create and open a file. If the file does not exist, first create it with the specified mode, and then open it. Open flags (with the exception of O_NOCTTY) are available in flags. Filesystem may store an arbitrary file handle (pointer, index, etc) in fh, and use this in other all other file operations (read, write, flush, release, fsync). There are also some flags (direct_io, keep_cache) which the filesystem may set, to change the way the file is opened. See fuse_file_info structure in <fuse_common.h> for more details. If this method is not implemented or under Linux kernel versions earlier than 2.6.15, the mknod() and open() methods will be called instead.

pub fn fuse_access( &mut self, ino: u64, uid: u16, gid: u16, mode: u16, mask: i32, ) -> bool

Check file access permissions. This will be called for the access() system call. If the ‘default_permissions’ mount option is given, this method is not called. This method is not called under Linux kernel versions 2.4.x int access(const char *pathname, int mode); int faccessat(int dirfd, const char *pathname, int mode, int flags);

uid and gid come from request

pub fn fuse_statfs(&mut self, ino: u64) -> Result<LinuxStat, Ext4Error>

Get file system statistics. Linux stat syscall defines: int stat(const char *restrict pathname, struct stat *restrict statbuf); int fstatat(int dirfd, const char *restrict pathname, struct stat *restrict statbuf, int flags);

pub fn fuse_init(&mut self) -> Result<usize, Ext4Error>

Initialize filesystem. Called before any other filesystem method. The kernel module connection can be configured using the KernelConfig object

pub fn fuse_destroy(&mut self) -> Result<usize, Ext4Error>

Clean up filesystem. Called on filesystem exit.

Auto Trait Implementations§

§

impl Freeze for Ext4

§

impl !RefUnwindSafe for Ext4

§

impl Send for Ext4

§

impl Sync for Ext4

§

impl Unpin for Ext4

§

impl UnsafeUnpin for Ext4

§

impl !UnwindSafe for Ext4

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.