vfs: fix various logical errors in the vfs
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
ab15b88cd6
commit
eb41b17fea
6 changed files with 146 additions and 45 deletions
|
|
@ -44,6 +44,7 @@ int ramfs_create(u64 flags, fs_t **out)
|
|||
fs->root_dirent = root;
|
||||
root->type = S_IFDIR;
|
||||
root->fs = fs;
|
||||
inode_inc_ref(root_inode);
|
||||
root->inode = root_inode;
|
||||
|
||||
*out = fs;
|
||||
|
|
@ -76,7 +77,7 @@ static int alloc_inode(fs_t *fs, u64 mode, inode_t **out)
|
|||
static int free_inode(fs_t *fs, inode_t *inode)
|
||||
{
|
||||
kfree(inode->data);
|
||||
inode_free(inode);
|
||||
inode_dec_ref_lock(inode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -123,12 +124,16 @@ static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
|||
}
|
||||
|
||||
if (inode->file_size < size + offset) {
|
||||
inode->data = krealloc(inode->data, size + offset, ALLOC_KERN);
|
||||
if (!inode->data) {
|
||||
size_t new_size = size + offset;
|
||||
u8 *new_data = krealloc(inode->data, new_size, ALLOC_KERN);
|
||||
if (!new_data) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
inode->file_size = size + offset;
|
||||
if (offset > inode->file_size)
|
||||
memset(new_data + inode->file_size, 0, offset - inode->file_size);
|
||||
inode->data = new_data;
|
||||
inode->file_size = new_size;
|
||||
}
|
||||
|
||||
memcpy(inode->data + offset, buf, size);
|
||||
|
|
@ -152,7 +157,11 @@ static int link(dirent_t *in, inode_t *to, const char *name, dirent_t **out)
|
|||
new->inode = to;
|
||||
new->fs = in->fs;
|
||||
|
||||
list_insert(&in->inode->dirents, new);
|
||||
if (!list_insert(&in->inode->dirents, new)) {
|
||||
inode_dec_ref_lock(to);
|
||||
dirent_free(new);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*out = new;
|
||||
|
||||
|
|
@ -176,6 +185,9 @@ static ssize_t get_dents(inode_t *parent, dirent_t **dents)
|
|||
|
||||
/* now copy */
|
||||
dirent_t *arr = kalloc(n * sizeof(dirent_t), ALLOC_KERN);
|
||||
if (!arr)
|
||||
return -ENOMEM;
|
||||
|
||||
item = parent->dirents.head;
|
||||
n = 0;
|
||||
while (item) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue