* [PATCH 1/1] fs: fat: fill creation and change date
@ 2024-04-09 20:06 Heinrich Schuchardt
2024-04-18 3:40 ` Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2024-04-09 20:06 UTC (permalink / raw)
To: Tom Rini; +Cc: Simon Glass, Bin Meng, u-boot, Heinrich Schuchardt
The FAT specification requires that the change date is set.
If a DM RTC device exists, set the creation and change date to the current
date when updating the directory entry. Otherwise use the date 2020-01-01.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
fs/fat/fat_write.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 8b5d669b005..c8e0fbf1a3b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -18,6 +18,7 @@
#include <rand.h>
#include <asm/byteorder.h>
#include <asm/cache.h>
+#include <dm/uclass.h>
#include <linux/ctype.h>
#include <linux/math64.h>
#include "fat.c"
@@ -1151,6 +1152,41 @@ getit:
return 0;
}
+/**
+ * dentry_set_time() - set change time
+ *
+ * @dentptr: directory entry
+ */
+static void dentry_set_time(dir_entry *dentptr)
+{
+ if (CONFIG_IS_ENABLED(DM_RTC)) {
+ struct udevice *dev;
+ struct rtc_time tm;
+ u16 date;
+ u16 time;
+
+ uclass_first_device(UCLASS_RTC, &dev);
+ if (!dev)
+ goto err;
+ if (dm_rtc_get(dev, &tm))
+ goto err;
+ if (tm.tm_year < 1980 || tm.tm_year > 2107)
+ goto err;
+ date = (tm.tm_mday & 0x1f) |
+ ((tm.tm_mon & 0xf) << 5) |
+ ((tm.tm_year - 1980) << 9);
+ time = (tm.tm_sec > 1) |
+ ((tm.tm_min & 0x3f) << 5) |
+ (tm.tm_hour << 11);
+ dentptr->date = date;
+ dentptr->time = time;
+ return;
+ }
+err:
+ dentptr->date = 0x2821; /* 2000-01-01 */
+ dentptr->time = 0;
+}
+
/**
* fill_dentry() - fill directory entry with shortname
*
@@ -1171,6 +1207,12 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr,
dentptr->attr = attr;
+ /* Set change date */
+ dentry_set_time(dentptr);
+ /* Set creation date */
+ dentptr->cdate = dentptr->date;
+ dentptr->ctime = dentptr->time;
+
memcpy(&dentptr->nameext, shortname, SHORT_NAME_SIZE);
}
@@ -1376,6 +1418,8 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer,
/* Update file size in a directory entry */
retdent->size = cpu_to_le32(pos + size);
+ /* Update change date */
+ dentry_set_time(retdent);
} else {
/* Create a new file */
char shortname[SHORT_NAME_SIZE];
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] fs: fat: fill creation and change date
2024-04-09 20:06 [PATCH 1/1] fs: fat: fill creation and change date Heinrich Schuchardt
@ 2024-04-18 3:40 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2024-04-18 3:40 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Simon Glass, Bin Meng, u-boot
On Tue, 09 Apr 2024 22:06:07 +0200, Heinrich Schuchardt wrote:
> The FAT specification requires that the change date is set.
>
> If a DM RTC device exists, set the creation and change date to the current
> date when updating the directory entry. Otherwise use the date 2020-01-01.
>
>
Applied to u-boot/master, thanks!
--
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-18 3:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 20:06 [PATCH 1/1] fs: fat: fill creation and change date Heinrich Schuchardt
2024-04-18 3:40 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.