31#include <aquila/fcntl.h>
92 if ((err =
vfs_vget(dir, dirent.d_ino, &parent)))
113 while (d != root && d->
covered)
134 struct dirent dirent;
139 return -ENAMETOOLONG;
160 char *path =
kmalloc(1024 + strlen(rest), &M_BUFFER, 0);
170 *err = len < 0 ? len : -ENOENT;
176 strcpy(path + len, rest);
182static int is_dot(
const char *c,
size_t len)
184 return len == 1 && c[0] ==
'.';
190 return len == 2 && c[0] ==
'.' && c[1] ==
'.';
204static int walk(
struct vnode *dir,
const char *path,
struct uio *
uio,
int flags,
int *links,
207 const char *
p = path;
227 while (c[len] && c[len] !=
'/')
232 const char *rest =
p;
236 int last = !*rest, slash = *
p ==
'/';
238 if (!S_ISDIR(dir->
mode)) {
254 if (!(*name =
kmalloc(len + 1, &M_BUFFER, 0))) {
282 if (S_ISLNK(next->
mode) && (!last || slash || !(
uio->
flags & O_NOFOLLOW))) {
297 err =
walk(dir, target,
uio, flags, links,
ref, name, where);
313 if (last && slash && !S_ISDIR(dir->
mode)) {
351 vfs_log(
LOG_DEBUG,
"vfs_lookup(path=%s, uio=%p, ref=%p)\n", path,
uio,
ref);
427 struct dirent dirent;
500 struct dirent dirent, found;
504 while ((r =
vfs_readdir(parent, off, &dirent)) > 0) {
507 if (!strcmp(dirent.d_name,
".") || !strcmp(dirent.d_name,
".."))
512 if (!
vfs_finddir(parent, dirent.d_name, &found) && found.d_ino == child->
ino) {
513 strcpy(name, dirent.d_name);
518 return r < 0 ? r : -ENOENT;
550 while (cur != root && cur->
covered) {
571 size_t len = strlen(name);
580 memcpy(buf + pos, name, len);
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
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 * memmove(void *dst, const void *src, size_t n)
Copies n bytes; dst and src may overlap.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
static int is_dotdot(const char *c, size_t len)
Says whether a component (len bytes) is ...
static struct vnode * walk_root(struct uio *uio)
Returns where absolute paths start: the process's root directory, or the system's.
static struct vnode * walk_start(struct uio *uio)
Returns where a relative path starts (with a reference): the current directory.
int vfs_lookup_dir(const char *path, struct uio *uio, struct vnode **ref, struct vnode **dir)
Finds the vnode a path names, as vfs_lookup() does, and the directory it was found in.
static int walk(struct vnode *dir, const char *path, struct uio *uio, int flags, int *links, struct vnode **ref, char **name, struct vnode **where)
Walks path from dir, whose reference the walk takes.
static int entry_name(struct vnode *parent, struct vnode *child, char *name)
Finds the name child has in parent (into name, NAME_MAX + 1 bytes).
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 ....
static char * link_path(struct vnode *link, const char *rest, int *err)
Returns the path a walk goes on with at a symbolic link: the link's target, then rest (what's left of...
static int is_dot(const char *c, size_t len)
Says whether a path component of len bytes is a single dot, the name of a directory itself.
int vfs_lookup_parent(const char *path, struct uio *uio, struct vnode **dir, char **name)
Finds the directory of a path's last component, and the component's name, to make or remove an entry ...
struct vnode * vfs_mount_root_of(struct vnode *vnode)
Finds the root of the mounted filesystem a vnode is in.
int vfs_under(struct vnode *vnode, struct vnode *dir)
Says whether a vnode is a directory or under it, in the same filesystem: rename() can't move a direct...
int vfs_lookup(const char *path, struct uio *uio, struct vnode **ref)
Finds the vnode a path names.
int vfs_vnode_path(struct vnode *vnode, struct vnode *root, char *buf, size_t size)
Computes a vnode's path, for getcwd() and /proc/mounts: it goes up through .., and finds each directo...
int vfs_parent(struct vnode *dir, struct vnode **ref)
Finds a directory's parent in its own filesystem, through its .. entry.
static struct vnode * vref(struct vnode *vnode)
Adds a reference to a vnode, and returns it.
static int lookup_name(struct vnode *dir, const char *name, size_t len, struct vnode **ref)
Finds the entry name (len bytes) of dir, and crosses into what is mounted on it.
static struct vnode * cross_down(struct vnode *vnode)
Returns the root of what's mounted on vnode (all the way down, if a mount is mounted on too),...
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
int vfs_finddir(struct vnode *dir, const char *name, struct dirent *dirent)
Finds the entry of a directory that has a name.
ssize_t vfs_readdir(struct vnode *dir, off_t off, struct dirent *dirent)
Reads a directory's entry at an offset.
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
struct vnode * mounted
for a directory that a filesystem is mounted on, that filesystem's root; for a mounted filesystem's r...
int vfs_access(struct vnode *vnode, struct uio *uio, int mode)
Checks whether a user may access a vnode in a way: the owner's permissions apply to its owner,...
int vfs_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.