![]() |
Max OS 0.3
|
Common operations for an ext2 volume that are used by both files & directories (like block & inode allocation) More...
#include <ext2.h>
Public Member Functions | |
| Ext2Volume (drivers::disk::Disk *disk, lba_t partition_offset) | |
| Construct a new Ext2 Volume object, reads the superblock and block group descriptors. | |
| void | write_block (uint32_t block_num, common::buffer_t *buffer) const |
| write a single block from a buffer into onto the disk | |
| void | write_inode (uint32_t inode_num, inode_t *inode) const |
| write an inode to the filesystem | |
| uint32_t | create_inode (bool is_directory) |
| Allocates a new inode and sets the base metadata. Also allocates block 0 of the inode. | |
| void | free_inode (uint32_t inode) |
| Mark an inode as free. Note: does NOT unallocated the inodes blocks, use free_group_blocks(). | |
| void | read_block (uint32_t block_num, common::buffer_t *buffer) const |
| Reads a single block from the disk into a buffer. | |
| inode_t | read_inode (uint32_t inode_num) const |
| read an inode from the filesystem | |
| uint32_t | allocate_block () |
| Allocates a single block to be used by an inode. | |
| common::Vector< uint32_t > | allocate_blocks (uint32_t amount) |
| Allocates a set of blocks to be used by an inode. | |
| uint32_t | bytes_to_blocks (size_t bytes) const |
| How many blocks are needed to contain a set amount of bytes. | |
| void | free_blocks (const common::Vector< uint32_t > &blocks) |
| Frees a group of blocks. Preferably with adjacent blocks apearing next to each other but not enforced. | |
Public Attributes | |
| drivers::disk::Disk * | disk |
| The disk that this volume is on. | |
| lba_t | partition_offset |
| How far into the disk this partition starts. | |
| superblock_t | superblock |
| The superblock of the ext2 filesystem. | |
| block_group_descriptor_t ** | block_groups |
| The block group descriptors. | |
| size_t | block_size |
| How large each block is (in bytes) | |
| uint32_t | block_group_descriptor_table_block |
| Where the block group descriptor table starts. | |
| uint32_t | block_group_descriptor_table_size |
| How many block groups are in the block group descriptor table. | |
| uint32_t | total_block_groups |
| How many block groups are in the filesystem. | |
| size_t | pointers_per_block |
| How many block pointers fit in a block. | |
| uint32_t | inodes_per_block |
| How many inodes fit in a block. | |
| uint32_t | sectors_per_block |
| How many sectors does a block take. | |
| common::Spinlock | ext2_lock |
| Lock for synchronised access to the volume (. | |
Common operations for an ext2 volume that are used by both files & directories (like block & inode allocation)
| Ext2Volume::Ext2Volume | ( | drivers::disk::Disk * | disk, |
| lba_t | partition_offset | ||
| ) |
Construct a new Ext2 Volume object, reads the superblock and block group descriptors.
| disk | The disk to read from |
| partition_offset | The offset of the partition on the disk in sectors |
Definition at line 27 of file ext2.cpp.
| uint32_t Ext2Volume::allocate_block | ( | ) |
Allocates a single block to be used by an inode.
Definition at line 177 of file ext2.cpp.
References allocate_blocks().
Referenced by create_inode().
Allocates a set of blocks to be used by an inode.
| amount | The amount of blocks to allocate |
Definition at line 188 of file ext2.cpp.
References block_groups, free_blocks(), and total_block_groups.
Referenced by allocate_block(), and MaxOS::filesystem::format::ext2::InodeHandler::grow().
How many blocks are needed to contain a set amount of bytes.
| bytes | Bytes needed |
Definition at line 360 of file ext2.cpp.
References block_size.
Referenced by MaxOS::filesystem::format::ext2::InodeHandler::grow().
Allocates a new inode and sets the base metadata. Also allocates block 0 of the inode.
| is_directory | is the inode to be used for a directory |
Definition at line 370 of file ext2.cpp.
References MaxOS::drivers::clock::Clock::active_clock(), allocate_block(), block_groups, block_size, ext2_lock, MaxOS::common::Spinlock::lock(), read_block(), superblock, total_block_groups, MaxOS::common::Spinlock::unlock(), write_block(), and write_inode().
| void Ext2Volume::free_blocks | ( | const common::Vector< uint32_t > & | blocks | ) |
Frees a group of blocks. Preferably with adjacent blocks apearing next to each other but not enforced.
| blocks | The blocks to free |
Definition at line 464 of file ext2.cpp.
References superblock.
Referenced by allocate_blocks(), and MaxOS::filesystem::format::ext2::InodeHandler::free().
Mark an inode as free. Note: does NOT unallocated the inodes blocks, use free_group_blocks().
| inode | The inode number to mark as free |
Definition at line 434 of file ext2.cpp.
References block_groups, block_size, read_block(), superblock, and write_block().
Referenced by MaxOS::filesystem::format::ext2::InodeHandler::free().
| void Ext2Volume::read_block | ( | uint32_t | block_num, |
| common::buffer_t * | buffer | ||
| ) | const |
Reads a single block from the disk into a buffer.
| block_num | The block to read |
| buffer | The buffer to read into |
Definition at line 129 of file ext2.cpp.
References disk, partition_offset, MaxOS::drivers::disk::Disk::read(), sectors_per_block, and MaxOS::common::Buffer::set_offset().
Referenced by create_inode(), free_inode(), MaxOS::filesystem::format::ext2::Ext2File::read(), MaxOS::filesystem::format::ext2::Ext2Directory::read_from_disk(), read_inode(), MaxOS::filesystem::format::ext2::Ext2File::write(), and write_inode().
read an inode from the filesystem
| inode_num | The inode index |
Definition at line 149 of file ext2.cpp.
References block_groups, block_size, MaxOS::common::Buffer::copy_to(), read_block(), and superblock.
| void Ext2Volume::write_block | ( | uint32_t | block_num, |
| common::buffer_t * | buffer | ||
| ) | const |
write a single block from a buffer into onto the disk
| block_num | The block to update |
| buffer | The buffer to read from |
Definition at line 80 of file ext2.cpp.
References disk, partition_offset, sectors_per_block, MaxOS::common::Buffer::set_offset(), MaxOS::common::Buffer::update_offset, and MaxOS::drivers::disk::Disk::write().
Referenced by create_inode(), free_inode(), MaxOS::filesystem::format::ext2::Ext2File::write(), and write_inode().
write an inode to the filesystem
| inode_num | The inode index |
| inode | The inode to read from |
Definition at line 102 of file ext2.cpp.
References block_groups, block_size, MaxOS::common::Buffer::copy_from(), read_block(), superblock, and write_block().
Referenced by create_inode(), and MaxOS::filesystem::format::ext2::InodeHandler::save().
| uint32_t MaxOS::filesystem::format::ext2::Ext2Volume::block_group_descriptor_table_block |
| uint32_t MaxOS::filesystem::format::ext2::Ext2Volume::block_group_descriptor_table_size |
| block_group_descriptor_t** MaxOS::filesystem::format::ext2::Ext2Volume::block_groups |
The block group descriptors.
Definition at line 340 of file ext2.h.
Referenced by allocate_blocks(), create_inode(), free_inode(), read_inode(), and write_inode().
| size_t MaxOS::filesystem::format::ext2::Ext2Volume::block_size |
How large each block is (in bytes)
Definition at line 342 of file ext2.h.
Referenced by bytes_to_blocks(), create_inode(), free_inode(), MaxOS::filesystem::format::ext2::InodeHandler::InodeHandler(), MaxOS::filesystem::format::ext2::Ext2File::read(), MaxOS::filesystem::format::ext2::Ext2Directory::read_from_disk(), read_inode(), MaxOS::filesystem::format::ext2::Ext2File::write(), and write_inode().
| drivers::disk::Disk* MaxOS::filesystem::format::ext2::Ext2Volume::disk |
The disk that this volume is on.
Definition at line 336 of file ext2.h.
Referenced by read_block(), and write_block().
| common::Spinlock MaxOS::filesystem::format::ext2::Ext2Volume::ext2_lock |
Lock for synchronised access to the volume (.
Definition at line 350 of file ext2.h.
Referenced by create_inode(), MaxOS::filesystem::format::ext2::InodeHandler::free(), MaxOS::filesystem::format::ext2::Ext2File::read(), MaxOS::filesystem::format::ext2::Ext2Directory::read_from_disk(), and MaxOS::filesystem::format::ext2::Ext2File::write().
| uint32_t MaxOS::filesystem::format::ext2::Ext2Volume::inodes_per_block |
| lba_t MaxOS::filesystem::format::ext2::Ext2Volume::partition_offset |
How far into the disk this partition starts.
Definition at line 337 of file ext2.h.
Referenced by read_block(), and write_block().
| size_t MaxOS::filesystem::format::ext2::Ext2Volume::pointers_per_block |
| uint32_t MaxOS::filesystem::format::ext2::Ext2Volume::sectors_per_block |
How many sectors does a block take.
Definition at line 348 of file ext2.h.
Referenced by read_block(), and write_block().
| superblock_t MaxOS::filesystem::format::ext2::Ext2Volume::superblock |
The superblock of the ext2 filesystem.
Definition at line 339 of file ext2.h.
Referenced by create_inode(), free_blocks(), free_inode(), read_inode(), and write_inode().
| uint32_t MaxOS::filesystem::format::ext2::Ext2Volume::total_block_groups |
How many block groups are in the filesystem.
Definition at line 345 of file ext2.h.
Referenced by allocate_blocks(), and create_inode().