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

📄 fileio-directories.html

📁 ecos3.0 beta 的官方文档,html格式
💻 HTML
字号:
<!-- Copyright (C) 2009 Free Software Foundation, 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.               -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Directories</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="File System Support Infrastructure"
HREF="fileio.html"><LINK
REL="PREVIOUS"
TITLE="File Table"
HREF="fileio-file-table.html"><LINK
REL="NEXT"
TITLE="Synchronization"
HREF="fileio-synchronization.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="fileio-file-table.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="fileio-synchronization.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="FILEIO-DIRECTORIES"
></A
>Chapter 18. Directories</H1
><P
>Filesystem operations all take a directory pointer as one of their
arguments.  A directory pointer is an opaque handle managed by the
filesystem. It should encapsulate a reference to a specific directory
within the filesystem. For example, it may be a pointer to the data
structure that represents that directory (such as an inode), or a
pointer to a pathname for the directory.</P
><P
>The <CODE
CLASS="FUNCTION"
>chdir()</CODE
> filesystem function pointer has two
modes of use. When passed a pointer in the
<CODE
CLASS="PARAMETER"
>dir_out</CODE
> argument, it should locate the named
directory and place a directory pointer there. If the
<CODE
CLASS="PARAMETER"
>dir_out</CODE
> argument is NULL then the
<CODE
CLASS="PARAMETER"
>dir</CODE
> argument is a previously generated
directory pointer that can now be disposed of. When the infrastructure
is implementing the <CODE
CLASS="FUNCTION"
>chdir()</CODE
> function it makes two
calls to filesystem <CODE
CLASS="FUNCTION"
>chdir()</CODE
> functions. The first
is to get a directory pointer for the new current directory. If this
succeeds the second is to dispose of the old current directory
pointer.</P
><P
>The <CODE
CLASS="FUNCTION"
>opendir()</CODE
> function is used to open a
directory for reading. This results in an open file object that can be
read to return a sequence of <CODE
CLASS="STRUCTNAME"
>struct dirent</CODE
>
objects. The only operations that are allowed on this file are
<CODE
CLASS="FUNCTION"
>read</CODE
>, <CODE
CLASS="FUNCTION"
>lseek</CODE
> and
<CODE
CLASS="FUNCTION"
>close</CODE
>. Each read operation on this file should
return a single <CODE
CLASS="STRUCTNAME"
>struct dirent</CODE
> object. When
the end of the directory is reached, zero should be returned. The only
seek operation allowed is a rewind to the start of the directory, by
supplying an offset of zero and a <CODE
CLASS="PARAMETER"
>whence</CODE
>
specifier of <TT
CLASS="LITERAL"
>SEEK_SET</TT
>.</P
><P
>Most of these considerations are invisible to clients of a filesystem
since they will access directories via the POSIX
<CODE
CLASS="FUNCTION"
>opendir()</CODE
>, <CODE
CLASS="FUNCTION"
>readdir()</CODE
> and
<CODE
CLASS="FUNCTION"
>closedir()</CODE
> functions. The <CODE
CLASS="STRUCTNAME"
> struct
dirent</CODE
> object returned by <CODE
CLASS="FUNCTION"
>readdir()</CODE
>
will always contain <CODE
CLASS="STRUCTNAME"
>d_name</CODE
> as required by
POSIX. When <TT
CLASS="LITERAL"
>CYGPKG_FILEIO_DIRENT_DTYPE</TT
> is enabled
it will also contain <CODE
CLASS="STRUCTNAME"
>d_type</CODE
>, which is not
part of POSIX, but often implemented by OSes. Currently only the
FATFS, RAMFS, ROMFS and JFFS2 filesystem sets this value. For other
filesystems a value of 0 will be returned in the member.</P
><P
>Support for the <CODE
CLASS="FUNCTION"
>getcwd()</CODE
> function is provided by
three mechanisms.  The first is to use the
<TT
CLASS="LITERAL"
>FS_INFO_GETCWD</TT
> getinfo key on the filesystem to use
any internal support that it has for this. If that fails it falls back
on one of the two other mechanisms. If
<TT
CLASS="LITERAL"
>CYGPKG_IO_FILEIO_TRACK_CWD</TT
> is set then the current
directory is tracked textually in <CODE
CLASS="FUNCTION"
>chdir()</CODE
> and the result of that is
reported in getcwd(). Otherwise an attempt is made to traverse the
directory tree to its root using &quot;..&quot; entries.</P
><P
>This last option is complicated and expensive, and relies on the
filesystem supporting &quot;.&quot; and &quot;..&quot;  entries. This is not always the
case, particularly if the filesystem has been ported from a
non-UNIX-compatible source. Tracking the pathname textually will
usually work, but might not produce optimum results when symbolic
links are being used.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="fileio-file-table.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="fileio-synchronization.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>File Table</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="fileio.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Synchronization</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

⌨️ 快捷键说明

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