Class Files
A file may only be opened if permission is granted by an entry in /opt/pigpio/access. This is intended to allow remote access to files in a more or less controlled manner.
Each entry in /opt/pigpio/access takes the form of a file path which may contain wildcards followed by a single letter permission. The permission may be R for read, W for write, U for read/write, and N for no access.
Where more than one entry matches a file the most specific rule applies. If no entry matches a file then access is denied.
Suppose /opt/pigpio/access contains the following entries
Files may be written in directory dir_1 with the exception of file.txt.
Files may be read in directory dir_2.
Files may be read and written in directory dir_3.
If a directory allows read, write, or read/write access then files may be created in that directory.
In an attempt to prevent risky permissions the following paths are ignored in /opt/pigpio/access.
Inherited Members
Namespace: Unosquare.PiGpio.NativeMethods
Syntax
public static class Files
Methods
FileClose(UIntPtr)
This function closes the file associated with handle.
Declaration
public static ResultCode FileClose(UIntPtr handle)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle |
|
Returns
| Type | Description |
|---|---|
| ResultCode | Returns 0 if OK, otherwise PI_BAD_HANDLE. |
Examples
fileClose(h);
FileList(String)
Retrieves a list of files matching the given pattern. See Unosquare.PiGpio.NativeMethods.Files.FileListUnmanaged(System.String,System.Byte[],System.UInt32).
Declaration
public static string[] FileList(string pathPattern)
Parameters
| Type | Name | Description |
|---|---|---|
| String | pathPattern | The path pattern. |
Returns
| Type | Description |
|---|---|
| String[] | A list of matching files. |
FileOpen(String, FileModeFlags)
A wrapper function for Unosquare.PiGpio.NativeMethods.Files.FileOpenUnmanaged(System.String,System.UInt32).
Declaration
public static UIntPtr FileOpen(string filePath, FileModeFlags mode)
Parameters
| Type | Name | Description |
|---|---|---|
| String | filePath | The file path. |
| FileModeFlags | mode | The mode. |
Returns
| Type | Description |
|---|---|
| UIntPtr | A file handle. |
Exceptions
| Type | Condition |
|---|---|
| IOException | When the file fails to open. |
FileRead(UIntPtr, Byte[], UInt32)
This function reads up to count bytes from the the file associated with handle and writes them to buf.
Declaration
public static int FileRead(UIntPtr handle, byte[] buffer, uint count)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle |
|
| Byte[] | buffer | an array to receive the read data. |
| UInt32 | count | the maximum number of bytes to read. |
Returns
| Type | Description |
|---|---|
| Int32 | Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. |
Examples
if (fileRead(h, buf, sizeof(buf)) > 0)
{
// process read data
}
FileRead(UIntPtr, Int32)
Reads from a file handle up to count bytes.
Declaration
public static byte[] FileRead(UIntPtr handle, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle | The handle. |
| Int32 | count | The count. |
Returns
| Type | Description |
|---|---|
| Byte[] | The array of bytes read. |
FileSeek(UIntPtr, Int32, SeekMode)
Seeks within a file.
Declaration
public static int FileSeek(UIntPtr handle, int seekOffset, SeekMode seekFrom)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle | The handle. |
| Int32 | seekOffset | The seek offset. |
| SeekMode | seekFrom | The seek from. |
Returns
| Type | Description |
|---|---|
| Int32 | The new byte position within the file. |
FileWrite(UIntPtr, Byte[])
Writes the given buffer to a file handle.
Declaration
public static ResultCode FileWrite(UIntPtr handle, byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle | The handle. |
| Byte[] | buffer | The buffer. |
Returns
| Type | Description |
|---|---|
| ResultCode | The Result Code. |
FileWrite(UIntPtr, Byte[], Int32)
Writes the given buffer to a file handle.
Declaration
public static ResultCode FileWrite(UIntPtr handle, byte[] buffer, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| UIntPtr | handle | The handle. |
| Byte[] | buffer | The buffer. |
| Int32 | length | The length. |
Returns
| Type | Description |
|---|---|
| ResultCode | The Result Code. |