From 5bdc5cfb2a157cf2a84a22ffc654b1a72cab1f9c Mon Sep 17 00:00:00 2001 From: TimmSkiller Date: Wed, 26 Jan 2022 15:14:01 +0300 Subject: [PATCH 1/3] changes to add created/modified/last accessed date --- arm9/source/fatfs/ff.c | 28 +++++++++++++++++++++------- arm9/source/fatfs/ff.h | 7 +++++-- arm9/source/filesys/vff.c | 6 +++--- arm9/source/godmode.c | 27 +++++++++++++++++++-------- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/arm9/source/fatfs/ff.c b/arm9/source/fatfs/ff.c index d313658b1..effdd75cd 100644 --- a/arm9/source/fatfs/ff.c +++ b/arm9/source/fatfs/ff.c @@ -149,9 +149,11 @@ #define DIR_NTres 12 /* Lower case flag (BYTE) */ #define DIR_CrtTime10 13 /* Created time sub-second (BYTE) */ #define DIR_CrtTime 14 /* Created time (DWORD) */ +#define DIR_CrtDate 16 /* Created date (WORD) */ #define DIR_LstAccDate 18 /* Last accessed date (WORD) */ #define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (WORD) */ #define DIR_ModTime 22 /* Modified time (DWORD) */ +#define DIR_ModDate 24 /* Modified date (WORD) */ #define DIR_FstClusLO 26 /* Lower 16-bit of first cluster (WORD) */ #define DIR_FileSize 28 /* File size (DWORD) */ #define LDIR_Ord 0 /* LFN: LFN order and LLE flag (BYTE) */ @@ -2765,8 +2767,11 @@ static void get_fileinfo ( fno->fattrib = dp->dir[DIR_Attr]; /* Attribute */ fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */ - fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */ - fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */ + fno->mod_ftime = ld_word(dp->dir + DIR_ModTime); /* Modified Time */ + fno->mod_fdate = ld_word(dp->dir + DIR_ModDate); /* Modified Date */ + fno->crt_ftime = ld_word(dp->dir + DIR_CrtTime); /* Created Time */ + fno->crt_fdate = ld_word(dp->dir + DIR_CrtDate); /* Created Date */ + fno->lac_fdate = ld_word(dp->dir + DIR_LstAccDate); /* Last Access Date */ } #endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */ @@ -3766,9 +3771,12 @@ FRESULT f_open ( } else #endif { + DWORD tm = GET_FATTIME(); /* Set directory entry initial state */ cl = ld_clust(fs, dj.dir); /* Get current cluster chain */ - st_dword(dj.dir + DIR_CrtTime, GET_FATTIME()); /* Set created time */ + st_dword(dj.dir + DIR_CrtTime, tm); /* Set created time */ + st_dword(dj.dir + DIR_ModTime, tm); /* Set modified time */ + st_word(dj.dir + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* Set last access date */ dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */ st_clust(fs, dj.dir, 0); /* Reset file allocation info */ st_dword(dj.dir + DIR_FileSize, 0); @@ -4165,7 +4173,7 @@ FRESULT f_sync ( st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ st_dword(dir + DIR_ModTime, tm); /* Update modified time */ - st_word(dir + DIR_LstAccDate, 0); + st_word(dir + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* Update last access date */ fs->wflag = 1; res = sync_fs(fs); /* Restore it to the directory */ fp->flag &= (BYTE)~FA_MODIFIED; @@ -5053,7 +5061,9 @@ FRESULT f_mkdir ( mem_set(fs->win + DIR_Name, ' ', 11); /* Create "." entry */ fs->win[DIR_Name] = '.'; fs->win[DIR_Attr] = AM_DIR; - st_dword(fs->win + DIR_ModTime, tm); + st_dword(fs->win + DIR_ModTime, tm); /* set modified time */ + st_dword(fs->win + DIR_CrtTime, tm); /* set created time */ + st_word(fs->win + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); st_clust(fs, fs->win, dcl); mem_cpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */ fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust; @@ -5076,7 +5086,9 @@ FRESULT f_mkdir ( } else #endif { - st_dword(dj.dir + DIR_ModTime, tm); /* Created time */ + st_dword(fs->win + DIR_ModTime, tm); /* set modified time */ + st_dword(fs->win + DIR_CrtTime, tm); /* set created time */ + st_word(fs->win + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* set last access date */ st_clust(fs, dj.dir, dcl); /* Table start cluster */ dj.dir[DIR_Attr] = AM_DIR; /* Attribute */ fs->wflag = 1; @@ -5283,7 +5295,9 @@ FRESULT f_utime ( } else #endif { - st_dword(dj.dir + DIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + st_dword(dj.dir + DIR_ModTime, (DWORD)fno->mod_fdate << 16 | fno->mod_ftime); + st_dword(dj.dir + DIR_CrtTime, (DWORD)fno->crt_fdate << 16 | fno->crt_ftime); + st_dword(dj.dir + DIR_LstAccDate, fno->lac_fdate); fs->wflag = 1; } if (res == FR_OK) { diff --git a/arm9/source/fatfs/ff.h b/arm9/source/fatfs/ff.h index 522504164..16bccd5af 100644 --- a/arm9/source/fatfs/ff.h +++ b/arm9/source/fatfs/ff.h @@ -246,8 +246,8 @@ typedef struct { typedef struct { FSIZE_t fsize; /* File size */ - WORD fdate; /* Modified date */ - WORD ftime; /* Modified time */ + WORD mod_fdate; /* Modified date */ + WORD mod_ftime; /* Modified time */ BYTE fattrib; /* File attribute */ #if FF_USE_LFN TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */ @@ -255,6 +255,9 @@ typedef struct { #else TCHAR fname[12 + 1]; /* File name */ #endif + WORD crt_fdate; /* Creation date */ + WORD crt_ftime; /* Creation time */ + WORD lac_fdate; /* Last access date */ } FILINFO; diff --git a/arm9/source/filesys/vff.c b/arm9/source/filesys/vff.c index aec41a30b..bf7019c7b 100644 --- a/arm9/source/filesys/vff.c +++ b/arm9/source/filesys/vff.c @@ -84,8 +84,8 @@ FRESULT fvx_stat (const TCHAR* path, FILINFO* fno) { if (!GetVirtualFile(&vfile, path, FA_READ)) return FR_NO_PATH; if (fno) { fno->fsize = vfile.size; - fno->fdate = (1<<5)|(1<<0); // 1 for month / day - fno->ftime = 0; + fno->mod_fdate = fno->crt_fdate = fno->lac_fdate = (1<<5)|(1<<0); // 1 for month / day + fno->mod_ftime = fno->crt_ftime = 0; fno->fattrib = (vfile.flags & VFLAG_DIR) ? (AM_DIR|AM_VRT) : AM_VRT; // could be better... if (FF_USE_LFN != 0) GetVirtualFilename(fno->fname, &vfile, FF_MAX_LFN + 1); @@ -137,7 +137,7 @@ FRESULT fvx_readdir (DIR* dp, FILINFO* fno) { VirtualFile vfile; if (ReadVirtualDir(&vfile, vdir)) { fno->fsize = vfile.size; - fno->fdate = fno->ftime = 0; + fno->mod_fdate = fno->crt_fdate = fno->lac_fdate = (1<<5)|(1<<0); // 1 for month / day fno->fattrib = (vfile.flags & VFLAG_DIR) ? (AM_DIR|AM_VRT) : AM_VRT; GetVirtualFilename(fno->fname, &vfile, FF_MAX_LFN + 1); } else *(fno->fname) = 0; diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index d0bc1e794..ed5922afc 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -1024,7 +1024,7 @@ u32 CartRawDump(void) { u32 DirFileAttrMenu(const char* path, const char *name) { bool drv = (path[2] == '\0'); bool vrt = (!drv); // will be checked below - char namestr[128], datestr[32], attrstr[128], sizestr[192]; + char namestr[128], mod_datestr[32], crt_datestr[32], lac_datestr[32], attrstr[128], sizestr[192]; FILINFO fno; u8 new_attrib; @@ -1036,12 +1036,21 @@ u32 DirFileAttrMenu(const char* path, const char *name) { if (fvx_stat(path, &fno) != FR_OK) return 1; vrt = (fno.fattrib & AM_VRT); new_attrib = fno.fattrib; - snprintf(datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", - (fno.fattrib & AM_DIR) ? "created" : "modified", - 1980 + ((fno.fdate >> 9) & 0x7F), (fno.fdate >> 5) & 0xF, fno.fdate & 0x1F, - (fno.ftime >> 11) & 0x1F, (fno.ftime >> 5) & 0x3F, (fno.ftime & 0x1F) << 1); + snprintf(mod_datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", + "modified", + 1980 + ((fno.mod_fdate >> 9) & 0x7F), (fno.mod_fdate >> 5) & 0xF, fno.mod_fdate & 0x1F, + (fno.mod_ftime >> 11) & 0x1F, (fno.mod_ftime >> 5) & 0x3F, (fno.mod_ftime & 0x1F) << 1); + snprintf(crt_datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", + "created ", + 1980 + ((fno.crt_fdate >> 9) & 0x7F), (fno.crt_fdate >> 5) & 0xF, fno.crt_fdate & 0x1F, + (fno.crt_ftime >> 11) & 0x1F, (fno.crt_ftime >> 5) & 0x3F, (fno.crt_ftime & 0x1F) << 1); + snprintf(lac_datestr, 32, "%s: %04d-%02d-%02d\n", + "accessed", + 1980 + ((fno.lac_fdate >> 9) & 0x7F), (fno.lac_fdate >> 5) & 0xF, fno.lac_fdate & 0x1F); } else { - *datestr = '\0'; + *mod_datestr = '\0'; + *crt_datestr = '\0'; + *lac_datestr = '\0'; *attrstr = '\0'; new_attrib = 0; } @@ -1095,11 +1104,13 @@ u32 DirFileAttrMenu(const char* path, const char *name) { ShowString( "%s\n \n" // name - "%s" // date (not for drives) + "%s" // modified date (not for drives) + "%s" // created date (not for drives) + "%s\n \n" // accessed date (not for drives) "%s\n" // size "%s \n" // attr (not for drives) "%s\n", // options - namestr, datestr, sizestr, attrstr, + namestr, mod_datestr, crt_datestr, lac_datestr, sizestr, attrstr, (drv || vrt || (new_attrib == fno.fattrib)) ? "( to continue)" : "( to apply, to cancel)" ); From 935dd460260c31c921b5818e673bd32abcda5609 Mon Sep 17 00:00:00 2001 From: TimmSkiller Date: Fri, 28 Jan 2022 12:13:14 +0300 Subject: [PATCH 2/3] small fix for correct virtual drive date/times --- arm9/source/filesys/vff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arm9/source/filesys/vff.c b/arm9/source/filesys/vff.c index bf7019c7b..de21b9a6b 100644 --- a/arm9/source/filesys/vff.c +++ b/arm9/source/filesys/vff.c @@ -137,7 +137,7 @@ FRESULT fvx_readdir (DIR* dp, FILINFO* fno) { VirtualFile vfile; if (ReadVirtualDir(&vfile, vdir)) { fno->fsize = vfile.size; - fno->mod_fdate = fno->crt_fdate = fno->lac_fdate = (1<<5)|(1<<0); // 1 for month / day + fno->mod_fdate = fno->crt_fdate = fno->lac_fdate = fno->mod_ftime = fno->crt_ftime = 0; fno->fattrib = (vfile.flags & VFLAG_DIR) ? (AM_DIR|AM_VRT) : AM_VRT; GetVirtualFilename(fno->fname, &vfile, FF_MAX_LFN + 1); } else *(fno->fname) = 0; From f52d3263678e92d77f05633342eee0a42128cd92 Mon Sep 17 00:00:00 2001 From: TimmSkiller Date: Fri, 28 Jan 2022 16:41:47 +0300 Subject: [PATCH 3/3] fixed tab/space formatting, added GET_FATDATE macro --- arm9/source/fatfs/ff.c | 9 +++++---- arm9/source/godmode.c | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arm9/source/fatfs/ff.c b/arm9/source/fatfs/ff.c index effdd75cd..45cd82bb8 100644 --- a/arm9/source/fatfs/ff.c +++ b/arm9/source/fatfs/ff.c @@ -274,6 +274,7 @@ #define GET_FATTIME() get_fattime() #endif +#define GET_FATDATE(tm) ((WORD)(((tm) >> 16) & 0xFFFF)) /* File lock controls */ #if FF_FS_LOCK != 0 @@ -3776,7 +3777,7 @@ FRESULT f_open ( cl = ld_clust(fs, dj.dir); /* Get current cluster chain */ st_dword(dj.dir + DIR_CrtTime, tm); /* Set created time */ st_dword(dj.dir + DIR_ModTime, tm); /* Set modified time */ - st_word(dj.dir + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* Set last access date */ + st_word(dj.dir + DIR_LstAccDate, GET_FATDATE(tm)); /* Set last access date */ dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */ st_clust(fs, dj.dir, 0); /* Reset file allocation info */ st_dword(dj.dir + DIR_FileSize, 0); @@ -4173,7 +4174,7 @@ FRESULT f_sync ( st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ st_dword(dir + DIR_ModTime, tm); /* Update modified time */ - st_word(dir + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* Update last access date */ + st_word(dir + DIR_LstAccDate, GET_FATDATE(tm)); /* Update last access date */ fs->wflag = 1; res = sync_fs(fs); /* Restore it to the directory */ fp->flag &= (BYTE)~FA_MODIFIED; @@ -5063,7 +5064,7 @@ FRESULT f_mkdir ( fs->win[DIR_Attr] = AM_DIR; st_dword(fs->win + DIR_ModTime, tm); /* set modified time */ st_dword(fs->win + DIR_CrtTime, tm); /* set created time */ - st_word(fs->win + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); + st_word(fs->win + DIR_LstAccDate, GET_FATDATE(tm)); /* set last access date */ st_clust(fs, fs->win, dcl); mem_cpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */ fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust; @@ -5088,7 +5089,7 @@ FRESULT f_mkdir ( { st_dword(fs->win + DIR_ModTime, tm); /* set modified time */ st_dword(fs->win + DIR_CrtTime, tm); /* set created time */ - st_word(fs->win + DIR_LstAccDate, (WORD)(((tm) >> 16) & 0xFFFF)); /* set last access date */ + st_word(fs->win + DIR_LstAccDate, GET_FATDATE(tm)); /* set last access date */ st_clust(fs, dj.dir, dcl); /* Table start cluster */ dj.dir[DIR_Attr] = AM_DIR; /* Attribute */ fs->wflag = 1; diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index ed5922afc..e18d9ba67 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -1040,17 +1040,17 @@ u32 DirFileAttrMenu(const char* path, const char *name) { "modified", 1980 + ((fno.mod_fdate >> 9) & 0x7F), (fno.mod_fdate >> 5) & 0xF, fno.mod_fdate & 0x1F, (fno.mod_ftime >> 11) & 0x1F, (fno.mod_ftime >> 5) & 0x3F, (fno.mod_ftime & 0x1F) << 1); - snprintf(crt_datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", + snprintf(crt_datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", "created ", 1980 + ((fno.crt_fdate >> 9) & 0x7F), (fno.crt_fdate >> 5) & 0xF, fno.crt_fdate & 0x1F, (fno.crt_ftime >> 11) & 0x1F, (fno.crt_ftime >> 5) & 0x3F, (fno.crt_ftime & 0x1F) << 1); - snprintf(lac_datestr, 32, "%s: %04d-%02d-%02d\n", + snprintf(lac_datestr, 32, "%s: %04d-%02d-%02d\n", "accessed", 1980 + ((fno.lac_fdate >> 9) & 0x7F), (fno.lac_fdate >> 5) & 0xF, fno.lac_fdate & 0x1F); } else { *mod_datestr = '\0'; - *crt_datestr = '\0'; - *lac_datestr = '\0'; + *crt_datestr = '\0'; + *lac_datestr = '\0'; *attrstr = '\0'; new_attrib = 0; } @@ -1105,8 +1105,8 @@ u32 DirFileAttrMenu(const char* path, const char *name) { ShowString( "%s\n \n" // name "%s" // modified date (not for drives) - "%s" // created date (not for drives) - "%s\n \n" // accessed date (not for drives) + "%s" // created date (not for drives) + "%s\n \n" // accessed date (not for drives) "%s\n" // size "%s \n" // attr (not for drives) "%s\n", // options