erofs-utils: mkfs: support exporting GNU tar archive labels
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 20 Sep 2023 03:51:41 +0000 (11:51 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 20 Sep 2023 11:35:12 +0000 (19:35 +0800)
GNU tar volume labels (by using `-V`) will be applied to EROFS.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230920035141.533474-1-hsiangkao@linux.alibaba.com
lib/tar.c

index 29fa15daa5ee0616dc21eaddd98213fc5e6a314a..54acba5d88b1ff76dca588fa3013640b23b973a8 100644 (file)
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -17,6 +17,9 @@
 #include "erofs/blobchunk.h"
 #include "erofs/rebuild.h"
 
+/* This file is a tape/volume header.  Ignore it on extraction.  */
+#define GNUTYPE_VOLHDR 'V'
+
 struct tar_header {
        char name[100];         /*   0-99 */
        char mode[8];           /* 100-107 */
@@ -634,12 +637,6 @@ restart:
                goto restart;
        }
 
-       if (memcmp(th->magic, "ustar", 5)) {
-               erofs_err("invalid tar magic @ %llu", tar_offset);
-               ret = -EIO;
-               goto out;
-       }
-
        /* chksum field itself treated as ' ' */
        csum = tarerofs_otoi(th->chksum, sizeof(th->chksum));
        if (errno) {
@@ -665,6 +662,21 @@ restart:
                goto out;
        }
 
+       if (th->typeflag == GNUTYPE_VOLHDR) {
+               if (th->size[0])
+                       erofs_warn("GNUTYPE_VOLHDR with non-zeroed size @ %llu",
+                                  tar_offset);
+               /* anyway, strncpy could cause some GCC warning here */
+               memcpy(sbi->volume_name, th->name, sizeof(sbi->volume_name));
+               goto restart;
+       }
+
+       if (memcmp(th->magic, "ustar", 5)) {
+               erofs_err("invalid tar magic @ %llu", tar_offset);
+               ret = -EIO;
+               goto out;
+       }
+
        st.st_mode = tarerofs_otoi(th->mode, sizeof(th->mode));
        if (errno)
                goto invalid_tar;