fatfs v0.09b Jan 23,2013:
- Added f_getlabel() and f_setlabel(). (_USE_LABEL == 1)
This commit is contained in:
1 parent
030f12c942
commit
750225eb33
112 files changed
+1847
-1043
No files matched your search
+27
-28
@@ -17,8 +17,8 @@
|
||||
|
||||
<pre>
|
||||
FRESULT f_lseek (
|
||||
FIL* <em>FileObject</em>, <span class="c">/* Pointer to the file object structure */</span>
|
||||
DWORD <em>Offset</em> <span class="c">/* File offset in unit of byte */</span>
|
||||
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
|
||||
DWORD <span class="arg">ofs</span> <span class="c">/* [IN] File read/write pointer */</span>
|
||||
);
|
||||
</pre>
|
||||
</div>
|
||||
@@ -26,10 +26,10 @@ FRESULT f_lseek (
|
||||
<div class="para arg">
|
||||
<h4>Parameters</h4>
|
||||
<dl class="par">
|
||||
<dt>FileObject</dt>
|
||||
<dt>fp</dt>
|
||||
<dd>Pointer to the open file object.</dd>
|
||||
<dt>Offset</dt>
|
||||
<dd>Number of bytes where from start of the file</dd>
|
||||
<dt>ofs</dt>
|
||||
<dd>Byte offset from top of the file.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
@@ -49,13 +49,13 @@ FRESULT f_lseek (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The f_lseek function moves the file read/write 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 to the offset 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, current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the current read/write pointer is not the expected value, either of followings has been occured.</p>
|
||||
<p>The <tt>f_lseek()</tt> function moves the file read/write 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 to the offset and the data in the expanded area is undefined. This is suitable to create a large file quickly, for fast write operation. 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 was moved correctry. In case of the current read/write pointer is not the expected value, either of followings has been occured.</p>
|
||||
<ul>
|
||||
<li>End of file. The specified Offset was clipped at end of the file because the file has been opened in read-only mode.</li>
|
||||
<li>Disk full. There is insufficient free space on the volume to expand the file size.</li>
|
||||
<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file is in read-only mode.</li>
|
||||
<li>Disk full. There is insufficient free space on the volume to expand the file.</li>
|
||||
</ul>
|
||||
<p>Fast seek feature is enabled when <tt>_USE_FASTSEEK</tt> is set to 1 and the member <tt>cltbl</tt> in the file object is not NULL. This feature enables fast backward/long seek operations without FAT access by cluster link map table (CLMT) stored in the user defined table. It is also applied to f_read/f_write functions. In this mode, the file size cannot be increased by f_write/f_lseek functions.</p>
|
||||
<p>The CLMT must be created in the user defined DWORD array prior to use fast seek feature. To create the CLMT, set pointer to the DWORD array to the member <tt>cltbl</tt> in the file object, set the array size in unit of items into the first item and call the f_lseek function with <tt>Offset = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent f_read/f_write/f_lseek functions to the file. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file and the required items is returned into the first item of the array. The required array size is (number of fragments + 1) * 2 items. For example, when the file is fragmented in 5, 12 items will be required for the CLMT. </p>
|
||||
<p>Fast seek feature is enabled when <tt>_USE_FASTSEEK</tt> is set to 1 and the member <tt>cltbl</tt> in the file object is not NULL. This feature enables fast backward/long seek operations without FAT access by using cluster link map table (CLMT). It is also applied to <tt>f_read()/f_write()</tt> functions. In this mode, the file cannot be expanded by <tt>f_write()/f_lseek()</tt> functions.</p>
|
||||
<p>The CLMT must be created in the user defined <tt>DWORD</tt> array prior to use fast seek feature. To create the CLMT, set pointer to the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the file object, set the array size in unit of items into 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()/f_write()/f_lseek()</tt> functions to the file. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file and number of items required is returned into the first item of the array. The required array size is (number of fragments + 1) * 2 items. For example, when the file is fragmented in 5, 12 items will be required for the CLMT.</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -69,53 +69,52 @@ FRESULT f_lseek (
|
||||
<h4>Example</h4>
|
||||
<pre>
|
||||
<span class="c">/* Open file */</span>
|
||||
file = malloc(sizeof (FIL));
|
||||
if (!file) ...
|
||||
res = f_open(file, "file.dat", FA_READ|FA_WRITE);
|
||||
fp = malloc(sizeof (FIL));
|
||||
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>
|
||||
res = f_lseek(file, 5000);
|
||||
res = f_lseek(fp, 5000);
|
||||
|
||||
<span class="c">/* Move to end of the file to append data */</span>
|
||||
res = f_lseek(file, f_size(file));
|
||||
res = f_lseek(fp, f_size(fp));
|
||||
|
||||
<span class="c">/* Forward 3000 bytes */</span>
|
||||
res = f_lseek(file, f_tell(file) + 3000);
|
||||
res = f_lseek(fp, f_tell(fp) + 3000);
|
||||
|
||||
<span class="c">/* Rewind 2000 bytes (take care on overflow) */</span>
|
||||
res = f_lseek(file, f_tell(file) - 2000);
|
||||
res = f_lseek(fp, f_tell(fp) - 2000);
|
||||
</pre>
|
||||
<pre>
|
||||
<span class="c">/* Cluster pre-allocation (to prevent buffer overrun on streaming write) */</span>
|
||||
|
||||
res = f_open(file, recfile, FA_CREATE_NEW | FA_WRITE); <span class="c">/* Create a file */</span>
|
||||
res = f_open(fp, recfile, FA_CREATE_NEW | FA_WRITE); <span class="c">/* Create a file */</span>
|
||||
|
||||
res = f_lseek(file, PRE_SIZE); <span class="c">/* Expand file size (cluster pre-allocation) */</span>
|
||||
if (res || f_tell(file) != PRE_SIZE) ... <span class="c">/* Check if the file has been expanded */</span>
|
||||
res = f_lseek(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 */</span>
|
||||
|
||||
res = f_lseek(file, DATA_START); <span class="c">/* Record data stream WITHOUT cluster allocation delay */</span>
|
||||
res = f_lseek(fp, DATA_START); <span class="c">/* Record data stream WITHOUT cluster allocation delay */</span>
|
||||
... <span class="c">/* DATA_START and write block size should be aligned to sector boundary */</span>
|
||||
|
||||
res = f_truncate(file); <span class="c">/* Truncate unused area */</span>
|
||||
res = f_lseek(file, 0); <span class="c">/* Put file header */</span>
|
||||
res = f_truncate(fp); <span class="c">/* Truncate unused area */</span>
|
||||
res = f_lseek(fp, 0); <span class="c">/* Put file header */</span>
|
||||
...
|
||||
|
||||
res = f_close(file);
|
||||
res = f_close(fp);
|
||||
</pre>
|
||||
<pre>
|
||||
<span class="c">/* Using fast seek feature */</span>
|
||||
|
||||
DWORD lktbl[SZ_TBL]; <span class="c">/* Link map table buffer */</span>
|
||||
|
||||
res = f_lseek(file, ofs1); <span class="c">/* This is normal seek (file.cltbl is nulled on file open) */</span>
|
||||
res = f_lseek(fp, ofs1); <span class="c">/* This is normal seek (cltbl member is nulled on file open) */</span>
|
||||
|
||||
file.cltbl = lktbl; <span class="c">/* Enable fast seek feature */</span>
|
||||
fp->cltbl = lktbl; <span class="c">/* Enable fast seek feature (cltbl != NULL) */</span>
|
||||
lktbl[0] = SZ_TBL; <span class="c">/* Set table size */</span>
|
||||
res = f_lseek(file, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
|
||||
res = f_lseek(fp, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
|
||||
...
|
||||
|
||||
res = f_lseek(file, ofs2); <span class="c">/* This is fast seek (file.cltbl != NULL) */</span>
|
||||
res = f_lseek(fp, ofs2); <span class="c">/* This is fast seek */</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user