13MALLOC_DEFINE(M_PSEUDOFS_DENT,
"pseudofs-dirent",
"pseudofs directory entry");
28 size_t len = strlen(name);
30 if (len >= MAXNAMELEN)
33 memcpy(dirent->d_name, name, len);
34 dirent->d_name[len] =
'\0';
55 if (strlen(fn) >= MAXNAMELEN)
58 struct dirent dirent_tmp;
65 if (!
vnode)
goto error_nomem;
87 if (!dirent)
goto error_nomem;
90 dirent->
d_name = strdup(fn);
92 if (!dirent->
d_name)
goto error_nomem;
97 if (!parent)
goto error_nomem;
106 dirent->
next = cur_dir;
139 if (!strcmp(e->d_name, fn))
157 dir->
p = entry->
next;
215 if (strlen(fn) >= MAXNAMELEN)
216 return -ENAMETOOLONG;
225 if (!(entry->
d_name = strdup(fn))) {
231 entry->
next = dir->
p;
254 if (strlen(nfn) >= MAXNAMELEN)
255 return -ENAMETOOLONG;
261 char *name = strdup(nfn);
278 odir->
p = entry->
next;
282 entry->
next = ndir->
p;
323 strcpy(dirent->d_name,
".");
328 strcpy(dirent->d_name,
"..");
349 dirent->d_ino = e->d_ino->ino;
369 if (!dir || !name || !dirent)
372 if (!S_ISDIR(dir->
mode))
376 if (!_dirent)
return -ENOENT;
379 if (!strcmp(name, e->d_name)) {
380 dirent->d_ino = e->d_ino->ino;
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
void vnode_pages_free(struct vnode *vnode)
Frees a vnode's vm object and its cached pages, when the vnode itself is freed.
#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.
static int dotdot(struct vnode *dir, struct uio *uio, struct vnode **ref)
Finds where .. goes from dir during a walk, up through mounts; the walk's root's ....
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.
static void entry_remove(struct vnode *dir, struct pseudofs_dirent *entry, struct pseudofs_dirent *prev)
Removes entry (which comes after prev) from directory dir, and drops a link to its vnode,...
static struct pseudofs_dirent * entry_find(struct vnode *dir, const char *fn, struct pseudofs_dirent **prev)
Finds the entry fn of directory dir, and the entry before it in *prev (NULL if it's the first).
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.
static void pseudofs_dirent_name(struct dirent *dirent, const char *name)
Copies an entry's name into a struct dirent, cut to fit.
A device driver: its operations, any of which may be NULL.
A directory entry, kept in memory.
struct pseudofs_dirent * next
Who does a filesystem operation: where its paths start, and its credentials and umask.
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).