Comtrol eCos User Manual

Page 437

Advertising
background image

Chapter 29. Writing a New Filesystem

};

These all point to functions supplied by the filesystem except the

fo_select

field which is filled with a pointer

to

cyg_fileio_seltrue()

. This is provided by the FILEIO package and is a select function that always returns

true to all operations.

Finally, we need to define a set of file operations for use when reading directories. This table only defines the

fo_read

and

fo_lseek

operations. The rest are filled with stub functions supplied by the FILEIO package that

just return an error code.

// -------------------------------------------------------------------------

// Directory file operations.

// This set of operations are used for open directories. Most entries

// point to error-returning stub functions. Only the read, lseek and

// close entries are functional.

static cyg_fileops ramfs_dirops =

{

ramfs_fo_dirread,

(cyg_fileop_write *)cyg_fileio_enosys,

ramfs_fo_dirlseek,

(cyg_fileop_ioctl *)cyg_fileio_enosys,

cyg_fileio_seltrue,

(cyg_fileop_fsync *)cyg_fileio_enosys,

ramfs_fo_close,

(cyg_fileop_fstat *)cyg_fileio_enosys,

(cyg_fileop_getinfo *)cyg_fileio_enosys,

(cyg_fileop_setinfo *)cyg_fileio_enosys

};

If the filesystem wants to have an instance automatically mounted on system startup, it must also define a mount
table entry. This is done with the

MTAB_ENTRY

macro. This is an example from the test filesystem of how this is

used:

MTAB_ENTRY( testfs_mte1,

"/",

"testfs",

"",

0);

The first argument provides a name for the table entry. The following arguments provide initialization for the

name

,

fsname

,

devname

and

data

fields respectively.

These definitions are adequate to let the new filesystem interact with the FILEIO package. The new filesystem now
needs to be fleshed out with implementations of the functions defined above. Obviously, the exact form this takes
will depend on what the filesystem is intended to do. Take a look at the RAM and ROM filesystems for examples
of how this has been done.

333

Advertising