Unify the time file creation for SPIFFS and SD
This commit is contained in:
parent
acc9b871d1
commit
b4c1bdb11b
3 changed files with 28 additions and 1 deletions
|
@ -389,6 +389,9 @@ static int vfs_fat_fstat(void* ctx, int fd, struct stat * st)
|
||||||
FIL* file = &fat_ctx->files[fd];
|
FIL* file = &fat_ctx->files[fd];
|
||||||
st->st_size = f_size(file);
|
st->st_size = f_size(file);
|
||||||
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
|
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
|
||||||
|
st->st_mtime = 0;
|
||||||
|
st->st_atime = 0;
|
||||||
|
st->st_ctime = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,6 +425,8 @@ static int vfs_fat_stat(void* ctx, const char * path, struct stat * st)
|
||||||
ftime >>= 6;
|
ftime >>= 6;
|
||||||
tm.tm_hour = (ftime & 0x1f);
|
tm.tm_hour = (ftime & 0x1f);
|
||||||
st->st_mtime = mktime(&tm);
|
st->st_mtime = mktime(&tm);
|
||||||
|
st->st_atime = 0;
|
||||||
|
st->st_ctime = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -513,6 +513,16 @@ static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode)
|
||||||
SPIFFS_clearerr(efs->fs);
|
SPIFFS_clearerr(efs->fs);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#if SPIFFS_OBJ_META_LEN > 0
|
||||||
|
if (!(spiffs_mode_conv(flags) & SPIFFS_O_RDONLY))
|
||||||
|
{
|
||||||
|
time_t t = time(NULL);
|
||||||
|
struct tm tmr;
|
||||||
|
localtime_r(&t, &tmr);
|
||||||
|
time_t meta = mktime(&tmr);
|
||||||
|
SPIFFS_fupdate_meta(efs->fs, fd, &meta);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,6 +588,9 @@ static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st)
|
||||||
}
|
}
|
||||||
st->st_size = s.size;
|
st->st_size = s.size;
|
||||||
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
|
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
|
||||||
|
st->st_mtime = 0;
|
||||||
|
st->st_atime = 0;
|
||||||
|
st->st_ctime = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,6 +610,15 @@ static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st)
|
||||||
st->st_size = s.size;
|
st->st_size = s.size;
|
||||||
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||||
st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG;
|
st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG;
|
||||||
|
#if SPIFFS_OBJ_META_LEN > 0
|
||||||
|
time_t t =0;
|
||||||
|
memcpy(&t, s.meta, sizeof(time_t));
|
||||||
|
st->st_mtime = t;
|
||||||
|
#else
|
||||||
|
st->st_mtime = 0;
|
||||||
|
#endif
|
||||||
|
st->st_atime = 0;
|
||||||
|
st->st_ctime = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ extern void spiffs_api_unlock(struct spiffs_t *fs);
|
||||||
// This is derived from following:
|
// This is derived from following:
|
||||||
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
|
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
|
||||||
// spiffs_object_ix_header fields + at least some LUT entries)
|
// spiffs_object_ix_header fields + at least some LUT entries)
|
||||||
#define SPIFFS_OBJ_META_LEN (0)
|
#define SPIFFS_OBJ_META_LEN (4)
|
||||||
|
|
||||||
// Size of buffer allocated on stack used when copying data.
|
// Size of buffer allocated on stack used when copying data.
|
||||||
// Lower value generates more read/writes. No meaning having it bigger
|
// Lower value generates more read/writes. No meaning having it bigger
|
||||||
|
|
Loading…
Reference in a new issue