Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ extern "C" {
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include "blockdevice/blockdevice.h"

#define PATH_MAX 256

enum {
FILESYSTEM_TYPE_FAT,
FILESYSTEM_TYPE_LITTLEFS,
Expand Down
10 changes: 10 additions & 0 deletions src/filesystem/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,22 @@ static int file_stat(filesystem_t *fs, const char *path, struct stat *st) {
if (res != FR_OK) {
return fat_error_remap(res);
}

struct tm mtime = {0};
mtime.tm_year = (f.fdate >> 9) + 80;
mtime.tm_mon = (f.fdate >> 5) & 0b1111;
mtime.tm_mday = f.fdate & 0b11111;
mtime.tm_hour = f.ftime >> 11;
mtime.tm_min = (f.ftime >> 5) & 0b111111;
mtime.tm_sec = (f.ftime & 0b11111) << 1;

st->st_size = f.fsize;
st->st_mode = 0;
st->st_mode |= (f.fattrib & AM_DIR) ? S_IFDIR : S_IFREG;
st->st_mode |= (f.fattrib & AM_RDO) ?
(S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) :
(S_IRWXU | S_IRWXG | S_IRWXO);
st->st_mtime = mktime(&mtime);
return 0;
}

Expand Down
23 changes: 0 additions & 23 deletions src/filesystem/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,29 +562,6 @@ off_t _lseek(int fildes, off_t offset, int whence) {
return _error_remap(pos);
}

off_t _ftello_r(struct _reent *ptr, register FILE *fp) {
(void)ptr;
int fildes = fp->_file;
auto_init_recursive_mutex(_mutex);
recursive_mutex_enter_blocking(&_mutex);

if (!is_valid_file_descriptor(fildes)) {
recursive_mutex_exit(&_mutex);
return _error_remap(-EBADF);
}
fs_file_t *file = file_descriptor[FILENO_INDEX(fildes)].file;
filesystem_t *fs = file_descriptor[FILENO_INDEX(fildes)].filesystem;
if (fs == NULL) {
recursive_mutex_exit(&_mutex);
return _error_remap(-EBADF);
}

off_t pos = fs->file_tell(fs, file);
recursive_mutex_exit(&_mutex);

return _error_remap(pos);
}

int ftruncate(int fildes, off_t length) {
auto_init_recursive_mutex(_mutex);
recursive_mutex_enter_blocking(&_mutex);
Expand Down