Embedded TCP/IP stack  3.9.4
File System API

FNET File System API. More...

Detailed Description

FNET File System API.

The FNET File System (FS) API provides standard interface for file and directory manipulations.
The FNET File System API is inspired by standard ANSI C and POSIX-based APIs.
The following table summarizes the supported File System API functions:

File System API
FunctionsDescription
fnet_fs_init(), fnet_fs_release() FNET file system interface initialization/release.
fnet_fs_mount(), fnet_fs_unmount() Mount/unmount a file system image.
fnet_fs_fopen(), fnet_fs_fopen_re(), fnet_fs_fclose() Open/close a file.
fnet_fs_fread(), fnet_fs_fgetc() Read a file.
fnet_fs_rewind(), fnet_fs_fseek(), fnet_fs_feof(), fnet_fs_ftell() Move/get a file pointer.
fnet_fs_opendir(), fnet_fs_closedir() Open/close a directory.
fnet_fs_readdir(), fnet_fs_rewinddir() Read a directory.

The path name that points to a file or directory has the following format:

/[mount name][/directory name]..[/file name] 


After the FS is initialized by calling the fnet_fs_init() function, a user application should call a FS registration function (for example the fnet_fs_rom_register() for the FNET ROM FS registration), and finally mount a FS image by the fnet_fs_mount() function. Thereafter an application has access to files and directories on the mounted FS image.

For example:

...
// FNET FS initialization.
{
// Register ROM FS.
// Mount ROM FS image.
if( fnet_fs_mount( FNET_FS_ROM_NAME, "rom", (void *)&fnet_fs_image ) == FNET_ERR )
fnet_println("ERROR: FS image mount is failed!");
...
// Print directory content.
{
struct fnet_fs_dirent ep;
fnet_uint8_t name[FNET_CFG_FS_MOUNT_NAME_MAX+1];
// Open dir.
dir = fnet_fs_opendir("\rom");
if (dir)
{
fnet_memset(&ep, 0, sizeof(struct fnet_fs_dirent) );
ep.d_name = name;
ep.d_name_size = sizeof(name);
// Print the dir content.
while ((fnet_fs_readdir (dir, &ep))==FNET_OK)
fnet_println ("%7s - %s", (ep.d_type == DT_DIR)?"<DIR>":"<FILE>",ep.d_name);
// Close dir.
}
else
fnet_println("ERROR: The directory is failed!");
}
...
}
else
{
fnet_println("ERROR: FNET FS initialization is failed!");
}
...


Configuration parameters:

Modules

 ROM File System API
 FNET ROM FS API.
 

Data Structures

struct  fnet_fs_dirent
 This structure is used by the fnet_fs_finfo() and the fnet_fs_readdir() function to get information about directory entries (files or directories). More...
 

Macros

#define FNET_FS_SPLITTER
 File-path splitter.
This symbol is used to delimit directories and files in a pathname string. More...
 
#define FNET_FS_EOF
 End-of-file condition.
This is a condition, where no data can be read from a data source. More...
 

Typedefs

typedef void * fnet_fs_dir_t
 Directory descriptor.
This is the abstract key for accessing a directory. More...
 
typedef void * fnet_fs_file_t
 File descriptor.
This is the abstract key for accessing a file. More...
 

Enumerations

Functions

fnet_return_t fnet_fs_init (void)
 Initializes the FNET File System Interface. More...
 
void fnet_fs_release (void)
 Releases the FNET File System Interface. More...
 
fnet_return_t fnet_fs_mount (fnet_char_t *fs_name, const fnet_char_t *mount_name, const void *arg)
 Mounts a file system. More...
 
fnet_return_t fnet_fs_unmount (const fnet_char_t *mount_name)
 Unmounts a file system. More...
 
fnet_fs_dir_t fnet_fs_opendir (const fnet_char_t *dirname)
 Opens a directory descriptor. More...
 
fnet_return_t fnet_fs_closedir (fnet_fs_dir_t dir)
 Closes a directory descriptor. More...
 
fnet_return_t fnet_fs_readdir (fnet_fs_dir_t dir, struct fnet_fs_dirent *dirent)
 Reads a directory entry. More...
 
void fnet_fs_rewinddir (fnet_fs_dir_t dir)
 Resets a directory position. More...
 
fnet_fs_file_t fnet_fs_fopen (const fnet_char_t *filename, const fnet_char_t *mode)
 Opens a file descriptor. More...
 
fnet_fs_file_t fnet_fs_fopen_re (const fnet_char_t *filename, const fnet_char_t *mode, fnet_fs_dir_t dir)
 Opens a file relatively in an opened directory. More...
 
fnet_return_t fnet_fs_fclose (fnet_fs_file_t file)
 Closes a file descriptor. More...
 
fnet_size_t fnet_fs_fread (void *buf, fnet_size_t size, fnet_fs_file_t file)
 Reads data from a file. More...
 
void fnet_fs_rewind (fnet_fs_file_t file)
 Resets a file position. More...
 
fnet_bool_t fnet_fs_feof (fnet_fs_file_t file)
 Checks the End-of-File indicator. More...
 
fnet_int32_t fnet_fs_fgetc (fnet_fs_file_t file)
 Gets a character from a file. More...
 
fnet_return_t fnet_fs_fseek (fnet_fs_file_t file, fnet_int32_t offset, fnet_fs_seek_origin_t origin)
 Changes the file-position indicator for the specified file. More...
 
fnet_int32_t fnet_fs_ftell (fnet_fs_file_t file)
 Gets the current position in a file. More...
 
fnet_return_t fnet_fs_finfo (fnet_fs_file_t file, struct fnet_fs_dirent *dirent)
 Gets a file information. More...
 

© 2005-2017 by Andrey Butok. http://fnet.sourceforge.net