fat: fix listing the root directory
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 21 Jan 2022 19:15:41 +0000 (20:15 +0100)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
ls / for a FAT partition leads to

   error: invalid modification timestamp for /.

Not all entries of the directory are displayed.

Linux never updates the modification timestamp of the /. directory entry.
The FAT specification allows the access and creation date fields to be
zero.

We should follow Linux and render initial FAT timestamps as start of
the epoch.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00116.html

Gbp-Pq: Name fat-fix-listing-the-root-directory.patch

grub-core/fs/fat.c

index c5efed72412444f90f28213f82c523ff1782a6ed..f786a9e4cf8f8efb175e7ea2234a4a52e429181a 100644 (file)
@@ -901,6 +901,18 @@ grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int64_t *nix) {
     .second = (time & 0x001F) * 2,
   };
 
+  /*
+   * The modification time of the root directory is never set by Linux.
+   * Creation and access time are optional and can be zero.
+   * Follow Linux and render FAT initial timestamps as the start of the epoch.
+   */
+  if (date == 0 && time == 0)
+    {
+      datetime.year = 1970;
+      datetime.month = 1;
+      datetime.day = 1;
+    }
+
   /* The conversion below allows seconds=60, so don't trust its validation. */
   if ((time & 0x1F) > 29)
     return 0;