1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="File System Support Infrastructure"
23 HREF="fileio.html"><LINK
26 HREF="fileio-mount-table.html"><LINK
29 HREF="fileio-directories.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="fileio-mount-table.html"
71 HREF="fileio-directories.html"
84 NAME="FILEIO-FILE-TABLE">Chapter 22. File Table</H1
86 >Once a file has been opened it is represented by an open file
87 object. These are allocated from an array of available file
88 objects. User code accesses these open file objects via a second array
89 of pointers which is indexed by small integer offsets. This gives the
90 usual Unix file descriptor functionality, complete with the various
91 duplication mechanisms.</P
93 >A file table entry has the following structure:</P
101 CLASS="PROGRAMLISTING"
104 cyg_uint32 f_flag; /* file state */
105 cyg_uint16 f_ucount; /* use count */
106 cyg_uint16 f_type; /* descriptor type */
107 cyg_uint32 f_syncmode; /* synchronization protocol */
108 struct CYG_FILEOPS_TAG *f_ops; /* file operations */
109 off_t f_offset; /* current offset */
110 CYG_ADDRWORD f_data; /* file or socket */
111 CYG_ADDRWORD f_xops; /* extra type specific ops */
112 cyg_mtab_entry *f_mte; /* mount table entry */
123 > field contains some FILEIO
124 control bits and some bits propagated from the
137 >CYG_FILE_MODE_MASK</TT
145 > field contains a use count that
146 controls when a file will be closed. Each duplicate in the file
147 descriptor array counts for one reference here. It is also
148 incremented around each I/O operation to ensure that the file cannot
149 be closed while it has current I/O operations.</P
156 > field indicates the type of the
157 underlying file object. Some of the possible values here are
160 >CYG_FILE_TYPE_FILE</TT
164 >CYG_FILE_TYPE_SOCKET</TT
167 >CYG_FILE_TYPE_DEVICE</TT
175 > field is copied from the
181 > field of the implementing
182 filesystem. Its use is described in <A
183 HREF="fileio-synchronization.html"
192 > field records the current file
193 position. It is the responsibility of the file operation functions to
194 keep this field up to date.</P
201 > field contains private data
202 placed here by the underlying filesystem. Normally this will be a
203 pointer to, or handle on, the filesystem object that implements this
211 > field contains a pointer to any
212 extra type specific operation functions. For example, the socket I/O
213 system installs a pointer to a table of functions that implement the
214 standard socket operations.</P
221 > field contains a pointer to the
222 parent mount table entry for this file. It is used mainly to implement
223 the synchronization protocol. This may contain a pointer to some other
224 data structure in file objects not derived from a filesystem.</P
231 > field contains a pointer to a
232 table of file I/O operations. This has the following structure:</P
240 CLASS="PROGRAMLISTING"
241 >struct CYG_FILEOPS_TAG
243 int (*fo_read) (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
244 int (*fo_write) (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
245 int (*fo_lseek) (struct CYG_FILE_TAG *fp, off_t *pos, int whence );
246 int (*fo_ioctl) (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,
248 int (*fo_select) (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info);
249 int (*fo_fsync) (struct CYG_FILE_TAG *fp, int mode );
250 int (*fo_close) (struct CYG_FILE_TAG *fp);
251 int (*fo_fstat) (struct CYG_FILE_TAG *fp, struct stat *buf );
252 int (*fo_getinfo) (struct CYG_FILE_TAG *fp, int key, char *buf, int len );
253 int (*fo_setinfo) (struct CYG_FILE_TAG *fp, int key, char *buf, int len );
259 >It should be obvious from the names of most of these functions what
260 their responsibilities are. The <TT
267 > function pointers, like their
268 counterparts in the filesystem structure, implement minor control and
269 info functions such as <TT
274 >The second argument to the <TT
281 > function pointers is a pointer to a
290 CLASS="PROGRAMLISTING"
293 struct CYG_IOVEC_TAG *uio_iov; /* pointer to array of iovecs */
294 int uio_iovcnt; /* number of iovecs in array */
295 off_t uio_offset; /* offset into file this uio corresponds to */
296 ssize_t uio_resid; /* residual i/o count */
297 enum cyg_uio_seg uio_segflg; /* see above */
298 enum cyg_uio_rw uio_rw; /* see above */
303 void *iov_base; /* Base address. */
304 ssize_t iov_len; /* Length. */
310 >This structure encapsulates the parameters of any data transfer
311 operation. It provides support for scatter/gather operations and
312 records the progress of any data transfer. It is also compatible with
313 the I/O operations of any BSD-derived network stacks and filesystems.</P
315 >When a file is opened (or a file object created by some other means,
323 responsibility of the filesystem open operation to initialize all the
324 fields of the object except the <TT
347 > field will already contain bits belonging to the FILEIO
348 infrastructure, any changes to it must be made with the appropriate
349 logical operations.</P
356 SUMMARY="Footer navigation table"
367 HREF="fileio-mount-table.html"
385 HREF="fileio-directories.html"