inode: add initial refcounts
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
bdd3915f83
commit
30c597c175
1 changed files with 10 additions and 4 deletions
|
|
@ -54,7 +54,9 @@ int inode_find_dirent(inode_t *inode, const char *name, dirent_t **out)
|
|||
dirent_t *dent = item->ptr;
|
||||
if (!strcmp(dent->name, name)) {
|
||||
/* found */
|
||||
dirent_inc_ref(dent);
|
||||
*out = dent;
|
||||
|
||||
return 0;
|
||||
}
|
||||
item = item->next;
|
||||
|
|
@ -67,9 +69,11 @@ inode_t *inode_create()
|
|||
{
|
||||
inode_t *ret = slab_alloc(inode_slab);
|
||||
|
||||
if (ret)
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->refcount = 1;
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
rwlock_init(&ret->rwlock);
|
||||
|
||||
return ret;
|
||||
|
|
@ -82,7 +86,7 @@ void inode_free(inode_t *inode)
|
|||
while (item) {
|
||||
dirent_t *dent = item->ptr;
|
||||
if (dent)
|
||||
dirent_dec_ref(dent);
|
||||
dirent_dec_ref(dent);
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -136,8 +140,10 @@ dirent_t *dirent_create(const char *name)
|
|||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->rec_len = sizeof(dirent_t);
|
||||
memset(ret, 0, sizeof(dirent_t));
|
||||
|
||||
ret->rec_len = sizeof(dirent_t);
|
||||
ret->refcount = 1;
|
||||
ret->name_len = strlen(name);
|
||||
ret->name = strdup(name);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue