1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

added implementation of readdir

This commit is contained in:
Falk Werner 2019-03-03 13:34:43 +01:00
parent bc38b5d9b1
commit 5f9096914e
6 changed files with 106 additions and 21 deletions

View File

@ -109,6 +109,7 @@ set(WSFS_PROVIDER_SOURCES
lib/wsfs/provider/client_protocol.c
lib/wsfs/provider/provider.c
lib/wsfs/provider/request.c
lib/wsfs/provider/dirbuffer.c
lib/wsfs/provider/operation/lookup.c
lib/wsfs/provider/operation/getattr.c
lib/wsfs/provider/operation/readdir.c

View File

@ -82,25 +82,21 @@ static void fs_getattr(
ino_t inode,
void * user_data)
{
puts("getattr");
struct fs * fs = (struct fs*) user_data;
struct fs_dir const * dir = fs_getdir(fs, inode);
struct fs_file const * f = fs_getfile(fs, inode);
if (NULL != dir)
{
puts("found: dir");
struct stat stat;
memset(&stat, 0, sizeof(stat));
stat.st_ino = inode;
stat.st_mode = S_IFDIR | 0555;
wsfsp_respond_getattr(request, &stat);
return;
}
struct fs_file const * f = fs_getfile(fs, inode);
else if (NULL != f)
{
puts("found: file");
struct stat stat;
memset(&stat, 0, sizeof(stat));
@ -108,11 +104,11 @@ static void fs_getattr(
stat.st_mode = S_IFREG | 0555;
stat.st_size = f->content_length;
wsfsp_respond_getattr(request, &stat);
return;
}
puts("getattr: not found");
wsfsp_respond_error(request, -1);
else
{
wsfsp_respond_error(request, -1);
}
}
static void fs_readdir(
@ -120,11 +116,40 @@ static void fs_readdir(
ino_t directory,
void * user_data)
{
(void) directory;
(void) user_data;
struct fs * fs = (struct fs*) user_data;
puts("readdir");
wsfsp_respond_error(request, -1);
struct fs_dir const * dir = fs_getdir(fs, directory);
if (NULL != dir)
{
struct wsfsp_dirbuffer * buffer = wsfsp_dirbuffer_create();
wsfsp_dirbuffer_add(buffer, ".", dir->inode);
wsfsp_dirbuffer_add(buffer, "..", dir->parent);
for(size_t i = 0; 0 != fs->directories[i].inode; i++)
{
struct fs_dir const * subdir = &fs->directories[i];
if (directory == subdir->parent)
{
wsfsp_dirbuffer_add(buffer, subdir->name, subdir->inode);
}
}
for(size_t i = 0; 0 != fs->files[i].inode; i++)
{
struct fs_file const * f = &fs->files[i];
if (directory == f->parent)
{
wsfsp_dirbuffer_add(buffer, f->name, f->inode);
}
}
wsfsp_respond_readdir(request, buffer);
wsfsp_dirbuffer_dispose(buffer);
}
else
{
wsfsp_respond_error(request, -1);
}
}
static void fs_open(

View File

@ -14,7 +14,7 @@ extern "C"
{
#endif
extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_init(void);
extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void);
extern WSFSP_API void wsfsp_dirbuffer_dispose(
struct wsfsp_dirbuffer * buffer);

View File

@ -0,0 +1,45 @@
#include "wsfs/provider/dirbuffer_intern.h"
#include <stdlib.h>
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
{
struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer));
if (NULL != buffer)
{
buffer->entries = json_array();
}
return buffer;
}
void wsfsp_dirbuffer_dispose(
struct wsfsp_dirbuffer * buffer)
{
if (NULL != buffer->entries)
{
json_decref(buffer->entries);
}
free(buffer);
}
void wsfsp_dirbuffer_add(
struct wsfsp_dirbuffer * buffer,
char const * name,
ino_t inode)
{
json_t * entry = json_object();
json_object_set_new(entry, "name", json_string(name));
json_object_set_new(entry, "inode", json_integer(inode));
json_array_append(buffer->entries, entry);
}
json_t * wsfsp_dirbuffer_take(
struct wsfsp_dirbuffer * buffer)
{
json_t * entries = buffer->entries;
buffer->entries = NULL;
return entries;
}

View File

@ -0,0 +1,15 @@
#ifndef WSFS_PROVIDER_DIRBUFFER_INTERN_H
#define WSFS_PROVIDER_DIRBUFFER_INTERN_H
#include "wsfs/provider/dirbuffer.h"
#include <jansson.h>
struct wsfsp_dirbuffer
{
json_t * entries;
};
extern json_t * wsfsp_dirbuffer_take(
struct wsfsp_dirbuffer * buffer);
#endif

View File

@ -3,6 +3,8 @@
#include <stdio.h>
#include "wsfs/provider/operation/error.h"
#include "wsfs/provider/dirbuffer_intern.h"
#include "wsfs/provider/request.h"
#include "wsfs/util.h"
void wsfsp_readdir(
@ -37,10 +39,7 @@ void wsfsp_respond_readdir(
struct wsfsp_request * request,
struct wsfsp_dirbuffer * dirbuffer)
{
(void) request;
(void) dirbuffer;
// ToDo: implement me
wsfsp_respond_error(request, -1);
json_t * result = wsfsp_dirbuffer_take(dirbuffer);
wsfsp_respond(request, result);
}