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/] [lseek.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_lseek</title>
9
</head>
10
 
11
<body>
12
 
13
<div class="para">
14
<h2>f_lseek</h2>
15
<p>The f_lseek function moves the file read/write pointer of an open file object. It can also be used to increase the file size (cluster pre-allocation).</p>
16
 
17
<pre>
18
FRESULT f_lseek (
19
  FIL* <em>FileObject</em>,   /* Pointer to the file object structure */
20
  DWORD <em>Offset</em>       /* File offset in unit of byte */
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 open file object.</dd>
30
<dt>Offset</dt>
31
<dd>Number of bytes where from start of the file</dd>
32
</dl>
33
</div>
34
 
35
 
36
<div class="para">
37
<h4>Return Values</h4>
38
<dl class="ret">
39
<dt>FR_OK (0)</dt>
40
<dd>The function succeeded.</dd>
41
<dt>FR_DISK_ERR</dt>
42
<dd>The function failed due to an error in the disk function.</dd>
43
<dt>FR_INT_ERR</dt>
44
<dd>The function failed due to a wrong FAT structure or an internal error.</dd>
45
<dt>FR_NOT_READY</dt>
46
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
47
<dt>FR_INVALID_OBJECT</dt>
48
<dd>The file object is invalid.</dd>
49
</dl>
50
</div>
51
 
52
 
53
<div class="para">
54
<h4>Description</h4>
55
<p>The f_lseek function moves the file R/W pointer of an open file. The offset can be specified in only origin from top of the file. When an offset above the file size is specified in write mode, the file size is increased and the data in the expanded area is undefined. This is suitable to create a large file quickly, for fast write operation. After the f_lseek function succeeded, member fptr in the file object should be checked in order to make sure the R/W pointer has been moved correctry. In case of fptr is not the expected value, either of followings has been occured.</p>
56
<ul>
57
<li>End of file. The specified Offset was clipped at the file size because the file has been opened in read-only mode.</li>
58
<li>Disk full. There is insufficient free space on the volume to expand the file size.</li>
59
</ul>
60
</div>
61
 
62
 
63
<div class="para">
64
<h4>QuickInfo</h4>
65
<p>Available when <tt>_FS_MINIMIZE &lt;= 2</tt>.</p>
66
</div>
67
 
68
 
69
<div class="para">
70
<h4>Example</h4>
71
<pre>
72
    /* Move to offset of 5000 from top of the file */
73
    res = f_lseek(file, 5000);
74
 
75
    /* Move to end of the file to append data */
76
    res = f_lseek(file, file-&gt;fsize);
77
 
78
    /* Forward 3000 bytes */
79
    res = f_lseek(file, file-&gt;fptr + 3000);
80
 
81
    /* Rewind 2000 bytes (take care on overflow) */
82
    res = f_lseek(file, file-&gt;fptr - 2000);
83
</pre>
84
<pre>
85
    /* Cluster pre-allocation (to prevent buffer overrun on streaming write) */
86
 
87
    res = f_open(file, recfile, FA_CREATE_NEW | FA_WRITE); /* Create a file */
88
 
89
    res = f_lseek(file, PRE_SIZE);         /* Pre-allocate clusters */
90
    if (res || file-&gt;fptr != PRE_SIZE) ... /* Check if the file size has been increased correctly */
91
 
92
    res = f_lseek(file, DATA_START);       /* Record data stream without cluster allocation delay */
93
    ...
94
 
95
    res = f_truncate(file);                /* Truncate unused area */
96
    res = f_lseek(file, 0);                /* Put file header */
97
    ...
98
 
99
    res = f_close(file);
100
</pre>
101
</div>
102
 
103
 
104
<div class="para">
105
<h4>See Also</h4>
106
<p><tt><a href="open.html">f_open</a>, <a href="truncate.html">f_truncate</a>, <a href="sfile.html">FIL</a></tt></p>
107
</div>
108
 
109
<p class="foot"><a href="../00index_e.html">Return</a></p>
110
</body>
111
</html>

powered by: WebSVN 2.1.0

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