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.protocol.html">luci.http.protocol</a>
50 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
54 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
58 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
62 <a href="../modules/luci.i18n.html">luci.i18n</a>
66 <a href="../modules/luci.ip.html">luci.ip</a>
70 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
74 <a href="../modules/luci.json.html">luci.json</a>
78 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
82 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
86 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
90 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
94 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
98 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
102 <a href="../modules/luci.sys.html">luci.sys</a>
106 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
110 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
114 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
118 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
122 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
126 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
130 <a href="../modules/luci.util.html">luci.util</a>
134 <a href="../modules/nixio.html">nixio</a>
138 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
142 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
146 <a href="../modules/nixio.File.html">nixio.File</a>
150 <a href="../modules/nixio.README.html">nixio.README</a>
154 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
158 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
162 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
166 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
170 <a href="../modules/nixio.bin.html">nixio.bin</a>
174 <a href="../modules/nixio.bit.html">nixio.bit</a>
178 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
181 <li><strong>nixio.fs</strong></li>
195 </div><!-- id="navigation" -->
199 <h1>Class <code>nixio.fs</code></h1>
202 Low-level and high-level filesystem manipulation library.</p>
211 <table class="function_list">
214 <td class="name" nowrap><a href="#nixio.fs.access">access</a> (path, mode1, ...)</td>
216 Check user's permission on a file.</td>
220 <td class="name" nowrap><a href="#nixio.fs.basename">basename</a> (path)</td>
222 Strip the directory part from a path.</td>
226 <td class="name" nowrap><a href="#nixio.fs.chmod">chmod</a> (path, mode)</td>
228 Change the file mode.</td>
232 <td class="name" nowrap><a href="#nixio.fs.chown">chown</a> (path, user, group)</td>
234 (POSIX) Change owner and group of a file.</td>
238 <td class="name" nowrap><a href="#nixio.fs.copy">copy</a> (src, dest)</td>
240 Copy a file, directory or symlink non-recursively preserving file mode,
241 timestamps, owner and group.</td>
245 <td class="name" nowrap><a href="#nixio.fs.copyr">copyr</a> (src, dest)</td>
247 Copy a file, directory or symlink recursively preserving file mode,
248 timestamps, owner and group.</td>
252 <td class="name" nowrap><a href="#nixio.fs.datacopy">datacopy</a> (src, dest, limit)</td>
254 Copy data between files.</td>
258 <td class="name" nowrap><a href="#nixio.fs.dir">dir</a> (path)</td>
260 Iterate over the entries of a directory.</td>
264 <td class="name" nowrap><a href="#nixio.fs.dirname">dirname</a> (path)</td>
266 Strip the base from a path.</td>
270 <td class="name" nowrap><a href="#nixio.fs.glob">glob</a> (pattern)</td>
272 (POSIX) Find pathnames matching a pattern.</td>
276 <td class="name" nowrap><a href="#nixio.fs.lchown">lchown</a> (path, user, group)</td>
278 (POSIX) Change owner and group of a file and do not resolve
279 if target is a symlink.</td>
283 <td class="name" nowrap><a href="#nixio.fs.link">link</a> (oldpath, newpath)</td>
285 Create a hard link.</td>
289 <td class="name" nowrap><a href="#nixio.fs.lstat">lstat</a> (path, field)</td>
291 Get file status and attributes and do not resolve if target is a symlink.</td>
295 <td class="name" nowrap><a href="#nixio.fs.mkdir">mkdir</a> (path, mode)</td>
297 Create a new directory.</td>
301 <td class="name" nowrap><a href="#nixio.fs.mkdirr">mkdirr</a> (dest, mode)</td>
303 Create a directory and all needed parent directories recursively.</td>
307 <td class="name" nowrap><a href="#nixio.fs.mkfifo">mkfifo</a> (path, mode)</td>
309 (POSIX) Create a FIFO (named pipe).</td>
313 <td class="name" nowrap><a href="#nixio.fs.move">move</a> (src, dest)</td>
315 Rename a file, directory or symlink non-recursively across filesystems.</td>
319 <td class="name" nowrap><a href="#nixio.fs.mover">mover</a> (src, dest)</td>
321 Rename a file, directory or symlink recursively across filesystems.</td>
325 <td class="name" nowrap><a href="#nixio.fs.readfile">readfile</a> (path, limit)</td>
327 Read the contents of a file into a buffer.</td>
331 <td class="name" nowrap><a href="#nixio.fs.readlink">readlink</a> (path)</td>
333 (POSIX) Read the target of a symbolic link.</td>
337 <td class="name" nowrap><a href="#nixio.fs.realpath">realpath</a> (path)</td>
339 Return the cannonicalized absolute pathname.</td>
343 <td class="name" nowrap><a href="#nixio.fs.remove">remove</a> (path)</td>
345 Remove a file or directory.</td>
349 <td class="name" nowrap><a href="#nixio.fs.rename">rename</a> (src, dest)</td>
351 Renames a file or directory.</td>
355 <td class="name" nowrap><a href="#nixio.fs.rmdir">rmdir</a> (path)</td>
357 Remove an empty directory.</td>
361 <td class="name" nowrap><a href="#nixio.fs.stat">stat</a> (path, field)</td>
363 Get file status and attributes.</td>
367 <td class="name" nowrap><a href="#nixio.fs.statvfs">statvfs</a> (path)</td>
369 (POSIX) Get filesystem statistics.</td>
373 <td class="name" nowrap><a href="#nixio.fs.symlink">symlink</a> (oldpath, newpath)</td>
375 (POSIX) Create a symbolic link.</td>
379 <td class="name" nowrap><a href="#nixio.fs.unlink">unlink</a> (path)</td>
381 Delete a name and - if no links are left - the associated file.</td>
385 <td class="name" nowrap><a href="#nixio.fs.utimes">utimes</a> (path, actime, mtime)</td>
387 Change file last access and last modification time.</td>
391 <td class="name" nowrap><a href="#nixio.fs.writefile">writefile</a> (path, data)</td>
393 Write a buffer into a file truncating the file first.</td>
407 <h2><a name="functions"></a>Functions</h2>
408 <dl class="function">
412 <dt><a name="nixio.fs.access"></a><strong>access</strong> (path, mode1, ...)</dt>
415 Check user's permission on a file.
426 mode1: First Mode to check ["f", "r", "w", "x"]
430 ...: More Modes to check [-"-]
440 <h3>Return value:</h3>
450 <dt><a name="nixio.fs.basename"></a><strong>basename</strong> (path)</dt>
453 Strip the directory part from a path.
469 This function cannot fail and will never return nil.
473 <h3>Return value:</h3>
483 <dt><a name="nixio.fs.chmod"></a><strong>chmod</strong> (path, mode)</dt>
486 Change the file mode.
498 [decimal mode number, "[-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT]"]
509 <li>Windows only supports setting the write-protection through the
510 "Writable to others" bit.
512 <li><strong>Notice:</strong> The mode-flag for the functions
513 open, mkdir, mkfifo are affected by the umask.
519 <h3>Return value:</h3>
538 <dt><a name="nixio.fs.chown"></a><strong>chown</strong> (path, user, group)</dt>
541 (POSIX) Change owner and group of a file.
552 user: User ID or Username (optional)
556 group: Group ID or Groupname (optional)
566 <h3>Return value:</h3>
576 <dt><a name="nixio.fs.copy"></a><strong>copy</strong> (src, dest)</dt>
579 Copy a file, directory or symlink non-recursively preserving file mode,
580 timestamps, owner and group.
591 dest: Destination path
600 The destination must always be a full destination path e.g. do not
601 omit the basename even if source and destination basename are equal.
605 <h3>Return value:</h3>
615 <dt><a name="nixio.fs.copyr"></a><strong>copyr</strong> (src, dest)</dt>
618 Copy a file, directory or symlink recursively preserving file mode,
619 timestamps, owner and group.
630 dest: Destination path
639 The destination must always be a full destination path e.g. do not
640 omit the basename even if source and destination basename are equal.
644 <h3>Return value:</h3>
654 <dt><a name="nixio.fs.datacopy"></a><strong>datacopy</strong> (src, dest, limit)</dt>
657 Copy data between files.
664 src: Source file path
668 dest: Destination file path
672 limit: Maximum bytes to copy (optional)
682 <h3>Return value:</h3>
692 <dt><a name="nixio.fs.dir"></a><strong>dir</strong> (path)</dt>
695 Iterate over the entries of a directory.
711 The special entries "." and ".." are omitted.
715 <h3>Return value:</h3>
716 directory iterator returning one entry per call
725 <dt><a name="nixio.fs.dirname"></a><strong>dirname</strong> (path)</dt>
728 Strip the base from a path.
744 This function cannot fail and will never return nil.
748 <h3>Return value:</h3>
758 <dt><a name="nixio.fs.glob"></a><strong>glob</strong> (pattern)</dt>
761 (POSIX) Find pathnames matching a pattern.
778 <h3>Return values:</h3>
783 <li>number of matches
794 <dt><a name="nixio.fs.lchown"></a><strong>lchown</strong> (path, user, group)</dt>
797 (POSIX) Change owner and group of a file and do not resolve
798 if target is a symlink.
809 user: User ID or Username (optional)
813 group: Group ID or Groupname (optional)
823 <h3>Return value:</h3>
833 <dt><a name="nixio.fs.link"></a><strong>link</strong> (oldpath, newpath)</dt>
856 This function calls link() on POSIX and CreateHardLink() on Windows.
860 <h3>Return value:</h3>
870 <dt><a name="nixio.fs.lstat"></a><strong>lstat</strong> (path, field)</dt>
873 Get file status and attributes and do not resolve if target is a symlink.
884 field: Only return a specific field, not the whole table (optional)
894 <h3>Return value:</h3>
895 Table containing attributes (see stat for a detailed description)
902 <li><a href="#nixio.fs.stat">
913 <dt><a name="nixio.fs.mkdir"></a><strong>mkdir</strong> (path, mode)</dt>
916 Create a new directory.
927 mode: File mode (optional, see chmod and umask)
937 <h3>Return value:</h3>
945 <li><a href="#nixio.fs.chmod">
960 <dt><a name="nixio.fs.mkdirr"></a><strong>mkdirr</strong> (dest, mode)</dt>
963 Create a directory and all needed parent directories recursively.
970 dest: Destination path
974 mode: File mode (optional, see chmod and umask)
984 <h3>Return value:</h3>
992 <li><a href="#nixio.fs.chmod">
1007 <dt><a name="nixio.fs.mkfifo"></a><strong>mkfifo</strong> (path, mode)</dt>
1010 (POSIX) Create a FIFO (named pipe).
1021 mode: File mode (optional, see chmod and umask)
1031 <h3>Return value:</h3>
1039 <li><a href="#nixio.fs.chmod">
1054 <dt><a name="nixio.fs.move"></a><strong>move</strong> (src, dest)</dt>
1057 Rename a file, directory or symlink non-recursively across filesystems.
1068 dest: Destination path
1077 The destination must always be a full destination path e.g. do not
1078 omit the basename even if source and destination basename are equal.
1082 <h3>Return value:</h3>
1092 <dt><a name="nixio.fs.mover"></a><strong>mover</strong> (src, dest)</dt>
1095 Rename a file, directory or symlink recursively across filesystems.
1106 dest: Destination path
1115 The destination must always be a full destination path e.g. do not
1116 omit the basename even if source and destination basename are equal.
1120 <h3>Return value:</h3>
1130 <dt><a name="nixio.fs.readfile"></a><strong>readfile</strong> (path, limit)</dt>
1133 Read the contents of a file into a buffer.
1144 limit: Maximum bytes to read (optional)
1154 <h3>Return value:</h3>
1164 <dt><a name="nixio.fs.readlink"></a><strong>readlink</strong> (path)</dt>
1167 (POSIX) Read the target of a symbolic link.
1184 <h3>Return value:</h3>
1194 <dt><a name="nixio.fs.realpath"></a><strong>realpath</strong> (path)</dt>
1197 Return the cannonicalized absolute pathname.
1214 <h3>Return value:</h3>
1224 <dt><a name="nixio.fs.remove"></a><strong>remove</strong> (path)</dt>
1227 Remove a file or directory.
1244 <h3>Return value:</h3>
1254 <dt><a name="nixio.fs.rename"></a><strong>rename</strong> (src, dest)</dt>
1257 Renames a file or directory.
1268 dest: Destination path
1277 It is normally not possible to rename files accross fileystems.
1281 <h3>Return value:</h3>
1291 <dt><a name="nixio.fs.rmdir"></a><strong>rmdir</strong> (path)</dt>
1294 Remove an empty directory.
1311 <h3>Return value:</h3>
1321 <dt><a name="nixio.fs.stat"></a><strong>stat</strong> (path, field)</dt>
1324 Get file status and attributes.
1335 field: Only return a specific field, not the whole table (optional)
1345 <h3>Return value:</h3>
1346 Table containing: <ul>
1347 <li>atime = Last access timestamp</li>
1348 <li>blksize = Blocksize (POSIX only)</li>
1349 <li>blocks = Blocks used (POSIX only)</li>
1350 <li>ctime = Creation timestamp</li>
1351 <li>dev = Device ID</li>
1352 <li>gid = Group ID</li>
1353 <li>ino = Inode</li>
1354 <li>modedec = Mode converted into a decimal number</li>
1355 <li>modestr = Mode as string as returned by <code>ls -l</code></li>
1356 <li>mtime = Last modification timestamp</li>
1357 <li>nlink = Number of links</li>
1358 <li>rdev = Device ID (if special file)</li>
1359 <li>size = Size in bytes</li>
1360 <li>type = ["reg", "dir", "chr", "blk", "fifo", "lnk", "sock"]</li>
1361 <li>uid = User ID</li>
1371 <dt><a name="nixio.fs.statvfs"></a><strong>statvfs</strong> (path)</dt>
1374 (POSIX) Get filesystem statistics.
1381 path: Path to any file within the filesystem.
1391 <h3>Return value:</h3>
1392 Table containing: <ul>
1393 <li>bavail = available blocks</li>
1394 <li>bfree = free blocks</li>
1395 <li>blocks = number of fragments</li>
1396 <li>frsize = fragment size</li>
1397 <li>favail = available inodes</li>
1398 <li>ffree = free inodes</li>
1399 <li>files = inodes</li>
1400 <li>flag = flags</li>
1401 <li>fsid = filesystem ID</li>
1402 <li>namemax = maximum filename length</li>
1412 <dt><a name="nixio.fs.symlink"></a><strong>symlink</strong> (oldpath, newpath)</dt>
1415 (POSIX) Create a symbolic link.
1436 <h3>Return value:</h3>
1446 <dt><a name="nixio.fs.unlink"></a><strong>unlink</strong> (path)</dt>
1449 Delete a name and - if no links are left - the associated file.
1466 <h3>Return value:</h3>
1476 <dt><a name="nixio.fs.utimes"></a><strong>utimes</strong> (path, actime, mtime)</dt>
1479 Change file last access and last modification time.
1490 actime: Last access timestamp (optional, default: current time)
1494 mtime: Last modification timestamp (optional, default: actime)
1504 <h3>Return value:</h3>
1514 <dt><a name="nixio.fs.writefile"></a><strong>writefile</strong> (path, data)</dt>
1517 Write a buffer into a file truncating the file first.
1538 <h3>Return value:</h3>
1552 </div> <!-- id="content" -->
1554 </div> <!-- id="main" -->
1557 <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>
1558 </div> <!-- id="about" -->
1560 </div> <!-- id="container" -->