Comtrol eCos User Manual

Page 436

Advertising
background image

Chapter 29. Writing a New Filesystem

static int ramfs_fo_dirread

(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);

static int ramfs_fo_dirlseek

(struct CYG_FILE_TAG *fp, off_t *pos, int whence );

We define all of the fstab entries and all of the file IO operations. We also define alternatives for the

fo_read

and

fo_lseek

file IO operations.

We can now define the filesystem table entry. There is a macro,

FSTAB_ENTRY

to do this:

//==========================================================================

// Filesystem table entries

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

// Fstab entry.

// This defines the entry in the filesystem table.

// For simplicity we use _FILESYSTEM synchronization for all accesses since

// we should never block in any filesystem operations.

FSTAB_ENTRY( ramfs_fste, "ramfs", 0,

CYG_SYNCMODE_FILE_FILESYSTEM|CYG_SYNCMODE_IO_FILESYSTEM,

ramfs_mount,

ramfs_umount,

ramfs_open,

ramfs_unlink,

ramfs_mkdir,

ramfs_rmdir,

ramfs_rename,

ramfs_link,

ramfs_opendir,

ramfs_chdir,

ramfs_stat,

ramfs_getinfo,

ramfs_setinfo);

The first argument to this macro gives the fstab entry a name, the remainder are initializers for the field of the
structure.

We must also define the file operations table that is installed in all open file table entries:

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

// File operations.

// This set of file operations are used for normal open files.

static cyg_fileops ramfs_fileops =

{

ramfs_fo_read,

ramfs_fo_write,

ramfs_fo_lseek,

ramfs_fo_ioctl,

cyg_fileio_seltrue,

ramfs_fo_fsync,

ramfs_fo_close,

ramfs_fo_fstat,

ramfs_fo_getinfo,

ramfs_fo_setinfo

332

Advertising