From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j7thG-0004aw-Mm for mharc-grub-devel@gnu.org; Fri, 28 Feb 2020 23:25:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51290) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7thE-0004ak-LT for grub-devel@gnu.org; Fri, 28 Feb 2020 23:25:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7thD-00020x-L9 for grub-devel@gnu.org; Fri, 28 Feb 2020 23:25:48 -0500 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:33388) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j7thD-00020g-Fs for grub-devel@gnu.org; Fri, 28 Feb 2020 23:25:47 -0500 Received: by mail-qt1-x841.google.com with SMTP id x8so1549253qts.0 for ; Fri, 28 Feb 2020 20:25:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=OlFEQkXDZPYk/wxK10S/Wls2o3aQAviDBbKyQedtSCw=; b=C3GZSOL9B0IV1qfCSUO7xq+0Jfdsi+tako4+kwSNgFtRCh0x87Gk5OBEWXkXT0d5iq b+5X9W+KN1x6YPLOpsudZc6I5ZsvMBnQPUEUTBJ9JOSkaD7nG+K5WBRpLHnVaIqVNYwb fj4N/RAPMDuKp1w+a28iIMGZWhc4eAKxtN2rv4/IELNFXhXT+URqskR6CkRz9p9b94vF kpvrKJQtAMpZjioi0Gr9yGY0CeUVKelu7hDB3lrHOhSpeFofvANLyUfjoO0qbqqKDa78 9WHZv220OgKW93jtmssnZ/d3zvMk0SCOxBfVwaSmvYhfHO5mqwrKZXlX7HmlxbO8xEqD 5Qtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=OlFEQkXDZPYk/wxK10S/Wls2o3aQAviDBbKyQedtSCw=; b=bGoaVa5AGZZ9EIUEJQzMEDIqY/qSex11xDcNSHk1x8U3MQ96E8/9KQ5IE2JI0qgkLh a7/Kzvwoz3uYcBQ1ixXRxcfRejmMdovHs7Jr2LKH4U+NyZ93guef1V1uiahsHgba3PRd t+tjTjPfA+EuSFshvp0VsCD7304+X+/X8SRmN76GHQERgVvlDHgDquXLiKQ2D+GtyhFn 0ffKc9HP/gVECrwbTC1cEoBIrMfaPD63odnRKbAqG9HSTSD8ucoGaCH0n1aKr4ap15ie 5dNmU418emqkfbLWfBUSMupMgQlL9NA+0uu52QlEHu8yqyeztLZnqCZIPWXqTJdQWl2E jc2w== X-Gm-Message-State: APjAAAWjZa77S/bXupOxbbkppkoJE7hy31D/vUaMaN+XVZmjxweImKut V7RXKPhdCwnYQ4pJVpsbW0RGAL6t X-Google-Smtp-Source: APXvYqytB1WQ3qSTCHOp2icQ1EQsgkxlZwd0bmi7mYEtKoh3XYyvpirDzhcFYk7HsJonEJYajBJNqA== X-Received: by 2002:ac8:36dd:: with SMTP id b29mr7034393qtc.285.1582950344827; Fri, 28 Feb 2020 20:25:44 -0800 (PST) Received: from callisto ([2601:986:200:7341:384b:df90:fb2f:c5df]) by smtp.gmail.com with ESMTPSA id t13sm6238912qkm.60.2020.02.28.20.25.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2020 20:25:44 -0800 (PST) From: David Michael To: grub-devel@gnu.org Subject: [PATCH] fat: Support file modification times Date: Fri, 28 Feb 2020 23:25:43 -0500 Message-ID: <877e06yq7s.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Feb 2020 04:25:49 -0000 E.g. this allows comparing file ages on EFI system partitions. Signed-off-by: David Michael --- 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 #include #include +#include #ifndef MODE_EXFAT #include #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