24 return r == (
ssize_t) size ? 0 : r < 0 ? (int) r : -EIO;
36 uint32_t bgd_table = (desc->
bs == 1024)? 2048 : desc->
bs;
87 for (
unsigned i = 0; i < desc->
ngroups; ++i) {
98 for (idx = 0; idx < bm.
max_idx && bitmap_check(&bm, idx); ++idx);
112 bitmap_set(&bm, idx);
167 bitmap_clear(&bm, block_idx);
int ext2_block_free(struct ext2 *desc, uint32_t block)
Frees a block: its bit is cleared in its group's block bitmap, and the free counts go up.
int ext2_block_write(struct ext2 *desc, uint32_t number, void *buf)
Writes a block to the disk.
int ext2_io(struct ext2 *desc, int write, off_t off, size_t size, void *buf)
Reads or writes bytes of the filesystem's disk, all of them.
int ext2_bgd_table_rewrite(struct ext2 *desc)
Writes the block group descriptor table back to the disk, after a change to a group's counts.
int ext2_block_read(struct ext2 *desc, uint32_t number, void *buf)
Reads a block from the disk.
int ext2_block_alloc(struct ext2 *desc, uint32_t *block)
Allocates a free block: its bit is set in its group's block bitmap, the free counts go down,...
int ext2_superblock_rewrite(struct ext2 *desc)
Writes the in-memory copy of the superblock back to the disk, after a change to its counts of free bl...
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
A bitmap: its blocks, and its last bit's index.
A block group descriptor, as it is on the disk.
uint16_t free_blocks
number of unallocated blocks
uint32_t bmap
blocks bitmap
uint32_t nblocks
number of blocks
uint32_t free_blocks
number of unallocated blocks
uint32_t dblock
first data block
uint32_t gblocks
number of blocks per block group
A mounted ext2 filesystem.
struct ext2_superblock * superblock
struct ext2_group * groups
size_t ngroups
number of block group descriptors
ssize_t vfs_write(struct vnode *vnode, off_t off, size_t size, void *buf)
Writes to a vnode from a kernel buffer.