Home | History | Annotate | Download | only in newfs_msdos

Lines Matching defs:bpb

162 struct bpb {
186 struct bpb bpb;
237 static int getstdfmt(const char *, struct bpb *);
238 static int getbpbinfo(int, const char *, const char *, int, struct bpb *, off_t);
239 static void print_bpb(struct bpb *);
252 struct bpb bpb;
315 memset(&bpb, 0, sizeof(bpb));
317 if (getstdfmt(o.floppy, &bpb) == -1)
319 bpb.bsec = bpb.sec;
320 bpb.sec = 0;
321 bpb.bspf = bpb.spf;
322 bpb.spf = 0;
325 bpb.hds = o.drive_heads;
327 bpb.spt = o.sectors_per_track;
329 bpb.bps = o.bytes_per_sector;
331 bpb.bsec = o.size;
333 bpb.hid = o.hidden_sectors;
336 if (getbpbinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb,
339 bpb.bsec -= (o.offset / bpb.bps);
340 if (bpb.spc == 0) { /* set defaults */
344 bpb.spc = 1; /* use 512 bytes */
348 bpb.spc = 1; /* use 512 bytes */
352 bpb.spc = 8; /* use 4k */
356 x1 = howmany(bpb.bsec, (1048576 / 512)); /* -> MB */
357 while (bpb.spc < 128 && x < x1) {
359 bpb.spc *= 2;
397 if (!powerof2(bpb.bps)) {
398 warnx("bytes/sector (%u) is not a power of 2", bpb.bps);
401 if (bpb.bps < MINBPS) {
403 bpb.bps, MINBPS);
408 bpb.rde = 0;
414 if (o.block_size < bpb.bps) {
416 o.block_size, bpb.bps);
419 if (o.block_size > bpb.bps * MAXSPC) {
421 o.block_size, bpb.bps * MAXSPC);
424 bpb.spc = o.block_size / bpb.bps;
432 bpb.spc = o.sectors_per_cluster;
435 bpb.res = o.reserved_sectors;
442 bpb.nft = o.num_FAT;
445 bpb.rde = o.directory_entries;
451 bpb.mid = o.media_descriptor;
454 bpb.bspf = o.sectors_per_fat;
456 bpb.infs = o.info_sector;
458 bpb.bkbs = o.backup_sector;
475 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bps ||
476 sb.st_size < bpb.bps || sb.st_size > bpb.bps * MAXU16) {
480 bss = sb.st_size / bpb.bps;
482 if (!bpb.nft)
483 bpb.nft = 2;
485 if (bpb.bsec < (bpb.res ? bpb.res : bss) +
486 howmany((RESFTE + (bpb.spc ? MINCLS16 : MAXCLS12 + 1)) *
487 ((bpb.spc ? 16 : 12) / BPN), bpb.bps * NPB) *
488 bpb.nft +
489 howmany(bpb.rde ? bpb.rde : DEFRDE,
490 bpb.bps / sizeof(struct de)) +
491 (bpb.spc ? MINCLS16 : MAXCLS12 + 1) *
492 (bpb.spc ? bpb.spc : howmany(DEFBLK, bpb.bps)))
494 else if (bpb.rde || bpb.bsec <
495 (bpb.res ? bpb.res : bss) +
496 howmany((RESFTE + MAXCLS16) * 2, bpb.bps) * bpb.nft +
497 howmany(DEFRDE, bpb.bps / sizeof(struct de)) +
499 (bpb.spc ? bpb.spc : howmany(8192, bpb.bps)))
506 if (!bpb.infs) {
507 if (x == MAXU16 || x == bpb.bkbs) {
511 bpb.infs = x;
513 if (bpb.infs != MAXU16 && x <= bpb.infs)
514 x = bpb.infs + 1;
515 if (!bpb.bkbs) {
520 bpb.bkbs = x;
521 } else if (bpb.bkbs != MAXU16 && bpb.bkbs == bpb.infs) {
525 if (bpb.bkbs != MAXU16 && x <= bpb.bkbs)
526 x = bpb.bkbs + 1;
528 if (!bpb.res)
529 bpb.res = o.fat_type == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x;
530 else if (bpb.res < x) {
531 warnx("too few reserved sectors (need %d have %d)", x, bpb.res);
534 if (o.fat_type != 32 && !bpb.rde)
535 bpb.rde = DEFRDE;
536 rds = howmany(bpb.rde, bpb.bps / sizeof(struct de));
537 if (!bpb.spc)
538 for (bpb.spc = howmany(o.fat_type == 16 ? DEFBLK16 : DEFBLK, bpb.bps);
539 bpb.spc < MAXSPC &&
540 bpb.res +
542 bpb.bps * NPB) * bpb.nft +
544 (u_int64_t)(maxcls(o.fat_type) + 1) * bpb.spc <= bpb.bsec;
545 bpb.spc <<= 1);
546 if (o.fat_type != 32 && bpb.bspf > MAXU16) {
550 x1 = bpb.res + rds;
551 x = bpb.bspf ? bpb.bspf : 1;
552 if (x1 + (u_int64_t)x * bpb.nft > bpb.bsec) {
556 x1 += x * bpb.nft;
557 x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB /
558 (bpb.spc * bpb.bps * NPB + o.fat_type / BPN * bpb.nft);
560 bpb.bps * NPB);
561 if (!bpb.bspf) {
563 bpb.bspf = x2;
564 x1 += (bpb.bspf - 1) * bpb.nft;
566 cls = (bpb.bsec - x1) / bpb.spc;
567 x = (u_int64_t)bpb.bspf * bpb.bps * NPB / (o.fat_type / BPN) - RESFTE;
570 if (bpb.bspf < x2) {
576 if (bspf_is_calculated && o.sectors_per_cluster == 0 && bpb.spc > 2) {
587 bpb.bsec = x1 + (cls + 1) * bpb.spc - 1;
589 bpb.bsec);
593 "(%u bytes/cluster)\n", fname, cls * bpb.spc,
594 cls * bpb.spc == 1 ? "" : "s", cls, o.fat_type,
595 cls == 1 ? "" : "s", bpb.bps * bpb.spc);
596 if (!bpb.mid)
597 bpb.mid = !bpb.hid ? 0xf0 : 0xf8;
599 bpb.rdcl = RESFTE;
600 if (bpb.hid + bpb.bsec <= MAXU16) {
601 bpb.sec = bpb.bsec;
602 bpb.bsec = 0;
605 bpb.spf = bpb.bspf;
606 bpb.bspf = 0;
612 if (bpb.bsec == 0)
631 print_bpb(&bpb);
642 if (!(img = malloc(bpb.bps)))
644 dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft;
648 for (lsn = 0; lsn < dir + (o.fat_type == 32 ? bpb.spc : rds); lsn++) {
651 fname,lsn,(dir + (o.fat_type == 32 ? bpb.spc : rds)),
652 (lsn*100)/(dir + (o.fat_type == 32 ? bpb.spc : rds)));
657 o.fat_type == 32 && bpb.bkbs != MAXU16 &&
658 bss <= bpb.bkbs && x >= bpb.bkbs) {
659 x -= bpb.bkbs;
666 if ((n = read(fd1, img, bpb.bps)) == -1) {
670 if ((size_t)n != bpb.bps) {
675 memset(img, 0, bpb.bps);
677 (o.fat_type == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) {
680 mk2(bsbpb->bps, bpb.bps);
681 mk1(bsbpb->spc, bpb.spc);
682 mk2(bsbpb->res, bpb.res);
683 mk1(bsbpb->nft, bpb.nft);
684 mk2(bsbpb->rde, bpb.rde);
685 mk2(bsbpb->sec, bpb.sec);
686 mk1(bsbpb->mid, bpb.mid);
687 mk2(bsbpb->spf, bpb.spf);
688 mk2(bsbpb->spt, bpb.spt);
689 mk2(bsbpb->hds, bpb.hds);
690 mk4(bsbpb->hid, bpb.hid);
691 mk4(bsbpb->bsec, bpb.bsec);
695 mk4(bsxbpb->bspf, bpb.bspf);
698 mk4(bsxbpb->rdcl, bpb.rdcl);
699 mk2(bsxbpb->infs, bpb.infs);
700 mk2(bsxbpb->bkbs, bpb.bkbs);
730 } else if (o.fat_type == 32 && bpb.infs != MAXU16 &&
731 (lsn == bpb.infs ||
732 (bpb.bkbs != MAXU16 &&
733 lsn == bpb.bkbs + bpb.infs))) {
739 } else if (lsn >= bpb.res && lsn < dir &&
740 !((lsn - bpb.res) %
741 (bpb.spf ? bpb.spf : bpb.bspf))) {
742 mk1(img[0], bpb.mid);
758 if ((n = write(fd, img, bpb.bps)) == -1) {
762 if ((size_t)n != bpb.bps) {
810 getstdfmt(const char *fmt, struct bpb *bpb)
820 *bpb = stdfmt[i].bpb;
829 struct bpb *bpb, off_t create_size)
856 if (!(((part != -1) && ((!iflag && part != -1) || !bpb->bsec)) ||
857 !bpb->bps || !bpb->spt || !bpb->hds)) {
888 if (!bpb->bps) {
891 bpb->bps = sector_size;
896 * The kernel doesn't accept BPB with spt > 63.
903 if (!bpb->spt) {
906 bpb->spt = nsectors;
908 if (!bpb->hds) {
911 bpb->hds = ntracks;
913 if (!bpb->bsec)
914 bpb->bsec = size;
920 * Print out BPB values.
923 print_bpb(struct bpb *bpb)
925 printf("bps=%u spc=%u res=%u nft=%u", bpb->bps, bpb->spc, bpb->res,
926 bpb->nft);
927 if (bpb->rde)
928 printf(" rde=%u", bpb->rde);
929 if (bpb->sec)
930 printf(" sec=%u", bpb->sec);
931 printf(" mid=%#x", bpb->mid);
932 if (bpb->spf)
933 printf(" spf=%u", bpb->spf);
934 printf(" spt=%u hds=%u hid=%u", bpb->spt, bpb->hds, bpb->hid);
935 if (bpb->bsec)
936 printf(" bsec=%u", bpb->bsec);
937 if (!bpb->spf) {
938 printf(" bspf=%u rdcl=%u", bpb->bspf, bpb->rdcl);
940 printf(bpb->infs == MAXU16 ? "%#x" : "%u", bpb->infs);
942 printf(bpb->bkbs == MAXU16 ? "%#x" : "%u", bpb->bkbs);