AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
minix.h File Reference
#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

Macro Definition Documentation

◆ MINIX2_MAGIC

#define MINIX2_MAGIC   0x2468

Definition at line 24 of file minix.h.

◆ MINIX2_MAGIC2

#define MINIX2_MAGIC2   0x2478

Definition at line 25 of file minix.h.

◆ MINIX3_MAGIC

#define MINIX3_MAGIC   0x4D5A

Definition at line 27 of file minix.h.

◆ MINIX_DIRECT_ZONES

#define MINIX_DIRECT_ZONES   7

Definition at line 29 of file minix.h.

Referenced by minix_zones_free(), and zone_tree().

◆ MINIX_MAGIC

#define MINIX_MAGIC   0x137F

Definition at line 21 of file minix.h.

Referenced by minix_load().

◆ MINIX_MAGIC2

#define MINIX_MAGIC2   0x138F

Definition at line 22 of file minix.h.

Referenced by minix_load().

Typedef Documentation

◆ blk_t

typedef uint32_t blk_t

Definition at line 113 of file minix.h.

Function Documentation

◆ minix_bcache_get()

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.

The cache keeps the block's memory.

Parameters
descthe mounted filesystem
blkthe block number
dataset to the cached block
Returns
0, -ENOMEM, or a negative errno from the read

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().

◆ minix_block_alloc()

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.

Parameters
descthe mounted filesystem
Returns
the zone's block number, or 0 if the filesystem is full

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().

◆ minix_block_free()

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.

Parameters
descthe mounted filesystem
blkthe 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().

◆ minix_block_read()

ssize_t minix_block_read ( struct minix * desc,
blk_t blk,
void * buf )

Reads a block from the disk.

Parameters
descthe mounted filesystem
blkthe block number
bufwhere it goes, a block's size
Returns
the number of bytes read, or a negative errno

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().

◆ minix_block_write()

ssize_t minix_block_write ( struct minix * desc,
blk_t blk,
void * buf )

Writes a block to the disk.

Parameters
descthe mounted filesystem
blkthe block number
bufthe block's new contents
Returns
the number of bytes written, or a negative errno

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().

◆ minix_dentry_create()

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.

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.

Parameters
dirthe directory
namethe new entry's name (cut to the filesystem's longest)
inoits inode number
modeits type and permissions (not used)
Returns
0, -ENOTDIR if dir isn't a directory, -ENOSPC or -EFBIG if it can't grow, or an I/O error

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().

◆ minix_dentry_find()

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.

Parameters
descthe mounted filesystem
m_inodethe directory's inode
namethe name
Returns
the inode number, or 0 if there's no such name (or the inode isn't a directory)

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().

◆ minix_finddir()

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.

Parameters
dirthe directory
fnthe name
direntif not NULL, the entry
Returns
0, -ENOTDIR if dir isn't a directory, -ENOENT, or an I/O error

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().

◆ 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_build()

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.

Parameters
descthe mounted filesystem
inothe inode number
refif not NULL, set to the vnode
Returns
0, -ENOMEM, or an I/O error

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().

◆ 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_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_sync()

int minix_inode_sync ( struct vnode * inode)

Writes a vnode's attributes back to its inode on the disk.

Parameters
inodethe vnode
Returns
0, or an I/O error

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().

◆ 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_read()

ssize_t minix_read ( struct vnode * vnode,
off_t offset,
struct iobuf * io )

Reads from a file.

Parameters
vnodethe file
offsetwhere to read from
iowhere the data goes, and how much is wanted
Returns
the number of bytes read (0 at or past the end), or a negative errno if nothing was read

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().

◆ minix_readdir()

ssize_t minix_readdir ( struct vnode * dir,
off_t off,
struct dirent * dirent )

Reads a directory's entry at an offset; unused entries don't count.

Parameters
dirthe directory
offwhich entry
direntthe entry, filled in
Returns
1 if an entry was read, 0 past the last one, -ENOTDIR, or an I/O error

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().

◆ minix_superblock_rewrite()

void minix_superblock_rewrite ( struct minix * desc)

Writes the in-memory copy of the superblock back to the disk.

Parameters
descthe 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().

◆ minix_trunc()

int minix_trunc ( struct vnode * vnode,
off_t len )

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.

Parameters
vnodethe file
lenthe new length, in bytes
Returns
0, -ENOMEM, or an I/O error

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().

◆ minix_vget()

int minix_vget ( struct vnode * super,
ino_t ino,
struct vnode ** ref )

Gets the vnode of an inode, by its number.

Parameters
superany vnode of the filesystem
inothe inode number
refif not NULL, set to the vnode
Returns
0, or a negative errno

Definition at line 363 of file vops.c.

References minix_inode_build(), minix_vget(), and vnode::p.

Referenced by minix_vget().

◆ minix_vmknod()

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.

Parameters
dirthe directory
fnthe new node's name
modeits type (S_IF*) and permissions
devits device number, for a device node
uiowho is asking (the owner)
refif not NULL, set to the new vnode
Returns
0, -EINVAL for an empty name, -ENOTDIR, -EEXIST, -ENOSPC, or an I/O error

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().

◆ minix_write()

ssize_t minix_write ( struct vnode * vnode,
off_t offset,
struct iobuf * io )

Writes to a file, which grows if the write goes past its end.

Parameters
vnodethe file
offsetwhere to write
iothe data, and how much of it
Returns
the number of bytes written, or a negative errno if nothing was written

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().

◆ 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().

Variable Documentation

◆ minixfs

struct fs minixfs
extern

Definition at line 265 of file minix.c.

Referenced by minix_init(), minix_inode_build(), and minix_mount().