1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <title>Reference</title>
6 <link rel="stylesheet" href="../luadoc.css" type="text/css" />
7 <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
14 <div id="product_logo"></div>
15 <div id="product_name"><big><b></b></big></div>
16 <div id="product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href="../index.html">Index</a></li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
42 <a href="../modules/luci.http.protocol.html">luci.http.protocol</a>
46 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
50 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
54 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
58 <a href="../modules/luci.i18n.html">luci.i18n</a>
62 <a href="../modules/luci.ip.html">luci.ip</a>
66 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
70 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
74 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
78 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
82 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
86 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
90 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
94 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
98 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
102 <a href="../modules/nixio.html">nixio</a>
106 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
110 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
114 <a href="../modules/nixio.File.html">nixio.File</a>
118 <a href="../modules/nixio.README.html">nixio.README</a>
122 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
126 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
130 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
134 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
138 <a href="../modules/nixio.bin.html">nixio.bin</a>
142 <a href="../modules/nixio.bit.html">nixio.bit</a>
146 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
149 <li><strong>nixio.fs</strong></li>
163 </div><!-- id="navigation" -->
167 <h1>Class <code>nixio.fs</code></h1>
170 Low-level and high-level filesystem manipulation library.</p>
179 <table class="function_list">
182 <td class="name" nowrap><a href="#nixio.fs.access">access</a> (path, mode1, ...)</td>
184 Check user's permission on a file.</td>
188 <td class="name" nowrap><a href="#nixio.fs.basename">basename</a> (path)</td>
190 Strip the directory part from a path.</td>
194 <td class="name" nowrap><a href="#nixio.fs.chmod">chmod</a> (path, mode)</td>
196 Change the file mode.</td>
200 <td class="name" nowrap><a href="#nixio.fs.chown">chown</a> (path, user, group)</td>
202 (POSIX) Change owner and group of a file.</td>
206 <td class="name" nowrap><a href="#nixio.fs.copy">copy</a> (src, dest)</td>
208 Copy a file, directory or symlink non-recursively preserving file mode,
209 timestamps, owner and group.</td>
213 <td class="name" nowrap><a href="#nixio.fs.copyr">copyr</a> (src, dest)</td>
215 Copy a file, directory or symlink recursively preserving file mode,
216 timestamps, owner and group.</td>
220 <td class="name" nowrap><a href="#nixio.fs.datacopy">datacopy</a> (src, dest, limit)</td>
222 Copy data between files.</td>
226 <td class="name" nowrap><a href="#nixio.fs.dir">dir</a> (path)</td>
228 Iterate over the entries of a directory.</td>
232 <td class="name" nowrap><a href="#nixio.fs.dirname">dirname</a> (path)</td>
234 Strip the base from a path.</td>
238 <td class="name" nowrap><a href="#nixio.fs.glob">glob</a> (pattern)</td>
240 (POSIX) Find pathnames matching a pattern.</td>
244 <td class="name" nowrap><a href="#nixio.fs.lchown">lchown</a> (path, user, group)</td>
246 (POSIX) Change owner and group of a file and do not resolve
247 if target is a symlink.</td>
251 <td class="name" nowrap><a href="#nixio.fs.link">link</a> (oldpath, newpath)</td>
253 Create a hard link.</td>
257 <td class="name" nowrap><a href="#nixio.fs.lstat">lstat</a> (path, field)</td>
259 Get file status and attributes and do not resolve if target is a symlink.</td>
263 <td class="name" nowrap><a href="#nixio.fs.mkdir">mkdir</a> (path, mode)</td>
265 Create a new directory.</td>
269 <td class="name" nowrap><a href="#nixio.fs.mkdirr">mkdirr</a> (dest, mode)</td>
271 Create a directory and all needed parent directories recursively.</td>
275 <td class="name" nowrap><a href="#nixio.fs.mkfifo">mkfifo</a> (path, mode)</td>
277 (POSIX) Create a FIFO (named pipe).</td>
281 <td class="name" nowrap><a href="#nixio.fs.move">move</a> (src, dest)</td>
283 Rename a file, directory or symlink non-recursively across filesystems.</td>
287 <td class="name" nowrap><a href="#nixio.fs.mover">mover</a> (src, dest)</td>
289 Rename a file, directory or symlink recursively across filesystems.</td>
293 <td class="name" nowrap><a href="#nixio.fs.readfile">readfile</a> (path, limit)</td>
295 Read the contents of a file into a buffer.</td>
299 <td class="name" nowrap><a href="#nixio.fs.readlink">readlink</a> (path)</td>
301 (POSIX) Read the target of a symbolic link.</td>
305 <td class="name" nowrap><a href="#nixio.fs.realpath">realpath</a> (path)</td>
307 Return the cannonicalized absolute pathname.</td>
311 <td class="name" nowrap><a href="#nixio.fs.remove">remove</a> (path)</td>
313 Remove a file or directory.</td>
317 <td class="name" nowrap><a href="#nixio.fs.rename">rename</a> (src, dest)</td>
319 Renames a file or directory.</td>
323 <td class="name" nowrap><a href="#nixio.fs.rmdir">rmdir</a> (path)</td>
325 Remove an empty directory.</td>
329 <td class="name" nowrap><a href="#nixio.fs.stat">stat</a> (path, field)</td>
331 Get file status and attributes.</td>
335 <td class="name" nowrap><a href="#nixio.fs.statvfs">statvfs</a> (path)</td>
337 (POSIX) Get filesystem statistics.</td>
341 <td class="name" nowrap><a href="#nixio.fs.symlink">symlink</a> (oldpath, newpath)</td>
343 (POSIX) Create a symbolic link.</td>
347 <td class="name" nowrap><a href="#nixio.fs.unlink">unlink</a> (path)</td>
349 Delete a name and - if no links are left - the associated file.</td>
353 <td class="name" nowrap><a href="#nixio.fs.utimes">utimes</a> (path, actime, mtime)</td>
355 Change file last access and last modification time.</td>
359 <td class="name" nowrap><a href="#nixio.fs.writefile">writefile</a> (path, data)</td>
361 Write a buffer into a file truncating the file first.</td>
375 <h2><a name="functions"></a>Functions</h2>
376 <dl class="function">
380 <dt><a name="nixio.fs.access"></a><strong>access</strong> (path, mode1, ...)</dt>
383 Check user's permission on a file.
394 mode1: First Mode to check ["f", "r", "w", "x"]
398 ...: More Modes to check [-"-]
408 <h3>Return value:</h3>
418 <dt><a name="nixio.fs.basename"></a><strong>basename</strong> (path)</dt>
421 Strip the directory part from a path.
437 This function cannot fail and will never return nil.
441 <h3>Return value:</h3>
451 <dt><a name="nixio.fs.chmod"></a><strong>chmod</strong> (path, mode)</dt>
454 Change the file mode.
466 [decimal mode number, "[-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT]"]
477 <li>Windows only supports setting the write-protection through the
478 "Writable to others" bit.
480 <li><strong>Notice:</strong> The mode-flag for the functions
481 open, mkdir, mkfifo are affected by the umask.
487 <h3>Return value:</h3>
506 <dt><a name="nixio.fs.chown"></a><strong>chown</strong> (path, user, group)</dt>
509 (POSIX) Change owner and group of a file.
520 user: User ID or Username (optional)
524 group: Group ID or Groupname (optional)
534 <h3>Return value:</h3>
544 <dt><a name="nixio.fs.copy"></a><strong>copy</strong> (src, dest)</dt>
547 Copy a file, directory or symlink non-recursively preserving file mode,
548 timestamps, owner and group.
559 dest: Destination path
568 The destination must always be a full destination path e.g. do not
569 omit the basename even if source and destination basename are equal.
573 <h3>Return value:</h3>
583 <dt><a name="nixio.fs.copyr"></a><strong>copyr</strong> (src, dest)</dt>
586 Copy a file, directory or symlink recursively preserving file mode,
587 timestamps, owner and group.
598 dest: Destination path
607 The destination must always be a full destination path e.g. do not
608 omit the basename even if source and destination basename are equal.
612 <h3>Return value:</h3>
622 <dt><a name="nixio.fs.datacopy"></a><strong>datacopy</strong> (src, dest, limit)</dt>
625 Copy data between files.
632 src: Source file path
636 dest: Destination file path
640 limit: Maximum bytes to copy (optional)
650 <h3>Return value:</h3>
660 <dt><a name="nixio.fs.dir"></a><strong>dir</strong> (path)</dt>
663 Iterate over the entries of a directory.
679 The special entries "." and ".." are omitted.
683 <h3>Return value:</h3>
684 directory iterator returning one entry per call
693 <dt><a name="nixio.fs.dirname"></a><strong>dirname</strong> (path)</dt>
696 Strip the base from a path.
712 This function cannot fail and will never return nil.
716 <h3>Return value:</h3>
726 <dt><a name="nixio.fs.glob"></a><strong>glob</strong> (pattern)</dt>
729 (POSIX) Find pathnames matching a pattern.
746 <h3>Return values:</h3>
751 <li>number of matches
762 <dt><a name="nixio.fs.lchown"></a><strong>lchown</strong> (path, user, group)</dt>
765 (POSIX) Change owner and group of a file and do not resolve
766 if target is a symlink.
777 user: User ID or Username (optional)
781 group: Group ID or Groupname (optional)
791 <h3>Return value:</h3>
801 <dt><a name="nixio.fs.link"></a><strong>link</strong> (oldpath, newpath)</dt>
824 This function calls link() on POSIX and CreateHardLink() on Windows.
828 <h3>Return value:</h3>
838 <dt><a name="nixio.fs.lstat"></a><strong>lstat</strong> (path, field)</dt>
841 Get file status and attributes and do not resolve if target is a symlink.
852 field: Only return a specific field, not the whole table (optional)
862 <h3>Return value:</h3>
863 Table containing attributes (see stat for a detailed description)
870 <li><a href="#nixio.fs.stat">
881 <dt><a name="nixio.fs.mkdir"></a><strong>mkdir</strong> (path, mode)</dt>
884 Create a new directory.
895 mode: File mode (optional, see chmod and umask)
905 <h3>Return value:</h3>
913 <li><a href="#nixio.fs.chmod">
928 <dt><a name="nixio.fs.mkdirr"></a><strong>mkdirr</strong> (dest, mode)</dt>
931 Create a directory and all needed parent directories recursively.
938 dest: Destination path
942 mode: File mode (optional, see chmod and umask)
952 <h3>Return value:</h3>
960 <li><a href="#nixio.fs.chmod">
975 <dt><a name="nixio.fs.mkfifo"></a><strong>mkfifo</strong> (path, mode)</dt>
978 (POSIX) Create a FIFO (named pipe).
989 mode: File mode (optional, see chmod and umask)
999 <h3>Return value:</h3>
1007 <li><a href="#nixio.fs.chmod">
1022 <dt><a name="nixio.fs.move"></a><strong>move</strong> (src, dest)</dt>
1025 Rename a file, directory or symlink non-recursively across filesystems.
1036 dest: Destination path
1045 The destination must always be a full destination path e.g. do not
1046 omit the basename even if source and destination basename are equal.
1050 <h3>Return value:</h3>
1060 <dt><a name="nixio.fs.mover"></a><strong>mover</strong> (src, dest)</dt>
1063 Rename a file, directory or symlink recursively across filesystems.
1074 dest: Destination path
1083 The destination must always be a full destination path e.g. do not
1084 omit the basename even if source and destination basename are equal.
1088 <h3>Return value:</h3>
1098 <dt><a name="nixio.fs.readfile"></a><strong>readfile</strong> (path, limit)</dt>
1101 Read the contents of a file into a buffer.
1112 limit: Maximum bytes to read (optional)
1122 <h3>Return value:</h3>
1132 <dt><a name="nixio.fs.readlink"></a><strong>readlink</strong> (path)</dt>
1135 (POSIX) Read the target of a symbolic link.
1152 <h3>Return value:</h3>
1162 <dt><a name="nixio.fs.realpath"></a><strong>realpath</strong> (path)</dt>
1165 Return the cannonicalized absolute pathname.
1182 <h3>Return value:</h3>
1192 <dt><a name="nixio.fs.remove"></a><strong>remove</strong> (path)</dt>
1195 Remove a file or directory.
1212 <h3>Return value:</h3>
1222 <dt><a name="nixio.fs.rename"></a><strong>rename</strong> (src, dest)</dt>
1225 Renames a file or directory.
1236 dest: Destination path
1245 It is normally not possible to rename files accross fileystems.
1249 <h3>Return value:</h3>
1259 <dt><a name="nixio.fs.rmdir"></a><strong>rmdir</strong> (path)</dt>
1262 Remove an empty directory.
1279 <h3>Return value:</h3>
1289 <dt><a name="nixio.fs.stat"></a><strong>stat</strong> (path, field)</dt>
1292 Get file status and attributes.
1303 field: Only return a specific field, not the whole table (optional)
1313 <h3>Return value:</h3>
1314 Table containing: <ul>
1315 <li>atime = Last access timestamp</li>
1316 <li>blksize = Blocksize (POSIX only)</li>
1317 <li>blocks = Blocks used (POSIX only)</li>
1318 <li>ctime = Creation timestamp</li>
1319 <li>dev = Device ID</li>
1320 <li>gid = Group ID</li>
1321 <li>ino = Inode</li>
1322 <li>modedec = Mode converted into a decimal number</li>
1323 <li>modestr = Mode as string as returned by <code>ls -l</code></li>
1324 <li>mtime = Last modification timestamp</li>
1325 <li>nlink = Number of links</li>
1326 <li>rdev = Device ID (if special file)</li>
1327 <li>size = Size in bytes</li>
1328 <li>type = ["reg", "dir", "chr", "blk", "fifo", "lnk", "sock"]</li>
1329 <li>uid = User ID</li>
1339 <dt><a name="nixio.fs.statvfs"></a><strong>statvfs</strong> (path)</dt>
1342 (POSIX) Get filesystem statistics.
1349 path: Path to any file within the filesystem.
1359 <h3>Return value:</h3>
1360 Table containing: <ul>
1361 <li>bavail = available blocks</li>
1362 <li>bfree = free blocks</li>
1363 <li>blocks = number of fragments</li>
1364 <li>frsize = fragment size</li>
1365 <li>favail = available inodes</li>
1366 <li>ffree = free inodes</li>
1367 <li>files = inodes</li>
1368 <li>flag = flags</li>
1369 <li>fsid = filesystem ID</li>
1370 <li>namemax = maximum filename length</li>
1380 <dt><a name="nixio.fs.symlink"></a><strong>symlink</strong> (oldpath, newpath)</dt>
1383 (POSIX) Create a symbolic link.
1404 <h3>Return value:</h3>
1414 <dt><a name="nixio.fs.unlink"></a><strong>unlink</strong> (path)</dt>
1417 Delete a name and - if no links are left - the associated file.
1434 <h3>Return value:</h3>
1444 <dt><a name="nixio.fs.utimes"></a><strong>utimes</strong> (path, actime, mtime)</dt>
1447 Change file last access and last modification time.
1458 actime: Last access timestamp (optional, default: current time)
1462 mtime: Last modification timestamp (optional, default: actime)
1472 <h3>Return value:</h3>
1482 <dt><a name="nixio.fs.writefile"></a><strong>writefile</strong> (path, data)</dt>
1485 Write a buffer into a file truncating the file first.
1506 <h3>Return value:</h3>
1520 </div> <!-- id="content" -->
1522 </div> <!-- id="main" -->
1525 <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
1526 </div> <!-- id="about" -->
1528 </div> <!-- id="container" -->