16#define EXT2_SIGNATURE 0xEF53
21#define EXT2_INCOMPAT_FILETYPE 0x0002
22#define EXT2_RO_COMPAT_SPARSE_SUPER 0x0001
23#define EXT2_RO_COMPAT_LARGE_FILE 0x0002
26#define EXT2_INCOMPAT_SUPPORTED EXT2_INCOMPAT_FILETYPE
27#define EXT2_RO_COMPAT_SUPPORTED (EXT2_RO_COMPAT_SPARSE_SUPER | EXT2_RO_COMPAT_LARGE_FILE)
31#define EXT2_GOOD_OLD_INODE_SIZE 128
156#define EXT2_DENTRY_TYPE_BAD 0
157#define EXT2_DENTRY_TYPE_RGL 1
158#define EXT2_DENTRY_TYPE_DIR 2
159#define EXT2_DENTRY_TYPE_CHR 3
160#define EXT2_DENTRY_TYPE_BLK 4
161#define EXT2_DENTRY_TYPE_FIFO 5
162#define EXT2_DENTRY_TYPE_SCKT 6
163#define EXT2_DENTRY_TYPE_SLINK 7
165#define EXT2_DIRECT_POINTERS 12
199int ext2_io(
struct ext2 *desc,
int write,
off_t off,
size_t size,
void *buf);
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_dentry_create(struct vnode *dir, const char *name, ino_t ino, mode_t mode)
Adds an entry to a directory.
int ext2_dentry_find(struct ext2 *desc, struct ext2_inode *inode, const char *name, ino_t *ino)
Finds the inode number of a name in a directory.
int ext2_inode_build(struct ext2 *desc, ino_t ino, struct vnode **ref_inode)
Gets the vnode of an inode: the cached one if it's in use, or a new one made from the inode on the di...
int ext2_inode_sync(struct vnode *inode)
Writes a vnode's attributes back to its inode on the disk.
ssize_t ext2_write(struct vnode *node, off_t offset, struct iobuf *io)
Writes to a file, which grows if the write goes past its end.
void ext2_blocks_free(struct ext2 *desc, struct ext2_inode *inode, size_t from)
Frees a file's blocks, from a block on, when the file is truncated or removed.
ssize_t ext2_read(struct vnode *node, off_t offset, struct iobuf *io)
Reads from a file.
int ext2_inode_alloc(struct ext2 *desc, ino_t *ino)
Allocates a free inode: its bit is set in its group's inode bitmap, and the free counts go down.
int ext2_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.
int ext2_close(struct vnode *vnode)
Releases a vnode when its last reference goes.
int ext2_inode_read(struct ext2 *desc, ino_t inode, struct ext2_inode *ref)
Reads an inode from the disk.
int ext2_vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
Adds an entry for an existing file (a hard link) to a directory.
int ext2_trunc(struct vnode *inode, off_t len)
Changes a file's length.
int ext2_vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
Renames an entry, possibly to another directory, replacing an entry at the new name (the VFS checked ...
void ext2_inode_discard(struct ext2 *desc, ino_t ino)
Frees an inode that has no links left, and the blocks it uses.
int ext2_inode_block_read(struct ext2 *desc, struct ext2_inode *inode, size_t idx, void *buf)
Reads a block of a file.
int ext2_vmknod(struct vnode *dir, const char *fn, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Makes a node in a directory: a new inode, and an entry for it.
int ext2_inode_write(struct ext2 *desc, ino_t inode, struct ext2_inode *i)
Writes an inode to the disk.
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...
ssize_t ext2_readdir(struct vnode *dir, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset; unused entries don't count.
int ext2_setattr(struct vnode *vnode)
Stores a vnode's attributes (mode, owner, times) in its inode.
int ext2_vunlink(struct vnode *dir, const char *fn, struct uio *uio)
Removes an entry from a directory, and drops a link to its file.
int ext2_finddir(struct vnode *dir, const char *fn, struct dirent *dirent)
Finds the entry of a directory that has a name.
int ext2_inode_block_write(struct ext2 *desc, struct ext2_inode *inode, uint32_t inode_nr, size_t idx, void *buf)
Writes a block of a file, allocating it and the indirect blocks above it if they don't exist yet.
unsigned short int uint16_t
A device driver: its operations, any of which may be NULL.
A directory entry, as it is on the disk.
uint16_t size
entry total size
uint8_t name[0]
the name follows (not NUL-terminated)
uint8_t length
name length
A block group descriptor, as it is on the disk.
uint16_t free_inodes
number of unallocated inodes
uint16_t directories_count
uint32_t imap
inodes bitmap
uint16_t free_blocks
number of unallocated blocks
uint32_t bmap
blocks bitmap
uint32_t inodes
inode table
An inode, as it is on the disk.
uint32_t extended_attribute_block
uint32_t doubly_indirect_pointer
uint32_t direct_pointer[12]
uint32_t triply_indirect_pointer
uint32_t generation_number
uint32_t singly_indirect_pointer
The superblock, as it is on the disk, 1024 bytes into it.
uint32_t mtime
last mount time
uint32_t head_of_orphan_inode_list
uint32_t ginodes
number of inodes per block group
uint32_t compression_algorithms
uint32_t time_between_fsck
uint32_t frag_size
log(fragment size)
uint32_t nrblocks
number of reserved blocks
uint16_t allowed_times_mounted
uint8_t blocks_to_preallocate_for_directories
uint32_t nblocks
number of blocks
uint32_t gfrags
number of fragments per block group
uint32_t free_inodes
number of unallocated inodes
uint32_t wtime
last write time
uint32_t free_blocks
number of unallocated blocks
uint32_t dblock
first data block
uint8_t path_last_mounted_to[64]
uint32_t first_non_reserved_inode
uint32_t ninodes
number of inodes
uint32_t feature_ro_compat
uint32_t feature_incompat
uint16_t filesystem_state
uint32_t gblocks
number of blocks per block group
uint32_t block_size
log(block size)
uint8_t blocks_to_preallocate_for_files
A mounted ext2 filesystem.
struct ext2_superblock * superblock
struct ext2_group * groups
struct vcache * vcache
its vnodes in use, by inode number
size_t ngroups
number of block group descriptors
size_t inode_size
an inode's size on the disk (revision 0's, or the superblock's)
int filetype
directory entries have their file's type (EXT2_INCOMPAT_FILETYPE); without it, the byte is 0
Who does a filesystem operation: where its paths start, and its credentials and umask.
A file in memory (a vnode): what its inode says, and the kernel's own state.