f_lseek

The f_lseek moves the file read/write pointer.

FRESULT f_lseek (
  FIL* FileObject,   // Pointer to the file object structure
  DWORD Offset       // File offset in unit of byte
);

Parameters

FileObject
Pointer to the file object structure.
Offset
Number of bytes where from start of file

Return Values

FR_OK
The function succeeded.
FR_ALIGN_ERROR
Out of alignment. In unbuffered mode, specified offset must be aligned on 512 byte boundary.
FR_RW_ERROR
Any error occured in low level disk I/O.
FR_INCORRECT_DISK_CHANGE
Incorrect disk removal, such as a medium change during any file opend, has been occured.
FR_NOT_ENABLED
FatFs module has not been enabled.

Description

The f_lseek moves the file read/write pointer. The offset can be specified in only origin from top of the file and cannot moved to above end of the file. When an offset above the file size was specified, the read/write pointer moves to end of the file.

Sample Code

    // Move to offset of 5000 from top of file.
    res = f_lseek(&file, 5000);
    if (res) die(res);

    // Move to 3000 bytes front of current offset.
    res = f_lseek(&file, file.fptr + 3000);
    if (res) die(res);

    // Move to 2000 bytes back of current offset.
    res = f_lseek(&file, file.fptr - 2000);
    if (res) die(res);

References

f_open, FIL

Return