11#include <aquila/errno.h>
17MALLOC_DEFINE(M_EXT2_SB,
"ext2-sb",
"ext2 filesystem superblock structure");
18MALLOC_DEFINE(M_EXT2_GROUP,
"ext2-group",
"ext2 block group descriptor");
38 vfs_log(
LOG_DEBUG,
"ext2_inode_build(desc=%p, ino=%d, ref_inode=%p)\n", desc,
ino, ref_inode);
61 if (S_ISCHR(einode.
mode) || S_ISBLK(einode.
mode)) {
65 DEV((
new & 0xFFF00) >> 8, (
new & 0xFF) | ((
new >> 12) & 0xFFF00));
95 vfs_log(
LOG_DEBUG,
"ext2_inode_sync(inode=%p)\n", inode);
99 struct ext2 *desc = (
struct ext2 *) inode->
p;
153 if (!sb)
goto e_nomem;
157 err = r < 0 ? (int) r : -EIO;
171 if (!desc)
goto e_nomem;
193 if (incompat || ro) {
194 printk(
"ext2: features it can't use: incompat %x, ro_compat %x\n", incompat, ro);
207 if (!desc->
groups)
goto e_nomem;
210 err = r < 0 ? (int) r : -EIO;
215 if (!desc->
vcache)
goto e_nomem;
265 if (!args || !args->dev)
#define DEV(major, minor)
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.
int ext2_init()
Installs the ext2 filesystem at boot.
int ext2_load(struct vnode *dev, struct vnode **super)
Loads an ext2 filesystem from a device: its superblock, its block group descriptors,...
int ext2_mount(struct vnode *dir, int flags, void *_args)
Mounts the ext2 filesystem of a device on a directory.
ssize_t ext2_write(struct vnode *node, off_t offset, struct iobuf *io)
Writes to a file, which grows if the write goes past its end.
ssize_t ext2_read(struct vnode *node, off_t offset, struct iobuf *io)
Reads from a file.
int ext2_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.
#define EXT2_GOOD_OLD_INODE_SIZE
#define EXT2_INCOMPAT_FILETYPE
int ext2_close(struct vnode *vnode)
Releases a vnode when its last reference goes.
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_trunc(struct vnode *inode, off_t len)
Changes a file's length.
#define EXT2_RO_COMPAT_SUPPORTED
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 ...
int ext2_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.
#define EXT2_INCOMPAT_SUPPORTED
int ext2_inode_write(struct ext2 *desc, ino_t inode, struct ext2_inode *i)
Writes an inode to the disk.
ssize_t ext2_readdir(struct vnode *dir, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset; unused entries don't count.
int ext2_setattr(struct vnode *vnode)
Stores a vnode's attributes (mode, owner, times) in its inode.
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_finddir(struct vnode *dir, const char *fn, struct dirent *dirent)
Finds the entry of a directory that has a name.
int posix_file_eof(struct file *file)
Says whether a file's offset is at or past its end, so that a read returns nothing.
#define MALLOC_DEFINE(type, _name, _desc)
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 vfs_lookup(const char *path, struct uio *uio, struct vnode **ref)
Finds the vnode a path names.
off_t posix_file_lseek(struct file *file, off_t offset, int whence)
Moves an open file's offset: to offset (SEEK_SET), by offset from where it is (SEEK_CUR),...
#define MODULE_INIT(name, i, f)
int posix_file_open(struct file *file)
Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
ssize_t posix_file_readdir(struct file *file, struct dirent *dirent)
Reads the directory entry at an open directory's offset, and moves the offset past it.
int posix_file_trunc(struct file *file, off_t len)
Truncates (or extends) an open file to a new length.
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
A device driver: its operations, any of which may be NULL.
A block group descriptor, as it is on the disk.
An inode, as it is on the disk.
uint32_t direct_pointer[12]
The superblock, as it is on the disk, 1024 bytes into it.
uint32_t nblocks
number of blocks
uint32_t feature_ro_compat
uint32_t feature_incompat
uint32_t gblocks
number of blocks per block group
uint32_t block_size
log(block size)
A mounted ext2 filesystem.
struct ext2_superblock * superblock
struct ext2_group * groups
struct vcache * vcache
its vnodes in use, by inode number
size_t ngroups
number of block group descriptors
size_t inode_size
an inode's size on the disk (revision 0's, or the superblock's)
int filetype
directory entries have their file's type (EXT2_INCOMPAT_FILETYPE); without it, the byte is 0
int(*) load(struct vnode *dev, struct vnode **super)
Who does a filesystem operation: where its paths start, and its credentials and umask.
A filesystem's vnode cache (fs/vcache.c): its vnodes in memory, by their inode number,...
A file in memory (a vnode): what its inode says, and the kernel's own state.
void * p
the filesystem's own data
void vcache_init(struct vcache *vcache)
Sets up an empty vnode cache.
struct vnode * vcache_find(struct vcache *vcache, ino_t ino)
Finds the cached vnode of an inode.
int vcache_insert(struct vcache *vcache, struct vnode *vnode)
Adds a vnode to a cache.
int vfs_bind(struct vnode *dir, struct vnode *root)
Mounts a filesystem on a directory: a lookup that reaches dir goes on in root instead.
int vfs_install(struct fs *fs)
Installs a filesystem, so that it can be mounted by name.