AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
mknod.c
Go to the documentation of this file.
1
5
6#include <core/system.h>
7#include <fs/vfs.h>
8
21int vfs_mknod(const char *path, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
22{
23 int ret = 0;
24 struct vnode *dir = NULL;
25 char *name = NULL;
26
27 if ((ret = vfs_lookup_parent(path, uio, &dir, &name)))
28 return ret == -EBUSY ? -EEXIST : ret;
29
30 /* creating an entry needs write and search permission on the directory */
31 if ((ret = vfs_access(dir, uio, VFS_W | VFS_X)))
32 goto done;
33
34 /* symbolic links are always 0777 */
35 if (!S_ISLNK(mode))
36 mode &= ~(uio->mask & 0777);
37
38 ret = vfs_vmknod(dir, name, mode, dev, uio, ref);
39
40done:
41 vfs_close(dir);
42 kfree(name);
43 return ret;
44}
45
55int vfs_mkdir(const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
56{
57 return vfs_mknod(path, S_IFDIR | mode, 0, uio, ref);
58}
59
69int vfs_creat(const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
70{
71 return vfs_mknod(path, S_IFREG | mode, 0, uio, ref);
72}
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
Definition close.c:18
void kfree(void *)
Frees an object that kmalloc() gave.
Definition kvmem.c:146
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 ...
Definition lookup.c:414
int vfs_mknod(const char *path, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Makes a node at a path.
Definition mknod.c:21
int vfs_mkdir(const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
Makes a directory at a path.
Definition mknod.c:55
int vfs_creat(const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
Makes a regular file at a path.
Definition mknod.c:69
#define NULL
Definition stddef.h:27
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
Who does a filesystem operation: where its paths start, and its credentials and umask.
Definition vfs.h:60
mode_t mask
Definition vfs.h:65
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
size_t ref
how many references there are to it
Definition vfs.h:133
mode_t mode
Definition vfs.h:118
uint16_t dev_t
Definition types.h:18
uint32_t mode_t
Definition types.h:15
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,...
Definition vfs.c:114
#define VFS_W
Definition vfs.h:296
#define VFS_X
Definition vfs.h:297
int vfs_vmknod(struct vnode *dir, const char *name, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Makes a node in a directory.
Definition vops.c:22