The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ext2_alloc.c File Reference
#include "ext2_internal.h"

Functions

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 ext2_write_inode (ext2_volume_t *volume, uint32_t inode_number, const ext2_inode_t *inode)
 write an inode back to the volume.

Function Documentation

◆ 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.

◆ ext2_write_inode()

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

write an inode back to the volume.

Returns
true on success.