summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-11-22 23:51:46 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-11-22 23:51:46 +0000
commitb5184d761b9c3b0fa79ba891ae148b0a44f13757 (patch)
tree4c74de8c3fc13911651cd7090fc4ca8463476637
parent5befad0a1bd049e5529857defaab1d058dd1dd22 (diff)
downloadrockbox-b5184d761b9c3b0fa79ba891ae148b0a44f13757.zip
rockbox-b5184d761b9c3b0fa79ba891ae148b0a44f13757.tar.gz
rockbox-b5184d761b9c3b0fa79ba891ae148b0a44f13757.tar.bz2
rockbox-b5184d761b9c3b0fa79ba891ae148b0a44f13757.tar.xz
Added creation and last-modified timestamps.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2875 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/fat.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 37e17c2..6418349 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -28,6 +28,7 @@
#include "debug.h"
#include "panic.h"
#include "system.h"
+#include "timefuncs.h"
#define BYTES2INT16(array,pos) \
(array[pos] | (array[pos+1] << 8 ))
@@ -637,6 +638,26 @@ static int flush_fat(void)
return 0;
}
+static void fat_time(unsigned short* date,
+ unsigned short* time,
+ unsigned short* tenth )
+{
+ struct tm* tm = get_time();
+
+ if (date)
+ *date = ((tm->tm_year - 80) << 9) |
+ ((tm->tm_mon + 1) << 5) |
+ tm->tm_mday;
+
+ if (time)
+ *time = (tm->tm_hour << 11) |
+ (tm->tm_min << 5) |
+ (tm->tm_sec >> 1);
+
+ if (tenth)
+ *tenth = (tm->tm_sec & 1) * 100;
+}
+
static int write_long_name(struct fat_file* file,
unsigned int firstentry,
unsigned int numentries,
@@ -745,10 +766,21 @@ static int write_long_name(struct fat_file* file,
}
else {
/* shortname entry */
+ unsigned short date=0, time=0, tenth=0;
LDEBUGF("Shortname entry: %.13s\n", shortname);
strncpy(entry + FATDIR_NAME, shortname, 11);
entry[FATDIR_ATTR] = 0;
entry[FATDIR_NTRES] = 0;
+
+#ifdef HAVE_RTC
+ fat_time(&date, &time, &tenth);
+#endif
+ entry[FATDIR_CRTTIMETENTH] = tenth;
+ *(unsigned short*)(entry + FATDIR_CRTTIME) = SWAB16(time);
+ *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
+ *(unsigned short*)(entry + FATDIR_CRTDATE) = SWAB16(date);
+ *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
+ *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
}
idx++;
nameidx -= NAME_BYTES_PER_ENTRY;
@@ -1012,6 +1044,7 @@ static int update_file_size( struct fat_file* file, int size )
unsigned int* sizeptr;
unsigned short* clusptr;
struct fat_file dir;
+ unsigned short date=0, time=0;
int err;
LDEBUGF("update_file_size(cluster:%x entry:%d size:%d)\n",
@@ -1042,6 +1075,13 @@ static int update_file_size( struct fat_file* file, int size )
sizeptr = (int*)(entry + FATDIR_FILESIZE);
*sizeptr = SWAB32(size);
+#ifdef HAVE_RTC
+ fat_time(&date, &time, NULL);
+ *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
+ *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
+ *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
+#endif
+
err = fat_seek( &dir, sector );
if (err<0)
return -4;