erofs-utils: add --hard-dereference option
authorPaul Meyer <katexochen0@gmail.com>
Thu, 12 Dec 2024 16:48:07 +0000 (17:48 +0100)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 13 Dec 2024 00:59:10 +0000 (08:59 +0800)
Add option --hard-dereference to dereference hardlinks when
creating an image. Instead of reusing the inode, hardlinks are added
as separate inodes. This is useful for reproducible builds, when the
rootfs is space-optimized using hardlinks on some machines, but not on
others.

Co-authored-by: Leonard Cohnen <leonard.cohnen@gmail.com>
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
Link: https://lore.kernel.org/r/20241212165550.58756-1-katexochen0@gmail.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
include/erofs/config.h
lib/inode.c
mkfs/main.c

index cff4ceadb7bceea0f1c27f45f2e523bc05017c30..bb03e708cfbb95140d73d6656b8cf2671f44abf9 100644 (file)
@@ -58,6 +58,7 @@ struct erofs_configure {
        bool c_extra_ea_name_prefixes;
        bool c_xattr_name_filter;
        bool c_ovlfs_strip;
+       bool c_hard_dereference;
 
 #ifdef HAVE_LIBSELINUX
        struct selabel_handle *sehnd;
index 7e5c58165e04783d1c75fa4ef30ce3ee42ecb5b3..0404a8d40751fa22d22db010362452e8c6239384 100644 (file)
@@ -1141,7 +1141,7 @@ static struct erofs_inode *erofs_iget_from_srcpath(struct erofs_sb_info *sbi,
         * hard-link, just return it. Also don't lookup for directories
         * since hard-link directory isn't allowed.
         */
-       if (!S_ISDIR(st.st_mode)) {
+       if (!S_ISDIR(st.st_mode) && (!cfg.c_hard_dereference)) {
                inode = erofs_iget(st.st_dev, st.st_ino);
                if (inode)
                        return inode;
index 17b1f46b6a68502b0559437dcec6db919cb8f6e6..9ca7dad93f465135d46eb8ee8b8e682ae10e8bef 100644 (file)
@@ -85,6 +85,7 @@ static struct option long_options[] = {
        {"mkfs-time", no_argument, NULL, 525},
        {"all-time", no_argument, NULL, 526},
        {"sort", required_argument, NULL, 527},
+       {"hard-dereference", no_argument, NULL, 528},
        {0, 0, 0, 0},
 };
 
@@ -174,6 +175,7 @@ static void usage(int argc, char **argv)
                " --force-gid=#         set all file gids to # (# = GID)\n"
                " --uid-offset=#        add offset # to all file uids (# = id offset)\n"
                " --gid-offset=#        add offset # to all file gids (# = id offset)\n"
+               " --hard-dereference    dereference hardlinks, add links as separate inodes\n"
                " --ignore-mtime        use build time instead of strict per-file modification time\n"
                " --max-extent-bytes=#  set maximum decompressed extent size # in bytes\n"
                " --mount-point=X       X=prefix of target fs path (default: /)\n"
@@ -851,6 +853,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                        if (!strcmp(optarg, "none"))
                                erofstar.try_no_reorder = true;
                        break;
+               case 528:
+                       cfg.c_hard_dereference = true;
+                       break;
                case 'V':
                        version();
                        exit(0);