This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

using Embedded File System and "fseek"

hi,
have a short question:
does anybody know why the fseek command works in files (EFS) which are opened in write-mode in mostly all cases? but not at jump to the end of the file.
as described it should not be supported in all cases, only if a file is opened in read-mode
regards
heiko

Parents
  • Hello Heiko,

    According to two places in online documentation, using fseek() on a file opened in write mode in the embedded file system is not supported:
    www.keil.com/.../group__stdio__routines.html
    This is also mentioned in EFS' main page in the Limitations section.

    I guess this is one of the many advantages of the middleware's FAT file system, where you can do fseek() in write mode.

    As a workaround, you may try calling fseek() then fgetpos() while in read mode. Close the file. Then open file in write mode, and use fsetpos() to get back to the same file position you want to go. You could store multiple file positions with multiple calls to fseek() and fgetpos(). But the workaround, especially extra fclose() and fopen() increases execution time.

    Also, bear in mind, file fragmentation may become an issue after many small writes, in different places.

    Thanks,
    Zack

Reply
  • Hello Heiko,

    According to two places in online documentation, using fseek() on a file opened in write mode in the embedded file system is not supported:
    www.keil.com/.../group__stdio__routines.html
    This is also mentioned in EFS' main page in the Limitations section.

    I guess this is one of the many advantages of the middleware's FAT file system, where you can do fseek() in write mode.

    As a workaround, you may try calling fseek() then fgetpos() while in read mode. Close the file. Then open file in write mode, and use fsetpos() to get back to the same file position you want to go. You could store multiple file positions with multiple calls to fseek() and fgetpos(). But the workaround, especially extra fclose() and fopen() increases execution time.

    Also, bear in mind, file fragmentation may become an issue after many small writes, in different places.

    Thanks,
    Zack

Children