added implementation for lookup (provider)

pull/10/head
Falk Werner 6 years ago
parent 119d08c42e
commit 3627ede1b1

@ -61,6 +61,43 @@ static struct fs_entry const * fs_getentry(
return NULL; return NULL;
} }
static struct fs_entry const * fs_getentry_byname(
struct fs * fs,
ino_t parent,
char const * name)
{
for( size_t i = 0; 0 != fs->entries[i].inode; i++)
{
struct fs_entry const * entry = &fs->entries[i];
if ((parent == entry->parent) && (0 == strcmp(name, entry->name)))
{
return entry;
}
}
return NULL;
}
static void fs_stat(
struct fs_entry const * entry,
struct stat * stat)
{
memset(stat, 0, sizeof(struct stat));
stat->st_ino = entry->inode;
stat->st_mode = entry->mode;
if (FS_DIR == entry->type)
{
stat->st_mode |= S_IFDIR;
}
if (FS_FILE == entry->type)
{
stat->st_mode |= S_IFREG;
stat->st_size = entry->content_length;
}
}
static void fs_lookup( static void fs_lookup(
struct wsfsp_request * request, struct wsfsp_request * request,
@ -69,19 +106,19 @@ static void fs_lookup(
void * user_data) void * user_data)
{ {
struct fs * fs = (struct fs*) user_data; struct fs * fs = (struct fs*) user_data;
struct fs_entry const * dir = fs_getentry(fs, parent); struct fs_entry const * entry = fs_getentry_byname(fs, parent, name);
if ((NULL != dir) && (FS_DIR == dir->type)) if (NULL != entry)
{ {
struct stat stat;
fs_stat(entry, &stat);
wsfsp_respond_lookup(request, &stat);
} }
else
{
(void) name;
(void) user_data;
puts("lookup");
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, -1);
} }
}
static void fs_getattr( static void fs_getattr(
@ -95,21 +132,7 @@ static void fs_getattr(
if (NULL != entry) if (NULL != entry)
{ {
struct stat stat; struct stat stat;
memset(&stat, 0, sizeof(stat)); fs_stat(entry, &stat);
stat.st_ino = entry->inode;
stat.st_mode = entry->mode;
if (FS_DIR == entry->type)
{
stat.st_mode |= S_IFDIR;
}
if (FS_FILE == entry->type)
{
stat.st_mode |= S_IFREG;
stat.st_size = entry->content_length;
}
wsfsp_respond_getattr(request, &stat); wsfsp_respond_getattr(request, &stat);
} }
@ -131,7 +154,7 @@ static void fs_readdir(
{ {
struct wsfsp_dirbuffer * buffer = wsfsp_dirbuffer_create(); struct wsfsp_dirbuffer * buffer = wsfsp_dirbuffer_create();
wsfsp_dirbuffer_add(buffer, ".", dir->inode); wsfsp_dirbuffer_add(buffer, ".", dir->inode);
wsfsp_dirbuffer_add(buffer, "..", dir->parent); wsfsp_dirbuffer_add(buffer, "..", dir->inode);
for(size_t i = 0; 0 != fs->entries[i].inode; i++) for(size_t i = 0; 0 != fs->entries[i].inode; i++)
{ {

@ -1,5 +1,8 @@
#include "wsfs/provider/operation/lookup_intern.h" #include "wsfs/provider/operation/lookup_intern.h"
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"
#include "wsfs/util.h" #include "wsfs/util.h"
@ -30,10 +33,28 @@ void wsfsp_respond_lookup(
struct wsfsp_request * request, struct wsfsp_request * request,
struct stat const * stat) struct stat const * stat)
{ {
(void) request; bool const is_file = (0 != (stat->st_mode & S_IFREG));
(void) stat; bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
wsfsp_respond_error(request, -1); json_t * result = json_object();
json_object_set_new(result, "inode", json_integer(stat->st_ino));
json_object_set_new(result, "mode", json_integer(stat->st_mode & 0777));
json_object_set_new(result, "atime", json_integer(stat->st_atime));
json_object_set_new(result, "mtime", json_integer(stat->st_mtime));
json_object_set_new(result, "ctime", json_integer(stat->st_ctime));
if (is_file)
{
json_object_set_new(result, "type", json_string("file"));
json_object_set_new(result, "size", json_integer(stat->st_size));
}
if (is_dir)
{
json_object_set_new(result, "type", json_string("dir"));
}
wsfsp_respond(request, result);
} }
void wsfsp_lookup_default( void wsfsp_lookup_default(

Loading…
Cancel
Save