* [PATCH] fat: Support file modification times
@ 2020-02-29 4:25 David Michael
2020-03-03 13:44 ` Daniel Kiper
0 siblings, 1 reply; 2+ messages in thread
From: David Michael @ 2020-02-29 4:25 UTC (permalink / raw)
To: grub-devel
E.g. this allows comparing file ages on EFI system partitions.
Signed-off-by: David Michael <fedora.dm0@gmail.com>
---
Hi,
I tried to make a quick patch for #57621 based on the FAT timestamp
format as described on Wikipedia. Is there still a chance to fix this
issue for 2.06?
Thanks.
David
P.S. I also made a timestamp conversion for exfat as well, but I didn't
test it and it's outside the scope of my ESP issue, so I didn't include
it. I'll paste it here in case someone wants it in the future.
static int
grub_fat_timestamp (grub_uint32_t field, grub_uint8_t usec, grub_int32_t *nix) {
struct grub_datetime structured = {
.year = (field >> 25) + 1980,
.month = (field & 0x01E00000) >> 21,
.day = (field & 0x001F0000) >> 16,
.hour = (field & 0x0000F800) >> 11,
.minute = (field & 0x000007E0) >> 5,
.second = (field & 0x0000001F) * 2 + (usec >= 100 ? 1 : 0),
};
/* The conversion below allows seconds=60, so don't trust its validation. */
if ((field & 0x1F) > 29)
return 0;
/* Validate the 10-msec field even though it is rounded down to seconds. */
if (usec > 199)
return 0;
return grub_datetime2unixtime (&structured, nix);
}
grub-core/fs/fat.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
index d544e0af1..b0efb6cbf 100644
--- a/grub-core/fs/fat.c
+++ b/grub-core/fs/fat.c
@@ -26,6 +26,7 @@
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/charset.h>
+#include <grub/datetime.h>
#ifndef MODE_EXFAT
#include <grub/fat.h>
#else
@@ -856,6 +857,24 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
return grub_errno ? : GRUB_ERR_EOF;
}
+static int
+grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int32_t *nix) {
+ struct grub_datetime structured = {
+ .year = (date >> 9) + 1980,
+ .month = (date & 0x01E0) >> 5,
+ .day = (date & 0x001F),
+ .hour = (time >> 11),
+ .minute = (time & 0x07E0) >> 5,
+ .second = (time & 0x001F) * 2,
+ };
+
+ /* The conversion below allows seconds=60, so don't trust its validation. */
+ if ((time & 0x1F) > 29)
+ return 0;
+
+ return grub_datetime2unixtime (&structured, nix);
+}
+
#endif
static grub_err_t lookup_file (grub_fshelp_node_t node,
@@ -968,6 +987,9 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
#else
if (ctxt.dir.attr & GRUB_FAT_ATTR_VOLUME_ID)
continue;
+ info.mtimeset = grub_fat_timestamp (grub_le_to_cpu16 (ctxt.dir.w_time),
+ grub_le_to_cpu16 (ctxt.dir.w_date),
+ &info.mtime);
#endif
if (hook (ctxt.filename, &info, hook_data))
--
2.21.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] fat: Support file modification times
2020-02-29 4:25 [PATCH] fat: Support file modification times David Michael
@ 2020-03-03 13:44 ` Daniel Kiper
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2020-03-03 13:44 UTC (permalink / raw)
To: David Michael; +Cc: grub-devel
On Fri, Feb 28, 2020 at 11:25:43PM -0500, David Michael wrote:
> E.g. this allows comparing file ages on EFI system partitions.
>
> Signed-off-by: David Michael <fedora.dm0@gmail.com>
> ---
>
> Hi,
>
> I tried to make a quick patch for #57621 based on the FAT timestamp
> format as described on Wikipedia. Is there still a chance to fix this
> issue for 2.06?
Sure thing!
> Thanks.
>
> David
>
> P.S. I also made a timestamp conversion for exfat as well, but I didn't
Please fix exFAT too...
> test it and it's outside the scope of my ESP issue, so I didn't include
> it. I'll paste it here in case someone wants it in the future.
>
> static int
> grub_fat_timestamp (grub_uint32_t field, grub_uint8_t usec, grub_int32_t *nix) {
> struct grub_datetime structured = {
> .year = (field >> 25) + 1980,
> .month = (field & 0x01E00000) >> 21,
> .day = (field & 0x001F0000) >> 16,
> .hour = (field & 0x0000F800) >> 11,
> .minute = (field & 0x000007E0) >> 5,
> .second = (field & 0x0000001F) * 2 + (usec >= 100 ? 1 : 0),
> };
>
> /* The conversion below allows seconds=60, so don't trust its validation. */
> if ((field & 0x1F) > 29)
> return 0;
>
> /* Validate the 10-msec field even though it is rounded down to seconds. */
> if (usec > 199)
> return 0;
>
> return grub_datetime2unixtime (&structured, nix);
> }
...and add your SOB.
> grub-core/fs/fat.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
> index d544e0af1..b0efb6cbf 100644
> --- a/grub-core/fs/fat.c
> +++ b/grub-core/fs/fat.c
> @@ -26,6 +26,7 @@
> #include <grub/err.h>
> #include <grub/dl.h>
> #include <grub/charset.h>
> +#include <grub/datetime.h>
> #ifndef MODE_EXFAT
> #include <grub/fat.h>
> #else
> @@ -856,6 +857,24 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
> return grub_errno ? : GRUB_ERR_EOF;
> }
>
> +static int
> +grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int32_t *nix) {
> + struct grub_datetime structured = {
Hmmm... What does structured means?
> + .year = (date >> 9) + 1980,
> + .month = (date & 0x01E0) >> 5,
> + .day = (date & 0x001F),
> + .hour = (time >> 11),
> + .minute = (time & 0x07E0) >> 5,
> + .second = (time & 0x001F) * 2,
> + };
> +
> + /* The conversion below allows seconds=60, so don't trust its validation. */
> + if ((time & 0x1F) > 29)
> + return 0;
> +
> + return grub_datetime2unixtime (&structured, nix);
> +}
> +
> #endif
>
> static grub_err_t lookup_file (grub_fshelp_node_t node,
> @@ -968,6 +987,9 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
> #else
> if (ctxt.dir.attr & GRUB_FAT_ATTR_VOLUME_ID)
> continue;
> + info.mtimeset = grub_fat_timestamp (grub_le_to_cpu16 (ctxt.dir.w_time),
> + grub_le_to_cpu16 (ctxt.dir.w_date),
> + &info.mtime);
> #endif
>
> if (hook (ctxt.filename, &info, hook_data))
Otherwise LGTM...
Daniel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-03 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-29 4:25 [PATCH] fat: Support file modification times David Michael
2020-03-03 13:44 ` Daniel Kiper
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.