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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue