i_ops: change link and unlink to inode-tracking
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
8c346a7018
commit
7e4e70853e
3 changed files with 26 additions and 35 deletions
|
|
@ -124,19 +124,18 @@ static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
|||
return size;
|
||||
}
|
||||
|
||||
static int link(dirent_t *in, inode_t *to, const char *name, dirent_t **out)
|
||||
static int link(inode_t *parent_dir, inode_t *child, const char *name, dirent_t **out)
|
||||
{
|
||||
if (!in || !to || !name || !out)
|
||||
if (!parent_dir || !child || !name || !out)
|
||||
return -EINVAL;
|
||||
|
||||
dirent_t *new = dirent_create(name);
|
||||
if (!new)
|
||||
return -ENOMEM;
|
||||
|
||||
new->inode = to;
|
||||
new->fs = in->fs;
|
||||
new->inode = child;
|
||||
|
||||
if (!list_insert(&in->inode->dirents, new)) {
|
||||
if (!list_insert(&parent_dir->dirents, new)) {
|
||||
dirent_free(new);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
@ -145,9 +144,23 @@ static int link(dirent_t *in, inode_t *to, const char *name, dirent_t **out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int unlink(dirent_t *dent)
|
||||
static int unlink(inode_t *parent_dir, const char *name)
|
||||
{
|
||||
return 0;
|
||||
if (!parent_dir || !name)
|
||||
return -EINVAL;
|
||||
|
||||
list_item_t *item = parent_dir->dirents.head;
|
||||
while (item) {
|
||||
dirent_t *dent = item->ptr;
|
||||
if (!strcmp(dent->name, name)) {
|
||||
list_remove(item);
|
||||
dirent_dec_ref(dent);
|
||||
return 0;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static ssize_t get_dents(inode_t *parent, dirent_t **dents)
|
||||
|
|
|
|||
30
fs/vfs/vfs.c
30
fs/vfs/vfs.c
|
|
@ -208,7 +208,7 @@ int vfs_creat(dirent_t *parent, const char *name, u64 mode, int flags, dirent_t
|
|||
return res;
|
||||
}
|
||||
|
||||
res = ino->i_ops.link(parent, new_ino, name, &new_dirent);
|
||||
res = ino->i_ops.link(ino, new_ino, name, &new_dirent);
|
||||
|
||||
if (res < 0) {
|
||||
fs->fs_ops.free_inode(fs, new_ino);
|
||||
|
|
@ -216,6 +216,7 @@ int vfs_creat(dirent_t *parent, const char *name, u64 mode, int flags, dirent_t
|
|||
return res;
|
||||
}
|
||||
|
||||
new_dirent->fs = fs;
|
||||
*out = new_dirent;
|
||||
write_unlock(&ino->rwlock);
|
||||
return 0;
|
||||
|
|
@ -235,33 +236,10 @@ int vfs_unlink(dirent_t *parent, const char *name)
|
|||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
dirent_t *dent = NULL;
|
||||
int res = inode_find_dirent_locked(ino, name, &dent);
|
||||
if (res < 0) {
|
||||
write_unlock(&ino->rwlock);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = ino->i_ops.unlink(dent);
|
||||
if (res < 0) {
|
||||
dirent_dec_ref(dent);
|
||||
write_unlock(&ino->rwlock);
|
||||
return res;
|
||||
}
|
||||
|
||||
list_item_t *item = ino->dirents.head;
|
||||
while (item) {
|
||||
if (item->ptr == dent) {
|
||||
list_remove(item);
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
dirent_dec_ref(dent);
|
||||
int res = ino->i_ops.unlink(ino, name);
|
||||
|
||||
write_unlock(&ino->rwlock);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
int vfs_mount(const char *mount_point, fs_t *fs_to_mount)
|
||||
|
|
|
|||
Loading…
Reference in a new issue