Page MenuHomeFreeBSD

D43425.id132700.diff
No OneTemporary

D43425.id132700.diff

diff --git a/usr.bin/mkuzip/mkuz_lzma.h b/usr.bin/mkuzip/mkuz_lzma.h
--- a/usr.bin/mkuzip/mkuz_lzma.h
+++ b/usr.bin/mkuzip/mkuz_lzma.h
@@ -26,14 +26,11 @@
*/
/* Format L3.0, since we move to XZ API */
-#define CLOOP_MAGIC_LZMA \
- "#!/bin/sh\n" \
- "#L3.0\n" \
- "n=uncompress\n" \
- "m=geom_$n\n" \
- "(kldstat -m $m 2>&-||kldload $m)>&-&&" \
- "mount_cd9660 /dev/`mdconfig -af $0`.$n $1\n" \
- "exit $?\n"
+#define CLOOP_MAGIC_LZMA \
+ "#!/bin/sh\n" \
+ "#L3.0\n" \
+ "kldload -n geom_uzip||exit 1\n"
+
#define DEFAULT_SUFX_LZMA ".ulzma"
size_t mkuz_lzma_cbound(size_t);
diff --git a/usr.bin/mkuzip/mkuz_zlib.h b/usr.bin/mkuzip/mkuz_zlib.h
--- a/usr.bin/mkuzip/mkuz_zlib.h
+++ b/usr.bin/mkuzip/mkuz_zlib.h
@@ -26,9 +26,10 @@
#define DEFAULT_SUFX_ZLIB ".uzip"
-#define CLOOP_MAGIC_ZLIB "#!/bin/sh\n#V2.0 Format\n" \
- "(kldstat -qm g_uzip||kldload geom_uzip)>&-&&" \
- "mount_cd9660 /dev/`mdconfig -af $0`.uzip $1\nexit $?\n"
+#define CLOOP_MAGIC_ZLIB \
+ "#!/bin/sh\n" \
+ "#V2.0 Format\n" \
+ "kldload -n geom_uzip||exit 1\n"
size_t mkuz_zlib_cbound(size_t);
void *mkuz_zlib_init(int *);
diff --git a/usr.bin/mkuzip/mkuz_zstd.h b/usr.bin/mkuzip/mkuz_zstd.h
--- a/usr.bin/mkuzip/mkuz_zstd.h
+++ b/usr.bin/mkuzip/mkuz_zstd.h
@@ -27,9 +27,10 @@
#define DEFAULT_SUFX_ZSTD ".uzst"
-#define CLOOP_MAGIC_ZSTD "#!/bin/sh\n#Z4.0 Format\n" \
- "(kldstat -qm g_uzip||kldload geom_uzip)>&-&&" \
- "mount_cd9660 /dev/`mdconfig -af $0`.uzip $1\nexit $?\n"
+#define CLOOP_MAGIC_ZSTD \
+ "#!/bin/sh\n" \
+ "#Z4.0 Format\n" \
+ "kldload -n geom_uzip||exit 1\n"
size_t mkuz_zstd_cbound(size_t);
void *mkuz_zstd_init(int *);
diff --git a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c
--- a/usr.bin/mkuzip/mkuzip.c
+++ b/usr.bin/mkuzip/mkuzip.c
@@ -111,6 +111,67 @@
return (bp->info.blkno == *ap);
}
+static int
+build_header(struct cloop_header *hdr, const struct mkuz_format *handler,
+ const char *file)
+{
+ int n;
+ FILE *fp;
+ char fstyp_cmd[MAXPATHLEN];
+ char fstyp_result[8];
+
+ snprintf(fstyp_cmd, sizeof(fstyp_cmd), "fstyp -u %s 2>/dev/null", file);
+ fp = popen(fstyp_cmd, "r");
+ if (fp == NULL)
+ return (-1);
+
+ if (fgets(fstyp_result, sizeof(fstyp_result), fp) == NULL) {
+ fclose(fp);
+ return (-1);
+ }
+
+ fstyp_result[strcspn(fstyp_result, "\n")] = '\0';
+ if (strcmp(fstyp_result, "ufs") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "MD=/dev/`mdconfig -a $0`\n"
+ "mount -r $MD.uzip $1\n"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "cd9660") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "MD=/dev/`mdconfig -a $0`\n"
+ "mount_cd9660 $MD.uzip $1\n"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "zfs") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "/dev/mdconfig -a $0\n"
+ "zpool import -o readonly=on $1\n"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "msdosfs") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "MD=/dev/`mdconfig -a $0`\n"
+ "mount_msdosfs -r $MD.uzip $1\n"
+ "exit $?\n");
+ } else {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "echo 'must manually mount filesystem'"
+ "exit $?\n");
+ }
+
+ fclose(fp);
+
+ return (n);
+}
+
int main(int argc, char **argv)
{
struct mkuz_cfg cfs;
@@ -229,8 +290,8 @@
cfs.handler = &uzip_fmts[comp_alg];
- magiclen = strlcpy(hdr.magic, cfs.handler->magic, sizeof(hdr.magic));
- assert(magiclen < sizeof(hdr.magic));
+ magiclen = build_header(&hdr, cfs.handler, argv[0]);
+ assert(magiclen > 0 && magiclen < sizeof(hdr.magic));
if (cfs.en_dedup != 0) {
/*

File Metadata

Mime Type
text/plain
Expires
Fri, Jun 26, 3:14 PM (5 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34361151
Default Alt Text
D43425.id132700.diff (3 KB)

Event Timeline