diff --git a/example/provider/main.c b/example/provider/main.c index dbe2576..15f7b94 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -4,6 +4,9 @@ #include #include +#include +#include + #include "wsfs_provider.h" enum fs_entry_type @@ -180,12 +183,24 @@ static void fs_open( int flags, void * user_data) { - (void) inode; - (void) flags; - (void) user_data; + struct fs * fs = (struct fs*) user_data; - puts("open"); - wsfsp_respond_error(request, -1); + struct fs_entry const * entry = fs_getentry(fs, inode); + if ((NULL != entry) && (FS_FILE == entry->type)) + { + if (O_RDONLY == (flags & O_ACCMODE)) + { + wsfsp_respond_open(request, 0U); + } + else + { + wsfsp_respond_error(request, -1); + } + } + else + { + wsfsp_respond_error(request, -1); + } } static void fs_read( diff --git a/lib/wsfs/provider/operation/open.c b/lib/wsfs/provider/operation/open.c index 8bb5573..1f4bcd4 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/operation/open.c @@ -1,6 +1,7 @@ #include "wsfs/provider/operation/open_intern.h" #include #include "wsfs/provider/operation/error.h" +#include "wsfs/provider/request.h" #include "wsfs/util.h" void wsfsp_open( @@ -8,11 +9,23 @@ void wsfsp_open( json_t * params, int id) { - (void) context; - (void) params; - (void) id; + size_t const count = json_array_size(params); + if (2 == count) + { + json_t * inode_holder = json_array_get(params, 0); + json_t * flags_holder = json_array_get(params, 1); - puts("open"); + if (json_is_integer(inode_holder) && + json_is_integer(flags_holder)) + { + ino_t inode = (ino_t) json_integer_value(inode_holder); + int flags = (ino_t) json_integer_value(flags_holder); + + struct wsfsp_request * request = wsfsp_request_create(context->request, id); + + context->provider->open(request, inode, flags, context->user_data); + } + } } void wsfsp_open_default( @@ -28,8 +41,8 @@ void wsfsp_respond_open( struct wsfsp_request * request, uint32_t handle) { - (void) request; - (void) handle; + json_t * result = json_object(); + json_object_set_new(result, "handle", json_integer((int) handle)); - // ToDo: implement me + wsfsp_respond(request, result); }