OLD | NEW |
1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
2 | 2 |
3 <section id="the-nacl-io-library"> | 3 <section id="the-nacl-io-library"> |
4 <span id="nacl-io"></span><h1 id="the-nacl-io-library"><span id="nacl-io"></span
>The nacl_io Library</h1> | 4 <span id="nacl-io"></span><h1 id="the-nacl-io-library"><span id="nacl-io"></span
>The nacl_io Library</h1> |
5 <div class="contents local" id="contents" style="display: none"> | 5 <div class="contents local" id="contents" style="display: none"> |
6 <ul class="small-gap"> | 6 <ul class="small-gap"> |
7 <li><a class="reference internal" href="#introduction" id="id1">Introduction</a>
</li> | 7 <li><a class="reference internal" href="#introduction" id="id1">Introduction</a>
</li> |
8 <li><a class="reference internal" href="#using-nacl-io" id="id2">Using nacl_io</
a></li> | 8 <li><a class="reference internal" href="#using-nacl-io" id="id2">Using nacl_io</
a></li> |
9 <li><p class="first"><a class="reference internal" href="#the-nacl-io-demo" id="
id3">The nacl_io demo</a></p> | 9 <li><a class="reference internal" href="#logging-in-nacl-io" id="id3">Logging in
nacl_io</a></li> |
| 10 <li><p class="first"><a class="reference internal" href="#the-nacl-io-demo" id="
id4">The nacl_io demo</a></p> |
10 <ul class="small-gap"> | 11 <ul class="small-gap"> |
11 <li><a class="reference internal" href="#building-and-running-the-demo" id="id4"
>Building and running the demo</a></li> | 12 <li><a class="reference internal" href="#building-and-running-the-demo" id="id5"
>Building and running the demo</a></li> |
12 <li><a class="reference internal" href="#a-look-at-the-code" id="id5">A look at
the code</a></li> | 13 <li><a class="reference internal" href="#a-look-at-the-code" id="id6">A look at
the code</a></li> |
13 </ul> | 14 </ul> |
14 </li> | 15 </li> |
15 <li><a class="reference internal" href="#reference-information" id="id6">Referen
ce information</a></li> | 16 <li><a class="reference internal" href="#reference-information" id="id7">Referen
ce Information</a></li> |
16 </ul> | 17 </ul> |
17 | 18 |
18 </div><h2 id="introduction">Introduction</h2> | 19 </div><h2 id="introduction">Introduction</h2> |
19 <p><code>nacl_io</code> is a utility library that provides implementations of st
andard | 20 <p><code>nacl_io</code> is a utility library that provides implementations of st
andard |
20 C APIs such as POSIX I/O (<code>stdio.h</code>) and BSD sockets (<code>sys/socke
t.h</code>). | 21 C APIs such as POSIX I/O (<code>stdio.h</code>) and BSD sockets (<code>sys/socke
t.h</code>). |
21 Its primary function is to allow code that uses these standard APIs to be | 22 Its primary function is to allow code that uses these standard APIs to be |
22 compiled and used in a Native Client module. The library is included as part | 23 compiled and used in a Native Client module. The library is included as part |
23 of Native Client SDK and is implemented in on top of Pepper API.</p> | 24 of Native Client SDK and is implemented in on top of Pepper API.</p> |
24 <p>Since Native Client modules cannot access the host machine’s file syste
m | 25 <p>Since Native Client modules cannot access the host machine’s file syste
m |
25 directly, nacl_io provides several alternative filesystem types which | 26 directly, nacl_io provides several alternative filesystem types which can be |
26 can be used by the application. For example, the Chrome browser supports the | 27 used by the application. For example, the Chrome browser supports the <a class="
reference external" href="http://www.html5rocks.com/en/tutorials/file/filesystem
/">HTML5 |
27 <a class="reference external" href="http://www.html5rocks.com/en/tutorials/file/
filesystem/">HTML5 File System API</a> which provides | 28 File System API</a> |
28 access to a protected area of the local file system. This filesystem can | 29 which provides access to a protected area of the local file system. This |
29 be accessed by an HTML page using JavaScript commands, and also by a Native | 30 filesystem can be accessed by an HTML page using JavaScript commands, and also |
30 Client module using the Pepper <a class="reference internal" href="/native-clien
t/devguide/coding/file-io.html"><em>File IO API</em></a>. With nacl_io | 31 by a Native Client module using the Pepper <a class="reference internal" href="/
native-client/devguide/coding/file-io.html"><em>File IO API</em></a>.</p> |
31 a Native Client application can mount an HTML5 filesystem and access it via | 32 <p>With nacl_io a Native Client application can mount an HTML5 filesystem and |
32 standard POSIX I/O function such as <code>fopen</code>, <code>fseek</code>, <cod
e>fread</code>, | 33 access it via standard POSIX I/O function such as <code>fopen</code>, <code>fsee
k</code>, |
33 <code>fwrite</code>, and <code>fclose</code>, or their low level UNIX counterpar
ts <code>open</code>, | 34 <code>fread</code>, <code>fwrite</code>, and <code>fclose</code>, or their low l
evel UNIX counterparts |
34 <code>lseek</code>, <code>read</code>, <code>write</code> and <code>close</code>
.</p> | 35 <code>open</code>, <code>lseek</code>, <code>read</code>, <code>write</code> and
<code>close</code>. As well as the HTML5 |
35 <p>As well as the HTML5 file system, nacl_io provides several other file system | 36 file system, nacl_io provides several other file system types which are |
36 types which are described in the table below:</p> | 37 described in the table below:</p> |
37 <table border="1" class="docutils"> | 38 <table border="1" class="docutils"> |
38 <colgroup> | 39 <colgroup> |
39 </colgroup> | 40 </colgroup> |
40 <thead valign="bottom"> | 41 <thead valign="bottom"> |
41 <tr class="row-odd"><th class="head">File System</th> | 42 <tr class="row-odd"><th class="head">File System</th> |
42 <th class="head">Description</th> | 43 <th class="head">Description</th> |
43 </tr> | 44 </tr> |
44 </thead> | 45 </thead> |
45 <tbody valign="top"> | 46 <tbody valign="top"> |
46 <tr class="row-even"><td>memfs</td> | 47 <tr class="row-even"><td>memfs</td> |
(...skipping 23 matching lines...) Expand all Loading... |
70 to <code>mount</code> for the different filesystem types are detailed in | 71 to <code>mount</code> for the different filesystem types are detailed in |
71 <code>include/nacl_io/nacl_io.h</code>.</li> | 72 <code>include/nacl_io/nacl_io.h</code>.</li> |
72 <li>If you are going to mount an HTML5 file system, be sure to allocate space | 73 <li>If you are going to mount an HTML5 file system, be sure to allocate space |
73 for it. You can either set the <code>unlimitedStorage</code> permission in the a
pp’s | 74 for it. You can either set the <code>unlimitedStorage</code> permission in the a
pp’s |
74 Web Store manifest file, or call the HTML5 QuotaManagement API. These | 75 Web Store manifest file, or call the HTML5 QuotaManagement API. These |
75 options are explained in the <a class="reference internal" href="/native-client/
devguide/coding/file-io.html#quota-management"><em>File IO documentation</em></a
>.</li> | 76 options are explained in the <a class="reference internal" href="/native-client/
devguide/coding/file-io.html#quota-management"><em>File IO documentation</em></a
>.</li> |
76 <li>Make sure that file and socket API calls are all made from the background | 77 <li>Make sure that file and socket API calls are all made from the background |
77 thread. This is because the main Pepper thread does not support the blocking | 78 thread. This is because the main Pepper thread does not support the blocking |
78 behavior needed by the POSIX I/O operations.</li> | 79 behavior needed by the POSIX I/O operations.</li> |
79 </ol> | 80 </ol> |
| 81 <h2 id="logging-in-nacl-io">Logging in nacl_io</h2> |
| 82 <p>Unlike most input/output for nacl_io, internal logging writes directly to the |
| 83 <code>stderr</code> stream of the NaCl process. It deliberately bypasses the sta
ndard |
| 84 library functions implemented in nacl_io to avoid circular calls to itself.</p> |
80 <h2 id="the-nacl-io-demo">The nacl_io demo</h2> | 85 <h2 id="the-nacl-io-demo">The nacl_io demo</h2> |
81 <h3 id="building-and-running-the-demo">Building and running the demo</h3> | 86 <h3 id="building-and-running-the-demo">Building and running the demo</h3> |
82 <p>The demo application launches a Native Client module that mounts three file | 87 <p>The demo application launches a Native Client module that mounts three file |
83 systems and displays a set of controls that let you work with them:</p> | 88 systems and displays a set of controls that let you work with them:</p> |
84 <img alt="/native-client/images/nacl_io1.png" src="/native-client/images/nacl_io
1.png" /> | 89 <img alt="/native-client/images/nacl_io1.png" src="/native-client/images/nacl_io
1.png" /> |
85 <p>Follow these steps to build and run the demo:</p> | 90 <p>Follow these steps to build and run the demo:</p> |
86 <ul class="small-gap"> | 91 <ul class="small-gap"> |
87 <li><p class="first">Open a terminal in the demo directory:</p> | 92 <li><p class="first">Open a terminal in the demo directory:</p> |
88 <pre class="prettyprint"> | 93 <pre class="prettyprint"> |
89 $ cd $NACL_SDK_ROOT/examples/demo/nacl_io_demo | 94 $ cd $NACL_SDK_ROOT/examples/demo/nacl_io_demo |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 return 2; | 201 return 2; |
197 } | 202 } |
198 | 203 |
199 bytes_written = fwrite(data, 1, data_len, file); | 204 bytes_written = fwrite(data, 1, data_len, file); |
200 | 205 |
201 *output = PrintfToNewString("fwrite\1%s\1%d", file_index_string, | 206 *output = PrintfToNewString("fwrite\1%s\1%d", file_index_string, |
202 bytes_written); | 207 bytes_written); |
203 return 0; | 208 return 0; |
204 } | 209 } |
205 </pre> | 210 </pre> |
206 <h2 id="reference-information">Reference information</h2> | 211 <h2 id="reference-information">Reference Information</h2> |
207 <p>The example discussed here is included in the SDK in the directory | 212 <p>The example discussed here is included in the SDK in the directory |
208 <code>examples/demo/nacl_io_demo</code>.</p> | 213 <code>examples/demo/nacl_io_demo</code>.</p> |
209 <p>The nacl_io library is included in the SDK toolchain and is not a part of the | 214 <p>The nacl_io library is included in the SDK toolchain and is not a part of the |
210 Pepper API. For reference information related to the nacl_io interface see | 215 Pepper API. For reference information related to the nacl_io interface see |
211 its header file in the SDK directory, located at | 216 its header file in the SDK directory, located at |
212 <code>include/nacl_io/nacl_io.h</code>.</p> | 217 <code>include/nacl_io/nacl_io.h</code>.</p> |
213 <p>For more about the HTML5 file system read the <a class="reference external" h
ref="http://dev.w3.org/2009/dap/file-system/pub/FileSystem/">specification</a>.<
/p> | 218 <p>For more about the HTML5 file system read the <a class="reference external" h
ref="http://dev.w3.org/2009/dap/file-system/pub/FileSystem/">specification</a>.<
/p> |
214 </section> | 219 </section> |
215 | 220 |
216 {{/partials.standard_nacl_article}} | 221 {{/partials.standard_nacl_article}} |
OLD | NEW |