OLD | NEW |
1 .. _nacl_io: | 1 .. _nacl_io: |
2 | 2 |
3 ################### | 3 ################### |
4 The nacl_io Library | 4 The nacl_io Library |
5 ################### | 5 ################### |
6 | 6 |
7 .. contents:: | 7 .. contents:: |
8 :local: | 8 :local: |
9 :backlinks: none | 9 :backlinks: none |
10 :depth: 2 | 10 :depth: 2 |
11 | 11 |
12 Introduction | 12 Introduction |
13 ============ | 13 ============ |
14 | 14 |
15 ``nacl_io`` is a utility library that provides implementations of standard | 15 ``nacl_io`` is a utility library that provides implementations of standard |
16 C APIs such as POSIX I/O (``stdio.h``) and BSD sockets (``sys/socket.h``). | 16 C APIs such as POSIX I/O (``stdio.h``) and BSD sockets (``sys/socket.h``). |
17 Its primary function is to allow code that uses these standard APIs to be | 17 Its primary function is to allow code that uses these standard APIs to be |
18 compiled and used in a Native Client module. The library is included as part | 18 compiled and used in a Native Client module. The library is included as part |
19 of Native Client SDK and is implemented in on top of Pepper API. | 19 of Native Client SDK and is implemented in on top of Pepper API. |
20 | 20 |
21 Since Native Client modules cannot access the host machine's file system | 21 Since Native Client modules cannot access the host machine's file system |
22 directly, nacl_io provides several alternative filesystem types which | 22 directly, nacl_io provides several alternative filesystem types which can be |
23 can be used by the application. For example, the Chrome browser supports the | 23 used by the application. For example, the Chrome browser supports the `HTML5 |
24 `HTML5 File System API | 24 File System API <http://www.html5rocks.com/en/tutorials/file/filesystem/>`_ |
25 <http://www.html5rocks.com/en/tutorials/file/filesystem/>`_ which provides | 25 which provides access to a protected area of the local file system. This |
26 access to a protected area of the local file system. This filesystem can | 26 filesystem can be accessed by an HTML page using JavaScript commands, and also |
27 be accessed by an HTML page using JavaScript commands, and also by a Native | 27 by a Native Client module using the Pepper :doc:`File IO API <file-io>`. |
28 Client module using the Pepper :doc:`File IO API <file-io>`. With nacl_io | |
29 a Native Client application can mount an HTML5 filesystem and access it via | |
30 standard POSIX I/O function such as ``fopen``, ``fseek``, ``fread``, | |
31 ``fwrite``, and ``fclose``, or their low level UNIX counterparts ``open``, | |
32 ``lseek``, ``read``, ``write`` and ``close``. | |
33 | 28 |
34 As well as the HTML5 file system, nacl_io provides several other file system | 29 With nacl_io a Native Client application can mount an HTML5 filesystem and |
35 types which are described in the table below: | 30 access it via standard POSIX I/O function such as ``fopen``, ``fseek``, |
| 31 ``fread``, ``fwrite``, and ``fclose``, or their low level UNIX counterparts |
| 32 ``open``, ``lseek``, ``read``, ``write`` and ``close``. As well as the HTML5 |
| 33 file system, nacl_io provides several other file system types which are |
| 34 described in the table below: |
36 | 35 |
37 =========== ================================================================== | 36 =========== ================================================================== |
38 File System Description | 37 File System Description |
39 =========== ================================================================== | 38 =========== ================================================================== |
40 memfs An in-memory file system | 39 memfs An in-memory file system |
41 html5fs An HTML5 local file system, which can be persistent or temporary | 40 html5fs An HTML5 local file system, which can be persistent or temporary |
42 http Maps files on a remote webserver into the local filesystem. | 41 http Maps files on a remote webserver into the local filesystem. |
43 dev A file system containing special files (e.g.: ``/dev/null``) | 42 dev A file system containing special files (e.g.: ``/dev/null``) |
44 =========== ================================================================== | 43 =========== ================================================================== |
45 | 44 |
(...skipping 12 matching lines...) Expand all Loading... |
58 to ``mount`` for the different filesystem types are detailed in | 57 to ``mount`` for the different filesystem types are detailed in |
59 ``include/nacl_io/nacl_io.h``. | 58 ``include/nacl_io/nacl_io.h``. |
60 #. If you are going to mount an HTML5 file system, be sure to allocate space | 59 #. If you are going to mount an HTML5 file system, be sure to allocate space |
61 for it. You can either set the ``unlimitedStorage`` permission in the app's | 60 for it. You can either set the ``unlimitedStorage`` permission in the app's |
62 Web Store manifest file, or call the HTML5 QuotaManagement API. These | 61 Web Store manifest file, or call the HTML5 QuotaManagement API. These |
63 options are explained in the :ref:`File IO documentation <quota_management>`. | 62 options are explained in the :ref:`File IO documentation <quota_management>`. |
64 #. Make sure that file and socket API calls are all made from the background | 63 #. Make sure that file and socket API calls are all made from the background |
65 thread. This is because the main Pepper thread does not support the blocking | 64 thread. This is because the main Pepper thread does not support the blocking |
66 behavior needed by the POSIX I/O operations. | 65 behavior needed by the POSIX I/O operations. |
67 | 66 |
| 67 Logging in nacl_io |
| 68 ================== |
| 69 |
| 70 Unlike most input/output for nacl_io, internal logging writes directly to the |
| 71 ``stderr`` stream of the NaCl process. It deliberately bypasses the standard |
| 72 library functions implemented in nacl_io to avoid circular calls to itself. |
| 73 |
68 The nacl_io demo | 74 The nacl_io demo |
69 ================ | 75 ================ |
70 | 76 |
71 Building and running the demo | 77 Building and running the demo |
72 ----------------------------- | 78 ----------------------------- |
73 | 79 |
74 The demo application launches a Native Client module that mounts three file | 80 The demo application launches a Native Client module that mounts three file |
75 systems and displays a set of controls that let you work with them: | 81 systems and displays a set of controls that let you work with them: |
76 | 82 |
77 .. image:: /images/nacl_io1.png | 83 .. image:: /images/nacl_io1.png |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return 2; | 211 return 2; |
206 } | 212 } |
207 | 213 |
208 bytes_written = fwrite(data, 1, data_len, file); | 214 bytes_written = fwrite(data, 1, data_len, file); |
209 | 215 |
210 *output = PrintfToNewString("fwrite\1%s\1%d", file_index_string, | 216 *output = PrintfToNewString("fwrite\1%s\1%d", file_index_string, |
211 bytes_written); | 217 bytes_written); |
212 return 0; | 218 return 0; |
213 } | 219 } |
214 | 220 |
215 Reference information | 221 Reference Information |
216 ===================== | 222 ===================== |
217 | 223 |
218 The example discussed here is included in the SDK in the directory | 224 The example discussed here is included in the SDK in the directory |
219 ``examples/demo/nacl_io_demo``. | 225 ``examples/demo/nacl_io_demo``. |
220 | 226 |
221 The nacl_io library is included in the SDK toolchain and is not a part of the | 227 The nacl_io library is included in the SDK toolchain and is not a part of the |
222 Pepper API. For reference information related to the nacl_io interface see | 228 Pepper API. For reference information related to the nacl_io interface see |
223 its header file in the SDK directory, located at | 229 its header file in the SDK directory, located at |
224 ``include/nacl_io/nacl_io.h``. | 230 ``include/nacl_io/nacl_io.h``. |
225 | 231 |
226 For more about the HTML5 file system read the `specification | 232 For more about the HTML5 file system read the `specification |
227 <http://dev.w3.org/2009/dap/file-system/pub/FileSystem/>`_. | 233 <http://dev.w3.org/2009/dap/file-system/pub/FileSystem/>`_. |
OLD | NEW |