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

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

#include <minix.h>
#include <fs/iobuf.h>

Go to the source code of this file.

Functions

ssize_t minix_read (struct vnode *vnode, off_t offset, struct iobuf *io)
 Reads from a file.
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.
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.
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_finddir (struct vnode *dir, const char *fn, struct dirent *dirent)
 Finds the entry of a directory that has a name.
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 *vnode, off_t len)
 Changes a file's length.

Detailed Description

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

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

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