Chapter 22. file table, File table – Comtrol eCos User Manual
Page 421
Chapter 22. File Table
Once a file has been opened it is represented by an open file object. These are allocated from an array of avail-
able file objects. User code accesses these open file objects via a second array of pointers which is indexed by
small integer offsets. This gives the usual Unix file descriptor functionality, complete with the various duplication
mechanisms.
A file table entry has the following structure:
struct CYG_FILE_TAG
{
cyg_uint32
f_flag;
/* file state
*/
cyg_uint16
f_ucount;
/* use count
*/
cyg_uint16
f_type;
/* descriptor type
*/
cyg_uint32
f_syncmode;
/* synchronization protocol
*/
struct CYG_FILEOPS_TAG
*f_ops;
/* file operations
*/
off_t
f_offset;
/* current offset
*/
CYG_ADDRWORD
f_data;
/* file or socket
*/
CYG_ADDRWORD
f_xops;
/* extra type specific ops
*/
cyg_mtab_entry
*f_mte;
/* mount table entry
*/
};
The
f_flag
field contains some FILEIO control bits and some bits propagated from the
flags
argument of the
open()
call (defined by
CYG_FILE_MODE_MASK
).
The
f_ucount
field contains a use count that controls when a file will be closed. Each duplicate in the file
descriptor array counts for one reference here. It is also incremented around each I/O operation to ensure that the
file cannot be closed while it has current I/O operations.
The
f_type
field indicates the type of the underlying file object. Some of the possible values here are
CYG_FILE_TYPE_FILE
,
CYG_FILE_TYPE_SOCKET
or
CYG_FILE_TYPE_DEVICE
.
The
f_syncmode
field is copied from the
syncmode
field of the implementing filesystem. Its use is described
in
The
f_offset
field records the current file position. It is the responsibility of the file operation functions to keep
this field up to date.
The
f_data
field contains private data placed here by the underlying filesystem. Normally this will be a pointer
to, or handle on, the filesystem object that implements this file.
The
f_xops
field contains a pointer to any extra type specific operation functions. For example, the socket I/O
system installs a pointer to a table of functions that implement the standard socket operations.
The
f_mte
field contains a pointer to the parent mount table entry for this file. It is used mainly to implement the
synchronization protocol. This may contain a pointer to some other data structure in file objects not derived from a
filesystem.
The
f_ops
field contains a pointer to a table of file I/O operations. This has the following structure:
struct CYG_FILEOPS_TAG
{
317