Data Structures | |
struct | dirent |
Directory entry struct written by readdir(). More... | |
struct | input_stream_from_file |
Concrete struct for a file input stream. More... | |
struct | ltrx_statfs |
Contains file system statistics. More... | |
struct | output_stream_to_file |
Concrete struct for a file output stream. More... | |
Macros | |
#define | DT_CHR 2 |
Directory entry type character device. | |
#define | DT_DIR 4 |
Directory entry type directory. | |
#define | DT_REG 8 |
Directory entry type regular file. | |
Typedefs | |
typedef void | DIR |
Directory stream type. More... | |
Enumerations | |
enum | ltrx_fs_bank { LTRX_FS_BANK__A = 1, LTRX_FS_BANK__B = 2 } |
Bank in the file system. More... | |
Functions | |
int | access (const char *path, int flags) |
Check permissions. More... | |
int | close (int fd) |
Close a file. More... | |
int | closedir (DIR *dir) |
Close a directory stream. More... | |
int | dirfd (DIR *dir) |
Extract the file descriptor used by a DIR stream. More... | |
int | fstat (int fd, struct stat *st) |
Get file status. More... | |
int | fstatat (int fd, const char *path, struct stat *st, int flag) |
Get file status relative to directory file descriptor. More... | |
int | fsync (int fd) |
Synchronize changes to a file. More... | |
off_t | lseek (int fd, off_t offset, int whence) |
Move the read/write file offset. More... | |
void | ltrx_fs_compact (void) |
Compact the file system. More... | |
void | ltrx_fs_format (bool all) |
Format the file system. More... | |
bool | ltrx_input_stream_init_from_file (struct input_stream_from_file *inStream, const char *fileName) |
Set up an input stream from a file. More... | |
bool | ltrx_output_stream_init_to_file (struct output_stream_to_file *outStream, const char *fileName) |
Set up an output stream to a file. More... | |
int | mkdir (const char *path, mode_t mode) |
Create directory. More... | |
int | mkdirat (int cwdfd, const char *path, mode_t mode) |
Create directory relative to directory descriptor. More... | |
int | open (const char *path, int flags,...) |
Open a file. More... | |
int | openat (int fd, const char *path, int flags,...) |
Open a file relative to directory file descriptor. More... | |
DIR * | opendir (const char *path) |
Open a directory stream. More... | |
int | read (int fd, void *buffer, size_t nbytes) |
Read from a file. More... | |
int | readdir (DIR *dir, struct dirent *dent) |
Read a directory. More... | |
int | rename (const char *oldname, const char *newname) |
Change a file's name. More... | |
int | renameat (int oldfd, const char *oldname, int newfd, const char *newname) |
Change a file's name. More... | |
int | rmdir (const char *path) |
Delete a directory. More... | |
int | stat (const char *fname, struct stat *st) |
Get file status. More... | |
int | unlink (const char *path) |
Delete a file. More... | |
int | unlinkat (int cwdfd, const char *path, int flags) |
Delete a file or directory. More... | |
int | write (int fd, const void *buffer, size_t nbytes) |
Write to a file. More... | |
File System contains the definitions for accessing files.
NOTE: This file system does not maintain a "current working directory". If your path is or might be relative, open() will implicitly use the root directory as its base. Use openat() to select an explicit base directory.
Here are the implicit and explicit versions of functions in the SDK:
Implicit | Explicit |
---|---|
open() | openat() |
stat() | fstatat() |
mkdir() | mkdirat() |
rename() | renameat() |
unlink(), rmdir() | unlinkat() |
opendir() | N/A |
typedef void DIR |
Directory stream type.
Typedef DIR
is a stream opened by opendir(), read by readdir(), and closed by closedir().
enum ltrx_fs_bank |
int access | ( | const char * | path, |
int | flags | ||
) |
Check permissions.
Check the file or directory named by path.
0 | Success. |
-1 | Denied. |
[in] | path | The pathname. |
[in] | flags | Use F_OK to test for existence. Use R_OK to test for read permission. Use W_OK to test for write permission. Multiple flags can be bitwise or'ed. |
int close | ( | int | fd | ) |
Close a file.
Closing a file frees up the file descriptor.
0 | Success. |
-1 | Error, see errno . |
[in] | fd | File descriptor to close. |
int closedir | ( | DIR * | dir | ) |
Close a directory stream.
Close a directory.
Closes a directory designated by dir. If a file descriptor has been extracted by dirfd(), it is also closed.
0 | Success. |
-1 | Error, see errno . |
Close the directory stream assocated with the dir argument. A successful to closedir() also closes the underlying file descriptor associated with dir.
-1 | Error, see errno . |
[in,out] | dir | An object of type DIR to be closed. |
int dirfd | ( | DIR * | dir | ) |
Extract the file descriptor used by a DIR stream.
Return a file descriptor referring to the same directory as the dir argument. This file descriptor shall be closed by a call to closedir().
-1 | Error, see errno . |
[in] | dir | Pointer from opendir(). |
int fstat | ( | int | fd, |
struct stat * | st | ||
) |
Get file status.
Obtain information about file fd, writing it to the structure st.
0 | Success. |
-1 | Error, see errno . |
[in] | fd | File descriptor to obtain information for. |
[out] | st | Structure to receive the information. |
int fstatat | ( | int | fd, |
const char * | path, | ||
struct stat * | st, | ||
int | flag | ||
) |
Get file status relative to directory file descriptor.
Obtain information about file fd, writing it to the structure st.
0 | Success. |
-1 | Error, see errno . |
[in] | fd | File descriptor whose associated directory is to be used if the path is relative. |
[in] | path | Directory and file pathname. |
[out] | st | Structure to receive the information. |
[in] | flag | flag – UNUSED. |
int fsync | ( | int | fd | ) |
Synchronize changes to a file.
Requests that all data for fd is to be transferred to Flash. It will not return until the transfer is complete or an error is detected.
0 | Success. |
-1 | Error, see errno . |
[in] | fd | File descriptor to synchronize. |
off_t lseek | ( | int | fd, |
off_t | offset, | ||
int | whence | ||
) |
Move the read/write file offset.
Sets the file offset for the designated file according to the value of whence:
-1 | Error, see errno . |
[in] | fd | File descriptor to seek. |
[in] | offset | Offset value in bytes. Can be positive or negative. |
[in] | whence | How to apply offset, as described above. |
void ltrx_fs_compact | ( | void | ) |
Compact the file system.
Preserves all files in the file system. Erases the unused bank of the file system and copies only the "clean" data into that bank. This frees up "dirty" space in the file system.
"Dirty" space results when a file or directory is deleted.
void ltrx_fs_format | ( | bool | all | ) |
Format the file system.
Removes directories and files from both banks of the file system.
[in] | all | If true , absolutely everything is removed. if false , system files are preserved; "/.hidden.*". |
bool ltrx_input_stream_init_from_file | ( | struct input_stream_from_file * | inStream, |
const char * | fileName | ||
) |
Set up an input stream from a file.
true | Success. |
false | Failed. |
[out] | inStream | Your file input stream struct to initialize. |
[in] | fileName | The full path name of the desired file. |
bool ltrx_output_stream_init_to_file | ( | struct output_stream_to_file * | outStream, |
const char * | fileName | ||
) |
Set up an output stream to a file.
true | Success. |
false | Failed. |
[out] | outStream | Your file output stream struct to initialize. |
[in] | fileName | The full path name of the desired file. |
int mkdir | ( | const char * | path, |
mode_t | mode | ||
) |
Create directory.
Creates a directory at the designated path.
0 | Success. |
-1 | Error, see errno . |
[in] | path | Directory pathname. |
[in] | mode | Mode, unused, present for compatibility (set to 0). |
int mkdirat | ( | int | cwdfd, |
const char * | path, | ||
mode_t | mode | ||
) |
Create directory relative to directory descriptor.
Creates a directory at the designated path.
0 | Success. |
-1 | Error, see errno . |
[in] | cwdfd | Directory descriptor is to be used if the path is relative. |
[in] | path | Directory pathname. |
[in] | mode | Mode, unused, present for compatibility (set to 0). |
int open | ( | const char * | path, |
int | flags, | ||
... | |||
) |
Open a file.
When opening a file, the flags govern the mode of operation:
O_EXCL
below. Otherwise, the file shall be created. errno
to ENOTDIR
. O_CREAT
and O_EXCL
are set, open() shall fail if the file exists. The check for the existence of the file and the creation of the file if it does not exist shall be atomic with respect to other threads executing open() naming the same filename in the same directory with O_EXCL
and O_CREAT
set. If O_EXCL
is set and O_CREAT
is not set, the result is undefined. O_RDWR
or O_WRONLY
, its length shall be truncated to 0. -1 | Error, see errno . |
[in] | path | Directory and file pathname. |
[in] | flags | One or more flags combined with bitwise-inclusive OR. |
int openat | ( | int | fd, |
const char * | path, | ||
int | flags, | ||
... | |||
) |
Open a file relative to directory file descriptor.
When opening a file, the flags govern the mode of operation:
O_EXCL
below. Otherwise, the file shall be created. errno
to ENOTDIR
. O_CREAT
and O_EXCL
are set, open() shall fail if the file exists. The check for the existence of the file and the creation of the file if it does not exist shall be atomic with respect to other threads executing open() naming the same filename in the same directory with O_EXCL
and O_CREAT
set. If O_EXCL
is set and O_CREAT
is not set, the result is undefined. O_RDWR
or O_WRONLY
, its length shall be truncated to 0. -1 | Error, see errno . |
[in] | fd | File descriptor whose associated directory is to be used if the path is relative. |
[in] | path | Directory and file pathname. |
[in] | flags | One or more flags combined with bitwise-inclusive OR. |
DIR * opendir | ( | const char * | path | ) |
Open a directory stream.
Open a directory.
Opens a directory stream corresponding to the directory named by path. The directory stream is positioned at the first entry.
DIR
. NULL | Error, see errno . |
Open a directory stream corresponding to the directory path, and return a pointer to the directory stream. The stream is positioned at the first entry in the directory.
NULL | Error, see errno . |
[in] | path | Directory pathname. |
int read | ( | int | fd, |
void * | buffer, | ||
size_t | nbytes | ||
) |
Read from a file.
Reads data from the designated file.
-1 | Error, see errno . |
[in] | fd | File descriptor to read. |
[out] | buffer | Buffer to be written with data. |
[in] | nbytes | Maximum number of bytes to read into buffer. |
Read a directory.
Reads a directory stream dir at its current position. The directory stream is positioned at the next entry.
0 | Success. |
-1 | Error, see errno . |
Return a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dirp. Return NULL on reaching the end of the directory stream or if an error occurs.
NULL | Error, see errno . |
[in,out] | dir | An object of type DIR to be read. |
[out] | dent | Structure to receive the information. |
int rename | ( | const char * | oldname, |
const char * | newname | ||
) |
Change a file's name.
Finds the file with oldname, then renames it to newname.
0 | Success. |
-1 | Error, see errno . |
[in] | oldname | The original name. |
[in] | newname | The new name. |
int renameat | ( | int | oldfd, |
const char * | oldname, | ||
int | newfd, | ||
const char * | newname | ||
) |
Change a file's name.
Finds the file with oldname, then renames it to newname.
0 | Success. |
-1 | Error, see errno . |
[in] | oldfd | File descriptor whose associated directory is to be used if the oldname is relative. |
[in] | oldname | File to look for. |
[in] | newfd | File descriptor whose associated directory is to be used if the newname is relative. |
[in] | newname | New name for the file. |
int rmdir | ( | const char * | path | ) |
Delete a directory.
Deletes the directory named by path.
0 | Success. |
-1 | Error, see errno . |
[in] | path | Directory pathname. |
int stat | ( | const char * | fname, |
struct stat * | st | ||
) |
Get file status.
Obtain information about the named file, writing it to the structure st.
0 | Success. |
-1 | Error, see errno . |
[in] | fname | Directory and file pathname. |
[out] | st | Structure to receive the information. |
int unlink | ( | const char * | path | ) |
Delete a file.
Deletes the file named by path.
0 | Success. |
-1 | Error, see errno . |
[in] | path | Directory and file pathname. |
int unlinkat | ( | int | cwdfd, |
const char * | path, | ||
int | flags | ||
) |
Delete a file or directory.
Deletes the file or directory named by path.
0 | Success. |
-1 | Error, see errno . |
[in] | cwdfd | File descriptor whose associated directory is to be used if the path is relative. |
[in] | path | The pathname. |
[in] | flags | Use AT_REMOVEDIR to remove a directory, or 0 to remove a file. |
int write | ( | int | fd, |
const void * | buffer, | ||
size_t | nbytes | ||
) |
Write to a file.
Writes data to the designated file.
-1 | Error, see errno . |
[in] | fd | File descriptor to write. |
[in] | buffer | Buffer supplying data to be written. |
[in] | nbytes | Maximum number of bytes to write into the file. |