Chapter 21. File System Table

The filesystem table is an array of entries that describe each filesystem implementation that is part of the system image. Each resident filesystem should export an entry to this table using the FSTAB_ENTRY() macro.

[Note]Note

At present we do not support dynamic addition or removal of table entries. However, an API similar to mount() would allow new entries to be added to the table.

The table entries are described by the following structure:

struct cyg_fstab_entry
{
    const char          *name;          // filesystem name
    CYG_ADDRWORD        data;           // private data value
    cyg_uint32          syncmode;       // synchronization mode

    int     (*mount)    ( cyg_fstab_entry *fste,
                          cyg_mtab_entry  *mte );
    int     (*umount)   ( cyg_mtab_entry  *mte,
                          cyg_bool        force );
    int     (*open)     ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          int             mode,
                          cyg_file        *fte );
    int     (*unlink)   ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name );
    int     (*mkdir)    ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name );
    int     (*rmdir)    ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name );
    int     (*rename)   ( cyg_mtab_entry  *mte,
                          cyg_dir         dir1,
                          const char      *name1,
                          cyg_dir         dir2,
                          const char      *name2 );
    int     (*link)     ( cyg_mtab_entry  *mte,
                          cyg_dir         dir1,
                          const char      *name1,
                          cyg_dir         dir2,
                          const char      *name2,
                          int             type );
    int     (*opendir)  ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          cyg_file        *fte );
    int     (*chdir)    ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          cyg_dir         *dir_out );
    int     (*stat)     ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          struct stat     *buf);
    int     (*getinfo)  ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          int             key,
                          char            *buf,
                          int             len );
    int     (*setinfo)  ( cyg_mtab_entry  *mte,
                          cyg_dir         dir,
                          const char      *name,
                          int             key,
                          char            *buf,
                          int             len );
};

The name field points to a string that identifies this filesystem implementation. Typical values might be "romfs", "fatfs", "ext2" etc.

The data field contains any private data that the filesystem needs, perhaps the root of its data structures.

The syncmode field contains a description of the locking protocol to be used when accessing this filesystem. It will be described in more detail in Chapter 25, Synchronization.

The remaining fields are pointers to functions that implement filesystem operations that apply to files and directories as whole objects. The operation implemented by each function should be obvious from the names, with a few exceptions:

The opendir() function pointer opens a directory for reading. See Chapter 24, Directories for details.

The getinfo() and setinfo() function pointers provide support for various minor control and information functions such as pathconf() and access().

With the exception of the mount() and umount() functions, all of these functions take three standard arguments, a pointer to a mount table entry (see later) a directory pointer (also see later) and a file name relative to the directory. These should be used by the filesystem to locate the object of interest.