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.html">luci.http</a>
46 <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
50 <a href="../modules/luci.http.date.html">luci.http.date</a>
54 <a href="../modules/luci.http.mime.html">luci.http.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.json.html">luci.json</a>
74 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
78 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
82 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
86 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
90 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
94 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
98 <a href="../modules/luci.sys.html">luci.sys</a>
102 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
106 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
110 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
114 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
118 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
122 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
126 <a href="../modules/luci.util.html">luci.util</a>
130 <a href="../modules/nixio.html">nixio</a>
134 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
138 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
142 <a href="../modules/nixio.File.html">nixio.File</a>
146 <a href="../modules/nixio.README.html">nixio.README</a>
150 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
154 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
158 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
162 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
166 <a href="../modules/nixio.bin.html">nixio.bin</a>
170 <a href="../modules/nixio.bit.html">nixio.bit</a>
174 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
177 <li><strong>nixio.fs</strong></li>
191 </div><!-- id="navigation" -->
195 <h1>Class <code>nixio.fs</code></h1>
198 Low-level and high-level filesystem manipulation library.</p>
207 <table class="function_list">
210 <td class="name" nowrap><a href="#nixio.fs.access">access</a> (path, mode1, ...)</td>
212 Check user's permission on a file.</td>
216 <td class="name" nowrap><a href="#nixio.fs.basename">basename</a> (path)</td>
218 Strip the directory part from a path.</td>
222 <td class="name" nowrap><a href="#nixio.fs.chmod">chmod</a> (path, mode)</td>
224 Change the file mode.</td>
228 <td class="name" nowrap><a href="#nixio.fs.chown">chown</a> (path, user, group)</td>
230 (POSIX) Change owner and group of a file.</td>
234 <td class="name" nowrap><a href="#nixio.fs.copy">copy</a> (src, dest)</td>
236 Copy a file, directory or symlink non-recursively preserving file mode,
237 timestamps, owner and group.</td>
241 <td class="name" nowrap><a href="#nixio.fs.copyr">copyr</a> (src, dest)</td>
243 Copy a file, directory or symlink recursively preserving file mode,
244 timestamps, owner and group.</td>
248 <td class="name" nowrap><a href="#nixio.fs.datacopy">datacopy</a> (src, dest, limit)</td>
250 Copy data between files.</td>
254 <td class="name" nowrap><a href="#nixio.fs.dir">dir</a> (path)</td>
256 Iterate over the entries of a directory.</td>
260 <td class="name" nowrap><a href="#nixio.fs.dirname">dirname</a> (path)</td>
262 Strip the base from a path.</td>
266 <td class="name" nowrap><a href="#nixio.fs.glob">glob</a> (pattern)</td>
268 (POSIX) Find pathnames matching a pattern.</td>
272 <td class="name" nowrap><a href="#nixio.fs.lchown">lchown</a> (path, user, group)</td>
274 (POSIX) Change owner and group of a file and do not resolve
275 if target is a symlink.</td>
279 <td class="name" nowrap><a href="#nixio.fs.link">link</a> (oldpath, newpath)</td>
281 Create a hard link.</td>
285 <td class="name" nowrap><a href="#nixio.fs.lstat">lstat</a> (path, field)</td>
287 Get file status and attributes and do not resolve if target is a symlink.</td>
291 <td class="name" nowrap><a href="#nixio.fs.mkdir">mkdir</a> (path, mode)</td>
293 Create a new directory.</td>
297 <td class="name" nowrap><a href="#nixio.fs.mkdirr">mkdirr</a> (dest, mode)</td>
299 Create a directory and all needed parent directories recursively.</td>
303 <td class="name" nowrap><a href="#nixio.fs.mkfifo">mkfifo</a> (path, mode)</td>
305 (POSIX) Create a FIFO (named pipe).</td>
309 <td class="name" nowrap><a href="#nixio.fs.move">move</a> (src, dest)</td>
311 Rename a file, directory or symlink non-recursively across filesystems.</td>
315 <td class="name" nowrap><a href="#nixio.fs.mover">mover</a> (src, dest)</td>
317 Rename a file, directory or symlink recursively across filesystems.</td>
321 <td class="name" nowrap><a href="#nixio.fs.readfile">readfile</a> (path, limit)</td>
323 Read the contents of a file into a buffer.</td>
327 <td class="name" nowrap><a href="#nixio.fs.readlink">readlink</a> (path)</td>
329 (POSIX) Read the target of a symbolic link.</td>
333 <td class="name" nowrap><a href="#nixio.fs.realpath">realpath</a> (path)</td>
335 Return the cannonicalized absolute pathname.</td>
339 <td class="name" nowrap><a href="#nixio.fs.remove">remove</a> (path)</td>
341 Remove a file or directory.</td>
345 <td class="name" nowrap><a href="#nixio.fs.rename">rename</a> (src, dest)</td>
347 Renames a file or directory.</td>
351 <td class="name" nowrap><a href="#nixio.fs.rmdir">rmdir</a> (path)</td>
353 Remove an empty directory.</td>
357 <td class="name" nowrap><a href="#nixio.fs.stat">stat</a> (path, field)</td>
359 Get file status and attributes.</td>
363 <td class="name" nowrap><a href="#nixio.fs.statvfs">statvfs</a> (path)</td>
365 (POSIX) Get filesystem statistics.</td>
369 <td class="name" nowrap><a href="#nixio.fs.symlink">symlink</a> (oldpath, newpath)</td>
371 (POSIX) Create a symbolic link.</td>
375 <td class="name" nowrap><a href="#nixio.fs.unlink">unlink</a> (path)</td>
377 Delete a name and - if no links are left - the associated file.</td>
381 <td class="name" nowrap><a href="#nixio.fs.utimes">utimes</a> (path, actime, mtime)</td>
383 Change file last access and last modification time.</td>
387 <td class="name" nowrap><a href="#nixio.fs.writefile">writefile</a> (path, data)</td>
389 Write a buffer into a file truncating the file first.</td>
403 <h2><a name="functions"></a>Functions</h2>
404 <dl class="function">
408 <dt><a name="nixio.fs.access"></a><strong>access</strong> (path, mode1, ...)</dt>
411 Check user's permission on a file.
422 mode1: First Mode to check ["f", "r", "w", "x"]
426 ...: More Modes to check [-"-]
436 <h3>Return value:</h3>
446 <dt><a name="nixio.fs.basename"></a><strong>basename</strong> (path)</dt>
449 Strip the directory part from a path.
465 This function cannot fail and will never return nil.
469 <h3>Return value:</h3>
479 <dt><a name="nixio.fs.chmod"></a><strong>chmod</strong> (path, mode)</dt>
482 Change the file mode.
494 [decimal mode number, "[-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT]"]
505 <li>Windows only supports setting the write-protection through the
506 "Writable to others" bit.
508 <li><strong>Notice:</strong> The mode-flag for the functions
509 open, mkdir, mkfifo are affected by the umask.
515 <h3>Return value:</h3>
534 <dt><a name="nixio.fs.chown"></a><strong>chown</strong> (path, user, group)</dt>
537 (POSIX) Change owner and group of a file.
548 user: User ID or Username (optional)
552 group: Group ID or Groupname (optional)
562 <h3>Return value:</h3>
572 <dt><a name="nixio.fs.copy"></a><strong>copy</strong> (src, dest)</dt>
575 Copy a file, directory or symlink non-recursively preserving file mode,
576 timestamps, owner and group.
587 dest: Destination path
596 The destination must always be a full destination path e.g. do not
597 omit the basename even if source and destination basename are equal.
601 <h3>Return value:</h3>
611 <dt><a name="nixio.fs.copyr"></a><strong>copyr</strong> (src, dest)</dt>
614 Copy a file, directory or symlink recursively preserving file mode,
615 timestamps, owner and group.
626 dest: Destination path
635 The destination must always be a full destination path e.g. do not
636 omit the basename even if source and destination basename are equal.
640 <h3>Return value:</h3>
650 <dt><a name="nixio.fs.datacopy"></a><strong>datacopy</strong> (src, dest, limit)</dt>
653 Copy data between files.
660 src: Source file path
664 dest: Destination file path
668 limit: Maximum bytes to copy (optional)
678 <h3>Return value:</h3>
688 <dt><a name="nixio.fs.dir"></a><strong>dir</strong> (path)</dt>
691 Iterate over the entries of a directory.
707 The special entries "." and ".." are omitted.
711 <h3>Return value:</h3>
712 directory iterator returning one entry per call
721 <dt><a name="nixio.fs.dirname"></a><strong>dirname</strong> (path)</dt>
724 Strip the base from a path.
740 This function cannot fail and will never return nil.
744 <h3>Return value:</h3>
754 <dt><a name="nixio.fs.glob"></a><strong>glob</strong> (pattern)</dt>
757 (POSIX) Find pathnames matching a pattern.
774 <h3>Return values:</h3>
779 <li>number of matches
790 <dt><a name="nixio.fs.lchown"></a><strong>lchown</strong> (path, user, group)</dt>
793 (POSIX) Change owner and group of a file and do not resolve
794 if target is a symlink.
805 user: User ID or Username (optional)
809 group: Group ID or Groupname (optional)
819 <h3>Return value:</h3>
829 <dt><a name="nixio.fs.link"></a><strong>link</strong> (oldpath, newpath)</dt>
852 This function calls link() on POSIX and CreateHardLink() on Windows.
856 <h3>Return value:</h3>
866 <dt><a name="nixio.fs.lstat"></a><strong>lstat</strong> (path, field)</dt>
869 Get file status and attributes and do not resolve if target is a symlink.
880 field: Only return a specific field, not the whole table (optional)
890 <h3>Return value:</h3>
891 Table containing attributes (see stat for a detailed description)
898 <li><a href="#nixio.fs.stat">
909 <dt><a name="nixio.fs.mkdir"></a><strong>mkdir</strong> (path, mode)</dt>
912 Create a new directory.
923 mode: File mode (optional, see chmod and umask)
933 <h3>Return value:</h3>
941 <li><a href="#nixio.fs.chmod">
956 <dt><a name="nixio.fs.mkdirr"></a><strong>mkdirr</strong> (dest, mode)</dt>
959 Create a directory and all needed parent directories recursively.
966 dest: Destination path
970 mode: File mode (optional, see chmod and umask)
980 <h3>Return value:</h3>
988 <li><a href="#nixio.fs.chmod">
1003 <dt><a name="nixio.fs.mkfifo"></a><strong>mkfifo</strong> (path, mode)</dt>
1006 (POSIX) Create a FIFO (named pipe).
1017 mode: File mode (optional, see chmod and umask)
1027 <h3>Return value:</h3>
1035 <li><a href="#nixio.fs.chmod">
1050 <dt><a name="nixio.fs.move"></a><strong>move</strong> (src, dest)</dt>
1053 Rename a file, directory or symlink non-recursively across filesystems.
1064 dest: Destination path
1073 The destination must always be a full destination path e.g. do not
1074 omit the basename even if source and destination basename are equal.
1078 <h3>Return value:</h3>
1088 <dt><a name="nixio.fs.mover"></a><strong>mover</strong> (src, dest)</dt>
1091 Rename a file, directory or symlink recursively across filesystems.
1102 dest: Destination path
1111 The destination must always be a full destination path e.g. do not
1112 omit the basename even if source and destination basename are equal.
1116 <h3>Return value:</h3>
1126 <dt><a name="nixio.fs.readfile"></a><strong>readfile</strong> (path, limit)</dt>
1129 Read the contents of a file into a buffer.
1140 limit: Maximum bytes to read (optional)
1150 <h3>Return value:</h3>
1160 <dt><a name="nixio.fs.readlink"></a><strong>readlink</strong> (path)</dt>
1163 (POSIX) Read the target of a symbolic link.
1180 <h3>Return value:</h3>
1190 <dt><a name="nixio.fs.realpath"></a><strong>realpath</strong> (path)</dt>
1193 Return the cannonicalized absolute pathname.
1210 <h3>Return value:</h3>
1220 <dt><a name="nixio.fs.remove"></a><strong>remove</strong> (path)</dt>
1223 Remove a file or directory.
1240 <h3>Return value:</h3>
1250 <dt><a name="nixio.fs.rename"></a><strong>rename</strong> (src, dest)</dt>
1253 Renames a file or directory.
1264 dest: Destination path
1273 It is normally not possible to rename files across filesystems.
1277 <h3>Return value:</h3>
1287 <dt><a name="nixio.fs.rmdir"></a><strong>rmdir</strong> (path)</dt>
1290 Remove an empty directory.
1307 <h3>Return value:</h3>
1317 <dt><a name="nixio.fs.stat"></a><strong>stat</strong> (path, field)</dt>
1320 Get file status and attributes.
1331 field: Only return a specific field, not the whole table (optional)
1341 <h3>Return value:</h3>
1342 Table containing: <ul>
1343 <li>atime = Last access timestamp</li>
1344 <li>blksize = Blocksize (POSIX only)</li>
1345 <li>blocks = Blocks used (POSIX only)</li>
1346 <li>ctime = Creation timestamp</li>
1347 <li>dev = Device ID</li>
1348 <li>gid = Group ID</li>
1349 <li>ino = Inode</li>
1350 <li>modedec = Mode converted into a decimal number</li>
1351 <li>modestr = Mode as string as returned by <code>ls -l</code></li>
1352 <li>mtime = Last modification timestamp</li>
1353 <li>nlink = Number of links</li>
1354 <li>rdev = Device ID (if special file)</li>
1355 <li>size = Size in bytes</li>
1356 <li>type = ["reg", "dir", "chr", "blk", "fifo", "lnk", "sock"]</li>
1357 <li>uid = User ID</li>
1367 <dt><a name="nixio.fs.statvfs"></a><strong>statvfs</strong> (path)</dt>
1370 (POSIX) Get filesystem statistics.
1377 path: Path to any file within the filesystem.
1387 <h3>Return value:</h3>
1388 Table containing: <ul>
1389 <li>bavail = available blocks</li>
1390 <li>bfree = free blocks</li>
1391 <li>blocks = number of fragments</li>
1392 <li>frsize = fragment size</li>
1393 <li>favail = available inodes</li>
1394 <li>ffree = free inodes</li>
1395 <li>files = inodes</li>
1396 <li>flag = flags</li>
1397 <li>fsid = filesystem ID</li>
1398 <li>namemax = maximum filename length</li>
1408 <dt><a name="nixio.fs.symlink"></a><strong>symlink</strong> (oldpath, newpath)</dt>
1411 (POSIX) Create a symbolic link.
1432 <h3>Return value:</h3>
1442 <dt><a name="nixio.fs.unlink"></a><strong>unlink</strong> (path)</dt>
1445 Delete a name and - if no links are left - the associated file.
1462 <h3>Return value:</h3>
1472 <dt><a name="nixio.fs.utimes"></a><strong>utimes</strong> (path, actime, mtime)</dt>
1475 Change file last access and last modification time.
1486 actime: Last access timestamp (optional, default: current time)
1490 mtime: Last modification timestamp (optional, default: actime)
1500 <h3>Return value:</h3>
1510 <dt><a name="nixio.fs.writefile"></a><strong>writefile</strong> (path, data)</dt>
1513 Write a buffer into a file truncating the file first.
1534 <h3>Return value:</h3>
1548 </div> <!-- id="content" -->
1550 </div> <!-- id="main" -->
1553 <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>
1554 </div> <!-- id="about" -->
1556 </div> <!-- id="container" -->