|
AquilaOS documentation
How it works, and its code
|
#include <core/system.h>#include <ds/bitmap.h>#include <ds/hashmap.h>#include <fs/vfs.h>#include <fs/vcache.h>#include <fs/bcache.h>Go to the source code of this file.
Data Structures | |
| struct | minix_superblock |
| The superblock of minix v1 and v2, as it is on the disk. More... | |
| struct | minix3_superblock |
| The superblock of minix v3, as it is on the disk (not supported). More... | |
| struct | minix_inode |
| A minix v1 inode, as it is on the disk. More... | |
| struct | minix_dentry |
| A directory entry, as it is on the disk: 0 as the inode number is an unused entry. More... | |
| struct | minix |
| A mounted minix filesystem. More... | |
Macros | |
| #define | MINIX_MAGIC 0x137F |
| #define | MINIX_MAGIC2 0x138F |
| #define | MINIX2_MAGIC 0x2468 |
| #define | MINIX2_MAGIC2 0x2478 |
| #define | MINIX3_MAGIC 0x4D5A |
| #define | MINIX_DIRECT_ZONES 7 |
Typedefs | |
| typedef uint32_t | blk_t |
Functions | |
| void | minix_superblock_rewrite (struct minix *desc) |
| Writes the in-memory copy of the superblock back to the disk. | |
| 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. | |
| 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, and its copy in the block cache goes. | |
| ssize_t | minix_block_read (struct minix *desc, blk_t blk, void *buf) |
| Reads a block from the disk. | |
| ssize_t | minix_block_write (struct minix *desc, blk_t blk, void *buf) |
| Writes a block to 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| uint32_t | minix_dentry_find (struct minix *desc, struct minix_inode *m_inode, const char *name) |
| Finds the inode number of a name in a directory. | |
| int | minix_dentry_create (struct vnode *dir, const char *name, ino_t ino, mode_t mode) |
| Adds an entry to a directory, in its first free slot. | |
| ssize_t | minix_read (struct vnode *inode, off_t offset, struct iobuf *io) |
| Reads from a file. | |
| ssize_t | minix_write (struct vnode *inode, off_t offset, struct iobuf *io) |
| Writes to a file, which grows if the write goes past its end. | |
| ssize_t | minix_readdir (struct vnode *dir, off_t offset, struct dirent *dirent) |
| Reads a directory's entry at an offset; unused entries don't count. | |
| int | minix_finddir (struct vnode *dir, const char *fn, struct dirent *dirent) |
| Finds the entry of a directory that has a name. | |
| int | minix_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 | minix_vget (struct vnode *super, ino_t ino, struct vnode **ref) |
| Gets the vnode of an inode, by its number. | |
| int | minix_trunc (struct vnode *inode, off_t len) |
| Changes a file's length. | |
| int | minix_inode_build (struct minix *desc, ino_t ino, struct vnode **ref) |
| Gets the vnode of an inode: the cached one if it's in use, or a new one made from the inode on the disk. | |
| int | minix_inode_sync (struct vnode *inode) |
| Writes a vnode's attributes back to its inode on the disk. | |
Variables | |
| struct fs | minixfs |
| #define MINIX_DIRECT_ZONES 7 |
Definition at line 29 of file minix.h.
Referenced by minix_zones_free(), and zone_tree().
| #define MINIX_MAGIC 0x137F |
Definition at line 21 of file minix.h.
Referenced by minix_load().
| #define MINIX_MAGIC2 0x138F |
Definition at line 22 of file minix.h.
Referenced by minix_load().
Gets a block from the block cache, reading it from the disk into the cache if it isn't there.
The cache keeps the block's memory.
| desc | the mounted filesystem |
| blk | the block number |
| data | set to the cached block |
Definition at line 97 of file block.c.
References minix::bcache, bcache_find(), bcache_insert(), minix::bs, kmalloc(), minix_bcache_get(), minix_block_read(), and NULL.
Referenced by free_tree(), minix_bcache_get(), minix_inode_block_read(), and minix_inode_block_write().
Allocates a free zone: its bit is set in the zone bitmap, which is written back to the disk at once.
| desc | the mounted filesystem |
Definition at line 16 of file block.c.
References minix::bs, minix_superblock::firstdatazone, bitmap::map, bitmap::max_idx, minix_block_alloc(), minix::superblock, minix::supernode, vfs_write(), minix::zmap, minix_superblock::zmap_blocks, and minix::zmap_off.
Referenced by minix_block_alloc(), minix_inode_block_write(), and table_alloc().
Frees a zone: its bit is cleared in the zone bitmap, which is written back at once, and its copy in the block cache goes.
| desc | the mounted filesystem |
| blk | the zone's block number |
Definition at line 42 of file block.c.
References minix::bcache, bcache_remove(), minix::bs, minix_superblock::firstdatazone, bitmap::map, bitmap::max_idx, minix_block_free(), minix::superblock, minix::supernode, vfs_write(), minix::zmap, minix_superblock::zmap_blocks, and minix::zmap_off.
Referenced by free_tree(), and minix_block_free().
Reads a block from the disk.
| desc | the mounted filesystem |
| blk | the block number |
| buf | where it goes, a block's size |
Definition at line 70 of file block.c.
References minix::bs, minix_block_read(), minix::supernode, and vfs_read().
Referenced by minix_bcache_get(), minix_block_read(), and minix_inode_block_read().
Writes a block to the disk.
| desc | the mounted filesystem |
| blk | the block number |
| buf | the block's new contents |
Definition at line 83 of file block.c.
References minix::bs, minix_block_write(), minix::supernode, and vfs_write().
Referenced by free_tree(), minix_block_write(), minix_inode_block_write(), and table_alloc().
Adds an entry to a directory, in its first free slot.
The directory's size grows if the slot is past its end. A directory whose blocks are all full grows by a block, with the entry at its start.
| dir | the directory |
| name | the new entry's name (cut to the filesystem's longest) |
| ino | its inode number |
| mode | its type and permissions (not used) |
Definition at line 68 of file dentry.c.
References minix::bs, minix::dentry_size, minix_dentry::ino, vnode::ino, memcpy(), memset(), MIN, minix_dentry_create(), minix_inode_block_read(), minix_inode_block_write(), minix_inode_read(), minix_inode_write(), vnode::mode, minix_dentry::name, minix::name_len, vnode::p, minix_inode::size, and vnode::size.
Referenced by minix_dentry_create(), and minix_vmknod().
| uint32_t minix_dentry_find | ( | struct minix * | desc, |
| struct minix_inode * | m_inode, | ||
| const char * | name ) |
Finds the inode number of a name in a directory.
The callers check that the inode is a directory: an inode that isn't one has no entries.
| desc | the mounted filesystem |
| m_inode | the directory's inode |
| name | the name |
Definition at line 19 of file dentry.c.
References minix::bs, minix::dentry_size, minix_dentry::ino, memcpy(), minix_dentry_find(), minix_inode_block_read(), minix_inode::mode, minix_dentry::name, minix::name_len, and minix_inode::size.
Referenced by minix_dentry_find(), minix_finddir(), and minix_vmknod().
| int minix_finddir | ( | struct vnode * | dir, |
| const char * | fn, | ||
| struct dirent * | dirent ) |
Finds the entry of a directory that has a name.
Only the entry's inode number is filled in.
| dir | the directory |
| fn | the name |
| dirent | if not NULL, the entry |
Definition at line 324 of file vops.c.
References vnode::ino, minix_dentry_find(), minix_finddir(), minix_inode_read(), minix_inode::mode, and vnode::p.
Referenced by minix_finddir().
Allocates a free inode: its bit is set in the inode bitmap, which is written back to the disk at once.
| desc | the mounted filesystem |
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().
| 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.
| desc | the mounted filesystem |
| m_inode | the file's inode |
| idx | the zone's index in the file |
| buf | where it goes, a block's size |
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().
| 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.
| desc | the mounted filesystem |
| inode | the file's inode |
| ino | its inode number |
| idx | the zone's index in the file |
| buf | the zone's new contents |
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().
Gets the vnode of an inode: the cached one if it's in use, or a new one made from the inode on the disk.
| desc | the mounted filesystem |
| ino | the inode number |
| ref | if not NULL, set to the vnode |
Definition at line 30 of file minix.c.
References vnode::fs, minix_inode::gid, vnode::gid, vnode::ino, kfree(), kmalloc(), M_ZERO, minix_inode_build(), minix_inode_read(), minixfs, minix_inode::mode, vnode::mode, minix_inode::mtime, vnode::mtime, vnode::nlink, minix_inode::nlinks, NULL, vnode::p, vnode::rdev, minix_inode::size, vnode::size, timespec::tv_nsec, timespec::tv_sec, minix_inode::uid, vnode::uid, minix::vcache, vcache_find(), vcache_insert(), and minix_inode::zones.
Referenced by minix_inode_build(), minix_load(), minix_vget(), and minix_vmknod().
Frees an inode: its bit is cleared in the inode bitmap, which is written back at once.
| desc | the mounted filesystem |
| ino | the 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().
| int minix_inode_read | ( | struct minix * | desc, |
| ino_t | ino, | ||
| struct minix_inode * | ref ) |
Reads an inode from the disk.
| desc | the mounted filesystem |
| ino | the inode number |
| ref | where it goes; NULL only checks the number |
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().
| int minix_inode_sync | ( | struct vnode * | inode | ) |
Writes a vnode's attributes back to its inode on the disk.
| inode | the vnode |
Definition at line 87 of file minix.c.
References minix_inode::gid, vnode::gid, vnode::ino, minix_inode_read(), minix_inode_sync(), minix_inode_write(), minix_inode::mode, vnode::mode, minix_inode::mtime, vnode::mtime, vnode::nlink, minix_inode::nlinks, vnode::p, minix_inode::size, vnode::size, timespec::tv_sec, minix_inode::uid, and vnode::uid.
Referenced by minix_inode_sync(), and minix_trunc().
| int minix_inode_write | ( | struct minix * | desc, |
| ino_t | ino, | ||
| struct minix_inode * | ref ) |
Writes an inode to the disk.
| desc | the mounted filesystem |
| ino | the inode number |
| ref | the inode; NULL only checks the number |
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().
Reads from a file.
| vnode | the file |
| offset | where to read from |
| io | where the data goes, and how much is wanted |
Definition at line 21 of file vops.c.
References minix::bs, vnode::ino, iobuf_out(), kfree(), kmalloc(), MIN, minix_inode_block_read(), minix_inode_read(), minix_read(), vnode::p, iobuf::resid, and minix_inode::size.
Referenced by minix_read().
Reads a directory's entry at an offset; unused entries don't count.
| dir | the directory |
| off | which entry |
| dirent | the entry, filled in |
Definition at line 151 of file vops.c.
References minix::bs, minix::dentry_size, minix_dentry::ino, vnode::ino, memcpy(), minix_inode_block_read(), minix_inode_read(), minix_readdir(), minix_inode::mode, vnode::mode, minix_dentry::name, minix::name_len, vnode::p, and minix_inode::size.
Referenced by minix_readdir().
| void minix_superblock_rewrite | ( | struct minix * | desc | ) |
Writes the in-memory copy of the superblock back to the disk.
| desc | the mounted filesystem |
Definition at line 12 of file super.c.
References minix_superblock_rewrite(), minix::superblock, minix::supernode, and vfs_write().
Referenced by minix_superblock_rewrite().
Changes a file's length.
A file that grows reads zeros past its old end; a file that shrinks frees its zones past the new end.
| vnode | the file |
| len | the new length, in bytes |
Definition at line 380 of file vops.c.
References minix::bs, vnode::ino, kfree(), kmalloc(), memset(), minix_inode_block_read(), minix_inode_block_write(), minix_inode_read(), minix_inode_sync(), minix_inode_write(), minix_trunc(), minix_zones_free(), vnode::p, minix_inode::size, and vnode::size.
Referenced by minix_trunc(), and minix_write().
Gets the vnode of an inode, by its number.
| super | any vnode of the filesystem |
| ino | the inode number |
| ref | if not NULL, set to the vnode |
Definition at line 363 of file vops.c.
References minix_inode_build(), minix_vget(), and vnode::p.
Referenced by minix_vget().
| int minix_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.
A new directory gets its . and .. entries.
| dir | the directory |
| fn | the new node's name |
| mode | its type (S_IF*) and permissions |
| dev | its device number, for a device node |
| uio | who is asking (the owner) |
| ref | if not NULL, set to the new vnode |
Definition at line 216 of file vops.c.
References minix::bs, minix::dentry_size, DEV, DEV_MAJOR, DEV_MINOR, minix_inode::gid, uio::gid, minix_dentry::ino, vnode::ino, memcpy(), memset(), minix_dentry_create(), minix_dentry_find(), minix_inode_alloc(), minix_inode_block_write(), minix_inode_build(), minix_inode_free(), minix_inode_read(), minix_inode_write(), minix_vmknod(), minix_zones_free(), minix_inode::mode, minix_dentry::name, vnode::nlink, minix_inode::nlinks, vnode::p, minix_inode::size, minix_inode::uid, uio::uid, and minix_inode::zones.
Referenced by minix_vmknod().
Writes to a file, which grows if the write goes past its end.
| vnode | the file |
| offset | where to write |
| io | the data, and how much of it |
Definition at line 75 of file vops.c.
References minix::bs, vnode::ino, iobuf_in(), kfree(), kmalloc(), MAX, MIN, minix_inode_block_read(), minix_inode_block_write(), minix_inode_read(), minix_inode_write(), minix_trunc(), minix_write(), vnode::p, iobuf::resid, minix_inode::size, and vnode::size.
Referenced by minix_write().
| 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.
| desc | the mounted filesystem |
| inode | the file's inode, its zone pointers cleared here |
| from | the 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().
|
extern |
Definition at line 265 of file minix.c.
Referenced by minix_init(), minix_inode_build(), and minix_mount().