Fat32FileSystem

Struct Fat32FileSystem 

Source
pub struct Fat32FileSystem {
    fs_id: FileSystemId,
    block_device: Arc<dyn BlockDevice>,
    boot_sector: Fat32BootSector,
    root_cluster: u32,
    sectors_per_cluster: u32,
    bytes_per_sector: u32,
    root: RwLock<Arc<Fat32Node>>,
    name: String,
    next_file_id: Mutex<u64>,
    fat_cache: Mutex<BTreeMap<u32, u32>>,
}
Expand description

FAT32 Filesystem implementation

This struct implements a FAT32 filesystem that can be mounted on block devices. It maintains the block device reference and provides filesystem operations through the VFS v2 interface.

Fields§

§fs_id: FileSystemId

Unique filesystem identifier

§block_device: Arc<dyn BlockDevice>

Reference to the underlying block device

§boot_sector: Fat32BootSector

Boot sector information

§root_cluster: u32

Root directory cluster

§sectors_per_cluster: u32

Sectors per cluster

§bytes_per_sector: u32

Bytes per sector

§root: RwLock<Arc<Fat32Node>>

Root directory node

§name: String

Filesystem name

§next_file_id: Mutex<u64>

Next file ID generator

§fat_cache: Mutex<BTreeMap<u32, u32>>

Cached FAT table entries

Implementations§

Source§

impl Fat32FileSystem

Source

pub fn new( block_device: Arc<dyn BlockDevice>, ) -> Result<Arc<Self>, FileSystemError>

Create a new FAT32 filesystem from a block device

Source

fn read_boot_sector( block_device: &dyn BlockDevice, ) -> Result<Fat32BootSector, FileSystemError>

Read boot sector from block device

Source

fn validate_fat32(boot_sector: &Fat32BootSector) -> Result<(), FileSystemError>

Validate that this is a FAT32 filesystem

Source

fn lookup_file_in_directory( &self, cluster: u32, target_name: &str, ) -> Result<Fat32DirectoryEntryInternal, FileSystemError>

Lookup a specific file in a directory cluster

Source

fn read_cluster_data(&self, cluster: u32) -> Result<Vec<u8>, FileSystemError>

Read complete cluster data

Source

fn generate_file_id(&self) -> u64

Generate next unique file ID

Source

fn read_cluster(&self, cluster: u32) -> Result<Vec<u8>, FileSystemError>

Read cluster data from the block device

Source

fn read_fat_entry(&self, cluster: u32) -> Result<u32, FileSystemError>

Read FAT entry for a given cluster

Source

fn write_fat_entry( &self, cluster: u32, value: u32, ) -> Result<(), FileSystemError>

Write FAT entry for a given cluster

Source

pub fn read_file_content( &self, start_cluster: u32, size: usize, ) -> Result<Vec<u8>, FileSystemError>

Read file content by following cluster chain

Source

pub fn read_page_content( &self, start_cluster: u32, page_index: u64, paddr: usize, ) -> Result<(), FileSystemError>

Read a single page (4096 bytes) of file content into physical memory.

This is used by the page cache manager for demand paging.

Source

pub fn write_file_content( &self, current_cluster: u32, content: &[u8], ) -> Result<u32, FileSystemError>

Write file content to disk and return the starting cluster

Source

fn read_fat_entry_direct(&self, cluster: u32) -> Result<u32, FileSystemError>

Read FAT entry directly from disk without caching

Source

fn allocate_cluster(&self) -> Result<u32, FileSystemError>

Allocate a free cluster from the FAT and mark it as allocated

Source

fn initialize_directory( &self, dir_cluster: u32, parent_cluster: u32, ) -> Result<(), FileSystemError>

Initialize a new directory cluster with . and .. entries

Source

fn update_fs_info_allocated_cluster( &self, _allocated_cluster: u32, ) -> Result<(), FileSystemError>

Update FS Info sector when a cluster is allocated

Source

fn update_fs_info_freed_cluster( &self, freed_count: u32, ) -> Result<(), FileSystemError>

Update FS Info sector to increment free cluster count

Source

fn free_cluster_chain(&self, start_cluster: u32) -> Result<(), FileSystemError>

Free a cluster chain starting from the given cluster

Source

fn write_cluster_data( &self, cluster: u32, data: &[u8], ) -> Result<(), FileSystemError>

Read data to a cluster

Source

fn cluster_to_sector(&self, cluster: u32) -> u32

Convert cluster number to first sector number

Source

fn read_directory_entries( &self, cluster: u32, entries: &mut Vec<Fat32DirectoryEntryInternal>, ) -> Result<(), FileSystemError>

Read directory entries from a cluster

Source

fn write_directory_entry_with_name( &self, dir_cluster: u32, filename: &str, cluster: u32, size: u32, is_directory: bool, ) -> Result<(), FileSystemError>

Write a new directory entry with LFN support to the specified directory cluster

Source

pub fn update_directory_entry( &self, dir_cluster: u32, filename: &str, entry: &Fat32DirectoryEntry, ) -> Result<(), FileSystemError>

Update an existing directory entry in the specified directory cluster Supports both LFN and SFN matching

Source

fn requires_lfn(filename: &str) -> bool

Check if a filename requires LFN (Long File Name) entries

Source

fn generate_lfn_entries(filename: &str, sfn_checksum: u8) -> Vec<Fat32LFNEntry>

Generate LFN entries for a given filename

Source

fn calculate_sfn_checksum(sfn: &[u8; 11]) -> u8

Calculate checksum for SFN (used in LFN entries)

Source

fn remove_directory_entry( &self, dir_cluster: u32, filename: &str, ) -> Result<(), FileSystemError>

Remove a directory entry from the specified directory cluster

Source

fn generate_sfn(filename: &str, numeric_tail: Option<u32>) -> [u8; 11]

Generate a FAT32-compliant SFN (Short File Name) from a long filename This implementation follows the Microsoft FAT32 specification

Source

fn is_valid_sfn_char(ch: char) -> bool

Check if a character is valid for SFN according to FAT32 specification

Source

fn filename_needs_numeric_tail(&self, filename: &str) -> bool

Check if filename needs numeric tail (Linux-style behavior) Returns true ONLY for filenames that cannot fit in 8.3 format or contain invalid characters

Source

fn generate_unique_sfn( &self, dir_cluster: u32, desired_filename: &str, ) -> Result<[u8; 11], FileSystemError>

Generate a unique SFN by checking for duplicates in the directory

Source

fn sfn_exists_in_directory( &self, dir_cluster: u32, sfn: &[u8; 11], ) -> Result<bool, FileSystemError>

Check if an SFN already exists in the specified directory

Trait Implementations§

Source§

impl Debug for Fat32FileSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FileSystemOperations for Fat32FileSystem

Source§

fn fs_id(&self) -> FileSystemId

Get the unique filesystem identifier. Read more
Source§

fn lookup( &self, parent: &Arc<dyn VfsNode>, name: &String, ) -> Result<Arc<dyn VfsNode>, FileSystemError>

Look up a child node by name within a parent directory Read more
Source§

fn open( &self, node: &Arc<dyn VfsNode>, _flags: u32, ) -> Result<Arc<dyn FileObject>, FileSystemError>

Open a file represented by a VfsNode Read more
Source§

fn create( &self, parent: &Arc<dyn VfsNode>, name: &String, file_type: FileType, _mode: u32, ) -> Result<Arc<dyn VfsNode>, FileSystemError>

Create a new file in the specified directory
Source§

fn remove( &self, parent: &Arc<dyn VfsNode>, name: &String, ) -> Result<(), FileSystemError>

Remove a file from the specified directory
Source§

fn readdir( &self, node: &Arc<dyn VfsNode>, ) -> Result<Vec<DirectoryEntryInternal>, FileSystemError>

Read directory entries from a directory node
Source§

fn root_node(&self) -> Arc<dyn VfsNode>

Get the root VfsNode for this filesystem
Source§

fn name(&self) -> &str

Get filesystem name
Source§

fn as_any(&self) -> &dyn Any

Access to Any trait for downcasting
Source§

fn is_read_only(&self) -> bool

Check if filesystem is read-only
Create a hard link to an existing file Read more

Auto Trait Implementations§

§

impl !Freeze for Fat32FileSystem

§

impl !RefUnwindSafe for Fat32FileSystem

§

impl Send for Fat32FileSystem

§

impl Sync for Fat32FileSystem

§

impl Unpin for Fat32FileSystem

§

impl !UnwindSafe for Fat32FileSystem

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.