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

ext2: the vnode operations: reading and writing files, directories, making nodes, truncating, and attributes. More...

#include <ext2.h>
#include <core/time.h>
#include <fs/iobuf.h>

Go to the source code of this file.

Functions

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_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_finddir (struct vnode *dir, const char *fn, struct dirent *dirent)
 Finds the entry of a directory that has a name.
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.

Detailed Description

ext2: the vnode operations: reading and writing files, directories, making nodes, truncating, and attributes.

Removing, linking and renaming are in remove.c.

A file's data moves one block at a time through a kernel buffer: the block's piece of the iobuf is copied into or out of it.

Definition in file vops.c.

Function Documentation

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