From: Darrick J. Wong Date: Mon, 8 Jun 2026 17:17:09 +0000 (-0700) Subject: mkfs: fix hardlink detection in directory import code X-Git-Tag: v7.1.0~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63a4a9d6966ce0850089954f88a517fc68ddce98;p=thirdparty%2Fxfsprogs-dev.git mkfs: fix hardlink detection in directory import code There's a serious problem in the hardlink detection code in the new mkfs protofile functionality that copies a directory tree into the new filesystem. It's been long established that hardlinks can only be detected by comparing st_ino *and* st_dev, but the new code doesn't do that. Fix the detector. Cc: # v6.17.0 Fixes: 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- diff --git a/mkfs/proto.c b/mkfs/proto.c index e435f2e6d..dd47e41d8 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -1314,6 +1314,7 @@ writetimestamps( } struct hardlink { + dev_t src_dev; ino_t src_ino; xfs_ino_t dst_ino; }; @@ -1368,7 +1369,8 @@ get_hardlink_dst_inode( size_t i = 0; for (; i < hardlink_tracker.count; i++, h++) { - if (h->src_ino == filestat->st_ino) + if (h->src_dev == filestat->st_dev && + h->src_ino == filestat->st_ino) return h->dst_ino; } return 0; @@ -1406,6 +1408,7 @@ track_hardlink_inode( } h = &hardlink_tracker.entries[hardlink_tracker.count]; + h->src_dev = filestat->st_dev; h->src_ino = filestat->st_ino; h->dst_ino = dst_ino; hardlink_tracker.count++;