Changeset View
Standalone View
usr.bin/mkuzip/mkuzip.c
| Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| uint32_t *ap; | uint32_t *ap; | ||||
| ap = (uint32_t *)p; | ap = (uint32_t *)p; | ||||
| return (bp->info.blkno == *ap); | 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"); | |||||
delphij: What if the user didn't specify a mountpoint? (same applies to cd9660 and msdosfs) | |||||
Done Inline ActionsWith the updated changes, if a mountpoint isn't provided the script will exit with no error message and exit code = 1. if the provided argument isn't valid, mount will error out with a message. the error handling isn't great but, not much extra room to work with. rew: With the updated changes, if a mountpoint isn't provided the script will exit with no error… | |||||
| } 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) { | |||||
Done Inline ActionsFor zpool it's probably reasonable to use -R $1. delphij: For zpool it's probably reasonable to use -R $1. | |||||
Done Inline Actionsfor ZFS, $1 is the pool name to import. -R would require passing another argument, adding this would push it over the 128-byte limit. rew: for ZFS, $1 is the pool name to import.
-R would require passing another argument, adding this… | |||||
| 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) | int main(int argc, char **argv) | ||||
| { | { | ||||
| struct mkuz_cfg cfs; | struct mkuz_cfg cfs; | ||||
| char *oname; | char *oname; | ||||
| uint64_t *toc; | uint64_t *toc; | ||||
| int i, io, opt, tmp; | int i, io, opt, tmp; | ||||
| struct { | struct { | ||||
| int en; | int en; | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | int main(int argc, char **argv) | ||||
| if (argc != 1) { | if (argc != 1) { | ||||
| usage(); | usage(); | ||||
| /* Not reached */ | /* Not reached */ | ||||
| } | } | ||||
| cfs.handler = &uzip_fmts[comp_alg]; | cfs.handler = &uzip_fmts[comp_alg]; | ||||
| magiclen = strlcpy(hdr.magic, cfs.handler->magic, sizeof(hdr.magic)); | magiclen = build_header(&hdr, cfs.handler, argv[0]); | ||||
| assert(magiclen < sizeof(hdr.magic)); | assert(magiclen > 0 && magiclen < sizeof(hdr.magic)); | ||||
sobomaxUnsubmitted Not Done Inline ActionsUghh, no please no. If you want to add this complex procedure just to run mkuzip either make it optional or ignore when it fails for whatever reason. I don't really care what it puts into that area, but by default mkuzip should be ROBUST. I often run it on chrooted environment, so ability to work without having any /dev/crap is of paramount importance! sobomax: Ughh, no please no. If you want to add this complex procedure just to run mkuzip either make it… | |||||
rewAuthorUnsubmitted Done Inline ActionsShould the "run the image like a shell script" feature just be dropped? The shell shebang and compression type will have to stay intact to remain compatible with the kernel. And then remove the documentation that references the shell script in the first part of the uzip image. Let me know and I'll update this review to either drop the feature or to have build_header() always succeed. rew: Should the "run the image like a shell script" feature just be dropped?
The shell shebang and… | |||||
sobomaxUnsubmitted Not Done Inline ActionsMaking it always succeed and reverting to a pre-baked default is fine with me. As long as it does not cause any corruption to the generated image or weird result code. :) sobomax: Making it always succeed and reverting to a pre-baked default is fine with me. As long as it… | |||||
| if (cfs.en_dedup != 0) { | if (cfs.en_dedup != 0) { | ||||
| /* | /* | ||||
| * Dedupe requires a version 3 format. Don't downgrade newer | * Dedupe requires a version 3 format. Don't downgrade newer | ||||
| * formats. | * formats. | ||||
| */ | */ | ||||
| if (hdr.magic[CLOOP_OFS_VERSN] == CLOOP_MAJVER_2) | if (hdr.magic[CLOOP_OFS_VERSN] == CLOOP_MAJVER_2) | ||||
| hdr.magic[CLOOP_OFS_VERSN] = CLOOP_MAJVER_3; | hdr.magic[CLOOP_OFS_VERSN] = CLOOP_MAJVER_3; | ||||
| ▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines | |||||
What if the user didn't specify a mountpoint? (same applies to cd9660 and msdosfs)