From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j9DPm-0001Ba-VP for mharc-grub-devel@gnu.org; Tue, 03 Mar 2020 14:41:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32848) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9DPk-00018E-62 for grub-devel@gnu.org; Tue, 03 Mar 2020 14:41:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9DPj-0003lo-2g for grub-devel@gnu.org; Tue, 03 Mar 2020 14:41:12 -0500 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]:44141) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j9DPi-0003lb-VI for grub-devel@gnu.org; Tue, 03 Mar 2020 14:41:11 -0500 Received: by mail-qk1-x730.google.com with SMTP id f198so4605989qke.11 for ; Tue, 03 Mar 2020 11:41:10 -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=+qkDSLnzdPQIva/yVixTyajcG0LObRQ8zL4uoADVUto=; b=Uxv2yYh3bW78pIHQxkB2Z01w0zz3BrYlWnCLQwDRNAbXu2IHCAMYNMn4/c8+KWojSd lac9txnE0lIb0kQKFT/AHufa7b70/mhMHFmNc7c5IZrH3o6mNbrAtBJwwVJIhTUPOKq8 tXhlx0Zzr8woLd8pzAFs0T07PdaoRQuDbCqh2yXFcz4UF+pG02V1B4j7OGOZP8F0caFO +u8Q/xXeuLAjF0oc2FuuSrSE2jY3RS42+mguRpuZsOdUexCvrkHJDmnkrajU2KUcWEGn 1LuUPueoW+xVMz0RqGAVafNEodelVeORsG0mXWfs3MA/WVdSOwfx+N01KsCRpodz4zyG ARFw== 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=+qkDSLnzdPQIva/yVixTyajcG0LObRQ8zL4uoADVUto=; b=om9lhvN0ZnGdDLbnJ04sF27nHTHjroU5dhBEfQ0NiCCclMYcPlIiwyW+9qzJfBYjeh tp2+NT4NCU8A2uh6el5zDZ1HDJ8p9kFor2e+rMfcZbm4ju8zL8j6WVGIZ4V8hv+dIiFT 3xNmcGktqUuRcDAbz5UaUIpe5jw2GBF5SfBpaaqhaq+4j5PhlCGYfdAbTNLR6kN5/XDe bUSsmnMV1NxsL5YzRFNTsG+JE42A9OC4JBQW5SrTQxa14eAiL/htwjMrUAi//u7ir2Un oVdVE38mzuok1+OvFD+yeRA3RQ4lhZS4na3z5yBN3hDhW9GSIdbwA7Kx191whFHHnvVT Z1Qw== X-Gm-Message-State: ANhLgQ0XFuTj25Z4mQ4JY9N2l957D/A1tlCqzA9bxyOK0eetKMjkZywW 3Nqi3OBfj+pLgNqyLbO0tTYcmKjB X-Google-Smtp-Source: ADFU+vv9skTquZDfnmcB9x5wBAbDVhZThNMBJrMU5kQ+UesxKhTAisOZG+yocp1T3LXBxKU6JZOQ+Q== X-Received: by 2002:a05:620a:21d5:: with SMTP id h21mr5881527qka.2.1583264470013; Tue, 03 Mar 2020 11:41:10 -0800 (PST) Received: from callisto ([2601:986:200:7341:384b:df90:fb2f:c5df]) by smtp.gmail.com with ESMTPSA id j7sm455046qkd.45.2020.03.03.11.41.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 11:41:09 -0800 (PST) From: David Michael To: grub-devel@gnu.org Subject: [PATCH v2 2/2] fat: Support file modification times Date: Tue, 03 Mar 2020 14:41:08 -0500 Message-ID: <87tv358bvv.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::730 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: Tue, 03 Mar 2020 19:41:13 -0000 This allows comparing file ages on EFI system partitions. Signed-off-by: David Michael --- Changes since v1: - Added the previous patch to help support exfat - Added exfat timestamp conversion + setting - Switched to datetime variable name for consistency with the header - Switched to tabs-for-alignment for consistency in the file grub-core/fs/fat.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index dc493add2..bacf9e60f 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 @@ -730,6 +731,28 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, return grub_errno ? : GRUB_ERR_EOF; } +static int +grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int32_t *nix) { + struct grub_datetime datetime = { + .year = (field >> 25) + 1980, + .month = (field & 0x01E00000) >> 21, + .day = (field & 0x001F0000) >> 16, + .hour = (field & 0x0000F800) >> 11, + .minute = (field & 0x000007E0) >> 5, + .second = (field & 0x0000001F) * 2 + (msec >= 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 (msec > 199) + return 0; + + return grub_datetime2unixtime (&datetime, nix); +} + #else static grub_err_t @@ -857,6 +880,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 datetime = { + .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 (&datetime, nix); +} + #endif static grub_err_t lookup_file (grub_fshelp_node_t node, @@ -966,9 +1007,15 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, #ifdef MODE_EXFAT if (!ctxt.dir.have_stream) continue; + info.mtimeset = grub_exfat_timestamp (grub_le_to_cpu32 (ctxt.entry.type_specific.file.m_time), + ctxt.entry.type_specific.file.m_time_tenth, + &info.mtime); #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