29 size_t len = strlen(
name);
31 if (len >= MAXNAMELEN)
35 dirent->d_name[len] =
'\0';
83 if (ref) *ref =
vnode;
137 if (!(p->
name = strdup(name))) {
142 if (ref) *ref =
vnode;
158 if (!parent || !child)
161 if (!S_ISDIR(parent->
mode))
165 struct cpio *cp = (
struct cpio *) child->
p;
183 char **tokens = tokenize(path,
'/');
186 if (!S_ISDIR(root->
mode))
193 if (tokens && *tokens)
199 for (
char **token_p = tokens; token_p && *token_p; ++token_p) {
200 char *token = *token_p;
203 for (
struct vnode *e =
dir; e; e = ((
struct cpio *) e->p)->next) {
204 if (((
struct cpio *) e->p)->name &&
205 !strcmp(((
struct cpio *) e->p)->name, token)) {
228 if (!S_ISDIR(root->
mode))
232 if (!strcmp(
name,
"..")) {
251 for (
struct vnode *e =
dir; e; e = ((
struct cpio *) e->p)->next) {
252 if (((
struct cpio *) e->p)->name &&
253 !strcmp(((
struct cpio *) e->p)->name,
name)) {
255 dirent->d_ino = (
vino_t) e;
273#define MAX_NAMESIZE 1024
293 for (; offset <
dev->size;
296 size_t data_offset = offset;
300 panic(
"Invalid CPIO archive\n");
305 data_offset +=
sizeof(
struct cpio_hdr);
314 if (!strcmp(path,
"."))
continue;
315 if (!strcmp(path,
"TRAILER!!!"))
break;
321 for (
int i = (
int)
namesize - 1; i >= 0; --i) {
322 if (path[i] ==
'/') {
341 printk(
"cpio: %s/%s: its directory isn't in the archive\n", dir, name);
366 struct vnode *super =
p->super;
369 size_t cut = iobuf_limit(io,
vnode->
size - offset);
371 iobuf_unlimit(io, cut);
382 strcpy(dirent->d_name,
".");
387 strcpy(dirent->d_name,
"..");
393 struct cpio *p = (
struct cpio *) node->
p;
395 if ((
size_t) offset == p->
count)
399 struct vnode *dir =
p->dir;
401 for (
struct vnode *e = dir; e; e = ((
struct cpio *) e->p)->next) {
403 dirent->d_ino = (
size_t) e;
423 if (S_ISDIR(
file->vnode->mode)) {
static int cpio_new_node(const char *name, struct cpio_hdr *hdr, size_t sz, size_t data, struct vnode *sp, struct vnode **ref)
Makes the vnode of an archive member: its name, its header, its data's size and where the data starts...
static ssize_t cpio_read(struct vnode *vnode, off_t offset, struct iobuf *io)
Reads a file's data, from the archive.
static struct vnode * cpio_find(struct vnode *root, const char *path)
Finds the vnode at a path from the root, while the archive is loaded.
static int cpio_root_node(struct vnode *super, struct vnode **ref)
Makes the root directory's vnode, for the archive on device super.
static int cpio_init()
Registers cpiofs as an archiver for the RAM disk, at boot.
static void cpio_dirent_name(struct dirent *dirent, const char *name)
Copies an entry's name into a struct dirent, cut to fit.
static int cpio_finddir(struct vnode *root, const char *name, struct dirent *dirent)
Finds the entry of a directory that has a name; .. is the directory's parent.
static int cpio_vget(struct vnode *super, ino_t ino, struct vnode **vnode)
Gets a vnode by its inode number, which is its address.
static ssize_t cpio_readdir(struct vnode *node, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset.
static int cpio_load(struct vnode *dev, struct vnode **super)
Loads the archive on a device: the root directory, then a vnode for each member, linked into its dire...
static int cpio_close(struct vnode *vnode)
Releases a vnode: nothing to do, the tree stays in memory.
static int cpio_eof(struct file *file)
Says whether an open file (or directory) is at its end.
static struct vnode * cpio_new_child_node(struct vnode *parent, struct vnode *child)
Adds a vnode to a directory's entries.
int initramfs_archiver_register(struct fs *fs)
Registers a filesystem that can make a root from a RAM disk archive.
#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.
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.
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.
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.
ssize_t vfs_read_io(struct vnode *vnode, off_t off, struct iobuf *io)
Reads from a vnode into an iobuf (user or kernel memory).
ssize_t rofs_write(struct vnode *vnode, off_t offset, struct iobuf *io)
Refuses a write to a read-only filesystem.
int rofs_setattr(struct vnode *vnode)
Refuses to change a node's attributes on a read-only filesystem.
int rofs_vunlink(struct vnode *dir, const char *fn, struct uio *uio)
Refuses to remove a name from a read-only filesystem.
int rofs_vmknod(struct vnode *dir, const char *fn, uint32_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Refuses to make a node on a read-only filesystem.
int rofs_vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
Refuses to rename on a read-only filesystem.
int rofs_trunc(struct vnode *vnode, off_t len)
Refuses to truncate a file on a read-only filesystem.
int rofs_vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
Refuses to make a hard link on a read-only filesystem.
The header of a member of an old binary cpio archive, as it is in the archive: its name follows,...
What cpiofs keeps for each of its vnodes, a member of the archive.
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).