AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ext2.h File Reference
#include <core/system.h>
#include <fs/vfs.h>

Go to the source code of this file.

Data Structures

struct  ext2_superblock
 The superblock, as it is on the disk, 1024 bytes into it. More...
struct  ext2_group
 A block group descriptor, as it is on the disk. More...
struct  ext2_inode
 An inode, as it is on the disk. More...
struct  ext2_dentry
 A directory entry, as it is on the disk. More...
struct  ext2
 A mounted ext2 filesystem. More...

Macros

#define EXT2_SIGNATURE   0xEF53
#define EXT2_INCOMPAT_FILETYPE   0x0002
#define EXT2_RO_COMPAT_SPARSE_SUPER   0x0001
#define EXT2_RO_COMPAT_LARGE_FILE   0x0002
#define EXT2_INCOMPAT_SUPPORTED   EXT2_INCOMPAT_FILETYPE
#define EXT2_RO_COMPAT_SUPPORTED   (EXT2_RO_COMPAT_SPARSE_SUPER | EXT2_RO_COMPAT_LARGE_FILE)
#define EXT2_GOOD_OLD_INODE_SIZE   128
#define EXT2_DENTRY_TYPE_BAD   0
#define EXT2_DENTRY_TYPE_RGL   1
#define EXT2_DENTRY_TYPE_DIR   2
#define EXT2_DENTRY_TYPE_CHR   3
#define EXT2_DENTRY_TYPE_BLK   4
#define EXT2_DENTRY_TYPE_FIFO   5
#define EXT2_DENTRY_TYPE_SCKT   6
#define EXT2_DENTRY_TYPE_SLINK   7
#define EXT2_DIRECT_POINTERS   12

Functions

int ext2_superblock_rewrite (struct ext2 *desc)
 Writes the in-memory copy of the superblock back to the disk, after a change to its counts of free blocks and inodes.
int ext2_io (struct ext2 *desc, int write, off_t off, size_t size, void *buf)
 Reads or writes bytes of the filesystem's disk, all of them.
int ext2_bgd_table_rewrite (struct ext2 *desc)
 Writes the block group descriptor table back to the disk, after a change to a group's counts.
int ext2_block_read (struct ext2 *desc, uint32_t number, void *buf)
 Reads a block from the disk.
int ext2_block_write (struct ext2 *desc, uint32_t number, void *buf)
 Writes a block to the disk.
int ext2_block_alloc (struct ext2 *desc, uint32_t *block)
 Allocates a free block: its bit is set in its group's block bitmap, the free counts go down, and the block is zeroed.
int ext2_block_free (struct ext2 *desc, uint32_t block)
 Frees a block: its bit is cleared in its group's block bitmap, and the free counts go up.
int ext2_inode_read (struct ext2 *desc, ino_t inode, struct ext2_inode *ref)
 Reads an inode from the disk.
int ext2_inode_write (struct ext2 *desc, ino_t inode, struct ext2_inode *i)
 Writes an inode to the disk.
int ext2_inode_block_read (struct ext2 *desc, struct ext2_inode *inode, size_t idx, void *buf)
 Reads a block of a file.
int ext2_inode_block_write (struct ext2 *desc, struct ext2_inode *inode, uint32_t inode_nr, size_t idx, void *buf)
 Writes a block of a file, allocating it and the indirect blocks above it if they don't exist yet.
int ext2_inode_alloc (struct ext2 *desc, ino_t *ino)
 Allocates a free inode: its bit is set in its group's inode bitmap, and the free counts go down.
int ext2_dentry_find (struct ext2 *desc, struct ext2_inode *inode, const char *name, ino_t *ino)
 Finds the inode number of a name in a directory.
int ext2_dentry_create (struct vnode *dir, const char *name, ino_t ino, mode_t mode)
 Adds an entry to a directory.
ssize_t ext2_read (struct vnode *node, off_t offset, struct iobuf *io)
 Reads from a file.
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_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_finddir (struct vnode *dir, const char *fn, struct dirent *dirent)
 Finds the entry of a directory that has a name.
int ext2_trunc (struct vnode *inode, off_t len)
 Changes a file's length.
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.
int ext2_vget (struct vnode *super, ino_t ino, struct vnode **ref)
 Gets the vnode of an inode, by its number.
int ext2_setattr (struct vnode *vnode)
 Stores a vnode's attributes (mode, owner, times) in its inode.
int ext2_close (struct vnode *vnode)
 Releases a vnode when its last reference goes.
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_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_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 its type already).
void ext2_blocks_free (struct ext2 *desc, struct ext2_inode *inode, size_t from)
 Frees a file's blocks, from a block on, when the file is truncated or removed.
void ext2_inode_discard (struct ext2 *desc, ino_t ino)
 Frees an inode that has no links left, and the blocks it uses.
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 disk.
int ext2_inode_sync (struct vnode *inode)
 Writes a vnode's attributes back to its inode on the disk.

Variables

struct fs ext2fs

Macro Definition Documentation

◆ EXT2_DENTRY_TYPE_BAD

#define EXT2_DENTRY_TYPE_BAD   0

Definition at line 156 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_BLK

#define EXT2_DENTRY_TYPE_BLK   4

Definition at line 160 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_CHR

#define EXT2_DENTRY_TYPE_CHR   3

Definition at line 159 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_DIR

#define EXT2_DENTRY_TYPE_DIR   2

Definition at line 158 of file ext2.h.

Referenced by ext2_dentry_type(), and ext2_vmknod().

◆ EXT2_DENTRY_TYPE_FIFO

#define EXT2_DENTRY_TYPE_FIFO   5

Definition at line 161 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_RGL

#define EXT2_DENTRY_TYPE_RGL   1

Definition at line 157 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_SCKT

#define EXT2_DENTRY_TYPE_SCKT   6

Definition at line 162 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DENTRY_TYPE_SLINK

#define EXT2_DENTRY_TYPE_SLINK   7

Definition at line 163 of file ext2.h.

Referenced by ext2_dentry_type().

◆ EXT2_DIRECT_POINTERS

#define EXT2_DIRECT_POINTERS   12

Definition at line 165 of file ext2.h.

Referenced by block_tree(), and ext2_blocks_free().

◆ EXT2_GOOD_OLD_INODE_SIZE

#define EXT2_GOOD_OLD_INODE_SIZE   128

Definition at line 31 of file ext2.h.

Referenced by ext2_load().

◆ EXT2_INCOMPAT_FILETYPE

#define EXT2_INCOMPAT_FILETYPE   0x0002

Definition at line 21 of file ext2.h.

Referenced by ext2_load().

◆ EXT2_INCOMPAT_SUPPORTED

#define EXT2_INCOMPAT_SUPPORTED   EXT2_INCOMPAT_FILETYPE

Definition at line 26 of file ext2.h.

Referenced by ext2_load().

◆ EXT2_RO_COMPAT_LARGE_FILE

#define EXT2_RO_COMPAT_LARGE_FILE   0x0002

Definition at line 23 of file ext2.h.

◆ EXT2_RO_COMPAT_SPARSE_SUPER

#define EXT2_RO_COMPAT_SPARSE_SUPER   0x0001

Definition at line 22 of file ext2.h.

◆ EXT2_RO_COMPAT_SUPPORTED

#define EXT2_RO_COMPAT_SUPPORTED   (EXT2_RO_COMPAT_SPARSE_SUPER | EXT2_RO_COMPAT_LARGE_FILE)

Definition at line 27 of file ext2.h.

Referenced by ext2_load().

◆ EXT2_SIGNATURE

#define EXT2_SIGNATURE   0xEF53

Definition at line 16 of file ext2.h.

Referenced by ext2_load().

Function Documentation

◆ ext2_bgd_table_rewrite()

int ext2_bgd_table_rewrite ( struct ext2 * desc)

Writes the block group descriptor table back to the disk, after a change to a group's counts.

Parameters
descthe mounted filesystem
Returns
0, or a negative errno

Definition at line 34 of file block.c.

References ext2::bs, ext2_bgd_table_rewrite(), ext2_io(), ext2::groups, and ext2::ngroups.

Referenced by ext2_bgd_table_rewrite(), ext2_block_alloc(), ext2_block_free(), ext2_inode_alloc(), ext2_inode_free(), and ext2_vmknod().

◆ ext2_block_alloc()

int ext2_block_alloc ( struct ext2 * desc,
uint32_t * block )

Allocates a free block: its bit is set in its group's block bitmap, the free counts go down, and the block is zeroed.

A bitmap that couldn't be read isn't written back.

Parameters
descthe mounted filesystem
blockset to the block's number
Returns
0, -ENOSPC if the filesystem is full, -ENOMEM, or an I/O error

Definition at line 77 of file block.c.

References ext2_group::bmap, ext2::bs, ext2_superblock::dblock, ext2_bgd_table_rewrite(), ext2_block_alloc(), ext2_block_read(), ext2_block_write(), ext2_superblock_rewrite(), ext2_group::free_blocks, ext2_superblock::free_blocks, ext2_superblock::gblocks, ext2::groups, kfree(), kmalloc(), bitmap::map, bitmap::max_idx, memset(), ext2::ngroups, and ext2::superblock.

Referenced by ext2_block_alloc(), and ext2_inode_block_alloc().

◆ ext2_block_free()

int ext2_block_free ( struct ext2 * desc,
uint32_t block )

Frees a block: its bit is cleared in its group's block bitmap, and the free counts go up.

If the bitmap can't be read, the block stays used.

Parameters
descthe mounted filesystem
blockthe block's number
Returns
0, -EINVAL for a block outside the filesystem, -ENOMEM, or an I/O error

Definition at line 145 of file block.c.

References ext2_group::bmap, ext2::bs, ext2_superblock::dblock, ext2_bgd_table_rewrite(), ext2_block_free(), ext2_block_read(), ext2_block_write(), ext2_superblock_rewrite(), ext2_group::free_blocks, ext2_superblock::free_blocks, ext2_superblock::gblocks, ext2::groups, kfree(), kmalloc(), bitmap::map, ext2_superblock::nblocks, and ext2::superblock.

Referenced by ext2_block_free(), and free_tree().

◆ ext2_block_read()

int ext2_block_read ( struct ext2 * desc,
uint32_t number,
void * buf )

Reads a block from the disk.

Parameters
descthe mounted filesystem
numberthe block number
bufwhere it goes, a block's size
Returns
0, or a negative errno

Definition at line 49 of file block.c.

References ext2::bs, ext2_block_read(), and ext2_io().

Referenced by ext2_block_alloc(), ext2_block_free(), ext2_block_read(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_read(), ext2_inode_free(), and free_tree().

◆ ext2_block_write()

int ext2_block_write ( struct ext2 * desc,
uint32_t number,
void * buf )

Writes a block to the disk.

Parameters
descthe mounted filesystem
numberthe block number
bufthe block's new contents
Returns
0, or a negative errno

Definition at line 62 of file block.c.

References ext2::bs, ext2_block_write(), and ext2_io().

Referenced by ext2_block_alloc(), ext2_block_free(), ext2_block_write(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_write(), ext2_inode_free(), and free_tree().

◆ ext2_blocks_free()

void ext2_blocks_free ( struct ext2 * desc,
struct ext2_inode * inode,
size_t from )

Frees a file's blocks, from a block on, when the file is truncated or removed.

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

Definition at line 69 of file remove.c.

References ext2_inode::blocks, ext2::bs, ext2_inode::direct_pointer, ext2_inode::doubly_indirect_pointer, ext2_blocks_free(), EXT2_DIRECT_POINTERS, free_tree(), ext2_inode::mode, ext2_inode::singly_indirect_pointer, and ext2_inode::triply_indirect_pointer.

Referenced by ext2_blocks_free(), ext2_inode_discard(), and ext2_trunc().

◆ ext2_close()

int ext2_close ( struct vnode * vnode)

Releases a vnode when its last reference goes.

A file that was unlinked while it was open is freed now, with its inode and blocks.

Parameters
vnodethe vnode
Returns
0

Definition at line 158 of file remove.c.

References ext2_close(), ext2_inode_discard(), vnode::ino, kfree(), vnode::nlink, vnode::p, ext2::vcache, vcache_remove(), and vnode_pages_free().

Referenced by ext2_close().

◆ ext2_dentry_create()

int ext2_dentry_create ( struct vnode * dir,
const char * name,
ino_t ino,
mode_t mode )

Adds an entry to a directory.

It takes an unused entry big enough, or splits an entry that has room after its name, or else gets a new block at the end of the directory.

Parameters
dirthe directory
namethe new entry's name
inoits inode number
modeits file's mode (for the entry's type)
Returns
0, -ENOTDIR, -ENOMEM, or an I/O error

Definition at line 87 of file dentry.c.

References ext2::bs, ext2_dentry_create(), ext2_dentry_type(), ext2_inode_block_read(), ext2_inode_block_write(), ext2_inode_read(), ext2_inode_write(), ext2::filetype, ext2_dentry::ino, vnode::ino, kfree(), kmalloc(), ext2_dentry::length, memcpy(), memset(), vnode::mode, ext2_dentry::name, NULL, vnode::p, ext2_dentry::size, ext2_inode::size, vnode::size, and ext2_dentry::type.

Referenced by ext2_dentry_create(), ext2_vlink(), ext2_vmknod(), and ext2_vrename().

◆ ext2_dentry_find()

int ext2_dentry_find ( struct ext2 * desc,
struct ext2_inode * inode,
const char * name,
ino_t * ino )

Finds the inode number of a name in a directory.

Parameters
descthe mounted filesystem
inodethe directory's inode
namethe name
inoset to the inode number
Returns
0, -ENOENT if there's no such name, -ENOTDIR, -ENOMEM, or an I/O error

Definition at line 20 of file dentry.c.

References ext2::bs, ext2_dentry_find(), ext2_inode_block_read(), ext2_dentry::ino, kfree(), kmalloc(), ext2_dentry::length, memcmp(), ext2_inode::mode, ext2_dentry::name, ext2_dentry::size, and ext2_inode::size.

Referenced by ext2_dentry_find(), ext2_finddir(), ext2_vlink(), ext2_vmknod(), and ext2_vrename().

◆ ext2_finddir()

int ext2_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, -ENOENT, or a negative errno

Definition at line 414 of file vops.c.

References ext2_dentry_find(), ext2_finddir(), ext2_inode_read(), vnode::ino, and vnode::p.

Referenced by ext2_finddir().

◆ ext2_inode_alloc()

int ext2_inode_alloc ( struct ext2 * desc,
ino_t * ino )

Allocates a free inode: its bit is set in its group's inode bitmap, and the free counts go down.

A bitmap that couldn't be read isn't written back.

Parameters
descthe mounted filesystem
inoset to the inode number
Returns
0, -ENOSPC if there's no free inode, -ENOMEM, or an I/O error

Definition at line 281 of file inode.c.

References ext2::bs, ext2_bgd_table_rewrite(), ext2_block_read(), ext2_block_write(), ext2_inode_alloc(), ext2_superblock_rewrite(), ext2_group::free_inodes, ext2_superblock::free_inodes, ext2_superblock::ginodes, ext2::groups, ext2_group::imap, kfree(), kmalloc(), LOG_DEBUG, bitmap::map, bitmap::max_idx, ext2::ngroups, and ext2::superblock.

Referenced by ext2_inode_alloc(), and ext2_vmknod().

◆ ext2_inode_block_read()

int ext2_inode_block_read ( struct ext2 * desc,
struct ext2_inode * inode,
size_t idx,
void * buf )

Reads a block of a file.

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

Parameters
descthe mounted filesystem
inodethe file's inode
idxthe block's index in the file
bufwhere it goes, a block's size
Returns
0, -EFBIG past the largest file, -ENOMEM, or an I/O error

Definition at line 144 of file inode.c.

References block_tree(), ext2::bs, ext2_block_read(), ext2_inode_block_read(), kfree(), kmalloc(), memset(), slot_get(), table(), and tree_span().

Referenced by dentry_update(), ext2_dentry_create(), ext2_dentry_find(), ext2_inode_block_read(), ext2_read(), ext2_readdir(), ext2_trunc(), and ext2_write().

◆ ext2_inode_block_write()

int ext2_inode_block_write ( struct ext2 * desc,
struct ext2_inode * inode,
uint32_t inode_nr,
size_t idx,
void * buf )

Writes a block of a file, allocating it and the indirect blocks above it if they don't exist yet.

The inode is written back if blocks were allocated.

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

Definition at line 235 of file inode.c.

References block_tree(), ext2_inode::blocks, ext2_block_write(), ext2_indirect_block_get(), ext2_inode_block_alloc(), ext2_inode_block_write(), ext2_inode_write(), slot_get(), slot_set(), and tree_span().

Referenced by dentry_update(), ext2_dentry_create(), ext2_inode_block_write(), ext2_trunc(), ext2_vmknod(), and ext2_write().

◆ ext2_inode_build()

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 disk.

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

Definition at line 29 of file ext2.c.

References ext2_inode::atime, vnode::atime, ext2_inode::ctime, vnode::ctime, DEV, ext2_inode::direct_pointer, ext2_inode_build(), ext2_inode_read(), ext2fs, vnode::fs, ext2_inode::gid, vnode::gid, vnode::ino, kmalloc(), LOG_DEBUG, M_ZERO, ext2_inode::mode, vnode::mode, ext2_inode::mtime, vnode::mtime, ext2_inode::nlink, vnode::nlink, NULL, vnode::p, vnode::rdev, ext2_inode::size, vnode::size, timespec::tv_nsec, timespec::tv_sec, ext2_inode::uid, vnode::uid, ext2::vcache, vcache_find(), and vcache_insert().

Referenced by ext2_inode_build(), ext2_load(), ext2_vget(), ext2_vmknod(), ext2_vrename(), and ext2_vunlink().

◆ ext2_inode_discard()

void ext2_inode_discard ( struct ext2 * desc,
ino_t ino )

Frees an inode that has no links left, and the blocks it uses.

Parameters
descthe mounted filesystem
inothe inode number

Definition at line 131 of file remove.c.

References ext2_inode::dtime, ext2_blocks_free(), ext2_inode_discard(), ext2_inode_free(), ext2_inode_read(), ext2_inode_write(), gettime(), ext2_inode::mode, ext2_inode::nlink, ext2_inode::size, and timespec::tv_sec.

Referenced by ext2_close(), ext2_inode_discard(), and ext2_vmknod().

◆ ext2_inode_read()

int ext2_inode_read ( struct ext2 * desc,
ino_t ino,
struct ext2_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 an I/O error

Definition at line 33 of file inode.c.

References ext2_inode_off(), ext2_inode_read(), and ext2_io().

Referenced by dentry_update(), ext2_dentry_create(), ext2_finddir(), ext2_inode_build(), ext2_inode_discard(), ext2_inode_read(), ext2_inode_sync(), ext2_read(), ext2_readdir(), ext2_setattr(), ext2_trunc(), ext2_vlink(), ext2_vmknod(), ext2_vrename(), and ext2_write().

◆ ext2_inode_sync()

◆ ext2_inode_write()

int ext2_inode_write ( struct ext2 * desc,
ino_t ino,
struct ext2_inode * ext2_inode )

Writes an inode to the disk.

Parameters
descthe mounted filesystem
inothe inode number
ext2_inodethe inode
Returns
0, -EINVAL for a bad inode number, or an I/O error

Definition at line 51 of file inode.c.

References ext2_inode_off(), ext2_inode_write(), and ext2_io().

Referenced by ext2_dentry_create(), ext2_inode_block_write(), ext2_inode_discard(), ext2_inode_sync(), ext2_inode_write(), ext2_setattr(), ext2_trunc(), ext2_vmknod(), and ext2_write().

◆ ext2_io()

int ext2_io ( struct ext2 * desc,
int write,
off_t off,
size_t size,
void * buf )

Reads or writes bytes of the filesystem's disk, all of them.

Parameters
descthe mounted filesystem
writewhether to write (1) or read (0)
offwhere on the disk, in bytes
sizehow many bytes
bufthe data
Returns
0, the device's error, or -EIO if fewer bytes went

Definition at line 19 of file block.c.

References ext2_io(), ext2::supernode, vfs_read(), and vfs_write().

Referenced by ext2_bgd_table_rewrite(), ext2_block_read(), ext2_block_write(), ext2_inode_read(), ext2_inode_write(), ext2_io(), and ext2_superblock_rewrite().

◆ ext2_read()

ssize_t ext2_read ( struct vnode * node,
off_t offset,
struct iobuf * io )

Reads from a file.

Parameters
nodethe 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 23 of file vops.c.

References ext2_inode::blocks, ext2::bs, ext2_inode::direct_pointer, ext2_inode_block_read(), ext2_inode_read(), ext2_read(), vnode::ino, iobuf_out(), kfree(), kmalloc(), MIN, ext2_inode::mode, vnode::p, iobuf::resid, and ext2_inode::size.

Referenced by ext2_read().

◆ ext2_readdir()

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.

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

Definition at line 174 of file vops.c.

References ext2::bs, ext2_inode_block_read(), ext2_inode_read(), ext2_readdir(), ext2_dentry::ino, vnode::ino, kfree(), kmalloc(), ext2_dentry::length, memcpy(), ext2_inode::mode, vnode::mode, ext2_dentry::name, vnode::p, ext2_dentry::size, and ext2_inode::size.

Referenced by ext2_readdir().

◆ ext2_setattr()

int ext2_setattr ( struct vnode * vnode)

Stores a vnode's attributes (mode, owner, times) in its inode.

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

Definition at line 456 of file vops.c.

References ext2_inode::atime, vnode::atime, ext2_inode::ctime, vnode::ctime, ext2_inode_read(), ext2_inode_write(), ext2_setattr(), ext2_inode::gid, vnode::gid, vnode::ino, ext2_inode::mode, vnode::mode, ext2_inode::mtime, vnode::mtime, vnode::p, timespec::tv_sec, ext2_inode::uid, and vnode::uid.

Referenced by ext2_setattr().

◆ ext2_superblock_rewrite()

int ext2_superblock_rewrite ( struct ext2 * desc)

Writes the in-memory copy of the superblock back to the disk, after a change to its counts of free blocks and inodes.

Parameters
descthe mounted filesystem
Returns
0, or a negative errno if the write failed

Definition at line 14 of file super.c.

References ext2_io(), ext2_superblock_rewrite(), and ext2::superblock.

Referenced by ext2_block_alloc(), ext2_block_free(), ext2_inode_alloc(), ext2_inode_free(), and ext2_superblock_rewrite().

◆ ext2_trunc()

int ext2_trunc ( struct vnode * inode,
off_t len )

Changes a file's length.

A file that grows reads zeros past its old end; a file that shrinks frees its blocks past the new end.

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

Definition at line 252 of file vops.c.

References ext2::bs, ext2_blocks_free(), ext2_inode_block_read(), ext2_inode_block_write(), ext2_inode_read(), ext2_inode_sync(), ext2_inode_write(), ext2_trunc(), vnode::ino, kfree(), kmalloc(), memset(), vnode::p, ext2_inode::size, and vnode::size.

Referenced by ext2_trunc(), and ext2_write().

◆ ext2_vget()

int ext2_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 443 of file vops.c.

References ext2_inode_build(), ext2_vget(), and vnode::p.

Referenced by ext2_vget().

◆ ext2_vlink()

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.

Parameters
dirthe directory
fnthe new name
vnodethe file
uiowho is asking
Returns
0, -EEXIST, or a negative errno

Definition at line 298 of file remove.c.

References vnode::ctime, ext2_dentry_create(), ext2_dentry_find(), ext2_inode_read(), ext2_inode_sync(), ext2_vlink(), gettime(), vnode::ino, vnode::mode, vnode::nlink, and vnode::p.

Referenced by ext2_vlink().

◆ ext2_vmknod()

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.

A new directory gets a block with 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, -EEXIST, -ENOSPC, -ENOMEM, or an I/O error

Definition at line 312 of file vops.c.

References ext2_inode::atime, ext2::bs, ext2_inode::ctime, DEV, DEV_MAJOR, DEV_MINOR, ext2_inode::direct_pointer, ext2_group::directories_count, ext2_bgd_table_rewrite(), ext2_dentry_create(), ext2_dentry_find(), EXT2_DENTRY_TYPE_DIR, ext2_inode_alloc(), ext2_inode_block_write(), ext2_inode_build(), ext2_inode_discard(), ext2_inode_read(), ext2_inode_sync(), ext2_inode_write(), ext2_vmknod(), ext2::filetype, gettime(), ext2_inode::gid, uio::gid, ext2_superblock::ginodes, ext2::groups, ext2_dentry::ino, vnode::ino, kfree(), kmalloc(), ext2_dentry::length, M_ZERO, memcpy(), memset(), ext2_inode::mode, ext2_inode::mtime, ext2_dentry::name, ext2_inode::nlink, vnode::nlink, vnode::p, ext2_dentry::size, ext2_inode::size, ext2::superblock, timespec::tv_sec, ext2_dentry::type, ext2_inode::uid, and uio::uid.

Referenced by ext2_vmknod().

◆ ext2_vrename()

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 its type already).

A directory that moves gets its .. pointed to its new parent.

Parameters
odirthe directory the entry is in
ofnits name
ndirthe directory it goes to
nfnits new name
uiowho is asking
Returns
0, -ENOENT, or a negative errno

Definition at line 337 of file remove.c.

References vnode::ctime, dentry_remove(), dentry_set_ino(), dentry_update(), ext2_dentry_create(), ext2_dentry_find(), ext2_inode_build(), ext2_inode_read(), ext2_inode_sync(), ext2_vrename(), ext2_vunlink(), gettime(), vnode::ino, vnode::mode, vnode::mtime, vnode::nlink, NULL, and vnode::p.

Referenced by ext2_vrename().

◆ ext2_vunlink()

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.

The file is freed when it has no links and nothing has it open.

Parameters
dirthe directory
fnthe entry's name
uiowho is asking
Returns
0, -ENOENT, or a negative errno

Definition at line 249 of file remove.c.

References vnode::ctime, dentry_remove(), dentry_update(), ext2_inode_build(), ext2_inode_sync(), ext2_vunlink(), gettime(), vnode::mode, vnode::mtime, vnode::nlink, NULL, vnode::p, vnode::ref, and vfs_close().

Referenced by ext2_vrename(), and ext2_vunlink().

◆ ext2_write()

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.

A short symbolic link keeps its target in the inode itself.

Parameters
nodethe 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 83 of file vops.c.

References ext2_inode::blocks, ext2::bs, ext2_inode::direct_pointer, ext2_inode_block_read(), ext2_inode_block_write(), ext2_inode_read(), ext2_inode_write(), ext2_trunc(), ext2_write(), vnode::ino, iobuf_in(), kfree(), kmalloc(), LOG_DEBUG, MAX, MIN, vnode::mode, vnode::p, iobuf::resid, ext2_inode::size, and vnode::size.

Referenced by ext2_write().

Variable Documentation

◆ ext2fs

struct fs ext2fs
extern

Definition at line 282 of file ext2.c.

Referenced by ext2_init(), ext2_inode_build(), and ext2_mount().