23 size_t bs = desc->
bs, p = bs / 4, span = 1;
31 for (
int i = 1; i < depth; ++i)
41 for (
size_t i = from / span; i < p; ++i)
75 if ((S_ISLNK(inode->
mode) && !inode->
blocks) ||
76 S_ISCHR(inode->
mode) || S_ISBLK(inode->
mode))
109 bitmap_clear(&bm, index);
181 void *arg,
ino_t *ino)
183 struct ext2 *desc = dir->
p;
185 size_t bs = desc->
bs, len = strlen(name);
191 char *buf =
kmalloc(bs, &M_BUFFER, 0);
198 for (
size_t i = 0; i < dir_inode.
size / bs && err == -ENOENT; ++i) {
207 while ((
char *) d < buf + bs && d->
size) {
251 struct ext2 *desc = dir->
p;
300 struct ext2 *desc = dir->
p;
339 struct ext2 *desc = odir->
p;
348 ino_t ino, other, dummy;
364 if (err && err != -ENOENT)
376 if (S_ISDIR(
vnode->
mode) && odir != ndir) {
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
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_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_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.
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.
int ext2_close(struct vnode *vnode)
Releases a vnode when its last reference goes.
#define EXT2_DIRECT_POINTERS
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_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_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...
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_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.
void vnode_pages_free(struct vnode *vnode)
Frees a vnode's vm object and its cached pages, when the vnode itself is freed.
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.
int memcmp(const void *a, const void *b, size_t n)
Compares n bytes.
static blk_t free_tree(struct minix *desc, blk_t zone, int depth, size_t from)
Frees the zones of the tree at zone (a data zone at depth 0, or an indirect zone depth levels above t...
static uint64_t * table(paddr_t paddr)
Returns a page table, through the direct map.
static void dentry_set_ino(struct ext2_dentry *d, struct ext2_dentry *prev, void *arg)
Points an entry to another inode, the one arg points to.
static void dentry_remove(struct ext2_dentry *d, struct ext2_dentry *prev, void *arg)
Removes an entry: the previous entry takes its space, or, for the first entry of a block,...
static void ext2_inode_free(struct ext2 *desc, ino_t ino, int dir)
Marks an inode free in its group's inode bitmap, and counts it as free.
static int dentry_update(struct vnode *dir, const char *name, void(*fn)(struct ext2_dentry *d, struct ext2_dentry *prev, void *arg), void *arg, ino_t *ino)
Finds the entry name of directory dir, calls fn on it, and writes its block back.
A bitmap: its blocks, and its last bit's index.
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
uint16_t free_inodes
number of unallocated inodes
uint16_t directories_count
uint32_t imap
inodes bitmap
An inode, as it is on the disk.
uint32_t doubly_indirect_pointer
uint32_t direct_pointer[12]
uint32_t triply_indirect_pointer
uint32_t singly_indirect_pointer
uint32_t ginodes
number of inodes per block group
uint32_t free_inodes
number of unallocated inodes
A mounted ext2 filesystem.
struct ext2_superblock * superblock
struct ext2_group * groups
struct vcache * vcache
its vnodes in use, by inode number
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.
size_t ref
how many references there are to it
void * p
the filesystem's own data
int gettime(struct timespec *ts)
Reads the wall clock (CLOCK_REALTIME).
int vcache_remove(struct vcache *vcache, struct vnode *vnode)
Takes a vnode out of a cache.