24#include <aquila/errno.h>
25#include <aquila/dirent.h>
54 if ((
size_t) offset >= node->
size)
57 return iobuf_out(io, (
char *) node->
p + offset, node->
size - offset);
68 if (((
size_t) offset +
size) > node->
size) {
85 size_t done = r > 0 ? r : 0;
89 node->
size =
MAX(old_size, (
size_t) offset + done);
97 if (!
vnode || len < 0)
111 char *buf =
kmalloc(len, &M_BUFFER, 0);
164 if (!tmpfs_root)
return -ENOMEM;
173 if (mdata && mdata->opt) {
174 char **tokens = tokenize(mdata->opt,
',');
175 for (
char **token_p = tokens; token_p && *token_p; ++token_p) {
176 char *token = *token_p;
177 if (!strncmp(token,
"mode=", 5)) {
182 mode |= (*t++ -
'0');
191 tmpfs_root->
mode = S_IFDIR | mode;
192 tmpfs_root->
size = 0;
193 tmpfs_root->
nlink = 2;
195 tmpfs_root->
p =
NULL;
201 tmpfs_root->
ctime = ts;
202 tmpfs_root->
atime = ts;
203 tmpfs_root->
mtime = ts;
206 int err =
vfs_bind(dir, tmpfs_root);
ssize_t iobuf_out(struct iobuf *io, const void *src, size_t n)
Copies bytes from the kernel into the iobuf's buffer, and moves past them.
ssize_t iobuf_in(struct iobuf *io, void *dst, size_t n)
Copies bytes from the iobuf's buffer into the kernel, and moves past them.
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.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
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.
int posix_file_close(struct file *file)
Closes an open file by dropping its reference to its vnode.
int posix_file_ioctl(struct file *file, int request, void *argp)
Passes an ioctl() request on to the file's vnode (a device's, or its filesystem's).
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 pseudofs_setattr(struct vnode *vnode)
Stores a vnode's attributes: there's nothing to do, since they only live in the vnode.
int pseudofs_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 vnode, owned by the caller, and an entry for it.
int pseudofs_finddir(struct vnode *dir, const char *name, struct dirent *dirent)
Finds the entry of a directory that has a name.
int pseudofs_vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
Adds an entry for an existing vnode (a hard link) to a directory.
int pseudofs_close(struct vnode *vnode)
Frees a vnode that has no names or references left, and its cached pages.
int pseudofs_vunlink(struct vnode *vnode, const char *fn, struct uio *uio)
Removes an entry from a directory.
ssize_t pseudofs_readdir(struct vnode *dir, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset.
int pseudofs_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.
A device driver: its operations, any of which may be NULL.
An open file (POSIX's "open file description", fs/file.c).
A file in memory (a vnode): what its inode says, and the kernel's own state.
size_t ref
how many references there are to it
void * p
the filesystem's own data
int gettime(struct timespec *ts)
Reads the wall clock (CLOCK_REALTIME).
static ssize_t tmpfs_read(struct vnode *node, off_t offset, struct iobuf *io)
Reads a file's data from its buffer.
static int tmpfs_file_can_read(struct file *file, size_t size)
Says whether size bytes can be read from the file's offset.
static int tmpfs_file_can_write(struct file *file, size_t size)
Says that a write can always go on: tmpfs has no size limit yet.
static ssize_t tmpfs_write(struct vnode *node, off_t offset, struct iobuf *io)
Writes a file's data into its buffer, which grows to hold it.
static int tmpfs_init()
Installs tmpfs at boot.
static int tmpfs_mount(struct vnode *dir, int flags, void *data)
Mounts a new, empty tmpfs on a directory.
static int tmpfs_close(struct vnode *vnode)
Frees a vnode that has neither references nor names left.
static int tmpfs_vget(struct vnode *super, ino_t ino, struct vnode **vnode)
Gets a vnode by its inode number, which is its address.
static int tmpfs_file_eof(struct file *file)
Says whether the file's offset is at its end.
static int tmpfs_trunc(struct vnode *vnode, off_t len)
Changes a file's length: its buffer is cut, or grows with zeros.
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.