Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F115802508
D43425.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D43425.diff
View Options
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,12 @@
*/
/* 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" \
+ "[ -z \"$1\" ] && exit 1;" \
+ "kldload -n geom_uzip && "
+
#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,11 @@
#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" \
+ "[ -z \"$1\" ] && exit 1;" \
+ "kldload -n geom_uzip && "
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,11 @@
#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" \
+ "[ -z \"$1\" ] && exit 1;" \
+ "kldload -n geom_uzip && "
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,64 @@
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,
+ "mount -r /dev/`mdconfig $0`.uzip $1;"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "cd9660") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "mount_cd9660 /dev/`mdconfig $0`.uzip $1;"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "zfs") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "mdconfig $0 && "
+ "zpool import -o readonly=on $1;"
+ "exit $?\n");
+ } else if (strcmp(fstyp_result, "msdosfs") == 0) {
+ n = snprintf(hdr->magic, CLOOP_MAGIC_LEN,
+ "%s%s",
+ handler->magic,
+ "mount_msdosfs -r /dev/`mdconfig $0`.uzip $1;"
+ "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 +287,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
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 29, 9:13 PM (3 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17846416
Default Alt Text
D43425.diff (3 KB)
Attached To
Mode
D43425: mkuzip: detect underlying filesystem when building uzip header
Attached
Detach File
Event Timeline
Log In to Comment