⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileio-file-table.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>File Table</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="File System Support Infrastructure"HREF="fileio.html"><LINKREL="PREVIOUS"TITLE="Mount Table"HREF="fileio-mount-table.html"><LINKREL="NEXT"TITLE="Directories"HREF="fileio-directories.html"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="fileio-mount-table.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="fileio-directories.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="FILEIO-FILE-TABLE">Chapter 22. File Table</H1><P>Once a file has been opened it is represented by an open fileobject. These are allocated from an array of available fileobjects. User code accesses these open file objects via a second arrayof pointers which is indexed by small integer offsets. This gives theusual Unix file descriptor functionality, complete with the variousduplication mechanisms.</P><P>A file table entry has the following structure:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">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            */};</PRE></TD></TR></TABLE><P>The <TTCLASS="STRUCTFIELD"><I>f_flag</I></TT> field contains some FILEIOcontrol bits and some bits propagated from the<TTCLASS="PARAMETER"><I>flags</I></TT> argument of the<TTCLASS="FUNCTION">open()</TT> call (defined by<TTCLASS="LITERAL">CYG_FILE_MODE_MASK</TT>).</P><P>The <TTCLASS="STRUCTFIELD"><I>f_ucount</I></TT> field contains a use count thatcontrols when a file will be closed. Each duplicate in the filedescriptor array counts for one reference here. It is alsoincremented around each I/O operation to ensure that the file cannotbe closed while it has current I/O operations.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_type</I></TT> field indicates the type of theunderlying file object. Some of the possible values here are<TTCLASS="LITERAL">CYG_FILE_TYPE_FILE</TT>,<TTCLASS="LITERAL">CYG_FILE_TYPE_SOCKET</TT> or <TTCLASS="LITERAL">CYG_FILE_TYPE_DEVICE</TT>.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_syncmode</I></TT> field is copied from the<TTCLASS="STRUCTFIELD"><I>syncmode</I></TT> field of the implementingfilesystem. Its use is described in <AHREF="fileio-synchronization.html">Chapter 24</A>.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_offset</I></TT> field records the current fileposition. It is the responsibility of the file operation functions tokeep this field up to date.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_data</I></TT> field contains private dataplaced here by the underlying filesystem. Normally this will be apointer to, or handle on, the filesystem object that implements thisfile.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_xops</I></TT> field contains a pointer to anyextra type specific operation functions. For example, the socket I/Osystem installs a pointer to a table of functions that implement thestandard socket operations.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_mte</I></TT> field contains a pointer to theparent mount table entry for this file. It is used mainly to implementthe synchronization protocol. This may contain a pointer to some otherdata structure in file objects not derived from a filesystem.</P><P>The <TTCLASS="STRUCTFIELD"><I>f_ops</I></TT> field contains a pointer to atable of file I/O operations. This has the following structure:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct CYG_FILEOPS_TAG{        int	(*fo_read)      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);        int	(*fo_write)     (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);        int     (*fo_lseek)     (struct CYG_FILE_TAG *fp, off_t *pos, int whence );        int	(*fo_ioctl)     (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,                                 CYG_ADDRWORD data);        int	(*fo_select)    (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info);        int     (*fo_fsync)     (struct CYG_FILE_TAG *fp, int mode );                int	(*fo_close)     (struct CYG_FILE_TAG *fp);        int     (*fo_fstat)     (struct CYG_FILE_TAG *fp, struct stat *buf );        int     (*fo_getinfo)   (struct CYG_FILE_TAG *fp, int key, char *buf, int len );        int     (*fo_setinfo)   (struct CYG_FILE_TAG *fp, int key, char *buf, int len );};</PRE></TD></TR></TABLE><P>It should be obvious from the names of most of these functions whattheir responsibilities are. The <TTCLASS="FUNCTION">fo_getinfo()</TT>and <TTCLASS="FUNCTION">fo_setinfo()</TT> function pointers, like theircounterparts in the filesystem structure, implement minor control andinfo functions such as <TTCLASS="FUNCTION">fpathconf()</TT>.</P><P>The second argument to the <TTCLASS="FUNCTION">fo_read()</TT> and<TTCLASS="FUNCTION">fo_write()</TT> function pointers is a pointer to aUIO structure:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct CYG_UIO_TAG{    struct CYG_IOVEC_TAG *uio_iov;	/* pointer to array of iovecs */    int	                 uio_iovcnt;	/* number of iovecs in array */    off_t       	 uio_offset;	/* offset into file this uio corresponds to */    ssize_t     	 uio_resid;	/* residual i/o count */    enum cyg_uio_seg     uio_segflg;    /* see above */    enum cyg_uio_rw      uio_rw;        /* see above */};struct CYG_IOVEC_TAG{    void           *iov_base;           /* Base address. */    ssize_t        iov_len;             /* Length. */};</PRE></TD></TR></TABLE><P>This structure encapsulates the parameters of any data transferoperation. It provides support for scatter/gather operations andrecords the progress of any data transfer. It is also compatible withthe I/O operations of any BSD-derived network stacks and filesystems.</P><P>When a file is opened (or a file object created by some other means,such as <TTCLASS="FUNCTION">socket()</TT> or <TTCLASS="FUNCTION">accept()</TT>) it is theresponsibility of the filesystem open operation to initialize all thefields of the object except the <TTCLASS="STRUCTFIELD"><I>f_ucount</I></TT>,<TTCLASS="STRUCTFIELD"><I>f_syncmode</I></TT> and<TTCLASS="STRUCTFIELD"><I>f_mte</I></TT> fields. Since the<TTCLASS="STRUCTFIELD"><I>f_flag</I></TT> field will already contain bits belonging to the FILEIOinfrastructure, any changes to it must be made with the appropriatelogical operations.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="fileio-mount-table.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="fileio-directories.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Mount Table</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="fileio.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Directories</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -