Lines Matching refs:bpb

155 struct bpb {  struct
178 struct bpb bpb; argument
225 static void getstdfmt(const char *, struct bpb *);
226 static void getdiskinfo(int, const char *, const char *, int, struct bpb *);
227 static void print_bpb(struct bpb *);
252 struct bpb bpb; in newfs_msdos_main() local
396 memset(&bpb, 0, sizeof(bpb)); in newfs_msdos_main()
398 getstdfmt(opt_f, &bpb); in newfs_msdos_main()
399 bpb.bsec = bpb.sec; in newfs_msdos_main()
400 bpb.sec = 0; in newfs_msdos_main()
401 bpb.bspf = bpb.spf; in newfs_msdos_main()
402 bpb.spf = 0; in newfs_msdos_main()
405 bpb.hds = opt_h; in newfs_msdos_main()
407 bpb.spt = opt_u; in newfs_msdos_main()
409 bpb.bps = opt_S; in newfs_msdos_main()
411 bpb.bsec = opt_s; in newfs_msdos_main()
413 bpb.hid = opt_o; in newfs_msdos_main()
416 getdiskinfo(fd, fname, dtype, oflag, &bpb); in newfs_msdos_main()
418 bpb.bsec = opt_s; in newfs_msdos_main()
420 bpb.bsec -= (opt_ofs / bpb.bps); in newfs_msdos_main()
421 delta = bpb.bsec % bpb.spt; in newfs_msdos_main()
424 (int)delta, bpb.bsec, bpb.spt); in newfs_msdos_main()
425 bpb.bsec -= delta; in newfs_msdos_main()
427 if (bpb.spc == 0) { /* set defaults */ in newfs_msdos_main()
428 if (bpb.bsec <= 6000) /* about 3MB -> 512 bytes */ in newfs_msdos_main()
429 bpb.spc = 1; in newfs_msdos_main()
430 else if (bpb.bsec <= (1<<17)) /* 64M -> 4k */ in newfs_msdos_main()
431 bpb.spc = 8; in newfs_msdos_main()
432 else if (bpb.bsec <= (1<<19)) /* 256M -> 8k */ in newfs_msdos_main()
433 bpb.spc = 16; in newfs_msdos_main()
434 else if (bpb.bsec <= (1<<22)) /* 2G -> 16k, some versions of windows in newfs_msdos_main()
436 bpb.spc = 32; in newfs_msdos_main()
438 bpb.spc = 64; /* otherwise 32k */ in newfs_msdos_main()
441 if (!powerof2(bpb.bps)) in newfs_msdos_main()
442 errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps); in newfs_msdos_main()
443 if (bpb.bps < MINBPS) in newfs_msdos_main()
445 bpb.bps, MINBPS); in newfs_msdos_main()
457 bpb.rde = 0; in newfs_msdos_main()
461 if (opt_b < bpb.bps) in newfs_msdos_main()
463 opt_b, bpb.bps); in newfs_msdos_main()
464 if (opt_b > bpb.bps * MAXSPC) in newfs_msdos_main()
465 errx(1, "block size (%u) is too large; maximum is %u", opt_b, bpb.bps * MAXSPC); in newfs_msdos_main()
466 bpb.spc = opt_b / bpb.bps; in newfs_msdos_main()
471 bpb.spc = opt_c; in newfs_msdos_main()
474 bpb.res = opt_r; in newfs_msdos_main()
478 bpb.nft = opt_n; in newfs_msdos_main()
481 bpb.rde = opt_e; in newfs_msdos_main()
485 bpb.mid = opt_m; in newfs_msdos_main()
488 bpb.bspf = opt_a; in newfs_msdos_main()
490 bpb.infs = opt_i; in newfs_msdos_main()
492 bpb.bkbs = opt_k; in newfs_msdos_main()
505 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bps || in newfs_msdos_main()
506 sb.st_size < bpb.bps || sb.st_size > bpb.bps * MAXU16) in newfs_msdos_main()
508 bss = sb.st_size / bpb.bps; in newfs_msdos_main()
510 if (!bpb.nft) in newfs_msdos_main()
511 bpb.nft = 2; in newfs_msdos_main()
513 if (bpb.bsec < (bpb.res ? bpb.res : bss) + in newfs_msdos_main()
514 howmany((RESFTE + (bpb.spc ? MINCLS16 : MAXCLS12 + 1)) * in newfs_msdos_main()
515 ((bpb.spc ? 16 : 12) / BPN), bpb.bps * NPB) * in newfs_msdos_main()
516 bpb.nft + in newfs_msdos_main()
517 howmany(bpb.rde ? bpb.rde : DEFRDE, in newfs_msdos_main()
518 bpb.bps / sizeof(struct de)) + in newfs_msdos_main()
519 (bpb.spc ? MINCLS16 : MAXCLS12 + 1) * in newfs_msdos_main()
520 (bpb.spc ? bpb.spc : howmany(DEFBLK, bpb.bps))) in newfs_msdos_main()
522 else if (bpb.rde || bpb.bsec < in newfs_msdos_main()
523 (bpb.res ? bpb.res : bss) + in newfs_msdos_main()
524 howmany((RESFTE + MAXCLS16) * 2, bpb.bps) * bpb.nft + in newfs_msdos_main()
525 howmany(DEFRDE, bpb.bps / sizeof(struct de)) + in newfs_msdos_main()
527 (bpb.spc ? bpb.spc : howmany(8192, bpb.bps))) in newfs_msdos_main()
534 if (!bpb.infs) { in newfs_msdos_main()
535 if (x == MAXU16 || x == bpb.bkbs) in newfs_msdos_main()
537 bpb.infs = x; in newfs_msdos_main()
539 if (bpb.infs != MAXU16 && x <= bpb.infs) in newfs_msdos_main()
540 x = bpb.infs + 1; in newfs_msdos_main()
541 if (!bpb.bkbs) { in newfs_msdos_main()
544 bpb.bkbs = x; in newfs_msdos_main()
545 } else if (bpb.bkbs != MAXU16 && bpb.bkbs == bpb.infs) in newfs_msdos_main()
547 if (bpb.bkbs != MAXU16 && x <= bpb.bkbs) in newfs_msdos_main()
548 x = bpb.bkbs + 1; in newfs_msdos_main()
552 set_res = !bpb.res; in newfs_msdos_main()
553 set_spf = !bpb.bspf; in newfs_msdos_main()
554 set_spc = !bpb.spc; in newfs_msdos_main()
567 bpb.res = (fat == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x) + extra_res; in newfs_msdos_main()
568 else if (bpb.res < x) in newfs_msdos_main()
570 if (fat != 32 && !bpb.rde) in newfs_msdos_main()
571 bpb.rde = DEFRDE; in newfs_msdos_main()
572 rds = howmany(bpb.rde, bpb.bps / sizeof(struct de)); in newfs_msdos_main()
574 for (bpb.spc = howmany(fat == 16 ? DEFBLK16 : DEFBLK, bpb.bps); in newfs_msdos_main()
575 bpb.spc < MAXSPC && in newfs_msdos_main()
576 bpb.res + in newfs_msdos_main()
578 bpb.bps * NPB) * bpb.nft + in newfs_msdos_main()
580 (u_int64_t)(maxcls(fat) + 1) * bpb.spc <= bpb.bsec; in newfs_msdos_main()
581 bpb.spc <<= 1); in newfs_msdos_main()
582 if (fat != 32 && bpb.bspf > MAXU16) in newfs_msdos_main()
584 x1 = bpb.res + rds; in newfs_msdos_main()
585 x = bpb.bspf ? bpb.bspf : 1; in newfs_msdos_main()
586 if (x1 + (u_int64_t)x * bpb.nft > bpb.bsec) in newfs_msdos_main()
588 x1 += x * bpb.nft; in newfs_msdos_main()
589 x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB / in newfs_msdos_main()
590 (bpb.spc * bpb.bps * NPB + fat / BPN * bpb.nft); in newfs_msdos_main()
591 x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), bpb.bps * NPB); in newfs_msdos_main()
593 if (!bpb.bspf) { in newfs_msdos_main()
594 bpb.bspf = x2; in newfs_msdos_main()
596 x1 += (bpb.bspf - 1) * bpb.nft; in newfs_msdos_main()
600 alignment = (bpb.res + bpb.bspf * bpb.nft) % bpb.spc; in newfs_msdos_main()
601 extra_res += bpb.spc - alignment; in newfs_msdos_main()
608 cls = (bpb.bsec - x1) / bpb.spc; in newfs_msdos_main()
609 x = (u_int64_t)bpb.bspf * bpb.bps * NPB / (fat / BPN) - RESFTE; in newfs_msdos_main()
612 if (bpb.bspf < x2) in newfs_msdos_main()
618 bpb.bsec = x1 + (cls + 1) * bpb.spc - 1; in newfs_msdos_main()
619 warnx("warning: FAT type limits file system to %u sectors", bpb.bsec); in newfs_msdos_main()
622 fname, cls * bpb.spc, cls * bpb.spc == 1 ? "" : "s", cls, fat, in newfs_msdos_main()
623 cls == 1 ? "" : "s", bpb.bps * bpb.spc); in newfs_msdos_main()
624 if (!bpb.mid) in newfs_msdos_main()
625 bpb.mid = !bpb.hid ? 0xf0 : 0xf8; in newfs_msdos_main()
627 bpb.rdcl = RESFTE; in newfs_msdos_main()
628 if (bpb.hid + bpb.bsec <= MAXU16) { in newfs_msdos_main()
629 bpb.sec = bpb.bsec; in newfs_msdos_main()
630 bpb.bsec = 0; in newfs_msdos_main()
633 bpb.spf = bpb.bspf; in newfs_msdos_main()
634 bpb.bspf = 0; in newfs_msdos_main()
636 print_bpb(&bpb); in newfs_msdos_main()
641 if (!(img = malloc(bpb.bps))) in newfs_msdos_main()
642 err(1, "%u", bpb.bps); in newfs_msdos_main()
643 dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; in newfs_msdos_main()
644 for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { in newfs_msdos_main()
646 if (opt_B && fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { in newfs_msdos_main()
647 x -= bpb.bkbs; in newfs_msdos_main()
652 if ((n = read(fd1, img, bpb.bps)) == -1) in newfs_msdos_main()
654 if ((unsigned)n != bpb.bps) in newfs_msdos_main()
657 memset(img, 0, bpb.bps); in newfs_msdos_main()
658 if (!lsn || (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { in newfs_msdos_main()
661 mk2(bsbpb->bps, bpb.bps); in newfs_msdos_main()
662 mk1(bsbpb->spc, bpb.spc); in newfs_msdos_main()
663 mk2(bsbpb->res, bpb.res); in newfs_msdos_main()
664 mk1(bsbpb->nft, bpb.nft); in newfs_msdos_main()
665 mk2(bsbpb->rde, bpb.rde); in newfs_msdos_main()
666 mk2(bsbpb->sec, bpb.sec); in newfs_msdos_main()
667 mk1(bsbpb->mid, bpb.mid); in newfs_msdos_main()
668 mk2(bsbpb->spf, bpb.spf); in newfs_msdos_main()
669 mk2(bsbpb->spt, bpb.spt); in newfs_msdos_main()
670 mk2(bsbpb->hds, bpb.hds); in newfs_msdos_main()
671 mk4(bsbpb->hid, bpb.hid); in newfs_msdos_main()
672 mk4(bsbpb->bsec, bpb.bsec); in newfs_msdos_main()
676 mk4(bsxbpb->bspf, bpb.bspf); in newfs_msdos_main()
679 mk4(bsxbpb->rdcl, bpb.rdcl); in newfs_msdos_main()
680 mk2(bsxbpb->infs, bpb.infs); in newfs_msdos_main()
681 mk2(bsxbpb->bkbs, bpb.bkbs); in newfs_msdos_main()
711 } else if (fat == 32 && bpb.infs != MAXU16 && in newfs_msdos_main()
712 (lsn == bpb.infs || (bpb.bkbs != MAXU16 && in newfs_msdos_main()
713 lsn == bpb.bkbs + bpb.infs))) { in newfs_msdos_main()
717 mk4(img + MINBPS - 20, bpb.rdcl); in newfs_msdos_main()
719 } else if (lsn >= bpb.res && lsn < dir && in newfs_msdos_main()
720 !((lsn - bpb.res) % (bpb.spf ? bpb.spf : bpb.bspf))) { in newfs_msdos_main()
721 mk1(img[0], bpb.mid); in newfs_msdos_main()
737 if ((n = write(fd, img, bpb.bps)) == -1) in newfs_msdos_main()
739 if ((unsigned)n != bpb.bps) { in newfs_msdos_main()
781 static void getstdfmt(const char *fmt, struct bpb *bpb) in getstdfmt() argument
789 *bpb = stdfmt[i].bpb; in getstdfmt()
798 __unused int oflag,struct bpb *bpb) in getdiskinfo() argument
803 if (ioctl(fd, BLKSSZGET, &bpb->bps)) { in getdiskinfo()
808 ckgeom(fname, bpb->bps, "bytes/sector"); in getdiskinfo()
820 bpb->bsec = (u_int)block_size; in getdiskinfo()
838 bpb->spt = geom.sectors; in getdiskinfo()
839 ckgeom(fname, bpb->spt, "sectors/track"); in getdiskinfo()
841 bpb->hds = geom.heads; in getdiskinfo()
842 ckgeom(fname, bpb->hds, "drive heads"); in getdiskinfo()
848 __unused int oflag, struct bpb *bpb) in getdiskinfo() argument
887 if (bpb->bps == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1) in getdiskinfo()
893 if (bpb->spt == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) { in getdiskinfo()
897 if (bpb->hds == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { in getdiskinfo()
912 if (bpb->bps == 0) in getdiskinfo()
913 bpb->bps = ckgeom(fname, lp->d_secsize, "bytes/sector"); in getdiskinfo()
914 if (bpb->spt == 0) in getdiskinfo()
915 bpb->spt = ckgeom(fname, lp->d_nsectors, "sectors/track"); in getdiskinfo()
916 if (bpb->hds == 0) in getdiskinfo()
917 bpb->hds = ckgeom(fname, lp->d_ntracks, "drive heads"); in getdiskinfo()
918 if (bpb->bsec == 0) in getdiskinfo()
919 bpb->bsec = lp->d_secperunit; in getdiskinfo()
920 if (bpb->hid == 0) in getdiskinfo()
921 bpb->hid = hs; in getdiskinfo()
928 static void print_bpb(struct bpb *bpb) in print_bpb() argument
930 printf("bps=%u spc=%u res=%u nft=%u", bpb->bps, bpb->spc, bpb->res, in print_bpb()
931 bpb->nft); in print_bpb()
932 if (bpb->rde) in print_bpb()
933 printf(" rde=%u", bpb->rde); in print_bpb()
934 if (bpb->sec) in print_bpb()
935 printf(" sec=%u", bpb->sec); in print_bpb()
936 printf(" mid=%#x", bpb->mid); in print_bpb()
937 if (bpb->spf) in print_bpb()
938 printf(" spf=%u", bpb->spf); in print_bpb()
939 printf(" spt=%u hds=%u hid=%u", bpb->spt, bpb->hds, bpb->hid); in print_bpb()
940 if (bpb->bsec) in print_bpb()
941 printf(" bsec=%u", bpb->bsec); in print_bpb()
942 if (!bpb->spf) { in print_bpb()
943 printf(" bspf=%u rdcl=%u", bpb->bspf, bpb->rdcl); in print_bpb()
945 printf(bpb->infs == MAXU16 ? "%#x" : "%u", bpb->infs); in print_bpb()
947 printf(bpb->bkbs == MAXU16 ? "%#x" : "%u", bpb->bkbs); in print_bpb()