Home | History | Annotate | Download | only in nacl_io
      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
      5 Use of this source code is governed by a BSD-style license that can be
      6 found in the LICENSE file.
      7 -->
      8 <head>
      9   <meta http-equiv="Pragma" content="no-cache">
     10   <meta http-equiv="Expires" content="-1">
     11   <title>{{title}}</title>
     12   <script type="text/javascript" src="common.js"></script>
     13   <script type="text/javascript" src="example.js"></script>
     14 </head>
     15 <body data-custom-load="true" {{attrs}}>
     16   <h1>{{title}}</h1>
     17   <h2>Status: <code id="statusField">NO-STATUS</code></h2>
     18   <p>
     19     This example shows how you can use standard C library file and socket
     20     operation functions in Native Client using a library called nacl_io.
     21   </p>
     22   <p>
     23     nacl_io provides a virtual filesystem. The filesystem can be "mounted"
     24     in a given directory tree. When you perform operations on files in those
     25     directories, the mount determines how those operations should be performed.
     26   </p>
     27   <p>
     28     This example has four mounts by default.
     29     <ol>
     30       <li><i>/</i> the root of the filesystem. This is a memory mount, and
     31           is non-persistent.</li>
     32       <li><i>/persistent</i> a persistent storage area. Any data written
     33           here can be read back after Chrome is restarted.</li>
     34       <li><i>/http</i> a mount that can read from a URL. Try reading from
     35           /http/index.html.</li>
     36       <li><i>/dev</i> a mount containing some utility files. /dev/null,
     37           /dev/zero, etc.</li>
     38     </ol>
     39   </p>
     40   <p>
     41     nacl_io also provides a (currently incomplete) posix socket api. Like the
     42     virtual filesystem, it is an abstraction layer on top of ppapi. To use this
     43     API, an app must be a packaged app with the appropriate socket permissions
     44     specified in the manifest file.
     45   <hr>
     46   <p><b>File Operations:</b></p>
     47   <div>
     48     <span>
     49       <input type="radio" id="radiofopen" name="filegroup" checked="checked">fopen
     50       <input type="radio" id="radiofclose" name="filegroup">fclose
     51       <input type="radio" id="radiofread" name="filegroup">fread
     52       <input type="radio" id="radiofwrite" name="filegroup">fwrite
     53       <input type="radio" id="radiofseek" name="filegroup">fseek
     54       <input type="radio" id="radiostat" name="filegroup">stat
     55       <input type="radio" id="radioopendir" name="filegroup">opendir
     56       <input type="radio" id="radioreaddir" name="filegroup">readdir
     57       <input type="radio" id="radioclosedir" name="filegroup">closedir
     58       <input type="radio" id="radiomkdir" name="filegroup">mkdir
     59     </span>
     60   </div>
     61   <div class="function" id="fopen">
     62     <span>
     63       Filename:
     64       <input type="text" id="fopenFilename">
     65       <select id="fopenMode">
     66         <option value="r">Read Existing (r)</option>
     67         <option value="r+">Read/Write Existing (r+)</option>
     68         <option value="w">Write New File (w)</option>
     69         <option value="w+">Read/Write New File (w+)</option>
     70         <option value="a">Append Write (a)</option>
     71         <option value="w+">Append Read/Write (a+)</option>
     72       </select>
     73       <button>fopen</button>
     74     </span>
     75   </div>
     76   <div class="function" id="fclose" hidden>
     77     <span>
     78       <select class="file-handle" id="fcloseHandle"></select>
     79       <button>fclose</button>
     80     </span>
     81   </div>
     82   <div class="function" id="fread" hidden>
     83     <span>
     84       <select class="file-handle" id="freadHandle"></select>
     85       Count:
     86       <input type="text" id="freadBytes">
     87       <button>fread</button>
     88     </span>
     89   </div>
     90   <div class="function" id="fwrite" hidden>
     91     <span>
     92       <select class="file-handle" id="fwriteHandle"></select>
     93       Data:
     94       <input type="text" id="fwriteData">
     95       <button>fwrite</button>
     96     </span>
     97   </div>
     98   <div class="function" id="fseek" hidden>
     99     <span>
    100       <select class="file-handle" id="fseekHandle"></select>
    101       Offset:
    102       <input type="text" id="fseekOffset">
    103       Whence:
    104       <select id="fseekWhence">
    105         <option value="0">SEEK_SET</option>
    106         <option value="1">SEEK_CUR</option>
    107         <option value="2">SEEK_END</option>
    108       </select>
    109       <button>fseek</button>
    110     </span>
    111   </div>
    112   <div class="function" id="stat" hidden>
    113     <span>
    114       Filename:
    115       <input type="text" id="statFilename">
    116       <button>stat</button>
    117     </span>
    118   </div>
    119   <div class="function" id="opendir" hidden>
    120     <span>
    121       Dirname:
    122       <input type="text" id="opendirDirname">
    123       <button>opendir</button>
    124     </span>
    125   </div>
    126   <div class="function" id="readdir" hidden>
    127     <span>
    128       <select class="dir-handle" id="readdirHandle"></select>
    129       <button>readdir</button>
    130     </span>
    131   </div>
    132   <div class="function" id="closedir" hidden>
    133     <span>
    134       <select class="dir-handle" id="closedirHandle"></select>
    135       <button>closedir</button>
    136     </span>
    137   </div>
    138   <div class="function" id="mkdir" hidden>
    139     <span>
    140       Dirname:
    141       <input type="text" id="mkdirDirname">
    142       Mode (in octal):
    143       <input type="text" id="mkdirMode" value="0644">
    144       <button>mkdir</button>
    145     </span>
    146   </div>
    147   <hr>
    148   <p><b>Socket Operations:</b></p>
    149   <div>
    150     <span>
    151       <input type="radio" id="radiogethostbyname" name="socketgroup" checked="checked">gethostbyname
    152     </span>
    153   </div>
    154   <div class="function" id="gethostbyname">
    155     <span>
    156       Name:
    157       <input type="text" id="gethostbynameName">
    158       <button>gethostbyname</button>
    159     </span>
    160   </div>
    161 
    162   <hr>
    163   <p><b>Log:</b></p>
    164   <pre id="log" style="font-weight: bold"></pre>
    165   <!-- The NaCl plugin will be embedded inside the element with id "listener".
    166       See common.js.-->
    167   <div id="listener"></div>
    168 </body>
    169 </html>
    170