Add FatFs module by ChaN.
[bertos.git] / bertos / fs / fatfs / doc / en / lseek.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
2 <html lang="en">\r
3 <head>\r
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\r
5 <meta http-equiv="Content-Style-Type" content="text/css">\r
6 <link rel="up" title="FatFs" href="../00index_e.html">\r
7 <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">\r
8 <title>FatFs - f_lseek</title>\r
9 </head>\r
10 \r
11 <body>\r
12 \r
13 <div class="para">\r
14 <h2>f_lseek</h2>\r
15 <p>The f_lseek function moves the file read/write pointer of an open file object. It can also be used to extend the file size (cluster pre-allocation).</p>\r
16 \r
17 <pre>\r
18 FRESULT f_lseek (\r
19   FIL* <em>FileObject</em>,   /* Pointer to the file object structure */\r
20   DWORD <em>Offset</em>       /* File offset in unit of byte */\r
21 );\r
22 </pre>\r
23 </div>\r
24 \r
25 <div class="para">\r
26 <h4>Parameters</h4>\r
27 <dl class="par">\r
28 <dt>FileObject</dt>\r
29 <dd>Pointer to the open file object.</dd>\r
30 <dt>Offset</dt>\r
31 <dd>Number of bytes where from start of file</dd>\r
32 </dl>\r
33 </div>\r
34 \r
35 \r
36 <div class="para">\r
37 <h4>Return Values</h4>\r
38 <dl class="ret">\r
39 <dt>FR_OK (0)</dt>\r
40 <dd>The function succeeded.</dd>\r
41 <dt>FR_DISK_ERR</dt>\r
42 <dd>The function failed due to an error in the disk function.</dd>\r
43 <dt>FR_INT_ERR</dt>\r
44 <dd>The function failed due to a wrong FAT structure or an internal error.</dd>\r
45 <dt>FR_NOT_READY</dt>\r
46 <dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>\r
47 <dt>FR_INVALID_OBJECT</dt>\r
48 <dd>The file object is invalid.</dd>\r
49 </dl>\r
50 </div>\r
51 \r
52 \r
53 <div class="para">\r
54 <h4>Description</h4>\r
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 extended to the offset and the data in the extended 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 less than expected value, any of the followings has been occured.</p>\r
56 <ul>\r
57 <li>In read-only mode, the Offset was clipped in file size.</li>\r
58 <li>The drive gets full during the file extending process.</li>\r
59 </ul>\r
60 <p>This function is not supported in minimization level of &gt;= 3.</p></div>\r
61 \r
62 \r
63 <div class="para">\r
64 <h4>Example</h4>\r
65 <pre>\r
66     // Move to offset of 5000 from top of the file.\r
67     res = f_lseek(&amp;file, 5000);\r
68 \r
69     // Forward 3000 bytes\r
70     res = f_lseek(&amp;file, file.fptr + 3000);\r
71 \r
72     // Rewind 2000 bytes (take care on overflow)\r
73     res = f_lseek(&amp;file, file.fptr - 2000);\r
74 \r
75     // Move to end of the file to append data\r
76     res = f_lseek(&amp;file, file.fsize);\r
77 </pre>\r
78 <pre>\r
79     // Cluster pre-allocation (to prevent data overrun on streaming write)\r
80 \r
81     res = f_open(&amp;file, recfile, FA_CREATE_NEW | FA_WRITE); // Create a file\r
82 \r
83     res = f_lseek(&amp;file, PRE_SIZE);    // Pre-allocate clusters\r
84     if (res || file.fptr != PRE_SIZE) .... // Check if the file is extended corrctly\r
85 \r
86     res = f_lseek(&amp;file, DATA_START);  // Record data stream without cluster allocation delay\r
87     ...\r
88 \r
89     res = f_truncate(&amp;file);           // Truncate unused area\r
90     res = f_lseek(&amp;file, 0);           // Put file header\r
91     ...\r
92 \r
93     res = f_close(&amp;file);\r
94 </pre>\r
95 </div>\r
96 \r
97 \r
98 <div class="para">\r
99 <h4>References</h4>\r
100 <p><tt><a href="open.html">f_open</a>, <a href="truncate.html">f_truncate</a>, <a href="sfile.html">FIL</a></tt></p>\r
101 </div>\r
102 \r
103 <p class="foot"><a href="../00index_e.html">Return</a></p>\r
104 </body>\r
105 </html>\r