4.2.0.0R6
Software Development Kit
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
File System

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...
 
DIRopendir (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...
 

Detailed Description

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:

ImplicitExplicit
open()openat()
stat()fstatat()
mkdir()mkdirat()
rename()renameat()
unlink(), rmdir()unlinkat()
opendir()N/A

Typedef Documentation

typedef void DIR

Directory stream type.

Typedef DIR is a stream opened by opendir(), read by readdir(), and closed by closedir().

Enumeration Type Documentation

Bank in the file system.

Enumerator
LTRX_FS_BANK__A 

Bank A.

LTRX_FS_BANK__B 

Bank B.

Function Documentation

int access ( const char *  path,
int  flags 
)

Check permissions.

Check the file or directory named by path.

Return values
0Success.
-1Denied.
Parameters
[in]pathThe pathname.
[in]flagsUse 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]fdFile 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.

Return values
0Success.
-1Error, see errno.

Close the directory stream assocated with the dir argument. A successful to closedir() also closes the underlying file descriptor associated with dir.

Returns
0 Success
Return values
-1Error, see errno.
Parameters
[in,out]dirAn 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().

Returns
File descriptor.
Return values
-1Error, see errno.
Parameters
[in]dirPointer from opendir().
int fstat ( int  fd,
struct stat st 
)

Get file status.

Obtain information about file fd, writing it to the structure st.

Return values
0Success.
-1Error, see errno.
Parameters
[in]fdFile descriptor to obtain information for.
[out]stStructure 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]fdFile descriptor whose associated directory is to be used if the path is relative.
[in]pathDirectory and file pathname.
[out]stStructure to receive the information.
[in]flagflag – 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]fdFile 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:

SEEK_SET
The file offset shall be set to offset bytes.
SEEK_CUR
The file offset shall be set to its current location plus offset.
SEEK_END
The file offset shall be set to the size of the file plus offset.
Returns
The resulting offset.
Return values
-1Error, see errno.
Parameters
[in]fdFile descriptor to seek.
[in]offsetOffset value in bytes. Can be positive or negative.
[in]whenceHow 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.

Parameters
[in]allIf 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.

Return values
trueSuccess.
falseFailed.
Parameters
[out]inStreamYour file input stream struct to initialize.
[in]fileNameThe 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.

Return values
trueSuccess.
falseFailed.
Parameters
[out]outStreamYour file output stream struct to initialize.
[in]fileNameThe full path name of the desired file.
int mkdir ( const char *  path,
mode_t  mode 
)

Create directory.

Creates a directory at the designated path.

Return values
0Success.
-1Error, see errno.
Parameters
[in]pathDirectory pathname.
[in]modeMode, 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]cwdfdDirectory descriptor is to be used if the path is relative.
[in]pathDirectory pathname.
[in]modeMode, 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_APPEND
If set, the file offset shall be set to the end of the file prior to each write.
O_CREAT
If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file shall be created.
O_DIRECTORY
If path resolves to a non-directory file, fail and set errno to ENOTDIR.
O_EXCL
If 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_RDONLY
Open for reading only.
O_RDWR
Open for reading and writing.
O_TRUNC
If the file exists and is a regular file, and the file is successfully opened O_RDWR or O_WRONLY, its length shall be truncated to 0.
O_WRONLY
Open for writing only.
Returns
File descriptor.
Return values
-1Error, see errno.
Parameters
[in]pathDirectory and file pathname.
[in]flagsOne 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_APPEND
If set, the file offset shall be set to the end of the file prior to each write.
O_CREAT
If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file shall be created.
O_DIRECTORY
If path resolves to a non-directory file, fail and set errno to ENOTDIR.
O_EXCL
If 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_RDONLY
Open for reading only.
O_RDWR
Open for reading and writing.
O_TRUNC
If the file exists and is a regular file, and the file is successfully opened O_RDWR or O_WRONLY, its length shall be truncated to 0.
O_WRONLY
Open for writing only.
Returns
File descriptor.
Return values
-1Error, see errno.
Parameters
[in]fdFile descriptor whose associated directory is to be used if the path is relative.
[in]pathDirectory and file pathname.
[in]flagsOne 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.

Returns
Pointer to an object of type DIR.
Return values
NULLError, 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.

Returns
Pointer to the directory stream.
Return values
NULLError, see errno.
Parameters
[in]pathDirectory pathname.
int read ( int  fd,
void *  buffer,
size_t  nbytes 
)

Read from a file.

Reads data from the designated file.

Returns
Number of bytes actually read.
Return values
-1Error, see errno.
Parameters
[in]fdFile descriptor to read.
[out]bufferBuffer to be written with data.
[in]nbytesMaximum number of bytes to read into buffer.
int readdir ( DIR dir,
struct dirent dent 
)

Read a directory.

Reads a directory stream dir at its current position. The directory stream is positioned at the next entry.

Return values
0Success.
-1Error, 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.

Returns
Pointer to the directory stream.
Return values
NULLError, see errno.
Parameters
[in,out]dirAn object of type DIR to be read.
[out]dentStructure 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]oldnameThe original name.
[in]newnameThe 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]oldfdFile descriptor whose associated directory is to be used if the oldname is relative.
[in]oldnameFile to look for.
[in]newfdFile descriptor whose associated directory is to be used if the newname is relative.
[in]newnameNew name for the file.
int rmdir ( const char *  path)

Delete a directory.

Deletes the directory named by path.

Return values
0Success.
-1Error, see errno.
Parameters
[in]pathDirectory pathname.
int stat ( const char *  fname,
struct stat *  st 
)

Get file status.

Obtain information about the named file, writing it to the structure st.

Return values
0Success.
-1Error, see errno.
Parameters
[in]fnameDirectory and file pathname.
[out]stStructure to receive the information.
int unlink ( const char *  path)

Delete a file.

Deletes the file named by path.

Return values
0Success.
-1Error, see errno.
Parameters
[in]pathDirectory 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.

Return values
0Success.
-1Error, see errno.
Parameters
[in]cwdfdFile descriptor whose associated directory is to be used if the path is relative.
[in]pathThe pathname.
[in]flagsUse 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.

Returns
Number of bytes actually written.
Return values
-1Error, see errno.
Parameters
[in]fdFile descriptor to write.
[in]bufferBuffer supplying data to be written.
[in]nbytesMaximum number of bytes to write into the file.