diff --git a/fs/vfs/ramfs.c b/fs/vfs/ramfs.c index c0d8e17..7b19406 100644 --- a/fs/vfs/ramfs.c +++ b/fs/vfs/ramfs.c @@ -89,16 +89,15 @@ static int open_inode(fs_t *fs, u64 id, dirent_t *dirent, inode_t **out) static ssize_t read(inode_t *inode, char *buf, size_t size, size_t offset) { ssize_t ret = 0; - read_lock(&inode->rwlock); if (!inode->data) - goto out; - - if (offset >= inode->file_size) - goto out; + return 0; if (inode->file_size == 0) goto out; + if (offset >= inode->file_size) + return -EINVAL; + if (size + offset >= inode->file_size) size = inode->file_size - offset - 1; @@ -106,14 +105,12 @@ static ssize_t read(inode_t *inode, char *buf, size_t size, size_t offset) ret = size; out: - read_unlock(&inode->rwlock); return ret; } static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset) { ssize_t ret = 0; - write_lock(&inode->rwlock); if (!inode->data) { inode->data = kalloc(size + offset, ALLOC_KERN); inode->file_size = size + offset; @@ -136,7 +133,6 @@ static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset) ret = size; out: - write_unlock(&inode->rwlock); return ret; } @@ -153,14 +149,8 @@ static int link(dirent_t *in, inode_t *to, const char *name, dirent_t **out) new->inode = to; new->fs_ptr = in->fs_ptr; - spinlock_acquire(&in->lock); - write_lock(&in->inode->rwlock); - list_insert(&in->inode->dirents, new); - write_unlock(&in->inode->rwlock); - spinlock_release(&in->lock); - *out = new; return 0; @@ -173,7 +163,6 @@ static int unlink(dirent_t *dent) static ssize_t get_dents(inode_t *parent, dirent_t **dents) { - read_lock(&parent->rwlock); /* count first */ list_item_t *item = parent->dirents.head; ssize_t n = 0; @@ -192,8 +181,6 @@ static ssize_t get_dents(inode_t *parent, dirent_t **dents) item = item->next; } - read_unlock(&parent->rwlock); - return n; }