Loading toolbox/newfs_msdos.c +617 −646 Original line number Diff line number Diff line Loading @@ -223,8 +223,7 @@ static const u_int8_t bootcode[] = { static void check_mounted(const char *, mode_t); static void getstdfmt(const char *, struct bpb *); static void getdiskinfo(int, const char *, const char *, int, struct bpb *); static void getdiskinfo(int, const char *, const char *, int, struct bpb *); static void print_bpb(struct bpb *); static u_int ckgeom(const char *, u_int, const char *); static u_int argtou(const char *, u_int, u_int, const char *); Loading @@ -237,8 +236,7 @@ static void usage(void); /* * Construct a FAT12, FAT16, or FAT32 file system. */ int newfs_msdos_main(int argc, char *argv[]) int newfs_msdos_main(int argc, char *argv[]) { static const char opts[] = "@:NB:C:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:u:"; const char *opt_B = NULL, *opt_L = NULL, *opt_O = NULL, *opt_f = NULL; Loading Loading @@ -280,9 +278,7 @@ newfs_msdos_main(int argc, char *argv[]) opt_create = argtooff(optarg, "create size"); break; case 'F': if (strcmp(optarg, "12") && strcmp(optarg, "16") && strcmp(optarg, "32")) if (strcmp(optarg, "12") && strcmp(optarg, "16") && strcmp(optarg, "32")) errx(1, "%s: bad FAT type", optarg); opt_F = atoi(optarg); break; Loading Loading @@ -455,8 +451,7 @@ newfs_msdos_main(int argc, char *argv[]) errx(1, "block size (%u) is too small; minimum is %u", opt_b, bpb.bps); if (opt_b > bpb.bps * MAXSPC) errx(1, "block size (%u) is too large; maximum is %u", opt_b, bpb.bps * MAXSPC); errx(1, "block size (%u) is too large; maximum is %u", opt_b, bpb.bps * MAXSPC); bpb.spc = opt_b / bpb.bps; } if (opt_c) { Loading @@ -468,8 +463,7 @@ newfs_msdos_main(int argc, char *argv[]) bpb.res = opt_r; if (opt_n) { if (opt_n > MAXNFT) errx(1, "number of FATs (%u) is too large; maximum is %u", opt_n, MAXNFT); errx(1, "number of FATs (%u) is too large; maximum is %u", opt_n, MAXNFT); bpb.nft = opt_n; } if (opt_e) Loading Loading @@ -567,8 +561,7 @@ newfs_msdos_main(int argc, char *argv[]) x1 += x * bpb.nft; x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB / (bpb.spc * bpb.bps * NPB + fat / BPN * bpb.nft); x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), bpb.bps * NPB); x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), bpb.bps * NPB); if (!bpb.bspf) { bpb.bspf = x2; x1 += (bpb.bspf - 1) * bpb.nft; Loading @@ -578,20 +571,16 @@ newfs_msdos_main(int argc, char *argv[]) if (cls > x) cls = x; if (bpb.bspf < x2) warnx("warning: sectors/FAT limits file system to %u clusters", cls); warnx("warning: sectors/FAT limits file system to %u clusters", cls); if (cls < mincls(fat)) errx(1, "%u clusters too few clusters for FAT%u, need %u", cls, fat, mincls(fat)); errx(1, "%u clusters too few clusters for FAT%u, need %u", cls, fat, mincls(fat)); if (cls > maxcls(fat)) { cls = maxcls(fat); bpb.bsec = x1 + (cls + 1) * bpb.spc - 1; warnx("warning: FAT type limits file system to %u sectors", bpb.bsec); warnx("warning: FAT type limits file system to %u sectors", bpb.bsec); } printf("%s: %u sector%s in %u FAT%u cluster%s " "(%u bytes/cluster)\n", fname, cls * bpb.spc, cls * bpb.spc == 1 ? "" : "s", cls, fat, printf("%s: %u sector%s in %u FAT%u cluster%s (%u bytes/cluster)\n", fname, cls * bpb.spc, cls * bpb.spc == 1 ? "" : "s", cls, fat, cls == 1 ? "" : "s", bpb.bps * bpb.spc); if (!bpb.mid) bpb.mid = !bpb.hid ? 0xf0 : 0xf8; Loading @@ -615,9 +604,7 @@ newfs_msdos_main(int argc, char *argv[]) dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { x = lsn; if (opt_B && fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { if (opt_B && fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { x -= bpb.bkbs; if (!x && lseek(fd1, opt_ofs, SEEK_SET)) err(1, "%s", bname); Loading @@ -629,8 +616,7 @@ newfs_msdos_main(int argc, char *argv[]) errx(1, "%s: can't read sector %u", bname, x); } else memset(img, 0, bpb.bps); if (!lsn || (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { if (!lsn || (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { x1 = sizeof(struct bs); bsbpb = (struct bsbpb *)(img + x1); mk2(bsbpb->bps, bpb.bps); Loading Loading @@ -684,8 +670,7 @@ newfs_msdos_main(int argc, char *argv[]) mk2(img + MINBPS - 2, DOSMAGIC); } } else if (fat == 32 && bpb.infs != MAXU16 && (lsn == bpb.infs || (bpb.bkbs != MAXU16 && (lsn == bpb.infs || (bpb.bkbs != MAXU16 && lsn == bpb.bkbs + bpb.infs))) { mk4(img, 0x41615252); mk4(img + MINBPS - 28, 0x61417272); Loading @@ -693,8 +678,7 @@ newfs_msdos_main(int argc, char *argv[]) mk4(img + MINBPS - 20, bpb.rdcl); mk2(img + MINBPS - 2, DOSMAGIC); } else if (lsn >= bpb.res && lsn < dir && !((lsn - bpb.res) % (bpb.spf ? bpb.spf : bpb.bspf))) { !((lsn - bpb.res) % (bpb.spf ? bpb.spf : bpb.bspf))) { mk1(img[0], bpb.mid); for (x = 1; x < fat * (fat == 32 ? 3 : 2) / 8; x++) mk1(img[x], fat == 32 && x % 4 == 3 ? 0x0f : 0xff); Loading Loading @@ -725,8 +709,7 @@ newfs_msdos_main(int argc, char *argv[]) /* * Exit with error if file system is mounted. */ static void check_mounted(const char *fname, mode_t mode) static void check_mounted(const char *fname, mode_t mode) { #ifdef ANDROID warnx("Skipping mount checks"); Loading @@ -747,8 +730,7 @@ check_mounted(const char *fname, mode_t mode) s2 = mp->f_mntfromname; if (!strncmp(s2, _PATH_DEV, len)) s2 += len; if ((r && s2 != mp->f_mntfromname && !strcmp(s1 + 1, s2)) || !strcmp(s1, s2)) if ((r && s2 != mp->f_mntfromname && !strcmp(s1 + 1, s2)) || !strcmp(s1, s2)) errx(1, "%s is mounted on %s", fname, mp->f_mntonname); } #endif Loading @@ -757,8 +739,7 @@ check_mounted(const char *fname, mode_t mode) /* * Get a standard format. */ static void getstdfmt(const char *fmt, struct bpb *bpb) static void getstdfmt(const char *fmt, struct bpb *bpb) { u_int x, i; Loading @@ -774,9 +755,8 @@ getstdfmt(const char *fmt, struct bpb *bpb) */ #ifdef ANDROID static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag,struct bpb *bpb) { struct hd_geometry geom; Loading Loading @@ -817,9 +797,8 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, #else static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) { struct disklabel *lp, dlp; struct fd_type type; Loading Loading @@ -899,8 +878,7 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, /* * Print out BPB values. */ static void print_bpb(struct bpb *bpb) static void print_bpb(struct bpb *bpb) { printf("bps=%u spc=%u res=%u nft=%u", bpb->bps, bpb->spc, bpb->res, bpb->nft); Loading @@ -927,8 +905,7 @@ print_bpb(struct bpb *bpb) /* * Check a disk geometry value. */ static u_int ckgeom(const char *fname, u_int val, const char *msg) static u_int ckgeom(const char *fname, u_int val, const char *msg) { if (!val) errx(1, "%s: no default %s", fname, msg); Loading @@ -940,8 +917,7 @@ ckgeom(const char *fname, u_int val, const char *msg) /* * Convert and check a numeric option argument. */ static u_int argtou(const char *arg, u_int lo, u_int hi, const char *msg) static u_int argtou(const char *arg, u_int lo, u_int hi, const char *msg) { char *s; u_long x; Loading @@ -956,8 +932,7 @@ argtou(const char *arg, u_int lo, u_int hi, const char *msg) /* * Same for off_t, with optional skmgpP suffix */ static off_t argtooff(const char *arg, const char *msg) static off_t argtooff(const char *arg, const char *msg) { char *s; off_t x; Loading Loading @@ -1006,8 +981,7 @@ argtooff(const char *arg, const char *msg) /* * Check a volume label. */ static int oklabel(const char *src) static int oklabel(const char *src) { int c, i; Loading @@ -1022,8 +996,7 @@ oklabel(const char *src) /* * Make a volume label. */ static void mklabel(u_int8_t *dest, const char *src) static void mklabel(u_int8_t *dest, const char *src) { int c, i; Loading @@ -1036,8 +1009,7 @@ mklabel(u_int8_t *dest, const char *src) /* * Copy string, padding with spaces. */ static void setstr(u_int8_t *dest, const char *src, size_t len) static void setstr(u_int8_t *dest, const char *src, size_t len) { while (len--) *dest++ = *src ? *src++ : ' '; Loading @@ -1046,8 +1018,7 @@ setstr(u_int8_t *dest, const char *src, size_t len) /* * Print usage message. */ static void usage(void) static void usage(void) { fprintf(stderr, "usage: newfs_msdos [ -options ] special [disktype]\n" Loading Loading
toolbox/newfs_msdos.c +617 −646 Original line number Diff line number Diff line Loading @@ -223,8 +223,7 @@ static const u_int8_t bootcode[] = { static void check_mounted(const char *, mode_t); static void getstdfmt(const char *, struct bpb *); static void getdiskinfo(int, const char *, const char *, int, struct bpb *); static void getdiskinfo(int, const char *, const char *, int, struct bpb *); static void print_bpb(struct bpb *); static u_int ckgeom(const char *, u_int, const char *); static u_int argtou(const char *, u_int, u_int, const char *); Loading @@ -237,8 +236,7 @@ static void usage(void); /* * Construct a FAT12, FAT16, or FAT32 file system. */ int newfs_msdos_main(int argc, char *argv[]) int newfs_msdos_main(int argc, char *argv[]) { static const char opts[] = "@:NB:C:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:u:"; const char *opt_B = NULL, *opt_L = NULL, *opt_O = NULL, *opt_f = NULL; Loading Loading @@ -280,9 +278,7 @@ newfs_msdos_main(int argc, char *argv[]) opt_create = argtooff(optarg, "create size"); break; case 'F': if (strcmp(optarg, "12") && strcmp(optarg, "16") && strcmp(optarg, "32")) if (strcmp(optarg, "12") && strcmp(optarg, "16") && strcmp(optarg, "32")) errx(1, "%s: bad FAT type", optarg); opt_F = atoi(optarg); break; Loading Loading @@ -455,8 +451,7 @@ newfs_msdos_main(int argc, char *argv[]) errx(1, "block size (%u) is too small; minimum is %u", opt_b, bpb.bps); if (opt_b > bpb.bps * MAXSPC) errx(1, "block size (%u) is too large; maximum is %u", opt_b, bpb.bps * MAXSPC); errx(1, "block size (%u) is too large; maximum is %u", opt_b, bpb.bps * MAXSPC); bpb.spc = opt_b / bpb.bps; } if (opt_c) { Loading @@ -468,8 +463,7 @@ newfs_msdos_main(int argc, char *argv[]) bpb.res = opt_r; if (opt_n) { if (opt_n > MAXNFT) errx(1, "number of FATs (%u) is too large; maximum is %u", opt_n, MAXNFT); errx(1, "number of FATs (%u) is too large; maximum is %u", opt_n, MAXNFT); bpb.nft = opt_n; } if (opt_e) Loading Loading @@ -567,8 +561,7 @@ newfs_msdos_main(int argc, char *argv[]) x1 += x * bpb.nft; x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB / (bpb.spc * bpb.bps * NPB + fat / BPN * bpb.nft); x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), bpb.bps * NPB); x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), bpb.bps * NPB); if (!bpb.bspf) { bpb.bspf = x2; x1 += (bpb.bspf - 1) * bpb.nft; Loading @@ -578,20 +571,16 @@ newfs_msdos_main(int argc, char *argv[]) if (cls > x) cls = x; if (bpb.bspf < x2) warnx("warning: sectors/FAT limits file system to %u clusters", cls); warnx("warning: sectors/FAT limits file system to %u clusters", cls); if (cls < mincls(fat)) errx(1, "%u clusters too few clusters for FAT%u, need %u", cls, fat, mincls(fat)); errx(1, "%u clusters too few clusters for FAT%u, need %u", cls, fat, mincls(fat)); if (cls > maxcls(fat)) { cls = maxcls(fat); bpb.bsec = x1 + (cls + 1) * bpb.spc - 1; warnx("warning: FAT type limits file system to %u sectors", bpb.bsec); warnx("warning: FAT type limits file system to %u sectors", bpb.bsec); } printf("%s: %u sector%s in %u FAT%u cluster%s " "(%u bytes/cluster)\n", fname, cls * bpb.spc, cls * bpb.spc == 1 ? "" : "s", cls, fat, printf("%s: %u sector%s in %u FAT%u cluster%s (%u bytes/cluster)\n", fname, cls * bpb.spc, cls * bpb.spc == 1 ? "" : "s", cls, fat, cls == 1 ? "" : "s", bpb.bps * bpb.spc); if (!bpb.mid) bpb.mid = !bpb.hid ? 0xf0 : 0xf8; Loading @@ -615,9 +604,7 @@ newfs_msdos_main(int argc, char *argv[]) dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { x = lsn; if (opt_B && fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { if (opt_B && fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { x -= bpb.bkbs; if (!x && lseek(fd1, opt_ofs, SEEK_SET)) err(1, "%s", bname); Loading @@ -629,8 +616,7 @@ newfs_msdos_main(int argc, char *argv[]) errx(1, "%s: can't read sector %u", bname, x); } else memset(img, 0, bpb.bps); if (!lsn || (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { if (!lsn || (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { x1 = sizeof(struct bs); bsbpb = (struct bsbpb *)(img + x1); mk2(bsbpb->bps, bpb.bps); Loading Loading @@ -684,8 +670,7 @@ newfs_msdos_main(int argc, char *argv[]) mk2(img + MINBPS - 2, DOSMAGIC); } } else if (fat == 32 && bpb.infs != MAXU16 && (lsn == bpb.infs || (bpb.bkbs != MAXU16 && (lsn == bpb.infs || (bpb.bkbs != MAXU16 && lsn == bpb.bkbs + bpb.infs))) { mk4(img, 0x41615252); mk4(img + MINBPS - 28, 0x61417272); Loading @@ -693,8 +678,7 @@ newfs_msdos_main(int argc, char *argv[]) mk4(img + MINBPS - 20, bpb.rdcl); mk2(img + MINBPS - 2, DOSMAGIC); } else if (lsn >= bpb.res && lsn < dir && !((lsn - bpb.res) % (bpb.spf ? bpb.spf : bpb.bspf))) { !((lsn - bpb.res) % (bpb.spf ? bpb.spf : bpb.bspf))) { mk1(img[0], bpb.mid); for (x = 1; x < fat * (fat == 32 ? 3 : 2) / 8; x++) mk1(img[x], fat == 32 && x % 4 == 3 ? 0x0f : 0xff); Loading Loading @@ -725,8 +709,7 @@ newfs_msdos_main(int argc, char *argv[]) /* * Exit with error if file system is mounted. */ static void check_mounted(const char *fname, mode_t mode) static void check_mounted(const char *fname, mode_t mode) { #ifdef ANDROID warnx("Skipping mount checks"); Loading @@ -747,8 +730,7 @@ check_mounted(const char *fname, mode_t mode) s2 = mp->f_mntfromname; if (!strncmp(s2, _PATH_DEV, len)) s2 += len; if ((r && s2 != mp->f_mntfromname && !strcmp(s1 + 1, s2)) || !strcmp(s1, s2)) if ((r && s2 != mp->f_mntfromname && !strcmp(s1 + 1, s2)) || !strcmp(s1, s2)) errx(1, "%s is mounted on %s", fname, mp->f_mntonname); } #endif Loading @@ -757,8 +739,7 @@ check_mounted(const char *fname, mode_t mode) /* * Get a standard format. */ static void getstdfmt(const char *fmt, struct bpb *bpb) static void getstdfmt(const char *fmt, struct bpb *bpb) { u_int x, i; Loading @@ -774,9 +755,8 @@ getstdfmt(const char *fmt, struct bpb *bpb) */ #ifdef ANDROID static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag,struct bpb *bpb) { struct hd_geometry geom; Loading Loading @@ -817,9 +797,8 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, #else static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) static void getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) { struct disklabel *lp, dlp; struct fd_type type; Loading Loading @@ -899,8 +878,7 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, /* * Print out BPB values. */ static void print_bpb(struct bpb *bpb) static void print_bpb(struct bpb *bpb) { printf("bps=%u spc=%u res=%u nft=%u", bpb->bps, bpb->spc, bpb->res, bpb->nft); Loading @@ -927,8 +905,7 @@ print_bpb(struct bpb *bpb) /* * Check a disk geometry value. */ static u_int ckgeom(const char *fname, u_int val, const char *msg) static u_int ckgeom(const char *fname, u_int val, const char *msg) { if (!val) errx(1, "%s: no default %s", fname, msg); Loading @@ -940,8 +917,7 @@ ckgeom(const char *fname, u_int val, const char *msg) /* * Convert and check a numeric option argument. */ static u_int argtou(const char *arg, u_int lo, u_int hi, const char *msg) static u_int argtou(const char *arg, u_int lo, u_int hi, const char *msg) { char *s; u_long x; Loading @@ -956,8 +932,7 @@ argtou(const char *arg, u_int lo, u_int hi, const char *msg) /* * Same for off_t, with optional skmgpP suffix */ static off_t argtooff(const char *arg, const char *msg) static off_t argtooff(const char *arg, const char *msg) { char *s; off_t x; Loading Loading @@ -1006,8 +981,7 @@ argtooff(const char *arg, const char *msg) /* * Check a volume label. */ static int oklabel(const char *src) static int oklabel(const char *src) { int c, i; Loading @@ -1022,8 +996,7 @@ oklabel(const char *src) /* * Make a volume label. */ static void mklabel(u_int8_t *dest, const char *src) static void mklabel(u_int8_t *dest, const char *src) { int c, i; Loading @@ -1036,8 +1009,7 @@ mklabel(u_int8_t *dest, const char *src) /* * Copy string, padding with spaces. */ static void setstr(u_int8_t *dest, const char *src, size_t len) static void setstr(u_int8_t *dest, const char *src, size_t len) { while (len--) *dest++ = *src ? *src++ : ' '; Loading @@ -1046,8 +1018,7 @@ setstr(u_int8_t *dest, const char *src, size_t len) /* * Print usage message. */ static void usage(void) static void usage(void) { fprintf(stderr, "usage: newfs_msdos [ -options ] special [disktype]\n" Loading