The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ext2_internal.h File Reference
#include "ext2.h"
#include "common/error.h"
#include "common/memory.h"
#include "common/string.h"
#include "common/stdio.h"

Go to the source code of this file.

Macros

#define EXT2_SECTOR_SIZE   512u
#define EXT2_MIN(a, b)
#define OFFSETOF(type, member)

Functions

bool read_abs_bytes (block_device_t *disk, uint32_t byte_offset, uint32_t size, void *out, uint8_t *sector_buf)
 reads bytes from the disk at the specified absolute byte offset and size into the provided output buffer.
bool read_block (ext2_volume_t *volume, uint32_t block, void *out)
 reads a block from the EXT2 volume into the provided output buffer.
bool read_group_desc (ext2_volume_t *volume, uint32_t group, ext2_block_group_desc_t *out_desc)
 reads the block group descriptor for the specified group from the EXT2 volume into the provided output structure.
bool write_abs_bytes (block_device_t *disk, uint32_t byte_offset, uint32_t size, const void *in, uint8_t *sector_buf)
 writes bytes to the disk at the specified absolute byte offset and size from the provided input buffer.
bool write_block (ext2_volume_t *volume, uint32_t block, const void *in)
 writes a block to the EXT2 volume from the provided input buffer.
bool write_group_desc (ext2_volume_t *volume, uint32_t group, const ext2_block_group_desc_t *desc)
 writes the block group descriptor for the specified group to the EXT2 volume from the provided input structure.
bool write_superblock (ext2_volume_t *volume)
 writes the superblock to the EXT2 volume.
bool read_inode_bitmap (ext2_volume_t *volume, uint32_t group, uint8_t *bitmap)
 reads the inode bitmap for the specified block group from the EXT2 volume into the provided output buffer.
bool write_inode_bitmap (ext2_volume_t *volume, uint32_t group, const uint8_t *bitmap)
 writes the inode bitmap for the specified block group to the EXT2 volume from the provided input buffer.
bool read_block_bitmap (ext2_volume_t *volume, uint32_t group, uint8_t *bitmap)
 reads the block bitmap for the specified block group from the EXT2 volume into the provided output buffer.
bool write_block_bitmap (ext2_volume_t *volume, uint32_t group, const uint8_t *bitmap)
 writes the block bitmap for the specified block group to the EXT2 volume from the provided input buffer.
bool inode_location (ext2_volume_t *volume, uint32_t inode_number, ext2_block_group_desc_t *desc_out, uint32_t *inode_byte_offset_out, uint32_t *group_out)
 determines the location of a specific inode within the EXT2 volume, including its block group descriptor and byte offset.
bool write_inode (ext2_volume_t *volume, uint32_t inode_number, const ext2_inode_t *inode)
 writes an inode to the EXT2 volume at the specified inode number.
bool update_group_and_super_counts (ext2_volume_t *volume, uint32_t group, int32_t free_blocks_delta, int32_t free_inodes_delta, int32_t used_dirs_delta)
 updates the free block count, free inode count, and used directory count in both the block group descriptor and the superblock for the specified block group.
bool alloc_inode (ext2_volume_t *volume, uint32_t *inode_number_out)
 allocates a free inode from the EXT2 volume and returns its inode number.
bool free_inode (ext2_volume_t *volume, uint32_t inode_number)
 frees an allocated inode in the EXT2 volume, marking it as available for future use.
bool alloc_block (ext2_volume_t *volume, uint32_t *block_number_out)
 allocates a free block from the EXT2 volume and returns its block number.
bool free_block (ext2_volume_t *volume, uint32_t block_number)
 frees an allocated block in the EXT2 volume, marking it as available for future use.
bool free_inode_block_chain (ext2_volume_t *volume, ext2_inode_t *inode)
 frees all blocks associated with an inode, including direct, single indirect, double indirect, and triple indirect blocks.
bool inode_is_dir (const ext2_inode_t *inode)
 determines if a given inode represents a directory by checking its mode against the directory file type constant.
bool inode_is_regular (const ext2_inode_t *inode)
 determines if a given inode represents a regular file by checking its mode against the regular file type constant.
bool inode_is_directory (const ext2_inode_t *inode)
 determines if a given inode represents a directory by checking its mode against the directory file type constant.
uint8_t inode_to_file_type (const ext2_inode_t *inode)
 maps an inode's mode to the corresponding EXT2 file type constant, returning the appropriate value for directory or regular file types, or 0 for unsupported types.
bool inode_is_symlink (const ext2_inode_t *inode)
bool inode_is_fast_symlink (const ext2_inode_t *inode)
bool inode_has_no_blocks (const ext2_inode_t *inode)
kerr_t find_in_directory (ext2_volume_t *volume, uint32_t dir_inode_number, const char *name, uint32_t name_len, uint32_t *inode_out)
 searches for a directory entry with a specific name within a given directory inode, returning the inode number of the found entry if it exists.
bool resolve_data_block (ext2_volume_t *volume, const ext2_inode_t *inode, uint32_t logical_block_index, uint32_t *physical_block_out)
 resolves a logical block index within an inode to its corresponding physical block number on disk, handling direct, single indirect, double indirect, and triple indirect block addressing as defined by the EXT2 filesystem structure.
bool find_directory_entry (ext2_volume_t *volume, uint32_t dir_inode_number, const char *name, uint32_t name_len, uint32_t *block_index_out, uint32_t *offset_out, ext2_dir_entry_t *entry_out)
 searches for a directory entry with a specific name within a given directory inode, returning the block index, offset, and entry details if found.
bool append_or_replace_directory_entry (ext2_volume_t *volume, uint32_t parent_inode_number, ext2_inode_t *parent_inode, const char *name, uint32_t name_len, uint32_t child_inode_number, uint8_t file_type)
 appends a new directory entry to a parent directory inode or replaces an existing entry with the same name, ensuring proper space allocation and alignment within the directory's data blocks.
bool update_directory_entry_name (ext2_volume_t *volume, uint32_t dir_inode_number, const char *old_name, uint32_t old_name_len, const char *new_name, uint32_t new_name_len)
 updates the name of an existing directory entry within a specified directory inode, ensuring that the new name fits within the allocated space for the entry.
bool directory_is_empty (ext2_volume_t *volume, uint32_t inode_number)
 checks if a directory represented by a given inode number is empty, meaning it contains no entries other than the standard '.
bool update_directory_parent_link (ext2_volume_t *volume, uint32_t dir_inode_number, uint32_t parent_inode_number)
 updates the '..' entry in a directory to point to a new parent inode number, effectively changing the parent directory reference for that directory.
bool remove_directory_entry (ext2_volume_t *volume, uint32_t dir_inode_number, const char *name, uint32_t name_len)
 removes a directory entry with a specific name from a given directory inode, effectively deleting the entry from the directory's data blocks.
bool setup_new_file_inode (ext2_inode_t *inode)
 initializes a new inode structure for a regular file, setting its mode, link count, and clearing other fields to prepare it for use in the filesystem.
bool setup_new_dir_inode (ext2_inode_t *inode, ext2_volume_t *volume)
 initializes a new inode structure for a directory, setting its mode, link count, size, and block count to prepare it for use in the filesystem.
bool initialize_directory_block (ext2_volume_t *volume, uint32_t inode_number, uint32_t parent_inode_number, uint32_t block_number)
 initializes a new directory block with the standard '.
bool lookup_parent_and_name (ext2_volume_t *volume, const char *path, uint32_t *parent_inode_out, char *name_out, uint32_t name_out_size, char *parent_path, uint32_t parent_path_size)
 looks up the parent directory inode and the name of the final component in a given path, splitting the path into its parent and child components and verifying that the parent is a valid directory.
bool lookup_child_type (ext2_volume_t *volume, uint32_t parent_inode_number, const char *name, uint32_t name_len, uint32_t *child_inode_out, uint8_t *child_type_out)
 looks up a child directory entry by name within a specified parent directory inode, returning the child's inode number and file type if found.
bool free_inode_and_blocks (ext2_volume_t *volume, uint32_t inode_number, ext2_inode_t *inode)
 frees the blocks associated with a given inode and then frees the inode itself, effectively removing the file or directory represented by that inode from the filesystem.

Macro Definition Documentation

◆ EXT2_SECTOR_SIZE

#define EXT2_SECTOR_SIZE   512u

◆ EXT2_MIN

#define EXT2_MIN ( a,
b )
Value:
((a) < (b) ? (a) : (b))

◆ OFFSETOF

#define OFFSETOF ( type,
member )
Value:
((uint32_t)offsetof(type, member))
unsigned int uint32_t
Definition fb.h:17
#define offsetof(type, member)
Definition stddef.h:17

Function Documentation

◆ read_abs_bytes()

bool read_abs_bytes ( block_device_t * disk,
uint32_t byte_offset,
uint32_t size,
void * out,
uint8_t * sector_buf )

reads bytes from the disk at the specified absolute byte offset and size into the provided output buffer.

Parameters
diskpointer to the block device representing the disk.
byte_offsetthe absolute byte offset on the disk to start reading from.
sizethe number of bytes to read.
outpointer to the output buffer where the read bytes will be stored.
sector_bufscratch buffer for partial-sector reads (must be EXT2_SECTOR_SIZE bytes).
Returns
true if the read operation was successful, false otherwise.

◆ read_block()

bool read_block ( ext2_volume_t * volume,
uint32_t block,
void * out )

reads a block from the EXT2 volume into the provided output buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
blockthe block number to read from the volume.
outpointer to the output buffer where the read block will be stored.
Returns
true if the read operation was successful, false otherwise.

◆ read_group_desc()

bool read_group_desc ( ext2_volume_t * volume,
uint32_t group,
ext2_block_group_desc_t * out_desc )

reads the block group descriptor for the specified group from the EXT2 volume into the provided output structure.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to read the descriptor for.
out_descpointer to the ext2_block_group_desc_t structure where the read descriptor will be stored.
Returns
true if the read operation was successful, false otherwise.

◆ write_abs_bytes()

bool write_abs_bytes ( block_device_t * disk,
uint32_t byte_offset,
uint32_t size,
const void * in,
uint8_t * sector_buf )

writes bytes to the disk at the specified absolute byte offset and size from the provided input buffer.

Parameters
diskpointer to the block device representing the disk.
byte_offsetthe absolute byte offset on the disk to start writing to.
sizethe number of bytes to write.
inpointer to the input buffer containing the bytes to be written.
sector_bufscratch buffer for partial-sector read-modify-write (must be EXT2_SECTOR_SIZE bytes).
Returns
true if the write operation was successful, false otherwise.

◆ write_block()

bool write_block ( ext2_volume_t * volume,
uint32_t block,
const void * in )

writes a block to the EXT2 volume from the provided input buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
blockthe block number to write to the volume.
inpointer to the input buffer containing the block data to be written.
Returns
true if the write operation was successful, false otherwise.

◆ write_group_desc()

bool write_group_desc ( ext2_volume_t * volume,
uint32_t group,
const ext2_block_group_desc_t * desc )

writes the block group descriptor for the specified group to the EXT2 volume from the provided input structure.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to write the descriptor for.
descpointer to the ext2_block_group_desc_t structure containing the descriptor data to be written.
Returns
true if the write operation was successful, false otherwise.

◆ write_superblock()

bool write_superblock ( ext2_volume_t * volume)

writes the superblock to the EXT2 volume.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
Returns
true if the write operation was successful, false otherwise.

◆ read_inode_bitmap()

bool read_inode_bitmap ( ext2_volume_t * volume,
uint32_t group,
uint8_t * bitmap )

reads the inode bitmap for the specified block group from the EXT2 volume into the provided output buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to read the inode bitmap for.
bitmappointer to the output buffer where the read inode bitmap will be stored.
Returns
true if the read operation was successful, false otherwise.

◆ write_inode_bitmap()

bool write_inode_bitmap ( ext2_volume_t * volume,
uint32_t group,
const uint8_t * bitmap )

writes the inode bitmap for the specified block group to the EXT2 volume from the provided input buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to write the inode bitmap for.
bitmappointer to the input buffer containing the inode bitmap data to be written.
Returns
true if the write operation was successful, false otherwise.

◆ read_block_bitmap()

bool read_block_bitmap ( ext2_volume_t * volume,
uint32_t group,
uint8_t * bitmap )

reads the block bitmap for the specified block group from the EXT2 volume into the provided output buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to read the block bitmap for.
bitmappointer to the output buffer where the read block bitmap will be stored.
Returns
true if the read operation was successful, false otherwise.

◆ write_block_bitmap()

bool write_block_bitmap ( ext2_volume_t * volume,
uint32_t group,
const uint8_t * bitmap )

writes the block bitmap for the specified block group to the EXT2 volume from the provided input buffer.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to write the block bitmap for.
bitmappointer to the input buffer containing the block bitmap data to be written.
Returns
true if the write operation was successful, false otherwise.

◆ inode_location()

bool inode_location ( ext2_volume_t * volume,
uint32_t inode_number,
ext2_block_group_desc_t * desc_out,
uint32_t * inode_byte_offset_out,
uint32_t * group_out )

determines the location of a specific inode within the EXT2 volume, including its block group descriptor and byte offset.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number to locate (1-based index).
desc_outpointer to an ext2_block_group_desc_t structure where the block group descriptor will be stored.
inode_byte_offset_outpointer to a variable where the byte offset of the inode within the volume will be stored.
group_outoptional pointer to a variable where the block group number will be stored (can be NULL if not needed).
Returns
true if the inode location was successfully determined, false otherwise.

◆ write_inode()

bool write_inode ( ext2_volume_t * volume,
uint32_t inode_number,
const ext2_inode_t * inode )

writes an inode to the EXT2 volume at the specified inode number.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number to write to (1-based index).
inodepointer to the ext2_inode_t structure containing the inode data to be written.
Returns
true if the write operation was successful, false otherwise.

◆ update_group_and_super_counts()

bool update_group_and_super_counts ( ext2_volume_t * volume,
uint32_t group,
int32_t free_blocks_delta,
int32_t free_inodes_delta,
int32_t used_dirs_delta )

updates the free block count, free inode count, and used directory count in both the block group descriptor and the superblock for the specified block group.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
groupthe block group number to update.
free_blocks_deltathe change in the number of free blocks (positive to increase, negative to decrease).
free_inodes_deltathe change in the number of free inodes (positive to increase, negative to decrease).
used_dirs_deltathe change in the number of used directories (positive to increase, negative to decrease).
Returns
true if the update operation was successful, false otherwise.

◆ alloc_inode()

bool alloc_inode ( ext2_volume_t * volume,
uint32_t * inode_number_out )

allocates a free inode from the EXT2 volume and returns its inode number.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_number_outpointer to a variable where the allocated inode number will be stored (1-based index).
Returns
true if an inode was successfully allocated and its number is stored in inode_number_out, false if no free inode was available or an error occurred.

◆ free_inode()

bool free_inode ( ext2_volume_t * volume,
uint32_t inode_number )

frees an allocated inode in the EXT2 volume, marking it as available for future use.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number to free (1-based index).
Returns
true if the inode was successfully freed, false if the inode number was invalid or an error occurred during the operation.

◆ alloc_block()

bool alloc_block ( ext2_volume_t * volume,
uint32_t * block_number_out )

allocates a free block from the EXT2 volume and returns its block number.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
block_number_outpointer to a variable where the allocated block number will be stored.
Returns
true if a block was successfully allocated and its number is stored in block_number_out, false if no free block was available or an error occurred.

◆ free_block()

bool free_block ( ext2_volume_t * volume,
uint32_t block_number )

frees an allocated block in the EXT2 volume, marking it as available for future use.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
block_numberthe block number to free.
Returns
true if the block was successfully freed, false if the block number was invalid or an error occurred during the operation.

◆ free_inode_block_chain()

bool free_inode_block_chain ( ext2_volume_t * volume,
ext2_inode_t * inode )

frees all blocks associated with an inode, including direct, single indirect, double indirect, and triple indirect blocks.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inodepointer to the ext2_inode_t structure representing the inode whose blocks are to be freed.
Returns
true if all blocks were successfully freed, false if an error occurred during the operation or if the volume or inode pointers were invalid.

◆ inode_is_dir()

bool inode_is_dir ( const ext2_inode_t * inode)

determines if a given inode represents a directory by checking its mode against the directory file type constant.

Parameters
inodepointer to the ext2_inode_t structure to be checked.
Returns
true if the inode represents a directory, false otherwise.

◆ inode_is_regular()

bool inode_is_regular ( const ext2_inode_t * inode)

determines if a given inode represents a regular file by checking its mode against the regular file type constant.

Parameters
inodepointer to the ext2_inode_t structure to be checked.
Returns
true if the inode represents a regular file, false otherwise.

◆ inode_is_directory()

bool inode_is_directory ( const ext2_inode_t * inode)

determines if a given inode represents a directory by checking its mode against the directory file type constant.

Parameters
inodepointer to the ext2_inode_t structure to be checked.
Returns
true if the inode represents a directory, false otherwise.

◆ inode_to_file_type()

uint8_t inode_to_file_type ( const ext2_inode_t * inode)

maps an inode's mode to the corresponding EXT2 file type constant, returning the appropriate value for directory or regular file types, or 0 for unsupported types.

Parameters
inodepointer to the ext2_inode_t structure whose file type is to be determined.
Returns
the EXT2 file type constant corresponding to the inode's mode, or 0 if the inode does not represent a directory or regular file.

◆ inode_is_symlink()

bool inode_is_symlink ( const ext2_inode_t * inode)

◆ inode_is_fast_symlink()

bool inode_is_fast_symlink ( const ext2_inode_t * inode)

◆ inode_has_no_blocks()

bool inode_has_no_blocks ( const ext2_inode_t * inode)

◆ find_in_directory()

kerr_t find_in_directory ( ext2_volume_t * volume,
uint32_t dir_inode_number,
const char * name,
uint32_t name_len,
uint32_t * inode_out )

searches for a directory entry with a specific name within a given directory inode, returning the inode number of the found entry if it exists.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
dir_inode_numberthe inode number of the directory to search within.
namethe name of the directory entry to search for.
name_lenthe length of the name to search for.
inode_outpointer to a variable where the inode number of the found entry will be stored if the entry is found.
Returns
KERR_OK if the entry was found and its inode number is stored in inode_out, KERR_NOTFOUND if the entry does not exist, or KERR_IO if an error occurred during the search or if the directory inode could not be read.

◆ resolve_data_block()

bool resolve_data_block ( ext2_volume_t * volume,
const ext2_inode_t * inode,
uint32_t logical_block_index,
uint32_t * physical_block_out )

resolves a logical block index within an inode to its corresponding physical block number on disk, handling direct, single indirect, double indirect, and triple indirect block addressing as defined by the EXT2 filesystem structure.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inodepointer to the ext2_inode_t structure representing the inode whose block is being resolved.
logical_block_indexthe logical block index to resolve (0-based).
physical_block_outpointer to a variable where the resolved physical block number will be stored.
Returns
true if the logical block index was successfully resolved to a physical block number, false if an error occurred during the resolution process or if the logical block index is out of range for the given inode.

◆ find_directory_entry()

bool find_directory_entry ( ext2_volume_t * volume,
uint32_t dir_inode_number,
const char * name,
uint32_t name_len,
uint32_t * block_index_out,
uint32_t * offset_out,
ext2_dir_entry_t * entry_out )

searches for a directory entry with a specific name within a given directory inode, returning the block index, offset, and entry details if found.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
dir_inode_numberthe inode number of the directory to search within.
namethe name of the directory entry to search for.
name_lenthe length of the name to search for.
block_index_outpointer to a variable where the block index of the found entry will be stored.
offset_outpointer to a variable where the byte offset of the found entry within the block will be stored.
entry_outpointer to an ext2_dir_entry_t structure where the details of the found entry will be stored.
Returns
true if the directory entry was found and its details are stored in the output parameters, false if the entry was not found or an error occurred during the search.

◆ append_or_replace_directory_entry()

bool append_or_replace_directory_entry ( ext2_volume_t * volume,
uint32_t parent_inode_number,
ext2_inode_t * parent_inode,
const char * name,
uint32_t name_len,
uint32_t child_inode_number,
uint8_t file_type )

appends a new directory entry to a parent directory inode or replaces an existing entry with the same name, ensuring proper space allocation and alignment within the directory's data blocks.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
parent_inode_numberthe inode number of the parent directory where the entry will be added or replaced.
parent_inodepointer to the ext2_inode_t structure representing the parent directory inode.
namethe name of the directory entry to add or replace.
name_lenthe length of the name of the directory entry.
child_inode_numberthe inode number of the child entry to be added or replaced.
file_typethe type of the file (e.g., regular file, directory) for the new directory entry.
Returns
true if the directory entry was successfully appended or replaced,

◆ update_directory_entry_name()

bool update_directory_entry_name ( ext2_volume_t * volume,
uint32_t dir_inode_number,
const char * old_name,
uint32_t old_name_len,
const char * new_name,
uint32_t new_name_len )

updates the name of an existing directory entry within a specified directory inode, ensuring that the new name fits within the allocated space for the entry.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
dir_inode_numberthe inode number of the directory containing the entry to be renamed.
old_namethe current name of the directory entry to be renamed.
old_name_lenthe length of the current name of the directory entry.
new_namethe new name to assign to the directory entry.
new_name_lenthe length of the new name to assign to the directory entry.
Returns
true if the directory entry name was successfully updated, false if the entry was not found, the new name does not fit, or an error occurred during the operation.

◆ directory_is_empty()

bool directory_is_empty ( ext2_volume_t * volume,
uint32_t inode_number )

checks if a directory represented by a given inode number is empty, meaning it contains no entries other than the standard '.

' and '..' entries.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number of the directory to check.
Returns
true if the directory is empty (only contains '.' and '..'), false if it contains other entries or if an error occurred during the check.

◆ update_directory_parent_link()

bool update_directory_parent_link ( ext2_volume_t * volume,
uint32_t dir_inode_number,
uint32_t parent_inode_number )

updates the '..' entry in a directory to point to a new parent inode number, effectively changing the parent directory reference for that directory.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
dir_inode_numberthe inode number of the directory whose parent link is to be updated.
parent_inode_numberthe inode number of the new parent directory to which the '..' entry should point.
Returns
true if the parent link was successfully updated, false if the directory inode could not be read, the directory is invalid, or an error occurred during the update process.

◆ remove_directory_entry()

bool remove_directory_entry ( ext2_volume_t * volume,
uint32_t dir_inode_number,
const char * name,
uint32_t name_len )

removes a directory entry with a specific name from a given directory inode, effectively deleting the entry from the directory's data blocks.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
dir_inode_numberthe inode number of the directory from which the entry will be removed.
namethe name of the directory entry to be removed.
name_lenthe length of the name of the directory entry to be removed.
Returns
true if the directory entry was successfully removed, false if the entry was not found, the directory inode could not be read, or an error occurred during the removal process.

◆ setup_new_file_inode()

bool setup_new_file_inode ( ext2_inode_t * inode)

initializes a new inode structure for a regular file, setting its mode, link count, and clearing other fields to prepare it for use in the filesystem.

Parameters
inodepointer to the ext2_inode_t structure to be initialized.
Returns
true if the inode was successfully initialized, false if the inode pointer was null.

◆ setup_new_dir_inode()

bool setup_new_dir_inode ( ext2_inode_t * inode,
ext2_volume_t * volume )

initializes a new inode structure for a directory, setting its mode, link count, size, and block count to prepare it for use in the filesystem.

Parameters
inodepointer to the ext2_inode_t structure to be initialized.
volumepointer to the ext2_volume_t structure representing the filesystem volume, used to determine the block size and sectors per block for the directory inode.
Returns
true if the inode was successfully initialized, false if either the inode or volume pointers were null.

◆ initialize_directory_block()

bool initialize_directory_block ( ext2_volume_t * volume,
uint32_t inode_number,
uint32_t parent_inode_number,
uint32_t block_number )

initializes a new directory block with the standard '.

' and '..' entries, setting their inode numbers and ensuring proper formatting for the directory structure.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number of the directory being initialized (for the '.' entry).
parent_inode_numberthe inode number of the parent directory (for the '..' entry).
block_numberthe block number where the new directory block will be written.
Returns
true if the directory block was successfully initialized and written to the specified block number, false if an error occurred during the initialization or writing process, or if the volume pointer was null or the block size was insufficient to hold the directory entries.

◆ lookup_parent_and_name()

bool lookup_parent_and_name ( ext2_volume_t * volume,
const char * path,
uint32_t * parent_inode_out,
char * name_out,
uint32_t name_out_size,
char * parent_path,
uint32_t parent_path_size )

looks up the parent directory inode and the name of the final component in a given path, splitting the path into its parent and child components and verifying that the parent is a valid directory.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
paththe input path string to be looked up (must start with '/').
parent_inode_outpointer to a variable where the inode number of the parent directory will be stored.
name_outbuffer to store the name of the final component (file or directory) in the path.
name_out_sizethe size of the name_out buffer in bytes.
parent_pathbuffer to store the parent directory path.
parent_path_sizethe size of the parent_path buffer in bytes.
Returns
true if the parent inode and name were successfully looked up and stored in the output parameters, false if the path was invalid, the parent directory could not be found, or the parent inode is not a valid directory.

◆ lookup_child_type()

bool lookup_child_type ( ext2_volume_t * volume,
uint32_t parent_inode_number,
const char * name,
uint32_t name_len,
uint32_t * child_inode_out,
uint8_t * child_type_out )

looks up a child directory entry by name within a specified parent directory inode, returning the child's inode number and file type if found.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
parent_inode_numberthe inode number of the parent directory to search within.
namethe name of the child directory entry to look up.
name_lenthe length of the name of the child directory entry.
child_inode_outpointer to a variable where the inode number of the found child entry will be stored.
child_type_outpointer to a variable where the file type of the found child entry will be stored.
Returns
true if the child directory entry was found and its details are stored in the output parameters, false if the entry was not found or an error occurred during the lookup process.

◆ free_inode_and_blocks()

bool free_inode_and_blocks ( ext2_volume_t * volume,
uint32_t inode_number,
ext2_inode_t * inode )

frees the blocks associated with a given inode and then frees the inode itself, effectively removing the file or directory represented by that inode from the filesystem.

Parameters
volumepointer to the ext2_volume_t structure representing the filesystem volume.
inode_numberthe inode number of the file or directory to be freed.
inodepointer to the ext2_inode_t structure representing the inode to be freed. If null, the function will read the inode from the filesystem.
Returns
true if the blocks and inode were successfully freed, false if an error occurred during the process or if the volume pointer was null.