OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [FileSystem/] [FatFs-0.7e/] [doc/] [en/] [open.html] - Blame information for rev 606

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 606 jeremybenn
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
<html lang="en">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5
<meta http-equiv="Content-Style-Type" content="text/css">
6
<link rel="up" title="FatFs" href="../00index_e.html">
7
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
8
<title>FatFs - f_open</title>
9
</head>
10
 
11
<body>
12
 
13
<div class="para">
14
<h2>f_open</h2>
15
<p>The f_open function creates a <em>file object</em> to be used to access the file.</p>
16
<pre>
17
FRESULT f_open (
18
  FIL* <em>FileObject</em>,       /* Pointer to the blank file object structure */
19
  const XCHAR* <em>FileName</em>, /* Pointer to the file neme */
20
  BYTE <em>ModeFlags</em>         /* Mode flags */
21
);
22
</pre>
23
</div>
24
 
25
<div class="para">
26
<h4>Parameters</h4>
27
<dl class="par">
28
<dt>FileObject</dt>
29
<dd>Pointer to the file object structure to be created.</dd>
30
<dt>FileName</dt>
31
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to create or open.</dd>
32
<dt>ModeFlags</dt>
33
<dd>Specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
34
<table class="lst">
35
<tr><th>Value</th><th>Description</th></tr>
36
<tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.<br>Combine with FA_WRITE for read-write access.</td></tr>
37
<tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file.<br>Combine with FA_READ for read-write access.</td></tr>
38
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file is not existing. (Default)</td></tr>
39
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file, if it is existing. If not, a new file is created.</td></tr>
40
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails if the file is already existing.</td></tr>
41
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it is truncated and overwritten.</td></tr>
42
</table>
43
</dd>
44
</dl>
45
</div>
46
 
47
 
48
<div class="para">
49
<h4>Return Values</h4>
50
<dl class="ret">
51
<dt>FR_OK (0)</dt>
52
<dd>The function succeeded and the file object is valid.</dd>
53
<dt>FR_NO_FILE</dt>
54
<dd>Could not find the file.</dd>
55
<dt>FR_NO_PATH</dt>
56
<dd>Could not find the path.</dd>
57
<dt>FR_INVALID_NAME</dt>
58
<dd>The file name is invalid.</dd>
59
<dt>FR_INVALID_DRIVE</dt>
60
<dd>The drive number is invalid.</dd>
61
<dt>FR_EXIST</dt>
62
<dd>The file is already existing.</dd>
63
<dt>FR_DENIED</dt>
64
<dd>The required access was denied due to one of the following reasons:
65
<ul><li>Write mode open of a read-only file.</li>
66
<li>File cannot be created due to a read-only file or same name directory is existing.</li>
67
<li>File cannot be created due to the directory table or disk is full.</li></ul></dd>
68
<dt>FR_NOT_READY</dt>
69
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
70
<dt>FR_WRITE_PROTECTED</dt>
71
<dd>Write mode open or creation under the medium is write protected.</dd>
72
<dt>FR_DISK_ERR</dt>
73
<dd>The function failed due to an error in the disk function.</dd>
74
<dt>FR_INT_ERR</dt>
75
<dd>The function failed due to a wrong FAT structure or an internal error.</dd>
76
<dt>FR_NOT_ENABLED</dt>
77
<dd>The logical drive has no work area.</dd>
78
<dt>FR_NO_FILESYSTEM</dt>
79
<dd>There is no valid FAT volume on the disk.</dd>
80
</dl>
81
</div>
82
 
83
 
84
<div class="para">
85
<h4>Description</h4>
86
<p>A file object is created when the function succeeded. The file object is used for subsequent read/write functions to refer to the file. When close an open file object, use <a href="close.html">f_close</a> function. If the modified file is not closed, the file may be collapsed.</p>
87
<p>Before using any file function, a work area (file system object) must be given to the logical drive with <a href="mount.html">f_mount</a> function. All file functions can work after this procedure.</p>
88
</div>
89
 
90
 
91
<div class="para">
92
<h4>QuickInfo</h4>
93
<p>Always available. The mode flags, <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_CREATE_NEW, FA_OPEN_ALWAYS</tt>, are not available when <tt>_FS_READONLY == 1</tt>.</p>
94
</div>
95
 
96
 
97
<div class="para">
98
<h4>Example (File Copy)</h4>
99
<pre>
100
void main (void)
101
{
102
    FATFS fs[2];         /* Work area (file system object) for logical drives */
103
    FIL fsrc, fdst;      /* file objects */
104
    BYTE buffer[4096];   /* file copy buffer */
105
    FRESULT res;         /* FatFs function common result code */
106
    UINT br, bw;         /* File R/W count */
107
 
108
 
109
    /* Register work area for logical drives */
110
    f_mount(0, &amp;fs[0]);
111
    f_mount(1, &amp;fs[1]);
112
 
113
    /* Open source file on the drive 1 */
114
    res = f_open(&amp;fsrc, "1:srcfile.dat", FA_OPEN_EXISTING | FA_READ);
115
    if (res) die(res);
116
 
117
    /* Create destination file on the drive 0 */
118
    res = f_open(&amp;fdst, "0:dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
119
    if (res) die(res);
120
 
121
    /* Copy source to destination */
122
    for (;;) {
123
        res = f_read(&amp;fsrc, buffer, sizeof(buffer), &amp;br);
124
        if (res || br == 0) break;   /* error or eof */
125
        res = f_write(&amp;fdst, buffer, br, &amp;bw);
126
        if (res || bw &lt; br) break;   /* error or disk full */
127
    }
128
 
129
    /* Close open files */
130
    f_close(&amp;fsrc);
131
    f_close(&amp;fdst);
132
 
133
    /* Unregister work area prior to discard it */
134
    f_mount(0, NULL);
135
    f_mount(1, NULL);
136
}
137
</pre>
138
</div>
139
 
140
 
141
<div class="para">
142
<h4>See Also</h4>
143
<p><tt><a href="read.html">f_read</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a>, <a href="sfatfs.html">FATFS</a></tt></p>
144
</div>
145
 
146
<p class="foot"><a href="../00index_e.html">Return</a></p>
147
</body>
148
</html>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.