File-System Module
FicsIt-Networks implements it’s own virtual filesystem for UNIX like experience using the FileSystem. The file system consists of nodes. Such a node can be a File, a Folder or something else. Each nodes is able to have child nodes and might be able to get opened with a file stream. A folder also delivers an abstract interface for adding and removing nodes. A Device implements lookup functions for searching for nodes in the filesystem structure. Such a device can be a temporary filesystem (tmpfs) which exists only in memory and which will get purged on a system reboot, or f.e. a disk filesystem (drives) which store the nodes on the real virtual filesystem in a folder. You can then mount such a device to a location in the root filesystem tree so when you now access a path, the filesystem looks first for the device and uses then the remaining path to get the node data from the device. There is also a DriveNode which simply holds a reference to a drive so you can access a drive via the filesystem. You can use then the mount function to mount the Drive of a DriveNode to the given location in the filesystem tree. Because you need at least one drive mounted to even be able to access any node, we provide the initFileSystem function which you can call only once in a system session. This functions will then mount the DevDevice to the given location. The DevDevice is a sepcial Device which holds all the DeviceNodes representing Device attached to the computer session, like hard drives, tempfs and the serial I/O.
Globals
filesystem
The filesystem api provides structures, functions and variables for interacting with the virtual file systems. You can’t access files outside the virtual filesystem. If you try to do so, the Lua runtime crashes.
filesystem.analyzePath (…: string) → …
Each provided string will be viewed as one filesystem-path and will be checked for lexical features.
Each of those string will then have a integer return value which is a bit-flag-register describing those lexical features.
Bit-Flags
1 |
Is filesystem root |
2 |
Is Empty (includes if it is root-path) |
3 |
Is absolute path |
4 |
Is only a file/folder name |
5 |
Filename has extension |
6 |
Ends with a |
Details
| Name | Type | Description |
|---|---|---|
Paths |
string |
Paths that will be analyzed |
| Name | Type | Description |
|---|---|---|
Results |
integer |
Analysis results |
filesystem.children (path: string) → string[]
Lists all children names of the node with the given path. (i.e. items in a folder)
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to list |
| Name | Type | Description |
|---|---|---|
Children |
string[] |
file names of children |
filesystem.createDir (path: string, recursive: bool) → boolean
Creates the folder path.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
folder path the function should create |
Recursive |
boolean |
If false creates only the last folder of the path. If true creates all folders in the path. |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
Returns true if it was able to create the directory. |
filesystem.doFile (path: string) → …
Executes Lua code in the file referd by the given path.
Function fails if path doesn¬タルt exist or path doesn¬タルt refer to a file.
Returns the result of the execute function or what ever it yielded.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to execute |
| Name | Type | Description |
|---|---|---|
Results |
any |
the result of the execute function or what ever it yielded |
filesystem.exists (path: string) → boolean
Returns true if the given path exists.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to check |
| Name | Type | Description |
|---|---|---|
Exists |
boolean |
returns true if the given file exists |
filesystem.isDir (path: string) → boolean
Returns true if the given path refers to directory.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to check |
| Name | Type | Description |
|---|---|---|
Is dir |
boolean |
returns true if the given path refers to a directory |
filesystem.isFile (path: string) → boolean
Returns true if the given path refers to a file.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to check |
| Name | Type | Description |
|---|---|---|
Is file |
boolean |
returns true if the given path refers to a file |
filesystem.isNode (…: string) → …
For each given string, returns a bool to tell if string is a valid node (file/folder) name.
Details
| Name | Type | Description |
|---|---|---|
Paths |
string |
Paths that will be checked |
| Name | Type | Description |
|---|---|---|
Results |
boolean |
True if path is a valid node (file/folder) name |
filesystem.loadFile (path: string) → fun(): …
Loads the file refered by the given path as a Lua function and returns it. Functions fails if path doesn¬タルt exist or path doesn¬タルt reger to a file.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to load |
| Name | Type | Description |
|---|---|---|
Code |
fun(): … |
a function that runs the loaded code |
filesystem.meta (…: string) → …
Returns for each given string path, a table that defines contains some meta information about node the string references.
Possible type-Field strings
| ===
| File | A normal File
| Directory | A directory or folder that can hold multiple nodes.
| Device | A special type of Node that represents a filesystem and can be mounted.
| Unknown | The node type is not known to this utility function.
| ===
Details
| Name | Type | Description |
|---|---|---|
Paths |
string |
Paths that will be checked |
| Name | Type | Description |
|---|---|---|
Results |
{type:string} |
Metadata for each path |
filesystem.mount (device: string, mountPoint: string) → boolean
This function mounts the device referenced by the the path to a device node to the given mount point.
Details
| Name | Type | Description |
|---|---|---|
Device |
string |
the path to the device you want to mount |
Mount Point |
string |
the path to the point were the device should get mounted to |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
true if the mount was executed successfully |
filesystem.move (from: string, to: string) → boolean
Moves the filesystem object from the given path to the other given path.
Function fails if it is not able to move the object.
Details
| Name | Type | Description |
|---|---|---|
From |
string |
path to the filesystem object you want to move |
To |
string |
path to the filesystem object the target should get moved to |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
returns true if it was able to move the node |
filesystem.open (path: string, mode: string) → File
Opens a file-stream and returns it as File-table.
Possible Modes
|
read only |
File-Stream can just read from file. |
|
write |
File-Stream can read and write. |
|
end of file |
File-Stream can read and write. |
|
truncate |
File-Stream can read and write. |
|
append |
File-Stream can read the full file, |
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
the path to the file you want to open a file-stream for |
Mode |
string |
The mode for the file stream |
| Name | Type | Description |
|---|---|---|
File |
The File table of the file stream. Nil if not able to open file in read only. |
filesystem.path ([conversion: integer,] …: string) → string
Combines a variable amount of strings as paths together to one big path.
Additionally, applies given conversion. Defined by the optionally given integer.
Possible Conversions
0 |
Normalize the path. |
1 |
Normalizes and converts the path to an absolute path. |
2 |
Normalizes and converts the path to an relative path. |
3 |
Returns the whole file/folder name. |
4 |
Returns the stem of the filename. |
5 |
Returns the file-extension of the filename. |
Details
| Name | Type | Description |
|---|---|---|
Conversion |
integer|string |
Conversion that will be applied to paths |
Paths |
string |
Paths that will be joined |
| Name | Type | Description |
|---|---|---|
Result |
string |
Joined and processed path |
filesystem.remove (path: string, recursive: bool) → boolean
Removes the filesystem object at the given path.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object |
Recursive |
boolean |
If false only removes the given filesystem object. If true removes all childs of the filesystem object. |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
Returns true if it was able to remove the node |
filesystem.rename (path: string, name: string) → boolean
Renames the filesystem object at the given path to the given name.
Details
| Name | Type | Description |
|---|---|---|
Path |
string |
path to the filesystem object you want to rename |
Name |
string |
the new name for your filesystem object |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
returns true if it was able to rename the node |
filesystem.unmount (mountPoint: string) → boolean
This function unmounts if the device at the given mount point.
Details
| Name | Type | Description |
|---|---|---|
Mount Point |
string |
the path the device is mounted to |
| Name | Type | Description |
|---|---|---|
Success |
boolean |
returns true if it was able to unmount the device located at the mount point |
Types
File.read (…: integer) → …
Reads up to the given amount of bytes from the file. Strings may be smaller than the given amount of bytes due to f.e. reaching the End-Of-File.
Details
| Name | Type | Description |
|---|---|---|
self |
||
Sizes |
integer |
Maximum sizes of strings |
| Name | Type | Description |
|---|---|---|
Contents |
string? |
Contents of the file |
File.seek (where: string, offset: integer) → integer
Moves the File-Streams pointer to a position defined by the offset and from what starting location.
Possble where values
-
curOffset is relative to the current location -
setOffset is relative to the beginning of the file -
endOffset is relative to the end of the file
Details
| Name | Type | Description |
|---|---|---|
self |
||
Where |
string |
Starting location |
Offset |
integer |
Offset |
| Name | Type | Description |
|---|---|---|
Position |
string? |
Current position in the file |