vfs: add vfs_readdir
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
cfda99c7c7
commit
898570d0ca
4 changed files with 42 additions and 1 deletions
|
|
@ -11,7 +11,7 @@
|
|||
static mem_cache_t *inode_slab = NULL;
|
||||
static mem_cache_t *dirent_slab = NULL;
|
||||
|
||||
static int inode_populate_dirents(inode_t *inode)
|
||||
int inode_populate_dirents(inode_t *inode)
|
||||
{
|
||||
write_lock(&inode->rwlock);
|
||||
|
||||
|
|
|
|||
34
fs/vfs/vfs.c
34
fs/vfs/vfs.c
|
|
@ -151,6 +151,40 @@ void vfs_close(dirent_t *dent)
|
|||
dirent_dec_ref(dent);
|
||||
}
|
||||
|
||||
int vfs_readdir(dirent_t *dir, struct dir_context *ctx, dirent_t **out)
|
||||
{
|
||||
if (!dir || !ctx || !out)
|
||||
return -EINVAL;
|
||||
|
||||
inode_t *ino = dir->inode;
|
||||
if ((ino->mode & S_IFMT) != S_IFDIR)
|
||||
return -ENOTDIR;
|
||||
|
||||
int res = inode_populate_dirents(ino);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
read_lock(&ino->rwlock);
|
||||
|
||||
if (!ctx->init) {
|
||||
ctx->cookie = ino->dirents.head;
|
||||
ctx->init = true;
|
||||
}
|
||||
|
||||
list_item_t *item = ctx->cookie;
|
||||
if (!item) {
|
||||
read_unlock(&ino->rwlock);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
dirent_inc_ref(item->ptr);
|
||||
*out = item->ptr;
|
||||
ctx->cookie = item->next;
|
||||
|
||||
read_unlock(&ino->rwlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t vfs_write(inode_t *ino, char *buf, size_t size, size_t offset)
|
||||
{
|
||||
if (!ino)
|
||||
|
|
|
|||
Loading…
Reference in a new issue