1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

implements operation read

This commit is contained in:
Falk Werner
2019-03-03 18:02:30 +01:00
parent de454516cb
commit e4d95f5dc9
2 changed files with 80 additions and 13 deletions

View File

@@ -203,6 +203,11 @@ static void fs_open(
}
}
static size_t min(size_t const a, size_t const b)
{
return (a < b) ? a : b;
}
static void fs_read(
struct wsfsp_request * request,
ino_t inode,
@@ -211,13 +216,28 @@ static void fs_read(
size_t length,
void * user_data)
{
(void) inode;
(void) handle;
(void) offset;
(void) length;
(void) user_data;
wsfsp_respond_error(request, -1);
struct fs * fs = (struct fs*) user_data;
struct fs_entry const * entry = fs_getentry(fs, inode);
if ((NULL != entry) && (FS_FILE == entry->type))
{
if (entry->content_length > offset)
{
size_t const remaining = entry->content_length - offset;
size_t const count = min(remaining, length);
wsfsp_respond_read(request, &entry->content[offset], count);
}
else
{
wsfsp_respond_error(request, -1);
}
}
else
{
wsfsp_respond_error(request, -1);
}
}
static struct wsfsp_provider fs_provider =