diff options
5 files changed, 117 insertions, 8 deletions
diff --git a/native_client_sdk/src/examples/hello_nacl_mounts/hello_nacl_mounts.c b/native_client_sdk/src/examples/hello_nacl_mounts/hello_nacl_mounts.c index 9782e9e..bf5ff77 100644 --- a/native_client_sdk/src/examples/hello_nacl_mounts/hello_nacl_mounts.c +++ b/native_client_sdk/src/examples/hello_nacl_mounts/hello_nacl_mounts.c @@ -20,7 +20,7 @@ #include "ppapi/c/ppp.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/ppp_messaging.h" -#include "nacl_mounts/kernel_intercept.h" +#include "nacl_mounts/nacl_mounts.h" #include "handlers.h" #include "queue.h" @@ -31,10 +31,6 @@ #define va_copy(d, s) ((d) = (s)) #endif -int mount(const char *source, const char *target, const char *filesystemtype, - unsigned long mountflags, const void *data); - - typedef struct { const char* name; HandleFunc function; @@ -279,7 +275,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance, const char* argn[], const char* argv[]) { g_instance = instance; - ki_init_ppapi(NULL, instance, get_browser_interface); + nacl_mounts_init_ppapi(instance, get_browser_interface); mount( "", /* source */ "/persistent", /* target */ diff --git a/native_client_sdk/src/libraries/nacl_mounts/library.dsc b/native_client_sdk/src/libraries/nacl_mounts/library.dsc index 1471268..b0de0e1 100644 --- a/native_client_sdk/src/libraries/nacl_mounts/library.dsc +++ b/native_client_sdk/src/libraries/nacl_mounts/library.dsc @@ -25,6 +25,7 @@ "mount_node_dir.cc", "mount_node_html5fs.cc", "mount_node_mem.cc", + "nacl_mounts.cc", "path.cc", "pepper_interface.cc", "real_pepper_interface.cc", @@ -47,6 +48,7 @@ "mount_node.h", "mount_node_html5fs.h", "mount_node_mem.h", + "nacl_mounts.h", "osdirent.h", "osstat.h", "ostypes.h", diff --git a/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.cc b/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.cc new file mode 100644 index 0000000..8490c30 --- /dev/null +++ b/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.cc @@ -0,0 +1,18 @@ +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "nacl_mounts/nacl_mounts.h" + +#include <stdlib.h> +#include "nacl_mounts/kernel_intercept.h" + +void nacl_mounts_init() { + ki_init(NULL); +} + +void nacl_mounts_init_ppapi(PP_Instance instance, + PPB_GetInterface get_interface) { + ki_init_ppapi(NULL, instance, get_interface); +} diff --git a/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.h b/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.h new file mode 100644 index 0000000..da14ba4 --- /dev/null +++ b/native_client_sdk/src/libraries/nacl_mounts/nacl_mounts.h @@ -0,0 +1,93 @@ +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef LIBRARIES_NACL_MOUNTS_NACL_MOUNTS_H_ +#define LIBRARIES_NACL_MOUNTS_NACL_MOUNTS_H_ + +#include <ppapi/c/pp_instance.h> +#include <ppapi/c/ppb.h> +#include "utils/macros.h" + +EXTERN_C_BEGIN + + +/** Initialize nacl_mounts. + * + * NOTE: If you initialize nacl_mounts with this constructor, you cannot + * use any mounts that require PPAPI; e.g. persistent storage, etc. + */ +void nacl_mounts_init(); + +/** Initialize nacl_mounts with PPAPI support. + * + * Usage: + * PP_Instance instance; + * PPB_GetInterface get_interface; + * nacl_mounts_init(instance, get_interface); + * + * If you are using the PPAPI C interface: + * |instance| is passed to your instance in the DidCreate function. + * |get_interface| is passed to your module in the PPP_InitializeModule + * function. + * + * If you are using the PPAPI C++ interface: + * |instance| can be retrieved via the Instance::pp_instance() method. + * |get_interface| can be retrieved via + * pp::Module()::Get()->get_browser_interface() + */ +void nacl_mounts_init_ppapi(PP_Instance instance, + PPB_GetInterface get_interface); + + +/** Mount a new filesystem type. + * + * Some parameters are dependent on the filesystem type being mounted. + * + * The |data| parameter, if used, is always parsed as a string of comma + * separated key-value pairs: + * e.g. "key1=param1,key2=param2" + * + * + * filesystem types: + * "memfs": An in-memory filesystem. + * source: Unused. + * data: Unused. + * + * "dev": A filesystem with various utility nodes. Some examples: + * "null": equivalent to /dev/null. + * "zero": equivalent to /dev/zero. + * "urandom": equivalent to /dev/urandom. + * "console[0-3]": logs to the JavaScript console with varying log + * levels. + * "tty": Posts a message to JavaScript, which will send a "message" + * event from this module's embed element. + * source: Unused. + * data: Unused. + * + * "html5fs": A filesystem that uses PPAPI FileSystem interface, which can be + * read in JavaScript via the HTML5 FileSystem API. This mount + * provides the use of persistent storage. Please read the + * documentation in ppapi/c/ppb_file_system.h for more information. + * source: Unused. + * data: A string of parameters: + * "type": Which type of filesystem to mount. Valid values are + * "PERSISTENT" and "TEMPORARY". The default is "PERSISTENT". + * "expected_size": The expected file-system size. Note that this does + * not request quota -- you must do that from JavaScript. + * + * + * @param[in] source Depends on the filesystem type. See above. + * @param[in] target The absolute path to mount the filesystem. + * @param[in] filesystemtype The name of the filesystem type to mount. See + * above for examples. + * @param[in] mountflags Unused. + * @param[in] data Depends on the filesystem type. See above. + * @return 0 on success, -1 on failure (with errno set). + */ +int mount(const char* source, const char* target, const char* filesystemtype, + unsigned long mountflags, const void *data); + +EXTERN_C_END + +#endif // LIBRARIES_NACL_MOUNTS_NACL_MOUNTS_H_ diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc index 97759fa..5389ca8 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc @@ -14,7 +14,7 @@ #include <string> #include <vector> -#include "nacl_mounts/kernel_intercept.h" +#include "nacl_mounts/nacl_mounts.h" #include "ppapi/cpp/input_event.h" #include "ppapi/cpp/rect.h" @@ -136,7 +136,7 @@ bool PPAPIInstance::ProcessProperties() { const char* stdout_path = GetProperty("PM_STDOUT", "/dev/tty"); const char* stderr_path = GetProperty("PM_STDERR", "/dev/console3"); - ki_init_ppapi(NULL, PPAPI_GetInstanceId(), PPAPI_GetInterface); + nacl_mounts_init_ppapi(PPAPI_GetInstanceId(), PPAPI_GetInterface); int f1 = open(stdin_path, O_RDONLY); int f2 = open(stdout_path, O_WRONLY); int f3 = open(stderr_path, O_WRONLY); |