Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lgr4i-00081x-Nr for mharc-grub-devel@gnu.org; Wed, 12 May 2021 11:47:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgr4P-0007si-MD for grub-devel@gnu.org; Wed, 12 May 2021 11:46:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgr4A-00014m-T3 for grub-devel@gnu.org; Wed, 12 May 2021 11:46:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620834389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qZTVebips6TYrQHeRJ2Pk5oSngO+PUDjc2tNpyk+DEs=; b=YHoI2ziGYg6106fGJAOzJ8Dey4/hvzZ4aDtzOWEaPnBCB4AObRuwXB7Ht20SLYB29Y9v6u 9b//0hQ0g9fju0RdwSzax7TkxIqom+SjYgMNXsuChmyk0/159AsddEjHLOh8v5mLZt9HCk NhupJA+dAsowHKV+xkw0hutOlVWGrB8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-173-JWXTEcZ0N3iLASzR_ggmWw-1; Wed, 12 May 2021 11:46:27 -0400 X-MC-Unique: JWXTEcZ0N3iLASzR_ggmWw-1 Received: by mail-wm1-f71.google.com with SMTP id z64-20020a1ce2430000b029016d56f15ac0so293658wmg.1 for ; Wed, 12 May 2021 08:46:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jNAwPGCWkrMPTuI0Wbu+iJ9Exb/jLwZmZENn1t81I8E=; b=YAs48D7gq7CSdpxFghUUeBJwWwSX1IqrZ7XbIy+Ru/HIUfNBmCdMLfIQgeIWQVxDXi M/AmuJOZslOEWNfKP4vcblOAGXlFCsvJNdIJdvNan5JB/Q56nLYHM21L1BsteCo0WItk BaL7ilSv+YyGXiRdkMMyuAAgwBdv72TO35k/Z4wUqdZC9FuPue2ek9tl5FfC6kB26jSy wxHtjiSVm4i7HTRK+zJqnv/vtSSc+nzaZXXtenlzpCl+T+h/urxcatIgnb1GWC7NF/WB Yh7tV122uSt23Eu3CUJh+M+2gfm7lguDS16a1LTMFtQ0RfcE4zFUZze552ftt51TB0OB 6YfA== X-Gm-Message-State: AOAM533NrMzP3+zT6EUaUqho9cDf71KvAeWVc0RUd42YFk/xBlUqpu1X nPfqVWid2gF7gtdarG3o8m5/YztVUF5qD3pq5yc6tF/P+dfHHwGLPfiMJg+gv4N0ug7cMoCwtHM abxSjqwO1dUgFs5WjvY2KSZBoIpQzdZyiB0beyN6naQO8+o0YQfrEdXhMrtW2mw== X-Received: by 2002:adf:f80f:: with SMTP id s15mr46278918wrp.341.1620834385984; Wed, 12 May 2021 08:46:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYvMdv24sF0uECJScNdu0DS540odlykz1MZz2IZ2MnTOgoacngyaU705G96U66vz7y2vVXng== X-Received: by 2002:adf:f80f:: with SMTP id s15mr46278891wrp.341.1620834385707; Wed, 12 May 2021 08:46:25 -0700 (PDT) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id w7sm46285wru.51.2021.05.12.08.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 08:46:24 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Carlos Maiolino , Daniel Kiper , Eric Sandeen , Javier Martinez Canillas Subject: [2.06 RELEASE PATCH v2 3/4] fs/xfs: Add bigtime incompat feature support Date: Wed, 12 May 2021 17:46:15 +0200 Message-Id: <20210512154616.998242-4-javierm@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512154616.998242-1-javierm@redhat.com> References: <20210512154616.998242-1-javierm@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=javierm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=216.205.24.124; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Wed, 12 May 2021 15:46:58 -0000 From: Carlos Maiolino The XFS filesystem supports a bigtime feature to overcome y2038 problem. This patch makes the GRUB able to support the XFS filesystems with this feature enabled. The XFS counter for the bigtime enabled timestamps starts on 0, which translates to GRUB_INT32_MIN (Dec 31 20:45:52 UTC 1901) in the legacy timestamps. The conversion to unix timestamps is made before passing the value to other GRUB functions. For this to work properly, GRUB requires to access flags2 field in the XFS ondisk inode. So, the grub_xfs_inode structure has been updated to the full ondisk inode size. This patch is enough to make the GRUB work properly with files that have timestamps with values up to GRUB_INT32_MAX (Jan 19 03:14:07 UTC 2038). Any file with a timestamps bigger than this will overflow the counter, causing GRUB to show wrong timestamps. This is not really different than the current situation, since the timestamps in GRUB are 32-bit values. Signed-off-by: Carlos Maiolino Signed-off-by: Javier Martinez Canillas --- Changes in v2: - Improve the commit message of patch #3 (dkiper). - Drop Reviewed-by tag from patch #3 (dkiper). _ Drop unrelated changes in patch #3 (dkiper). grub-core/fs/xfs.c | 63 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 43023e03fb3..bcf281cf80d 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -75,10 +75,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); XFS_SB_VERSION2_PROJID32BIT | \ XFS_SB_VERSION2_FTYPE) +/* Inode flags2 flags */ +#define XFS_DIFLAG2_BIGTIME_BIT 3 +#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT) + /* incompat feature flags */ #define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ +#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ /* * Directory entries with ftype are explicitly handled by GRUB code. @@ -92,7 +97,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define XFS_SB_FEAT_INCOMPAT_SUPPORTED \ (XFS_SB_FEAT_INCOMPAT_FTYPE | \ XFS_SB_FEAT_INCOMPAT_SPINODES | \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID | \ + XFS_SB_FEAT_INCOMPAT_BIGTIME) struct grub_xfs_sblock { @@ -177,7 +183,7 @@ struct grub_xfs_btree_root grub_uint64_t keys[1]; } GRUB_PACKED; -struct grub_xfs_time +struct grub_xfs_time_legacy { grub_uint32_t sec; grub_uint32_t nanosec; @@ -190,20 +196,23 @@ struct grub_xfs_inode grub_uint8_t version; grub_uint8_t format; grub_uint8_t unused2[26]; - struct grub_xfs_time atime; - struct grub_xfs_time mtime; - struct grub_xfs_time ctime; + grub_uint64_t atime; + grub_uint64_t mtime; + grub_uint64_t ctime; grub_uint64_t size; grub_uint64_t nblocks; grub_uint32_t extsize; grub_uint32_t nextents; grub_uint16_t unused3; grub_uint8_t fork_offset; - grub_uint8_t unused4[17]; + grub_uint8_t unused4[37]; + grub_uint64_t flags2; + grub_uint8_t unused5[48]; } GRUB_PACKED; -#define XFS_V2_INODE_SIZE sizeof(struct grub_xfs_inode) -#define XFS_V3_INODE_SIZE (XFS_V2_INODE_SIZE + 76) +#define XFS_V3_INODE_SIZE sizeof(struct grub_xfs_inode) +/* Size of struct grub_xfs_inode until fork_offset (included)*/ +#define XFS_V2_INODE_SIZE (XFS_V3_INODE_SIZE - 92) struct grub_xfs_dirblock_tail { @@ -233,8 +242,6 @@ struct grub_xfs_data static grub_dl_t my_mod; - - static int grub_xfs_sb_hascrc(struct grub_xfs_data *data) { return (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) == @@ -950,7 +957,6 @@ grub_xfs_mount (grub_disk_t disk) return 0; } - /* Context for grub_xfs_dir. */ struct grub_xfs_dir_ctx { @@ -958,6 +964,39 @@ struct grub_xfs_dir_ctx void *hook_data; }; +/* Bigtime inodes helpers */ + +#define NSEC_PER_SEC 1000000000L +#define XFS_BIGTIME_EPOCH_OFFSET (-(grub_int64_t)GRUB_INT32_MIN) + +static int grub_xfs_inode_has_bigtime(const struct grub_xfs_inode *inode) +{ + return inode->version >= 3 && + (inode->flags2 & grub_cpu_to_be64_compile_time(XFS_DIFLAG2_BIGTIME)); +} + +static grub_int64_t +grub_xfs_bigtime_to_unix(grub_uint64_t time) +{ + grub_uint64_t rem; + grub_int64_t nsec = NSEC_PER_SEC; + grub_int64_t seconds = grub_divmod64((grub_int64_t)time, nsec, &rem); + + return seconds - XFS_BIGTIME_EPOCH_OFFSET; +} + +static grub_int64_t +grub_xfs_get_inode_time(struct grub_xfs_inode *inode) +{ + struct grub_xfs_time_legacy *lts; + + if (grub_xfs_inode_has_bigtime(inode)) + return grub_xfs_bigtime_to_unix(grub_be_to_cpu64(inode->mtime)); + + lts = (struct grub_xfs_time_legacy *)&inode->mtime; + return grub_be_to_cpu32(lts->sec); +} + /* Helper for grub_xfs_dir. */ static int grub_xfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype, @@ -970,7 +1009,7 @@ grub_xfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype, if (node->inode_read) { info.mtimeset = 1; - info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec); + info.mtime = grub_xfs_get_inode_time(&node->inode); } info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); grub_free (node); -- 2.31.1