]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
mke2fs: call create_inode's populate_fs3() requesting EXT2FS_LINK_APPEND
authorTheodore Ts'o <tytso@mit.edu>
Tue, 20 May 2025 03:24:31 +0000 (23:24 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2025 14:47:15 +0000 (10:47 -0400)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/create_inode.c
misc/create_inode.h
misc/create_inode_libarchive.c
misc/mke2fs.c

index b83b2f5b0e2ae6d85cec3e680de3312f2d50635e..d3136df9327f365a49a3fc9e2e2ad7cf94cf3ec0 100644 (file)
@@ -43,6 +43,8 @@
 /* 64KiB is the minimum blksize to best minimize system call overhead. */
 #define COPY_FILE_BUFLEN       65536
 
+int link_append_flag = 0;
+
 static int ext2_file_type(unsigned int mode)
 {
        if (LINUX_S_ISREG(mode))
@@ -83,7 +85,7 @@ errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
        }
 
        retval = ext2fs_link(fs, parent_ino, name, ino,
-                            ext2_file_type(inode.i_mode));
+                            ext2_file_type(inode.i_mode) | link_append_flag);
        if (retval == EXT2_ET_DIR_NO_SPACE) {
                retval = ext2fs_expand_dir(fs, parent_ino);
                if (retval) {
@@ -92,7 +94,8 @@ errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
                        return retval;
                }
                retval = ext2fs_link(fs, parent_ino, name, ino,
-                                    ext2_file_type(inode.i_mode));
+                                    (ext2_file_type(inode.i_mode) |
+                                     link_append_flag));
        }
        if (retval) {
                com_err(__func__, retval, _("while linking \"%s\""), name);
@@ -296,7 +299,7 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
 #ifdef DEBUGFS
        printf("Allocated inode: %u\n", ino);
 #endif
-       retval = ext2fs_link(fs, cwd, name, ino, filetype);
+       retval = ext2fs_link(fs, cwd, name, ino, filetype | link_append_flag);
        if (retval == EXT2_ET_DIR_NO_SPACE) {
                retval = ext2fs_expand_dir(fs, cwd);
                if (retval) {
@@ -304,7 +307,8 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
                                _("while expanding directory"));
                        return retval;
                }
-               retval = ext2fs_link(fs, cwd, name, ino, filetype);
+               retval = ext2fs_link(fs, cwd, name, ino,
+                                    filetype | link_append_flag);
        }
        if (retval) {
                com_err(name, retval, _("while creating inode \"%s\""), name);
@@ -678,13 +682,14 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
 #ifdef DEBUGFS
        printf("Allocated inode: %u\n", newfile);
 #endif
-       retval = ext2fs_link(fs, parent_ino, dest, newfile, EXT2_FT_REG_FILE);
+       retval = ext2fs_link(fs, parent_ino, dest, newfile,
+                            EXT2_FT_REG_FILE | link_append_flag);
        if (retval == EXT2_ET_DIR_NO_SPACE) {
                retval = ext2fs_expand_dir(fs, parent_ino);
                if (retval)
                        goto out;
                retval = ext2fs_link(fs, parent_ino, dest, newfile,
-                                       EXT2_FT_REG_FILE);
+                                       EXT2_FT_REG_FILE | link_append_flag);
        }
        if (retval)
                goto out;
@@ -1078,6 +1083,9 @@ errcode_t populate_fs3(ext2_filsys fs, ext2_ino_t parent_ino,
        file_info.path_max_len = 255;
        file_info.path = calloc(file_info.path_max_len, 1);
 
+       link_append_flag = (flags & POPULATE_FS_LINK_APPEND) ?
+               EXT2FS_LINK_APPEND : 0;
+
        /* interpret input as tarball either if it's "-" (stdin) or if it's
         * a regular file (or a symlink pointing to a regular file)
         */
@@ -1092,7 +1100,7 @@ errcode_t populate_fs3(ext2_filsys fs, ext2_ino_t parent_ino,
        if (stat(source, &st)) {
                retval = errno;
                com_err(__func__, retval, _("while calling stat"));
-               return retval;
+               goto out;
        }
        if (S_ISREG(st.st_mode)) {
                retval = __populate_fs_from_tar(fs, parent_ino, source, root,
@@ -1116,6 +1124,7 @@ errcode_t populate_fs3(ext2_filsys fs, ext2_ino_t parent_ino,
 out:
        free(file_info.path);
        free(hdlinks.hdl);
+       link_append_flag = 0;
        return retval;
 }
 
index 186c3d0cfc5867b121a72dfb8f459acbcdda17fb..4a296ded64707a5298875a34bb96e9fcebb5413e 100644 (file)
@@ -32,6 +32,7 @@ struct file_info {
 
 /* flags for populate_fs3 */
 #define POPULATE_FS_NO_COPY_XATTRS     0x0001
+#define POPULATE_FS_LINK_APPEND                0x0002
 
 struct fs_ops_callbacks {
        errcode_t (* create_new_inode)(ext2_filsys fs, const char *target_path,
index d109ca289e9be9bcd3ca96996302dc83bb00de0a..b088e34317da90ec559af887e9bfb35a9ac63bb3 100644 (file)
@@ -17,6 +17,8 @@
 #include "create_inode_libarchive.h"
 #include "support/nls-enable.h"
 
+extern int link_append_flag;
+
 #if (!(defined(CONFIG_DLOPEN_LIBARCHIVE) || defined(HAVE_ARCHIVE_H)) || \
      defined(CONFIG_DISABLE_LIBARCHIVE))
 
@@ -389,12 +391,14 @@ static errcode_t do_write_internal_tar(ext2_filsys fs, ext2_ino_t cwd,
 #ifdef DEBUGFS
        printf("Allocated inode: %u\n", newfile);
 #endif
-       retval = ext2fs_link(fs, cwd, dest, newfile, EXT2_FT_REG_FILE);
+       retval = ext2fs_link(fs, cwd, dest, newfile,
+                            EXT2_FT_REG_FILE | link_append_flag);
        if (retval == EXT2_ET_DIR_NO_SPACE) {
                retval = ext2fs_expand_dir(fs, cwd);
                if (retval)
                        goto out;
-               retval = ext2fs_link(fs, cwd, dest, newfile, EXT2_FT_REG_FILE);
+               retval = ext2fs_link(fs, cwd, dest, newfile,
+                                    EXT2_FT_REG_FILE | link_append_flag);
        }
        if (retval)
                goto out;
index 71e3704bad79c3082b9d6fa5b4e3cccd5c1ea360..66675976e538c643a24ea5a19734db635389f101 100644 (file)
@@ -102,7 +102,7 @@ static e2_blkcnt_t  orphan_file_blocks;
 static int     lazy_itable_init;
 static int     assume_storage_prezeroed;
 static int     packed_meta_blocks;
-static int     populate_flags;
+static int     populate_flags = POPULATE_FS_LINK_APPEND;
 static char    *bad_blocks_filename = NULL;
 static __u32   fs_stride;
 /* Initialize usr/grp quotas by default */