AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vops.c
Go to the documentation of this file.
1
6
7#include <core/system.h>
8#include <fs/vfs.h>
9
22int vfs_vmknod(struct vnode *dir, const char *name, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
23{
24 /* invalid request */
25 if (!dir || !dir->fs)
26 return -EINVAL;
27
28 if (!S_ISDIR(dir->mode))
29 return -ENOTDIR;
30
31 /* the filesystem doesn't support it */
32 if (!dir->fs->vops.vmknod)
33 return -ENOSYS;
34
35 int ret = dir->fs->vops.vmknod(dir, name, mode, dev, uio, ref);
36
37 if (!ret && ref && *ref)
38 (*ref)->ref++;
39
40 return ret;
41}
42
52int vfs_vcreat(struct vnode *dir, const char *name, struct uio *uio, struct vnode **ref)
53{
54 return vfs_vmknod(dir, name, S_IFREG, 0, uio, ref);
55}
56
66int vfs_vmkdir(struct vnode *dir, const char *name, struct uio *uio, struct vnode **ref)
67{
68 return vfs_vmknod(dir, name, S_IFDIR, 0, uio, ref);
69}
70
79int vfs_vunlink(struct vnode *dir, const char *fn, struct uio *uio)
80{
81 /* invalid request */
82 if (!dir|| !dir->fs)
83 return -EINVAL;
84
85 /* the filesystem doesn't support it */
86 if (!dir->fs->vops.vunlink)
87 return -ENOSYS;
88
89 return dir->fs->vops.vunlink(dir, fn, uio);
90}
91
103int vfs_vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
104{
105 if (!dir || !dir->fs || !vnode)
106 return -EINVAL;
107
108 if (!S_ISDIR(dir->mode))
109 return -ENOTDIR;
110
111 if (vnode->fs != dir->fs)
112 return -EXDEV;
113
114 if (!dir->fs->vops.vlink)
115 return -ENOSYS;
116
117 return dir->fs->vops.vlink(dir, fn, vnode, uio);
118}
119
132int vfs_vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
133{
134 if (!odir || !odir->fs || !ndir)
135 return -EINVAL;
136
137 if (!S_ISDIR(odir->mode) || !S_ISDIR(ndir->mode))
138 return -ENOTDIR;
139
140 if (odir->fs != ndir->fs)
141 return -EXDEV;
142
143 if (!odir->fs->vops.vrename)
144 return -ENOSYS;
145
146 return odir->fs->vops.vrename(odir, ofn, ndir, nfn, uio);
147}
148
157{
158 if (!vnode || !vnode->fs)
159 return -EINVAL;
160
161 if (!vnode->fs->vops.setattr)
162 return -ENOSYS;
163
164 return vnode->fs->vops.setattr(vnode);
165}
166
176int vfs_vget(struct vnode *super, ino_t ino, struct vnode **ref)
177{
178 int err = 0;
179 struct vnode *vnode = NULL;
180
181 if (!super || !super->fs)
182 return -EINVAL;
183
184 if (!super->fs->vops.vget)
185 return -ENOSYS;
186
187 if ((err = super->fs->vops.vget(super, ino, &vnode)))
188 return err;
189
190 if (vnode) vnode->ref++;
191 if (ref) *ref = vnode;
192
193 return err;
194}
195
206{
208 return -EINVAL;
209
210 struct vnode *vnode = (struct vnode *) vm_entry->vm_object->p;
211
212 if (!vnode || !vnode->fs)
213 return -EINVAL;
214
215 if (ISDEV(vnode))
217
218 if (!vnode->fs->vops.map)
219 return -ENOSYS;
220
221 return vnode->fs->vops.map(vm_space, vm_entry);
222}
#define VNODE_DEV(vnode)
Definition dev.h:79
int kdev_map(struct devid *dd, struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a device into an address space (mmap() of a framebuffer).
Definition kdev.c:361
#define NULL
Definition stddef.h:27
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
struct vops vops
Definition vfs.h:104
Who does a filesystem operation: where its paths start, and its credentials and umask.
Definition vfs.h:60
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
Definition vm.h:66
struct vm_object * vm_object
its object: what its other pages come from (a file)
Definition vm.h:84
void * p
the pager's own data (a file's vnode)
Definition vm.h:146
int type
its kind (VMOBJ_*)
Definition vm.h:137
An address space: its mappings, and its page tables.
Definition vm.h:25
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
ino_t ino
Definition vfs.h:114
size_t ref
how many references there are to it
Definition vfs.h:133
struct fs * fs
Definition vfs.h:127
mode_t mode
Definition vfs.h:118
int(*) setattr(struct vnode *vnode)
Definition vfs.h:87
int(*) vmknod(struct vnode *dir, const char *fn, uint32_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Definition vfs.h:81
int(*) vget(struct vnode *super, ino_t ino, struct vnode **vnode)
Definition vfs.h:89
int(*) vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
Definition vfs.h:84
int(*) vunlink(struct vnode *dir, const char *fn, struct uio *uio)
Definition vfs.h:82
int(*) map(struct vm_space *vm_space, struct vm_entry *vm_entry)
Definition vfs.h:94
int(*) vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
Definition vfs.h:83
uint16_t dev_t
Definition types.h:18
uintptr_t ino_t
Definition types.h:23
uint32_t mode_t
Definition types.h:15
#define ISDEV(vnode)
Definition vfs.h:209
#define VMOBJ_FILE
a file's pages
Definition vm.h:60
int vfs_vmkdir(struct vnode *dir, const char *name, struct uio *uio, struct vnode **ref)
Makes a directory in a directory, with no permissions set.
Definition vops.c:66
int vfs_map(struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a file into an address space, for mmap(): a device's own mapping, or the filesystem's.
Definition vops.c:205
int vfs_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.
Definition vops.c:176
int vfs_vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
Adds a name for an existing file (a hard link) to a directory of the same filesystem.
Definition vops.c:103
int vfs_vunlink(struct vnode *dir, const char *fn, struct uio *uio)
Removes a name from a directory.
Definition vops.c:79
int vfs_setattr(struct vnode *vnode)
Has the filesystem store a vnode's attributes (mode, owner, times) after they were changed in memory.
Definition vops.c:156
int vfs_vcreat(struct vnode *dir, const char *name, struct uio *uio, struct vnode **ref)
Makes a regular file in a directory, with no permissions set.
Definition vops.c:52
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
int vfs_vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
Renames an entry, possibly to another directory of the same filesystem.
Definition vops.c:132