summaryrefslogtreecommitdiff
path: root/fatfs/documents/doc/lseek.html
diff options
context:
space:
mode:
Diffstat (limited to 'fatfs/documents/doc/lseek.html')
-rw-r--r--fatfs/documents/doc/lseek.html36
1 files changed, 22 insertions, 14 deletions
diff --git a/fatfs/documents/doc/lseek.html b/fatfs/documents/doc/lseek.html
index 7173b0e..ffd1f62 100644
--- a/fatfs/documents/doc/lseek.html
+++ b/fatfs/documents/doc/lseek.html
@@ -18,7 +18,12 @@
<pre>
FRESULT f_lseek (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
- FSIZE_t <span class="arg">ofs</span> <span class="c">/* [IN] File read/write pointer */</span>
+ FSIZE_t <span class="arg">ofs</span> <span class="c">/* [IN] Offset of file read/write pointer to be set */</span>
+);
+</pre>
+<pre>
+FRESULT f_rewind (
+ FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
@@ -48,14 +53,17 @@ FRESULT f_lseek (
<div class="para desc">
<h4>Description</h4>
-<p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file.</p>
-<p>When an offset beyond the file size is specified at write mode, the file size is expanded to the specified offset. The file data in the expanded area is <em>undefined</em> because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.</p>
+<p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file. The <tt>f_rewind</tt> function is impremented as a macro.</p>
+<pre>
+#define <em>f_rewind</em>(fp) f_lseek((fp), 0)
+</pre>
+<p>If an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset. The file data in the expanded part is <em>undefined</em>, because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not pointing expected offset, either of followings has been occured.</p>
<ul>
-<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file has been opened in read-only mode.</li>
+<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file in read-only mode.</li>
<li>Disk full. There is no free space on the volume to expand the file.</li>
</ul>
-<p>The fast seek function enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p>
-<p>The fast seek mode is enabled when the member <tt>cltbl</tt> in the file object is not NULL. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek function. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the first item and call the <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, when the file is fragmented in 5, 12 items in the array will be used. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file.</p>
+<p>The fast seek feature enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p>
+<p>The fast seek mode is available when <tt>FF_USE_FASTSEEK = 1</tt>. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek mode. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the <tt>cltbl[0]</tt> and then call <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the <tt>cltbl[0]</tt>. The number of items needed is (number of the file fragments + 1) * 2. For example, 12 items in the array will be used for the file fragmented in 5 portions. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the size of given array is insufficient for the file.</p>
</div>
@@ -73,16 +81,16 @@ FRESULT f_lseek (
res = f_open(fp, "file.dat", FA_READ|FA_WRITE);
if (res) ...
- <span class="c">/* Move to offset of 5000 from top of the file */</span>
+ <span class="c">/* Set read/write pointer to 5000 */</span>
res = <em>f_lseek</em>(fp, 5000);
- <span class="c">/* Move to end of the file to append data */</span>
+ <span class="c">/* Set read/write pointer to end of the file to append data */</span>
res = <em>f_lseek</em>(fp, f_size(fp));
- <span class="c">/* Forward 3000 bytes */</span>
+ <span class="c">/* Advance read/write pointer 3000 bytes */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) + 3000);
- <span class="c">/* Rewind 2000 bytes (take care on wraparound) */</span>
+ <span class="c">/* Rewind read/write pointer 2000 bytes (take care on wraparound) */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) - 2000);
</pre>
<pre>
@@ -93,17 +101,17 @@ FRESULT f_lseek (
res = <em>f_lseek</em>(fp, PRE_SIZE); <span class="c">/* Expand file size (cluster pre-allocation) */</span>
if (res || f_tell(fp) != PRE_SIZE) ... <span class="c">/* Check if the file has been expanded successfly */</span>
- res = <em>f_lseek</em>(fp, DATA_START); <span class="c">/* Record data stream WITHOUT cluster allocation delay */</span>
+ res = <em>f_lseek</em>(fp, OFS_DATA); <span class="c">/* Record data stream with free from cluster allocation delay */</span>
... <span class="c">/* Write operation should be aligned to sector boundary to optimize the write throughput */</span>
res = f_truncate(fp); <span class="c">/* Truncate unused area */</span>
- res = <em>f_lseek</em>(fp, 0); <span class="c">/* Set file header */</span>
+ res = <em>f_lseek</em>(fp, OFS_HEADER); <span class="c">/* Set file header */</span>
...
res = f_close(fp);
</pre>
<pre>
-<span class="c">/* Using fast seek function */</span>
+<span class="c">/* Using fast seek mode */</span>
DWORD clmt[SZ_TBL]; <span class="c">/* Cluster link map table buffer */</span>
@@ -111,7 +119,7 @@ FRESULT f_lseek (
res = <em>f_lseek</em>(fp, ofs1); <span class="c">/* This is normal seek (cltbl is nulled on file open) */</span>
- fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek function (cltbl != NULL) */</span>
+ fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek mode (cltbl != NULL) */</span>
clmt[0] = SZ_TBL; <span class="c">/* Set table size */</span>
res = <em>f_lseek</em>(fp, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
...