Commit d4a24d51 authored by q3k's avatar q3k Committed by Rahix
Browse files

feat(fatfs): Add seek and tell implementation

parent 79ec7d37
......@@ -54,8 +54,8 @@ typedef unsigned int size_t;
#define API_FILE_READ 0x32
#define API_FILE_WRITE 0x34
#define API_FILE_FLUSH 0x35
#define API_FILE_SEEK 0x36 //NYI
#define API_FILE_TELL 0x37 //NYI
#define API_FILE_SEEK 0x36
#define API_FILE_TELL 0x37
#define API_FILE_STAT 0x38
/* clang-format on */
......@@ -483,6 +483,12 @@ API(
/** */
API(API_FILE_FLUSH, int epic_file_flush(int fd));
/** */
API(API_FILE_SEEK, int epic_file_seek(int fd, long offset, int whence));
/** */
API(API_FILE_TELL, int epic_file_tell(int fd));
/** */
enum epic_stat_type {
/** */
......
......@@ -326,6 +326,43 @@ int epic_file_flush(int fd)
return 0;
}
int epic_file_seek(int fd, long offset, int whence)
{
int res;
struct FatObject *o;
res = get_fat_object(fd, FO_File, &o);
if (res) {
return -res;
}
switch (whence) {
case SEEK_SET:
res = f_lseek(&o->file, offset);
return -fresult_to_errno_table[res];
case SEEK_CUR:
res = f_lseek(&o->file, f_tell(&o->file) + offset);
return -fresult_to_errno_table[res];
case SEEK_END:
res = f_lseek(&o->file, f_size(&o->file) + offset);
return -fresult_to_errno_table[res];
default:
return -EINVAL;
}
return 0;
}
int epic_file_tell(int fd)
{
int res;
struct FatObject *o;
res = get_fat_object(fd, FO_File, &o);
if (res) {
return -1;
}
return f_tell(&o->file);
}
int epic_file_stat(const char *filename, epic_stat_t *stat)
{
int res;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment