fs: Use 64-bit type for filesystem timestamp

Some filesystems nowadays use 64-bit types for timestamps. So, update
grub_dirhook_info struct to use an grub_int64_t type to store mtime.
This also updates the grub_unixtime2datetime() function to receive
a 64-bit timestamp argument and do 64-bit-safe divisions.

All the remaining conversion from 32-bit to 64-bit should be safe, as
32-bit to 64-bit attributions will be implicitly casted. The most
critical part in the 32-bit to 64-bit conversion is in the function
grub_unixtime2datetime() where it needs to deal with the 64-bit type.
So, for that, the grub_divmod64() helper has been used.

These changes enables the GRUB to support dates beyond y2038.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Carlos Maiolino authored and Daniel Kiper committed 2021-06-01 17:19:13 +02:00
1 parent af54062b54
commit 81f1962393
16 files changed
+32 -25

No files matched your search

+2 -2
View File
@@ -737,7 +737,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
* https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification
*/
static int
grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int32_t *nix) {
grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int64_t *nix) {
struct grub_datetime datetime = {
.year = (field >> 25) + 1980,
.month = (field & 0x01E00000) >> 21,
@@ -891,7 +891,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
* https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-107.pdf
*/
static int
grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int32_t *nix) {
grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int64_t *nix) {
struct grub_datetime datetime = {
.year = (date >> 9) + 1980,
.month = (date & 0x01E0) >> 5,