127 return depth == 2 ? desc->
bs /
sizeof(
uint16_t) : 1;
143 size_t bs = desc->
bs;
144 size_t nr_blocks = (m_inode->
size + bs - 1) / bs;
148 if (idx >= nr_blocks)
151 int depth =
zone_tree(desc, idx, &slot, &rel);
158 for (; depth && zone; --depth) {
165 zone =
table[rel / span];
175 return r == (
ssize_t) bs ? 0 : r < 0 ? r : -EIO;
194 return r == (
ssize_t) desc->
bs ? 0 : r < 0 ? r : -EIO;
210 int slot, err = 0, changed = 0;
212 int depth =
zone_tree(desc, idx, &slot, &rel);
226 inode->
zones[slot] = zone;
233 for (; !err && depth; --depth) {
241 if (!(next =
table[rel / span])) {
255 table[rel / span] = next;
265 err = err ? err : werr;
272 return r == (
ssize_t) desc->
bs ? 0 : r < 0 ? r : -EIO;
293 for (
size_t i = from / span; i < p; ++i)
320 if (S_ISCHR(inode->
mode) || S_ISBLK(inode->
mode))
345 for (; ino <= desc->
imap.
max_idx && bitmap_check(&desc->
imap, ino); ++ino);
351 bitmap_set(&desc->
imap, ino);
372 bitmap_clear(&desc->
imap, ino);
int bcache_remove(struct bcache *bcache, uint64_t off)
Takes a block out of a cache.
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 minix_block_write(struct minix *desc, blk_t blk, void *buf)
Writes a block to the disk.
void minix_block_free(struct minix *desc, blk_t blk)
Frees a zone: its bit is cleared in the zone bitmap, which is written back at once,...
ssize_t minix_block_read(struct minix *desc, blk_t blk, void *buf)
Reads a block from the disk.
int minix_bcache_get(struct minix *desc, blk_t blk, void **data)
Gets a block from the block cache, reading it from the disk into the cache if it isn't there.
blk_t minix_block_alloc(struct minix *desc)
Allocates a free zone: its bit is set in the zone bitmap, which is written back to the disk at once.
static off_t minix_inode_off(struct minix *desc, ino_t ino)
Returns where an inode is on the disk, in bytes, or -EINVAL for an inode number that doesn't exist.
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...
ssize_t minix_inode_block_write(struct minix *desc, struct minix_inode *inode, ino_t ino, size_t idx, void *buf)
Writes a zone of a file, allocating it and the indirect zones above it if they don't exist yet.
ssize_t minix_inode_block_read(struct minix *desc, struct minix_inode *m_inode, size_t idx, void *buf)
Reads a zone of a file.
int minix_inode_read(struct minix *desc, ino_t ino, struct minix_inode *ref)
Reads an inode from the disk.
int minix_inode_write(struct minix *desc, ino_t ino, struct minix_inode *ref)
Writes an inode to the disk.
void minix_zones_free(struct minix *desc, struct minix_inode *inode, size_t from)
Frees a file's zones, from a zone on, when the file is truncated or removed.
void minix_inode_free(struct minix *desc, ino_t ino)
Frees an inode: its bit is cleared in the inode bitmap, which is written back at once.
static int zone_tree(struct minix *desc, size_t idx, int *slot, size_t *rel)
Finds where zone idx of a file is in its tree: the slot of zones[] it hangs from (0 to 6 for the dire...
static size_t zone_span(struct minix *desc, int depth)
Returns how many data zones are under one pointer of an indirect zone that is depth levels above them...
ino_t minix_inode_alloc(struct minix *desc)
Allocates a free inode: its bit is set in the inode bitmap, which is written back to the disk at once...
#define MINIX_DIRECT_ZONES
static uint64_t * table(paddr_t paddr)
Returns a page table, through the direct map.
static paddr_t table_alloc(void)
Allocates an empty page table.
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
unsigned short int uint16_t
A minix v1 inode, as it is on the disk.
A mounted minix filesystem.
struct minix_superblock * superblock
ssize_t vfs_write(struct vnode *vnode, off_t off, size_t size, void *buf)
Writes to a vnode from a kernel buffer.