AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
inode.c File Reference

minix: inodes, and the zones of a file. More...

#include <ds/bitmap.h>
#include <minix.h>

Go to the source code of this file.

Functions

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.
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.
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 direct zones, 7 for the singly indirect one, 8 for the doubly indirect one) in *slot, and its index under that slot in *rel.
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.
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.
static int table_alloc (struct minix *desc, blk_t *zone)
 Allocates a zone for an indirect table, zeroed on the disk, and drops any cached copy of it (the zone may have been a table before).
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.
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 the data), from data zone from of the tree on.
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.
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.
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.

Detailed Description

minix: inodes, and the zones of a file.

A file's zones are found through its inode's 7 direct zones, then a singly and a doubly indirect one: a tree of zones of 16-bit zone numbers. The indirect zones are read through the block cache.

Definition in file inode.c.

Function Documentation

◆ free_tree()

blk_t free_tree ( struct minix * desc,
blk_t zone,
int depth,
size_t from )
static

Frees the zones of the tree at zone (a data zone at depth 0, or an indirect zone depth levels above the data), from data zone from of the tree on.

Returns the zone, or 0 if it was freed. A table that can't be read stays, with what's under it.

Definition at line 281 of file inode.c.

References minix::bs, free_tree(), minix_bcache_get(), minix_block_free(), minix_block_write(), table(), and zone_span().

Referenced by ext2_blocks_free(), free_tree(), free_tree(), and minix_zones_free().

◆ minix_inode_alloc()

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.

Parameters
descthe mounted filesystem
Returns
the inode number, or 0 if there's no free inode

Definition at line 340 of file inode.c.

References minix::bs, minix::imap, minix_superblock::imap_blocks, minix::imap_off, bitmap::map, bitmap::max_idx, minix_inode_alloc(), minix::superblock, minix::supernode, and vfs_write().

Referenced by minix_inode_alloc(), and minix_vmknod().

◆ minix_inode_block_read()

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.

A zone that was never written (the file is sparse there) reads as zeros.

Parameters
descthe mounted filesystem
m_inodethe file's inode
idxthe zone's index in the file
bufwhere it goes, a block's size
Returns
0, -EINVAL past the end of the file, -EFBIG, or an I/O error

Definition at line 141 of file inode.c.

References minix::bs, memset(), minix_bcache_get(), minix_block_read(), minix_inode_block_read(), minix_inode::size, table(), zone_span(), zone_tree(), and minix_inode::zones.

Referenced by minix_dentry_create(), minix_dentry_find(), minix_inode_block_read(), minix_read(), minix_readdir(), minix_trunc(), and minix_write().

◆ minix_inode_block_write()

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.

The inode is written back if its zones changed.

Parameters
descthe mounted filesystem
inodethe file's inode
inoits inode number
idxthe zone's index in the file
bufthe zone's new contents
Returns
0, -EFBIG, -ENOSPC, -ENOMEM, or an I/O error

Definition at line 208 of file inode.c.

References minix::bs, minix_bcache_get(), minix_block_alloc(), minix_block_write(), minix_inode_block_write(), minix_inode_write(), table(), table_alloc(), zone_span(), zone_tree(), and minix_inode::zones.

Referenced by minix_dentry_create(), minix_inode_block_write(), minix_trunc(), minix_vmknod(), and minix_write().

◆ minix_inode_free()

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.

Parameters
descthe mounted filesystem
inothe inode number

Definition at line 366 of file inode.c.

References minix::bs, minix::imap, minix_superblock::imap_blocks, minix::imap_off, bitmap::map, bitmap::max_idx, minix_inode_free(), minix::superblock, minix::supernode, and vfs_write().

Referenced by minix_inode_free(), and minix_vmknod().

◆ minix_inode_off()

off_t minix_inode_off ( struct minix * desc,
ino_t ino )
inlinestatic

Returns where an inode is on the disk, in bytes, or -EINVAL for an inode number that doesn't exist.

Definition at line 13 of file inode.c.

References minix::inode_size, minix::inode_table, minix_inode_off(), minix_superblock::ninodes, and minix::superblock.

Referenced by minix_inode_off(), minix_inode_read(), and minix_inode_write().

◆ minix_inode_read()

int minix_inode_read ( struct minix * desc,
ino_t ino,
struct minix_inode * ref )

Reads an inode from the disk.

Parameters
descthe mounted filesystem
inothe inode number
refwhere it goes; NULL only checks the number
Returns
0, -EINVAL for a bad inode number or a short read, or an I/O error

Definition at line 31 of file inode.c.

References minix_inode_off(), minix_inode_read(), minix_inode::size, minix::supernode, and vfs_read().

Referenced by minix_dentry_create(), minix_finddir(), minix_inode_build(), minix_inode_read(), minix_inode_sync(), minix_read(), minix_readdir(), minix_trunc(), minix_vmknod(), and minix_write().

◆ minix_inode_write()

int minix_inode_write ( struct minix * desc,
ino_t ino,
struct minix_inode * ref )

Writes an inode to the disk.

Parameters
descthe mounted filesystem
inothe inode number
refthe inode; NULL only checks the number
Returns
0, -EINVAL for a bad inode number or a short write, or an I/O error

Definition at line 63 of file inode.c.

References minix_inode_off(), minix_inode_write(), minix_inode::size, minix::supernode, and vfs_write().

Referenced by minix_dentry_create(), minix_inode_block_write(), minix_inode_sync(), minix_inode_write(), minix_trunc(), minix_vmknod(), and minix_write().

◆ minix_zones_free()

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.

Parameters
descthe mounted filesystem
inodethe file's inode, its zone pointers cleared here
fromthe index of the first zone to free

Definition at line 315 of file inode.c.

References minix::bs, free_tree(), MINIX_DIRECT_ZONES, minix_zones_free(), minix_inode::mode, and minix_inode::zones.

Referenced by minix_trunc(), minix_vmknod(), and minix_zones_free().

◆ table_alloc()

int table_alloc ( struct minix * desc,
blk_t * zone )
static

Allocates a zone for an indirect table, zeroed on the disk, and drops any cached copy of it (the zone may have been a table before).

Definition at line 180 of file inode.c.

References minix::bcache, bcache_remove(), minix::bs, kfree(), kmalloc(), M_ZERO, minix_block_alloc(), minix_block_write(), and table_alloc().

◆ zone_span()

size_t zone_span ( struct minix * desc,
int depth )
static

Returns how many data zones are under one pointer of an indirect zone that is depth levels above them.

Definition at line 125 of file inode.c.

References minix::bs, and zone_span().

Referenced by free_tree(), minix_inode_block_read(), minix_inode_block_write(), and zone_span().

◆ zone_tree()

int zone_tree ( struct minix * desc,
size_t idx,
int * slot,
size_t * rel )
static

Finds where zone idx of a file is in its tree: the slot of zones[] it hangs from (0 to 6 for the direct zones, 7 for the singly indirect one, 8 for the doubly indirect one) in *slot, and its index under that slot in *rel.

Returns the depth: 0 if the slot is the zone itself, 1 or 2 for the levels of indirect zones above it, or -EFBIG past the largest file.

Definition at line 94 of file inode.c.

References minix::bs, MINIX_DIRECT_ZONES, and zone_tree().

Referenced by minix_inode_block_read(), minix_inode_block_write(), and zone_tree().