Lines Matching refs:bpb

160 struct bpb {  struct
183 struct bpb bpb; member
233 static int getstdfmt(const char *, struct bpb *);
234 static int getdiskinfo(int, const char *, const char *, int, struct bpb *);
235 static void print_bpb(struct bpb *);
248 struct bpb bpb; in mkfs_msdos() local
313 memset(&bpb, 0, sizeof(bpb)); in mkfs_msdos()
315 if (getstdfmt(o.floppy, &bpb) == -1) in mkfs_msdos()
317 bpb.bpbHugeSectors = bpb.bpbSectors; in mkfs_msdos()
318 bpb.bpbSectors = 0; in mkfs_msdos()
319 bpb.bpbBigFATsecs = bpb.bpbFATsecs; in mkfs_msdos()
320 bpb.bpbFATsecs = 0; in mkfs_msdos()
323 bpb.bpbHeads = o.drive_heads; in mkfs_msdos()
325 bpb.bpbSecPerTrack = o.sectors_per_track; in mkfs_msdos()
327 bpb.bpbBytesPerSec = o.bytes_per_sector; in mkfs_msdos()
329 bpb.bpbHugeSectors = o.size; in mkfs_msdos()
331 bpb.bpbHiddenSecs = o.hidden_sectors; in mkfs_msdos()
334 getdiskinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb); in mkfs_msdos()
335 bpb.bpbHugeSectors -= (o.offset / bpb.bpbBytesPerSec); in mkfs_msdos()
336 if (bpb.bpbSecPerClust == 0) { /* set defaults */ in mkfs_msdos()
337 if (bpb.bpbHugeSectors <= 6000) /* about 3MB -> 512 bytes */ in mkfs_msdos()
338 bpb.bpbSecPerClust = 1; in mkfs_msdos()
339 else if (bpb.bpbHugeSectors <= (1<<17)) /* 64M -> 4k */ in mkfs_msdos()
340 bpb.bpbSecPerClust = 8; in mkfs_msdos()
341 else if (bpb.bpbHugeSectors <= (1<<19)) /* 256M -> 8k */ in mkfs_msdos()
342 bpb.bpbSecPerClust = 16; in mkfs_msdos()
343 else if (bpb.bpbHugeSectors <= (1<<21)) /* 1G -> 16k */ in mkfs_msdos()
344 bpb.bpbSecPerClust = 32; in mkfs_msdos()
346 bpb.bpbSecPerClust = 64; /* otherwise 32k */ in mkfs_msdos()
349 if (!powerof2(bpb.bpbBytesPerSec)) { in mkfs_msdos()
350 warnx("bytes/sector (%u) is not a power of 2", bpb.bpbBytesPerSec); in mkfs_msdos()
353 if (bpb.bpbBytesPerSec < MINBPS) { in mkfs_msdos()
355 bpb.bpbBytesPerSec, MINBPS); in mkfs_msdos()
376 bpb.bpbRootDirEnts = 0; in mkfs_msdos()
387 if (o.block_size < bpb.bpbBytesPerSec) { in mkfs_msdos()
389 o.block_size, bpb.bpbBytesPerSec); in mkfs_msdos()
392 if (o.block_size > bpb.bpbBytesPerSec * MAXSPC) { in mkfs_msdos()
394 o.block_size, bpb.bpbBytesPerSec * MAXSPC); in mkfs_msdos()
397 bpb.bpbSecPerClust = o.block_size / bpb.bpbBytesPerSec; in mkfs_msdos()
405 bpb.bpbSecPerClust = o.sectors_per_cluster; in mkfs_msdos()
408 bpb.bpbResSectors = o.reserved_sectors; in mkfs_msdos()
415 bpb.bpbFATs = o.num_FAT; in mkfs_msdos()
418 bpb.bpbRootDirEnts = o.directory_entries; in mkfs_msdos()
424 bpb.bpbMedia = o.media_descriptor; in mkfs_msdos()
427 bpb.bpbBigFATsecs = o.sectors_per_fat; in mkfs_msdos()
429 bpb.bpbFSInfo = o.info_sector; in mkfs_msdos()
431 bpb.bpbBackup = o.backup_sector; in mkfs_msdos()
448 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bpbBytesPerSec || in mkfs_msdos()
449 sb.st_size < bpb.bpbBytesPerSec || in mkfs_msdos()
450 sb.st_size > bpb.bpbBytesPerSec * MAXU16) { in mkfs_msdos()
454 bss = sb.st_size / bpb.bpbBytesPerSec; in mkfs_msdos()
456 if (!bpb.bpbFATs) in mkfs_msdos()
457 bpb.bpbFATs = 2; in mkfs_msdos()
459 if (bpb.bpbHugeSectors < (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + in mkfs_msdos()
460 howmany((RESFTE + (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1)) * in mkfs_msdos()
461 (bpb.bpbSecPerClust ? 16 : 12) / BPN, in mkfs_msdos()
462 bpb.bpbBytesPerSec * NPB) * in mkfs_msdos()
463 bpb.bpbFATs + in mkfs_msdos()
464 howmany(bpb.bpbRootDirEnts ? bpb.bpbRootDirEnts : DEFRDE, in mkfs_msdos()
465 bpb.bpbBytesPerSec / sizeof(struct de)) + in mkfs_msdos()
466 (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1) * in mkfs_msdos()
467 (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : in mkfs_msdos()
468 howmany(DEFBLK, bpb.bpbBytesPerSec))) in mkfs_msdos()
470 else if (bpb.bpbRootDirEnts || bpb.bpbHugeSectors < in mkfs_msdos()
471 (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + in mkfs_msdos()
472 howmany((RESFTE + MAXCLS16) * 2, bpb.bpbBytesPerSec) * in mkfs_msdos()
473 bpb.bpbFATs + in mkfs_msdos()
474 howmany(DEFRDE, bpb.bpbBytesPerSec / sizeof(struct de)) + in mkfs_msdos()
476 (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : in mkfs_msdos()
477 howmany(8192, bpb.bpbBytesPerSec))) in mkfs_msdos()
484 if (!bpb.bpbFSInfo) { in mkfs_msdos()
485 if (x == MAXU16 || x == bpb.bpbBackup) { in mkfs_msdos()
489 bpb.bpbFSInfo = x; in mkfs_msdos()
491 if (bpb.bpbFSInfo != MAXU16 && x <= bpb.bpbFSInfo) in mkfs_msdos()
492 x = bpb.bpbFSInfo + 1; in mkfs_msdos()
493 if (!bpb.bpbBackup) { in mkfs_msdos()
498 bpb.bpbBackup = x; in mkfs_msdos()
499 } else if (bpb.bpbBackup != MAXU16 && bpb.bpbBackup == bpb.bpbFSInfo) { in mkfs_msdos()
503 if (bpb.bpbBackup != MAXU16 && x <= bpb.bpbBackup) in mkfs_msdos()
504 x = bpb.bpbBackup + 1; in mkfs_msdos()
509 set_res = (bpb.bpbResSectors == 0); in mkfs_msdos()
510 set_spf = (bpb.bpbBigFATsecs == 0); in mkfs_msdos()
511 set_spc = (bpb.bpbSecPerClust == 0); in mkfs_msdos()
526 bpb.bpbResSectors = ((fat == 32) ? in mkfs_msdos()
527 MAX(x, MAX(16384 / bpb.bpbBytesPerSec, 4)) : x) + extra_res; in mkfs_msdos()
528 else if (bpb.bpbResSectors < x) { in mkfs_msdos()
530 bpb.bpbResSectors); in mkfs_msdos()
533 if (fat != 32 && !bpb.bpbRootDirEnts) in mkfs_msdos()
534 bpb.bpbRootDirEnts = DEFRDE; in mkfs_msdos()
535 rds = howmany(bpb.bpbRootDirEnts, in mkfs_msdos()
536 bpb.bpbBytesPerSec / sizeof(struct de)); in mkfs_msdos()
538 for (bpb.bpbSecPerClust = howmany(fat == 16 ? DEFBLK16 : in mkfs_msdos()
539 DEFBLK, bpb.bpbBytesPerSec); in mkfs_msdos()
540 bpb.bpbSecPerClust < MAXSPC && (bpb.bpbResSectors + in mkfs_msdos()
542 bpb.bpbBytesPerSec * NPB) * bpb.bpbFATs + in mkfs_msdos()
544 (u_int64_t) (maxcls(fat) + 1) * bpb.bpbSecPerClust) <= in mkfs_msdos()
545 bpb.bpbHugeSectors; in mkfs_msdos()
546 bpb.bpbSecPerClust <<= 1) in mkfs_msdos()
550 if (fat != 32 && bpb.bpbBigFATsecs > MAXU16) { in mkfs_msdos()
554 x1 = bpb.bpbResSectors + rds; in mkfs_msdos()
555 x = bpb.bpbBigFATsecs ? bpb.bpbBigFATsecs : 1; in mkfs_msdos()
556 if (x1 + (u_int64_t)x * bpb.bpbFATs > bpb.bpbHugeSectors) { in mkfs_msdos()
560 x1 += x * bpb.bpbFATs; in mkfs_msdos()
561 x = (u_int64_t)(bpb.bpbHugeSectors - x1) * bpb.bpbBytesPerSec * NPB / in mkfs_msdos()
562 (bpb.bpbSecPerClust * bpb.bpbBytesPerSec * NPB + in mkfs_msdos()
563 fat / BPN * bpb.bpbFATs); in mkfs_msdos()
565 bpb.bpbBytesPerSec * NPB); in mkfs_msdos()
567 if (bpb.bpbBigFATsecs == 0) in mkfs_msdos()
568 bpb.bpbBigFATsecs = x2; in mkfs_msdos()
569 x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs; in mkfs_msdos()
573 alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs) % in mkfs_msdos()
574 bpb.bpbSecPerClust; in mkfs_msdos()
576 extra_res += bpb.bpbSecPerClust - alignment; in mkfs_msdos()
583 cls = (bpb.bpbHugeSectors - x1) / bpb.bpbSecPerClust; in mkfs_msdos()
584 x = (u_int64_t)bpb.bpbBigFATsecs * bpb.bpbBytesPerSec * NPB / (fat / BPN) - in mkfs_msdos()
588 if (bpb.bpbBigFATsecs < x2) in mkfs_msdos()
598 bpb.bpbHugeSectors = x1 + (cls + 1) * bpb.bpbSecPerClust - 1; in mkfs_msdos()
600 bpb.bpbHugeSectors); in mkfs_msdos()
603 "(%u bytes/cluster)\n", fname, cls * bpb.bpbSecPerClust, in mkfs_msdos()
604 cls * bpb.bpbSecPerClust == 1 ? "" : "s", cls, fat, in mkfs_msdos()
605 cls == 1 ? "" : "s", bpb.bpbBytesPerSec * bpb.bpbSecPerClust); in mkfs_msdos()
606 if (!bpb.bpbMedia) in mkfs_msdos()
607 bpb.bpbMedia = !bpb.bpbHiddenSecs ? 0xf0 : 0xf8; in mkfs_msdos()
609 bpb.bpbRootClust = RESFTE; in mkfs_msdos()
610 if (bpb.bpbHugeSectors <= MAXU16) { in mkfs_msdos()
611 bpb.bpbSectors = bpb.bpbHugeSectors; in mkfs_msdos()
612 bpb.bpbHugeSectors = 0; in mkfs_msdos()
615 bpb.bpbFATsecs = bpb.bpbBigFATsecs; in mkfs_msdos()
616 bpb.bpbBigFATsecs = 0; in mkfs_msdos()
618 print_bpb(&bpb); in mkfs_msdos()
631 if (!(img = malloc(bpb.bpbBytesPerSec))) { in mkfs_msdos()
635 dir = bpb.bpbResSectors + (bpb.bpbFATsecs ? bpb.bpbFATsecs : in mkfs_msdos()
636 bpb.bpbBigFATsecs) * bpb.bpbFATs; in mkfs_msdos()
643 for (lsn = 0; lsn < dir + (fat == 32 ? bpb.bpbSecPerClust : rds); lsn++) { in mkfs_msdos()
647 (dir + (fat == 32 ? bpb.bpbSecPerClust: rds)), in mkfs_msdos()
649 (fat == 32 ? bpb.bpbSecPerClust: rds))); in mkfs_msdos()
654 fat == 32 && bpb.bpbBackup != MAXU16 && in mkfs_msdos()
655 bss <= bpb.bpbBackup && x >= bpb.bpbBackup) { in mkfs_msdos()
656 x -= bpb.bpbBackup; in mkfs_msdos()
663 if ((n = read(fd1, img, bpb.bpbBytesPerSec)) == -1) { in mkfs_msdos()
667 if ((unsigned)n != bpb.bpbBytesPerSec) { in mkfs_msdos()
672 memset(img, 0, bpb.bpbBytesPerSec); in mkfs_msdos()
674 (fat == 32 && bpb.bpbBackup != MAXU16 && in mkfs_msdos()
675 lsn == bpb.bpbBackup)) { in mkfs_msdos()
678 mk2(bsbpb->bpbBytesPerSec, bpb.bpbBytesPerSec); in mkfs_msdos()
679 mk1(bsbpb->bpbSecPerClust, bpb.bpbSecPerClust); in mkfs_msdos()
680 mk2(bsbpb->bpbResSectors, bpb.bpbResSectors); in mkfs_msdos()
681 mk1(bsbpb->bpbFATs, bpb.bpbFATs); in mkfs_msdos()
682 mk2(bsbpb->bpbRootDirEnts, bpb.bpbRootDirEnts); in mkfs_msdos()
683 mk2(bsbpb->bpbSectors, bpb.bpbSectors); in mkfs_msdos()
684 mk1(bsbpb->bpbMedia, bpb.bpbMedia); in mkfs_msdos()
685 mk2(bsbpb->bpbFATsecs, bpb.bpbFATsecs); in mkfs_msdos()
686 mk2(bsbpb->bpbSecPerTrack, bpb.bpbSecPerTrack); in mkfs_msdos()
687 mk2(bsbpb->bpbHeads, bpb.bpbHeads); in mkfs_msdos()
688 mk4(bsbpb->bpbHiddenSecs, bpb.bpbHiddenSecs); in mkfs_msdos()
689 mk4(bsbpb->bpbHugeSectors, bpb.bpbHugeSectors); in mkfs_msdos()
693 mk4(bsxbpb->bpbBigFATsecs, bpb.bpbBigFATsecs); in mkfs_msdos()
696 mk4(bsxbpb->bpbRootClust, bpb.bpbRootClust); in mkfs_msdos()
697 mk2(bsxbpb->bpbFSInfo, bpb.bpbFSInfo); in mkfs_msdos()
698 mk2(bsxbpb->bpbBackup, bpb.bpbBackup); in mkfs_msdos()
728 } else if (fat == 32 && bpb.bpbFSInfo != MAXU16 && in mkfs_msdos()
729 (lsn == bpb.bpbFSInfo || in mkfs_msdos()
730 (bpb.bpbBackup != MAXU16 && in mkfs_msdos()
731 lsn == bpb.bpbBackup + bpb.bpbFSInfo))) { in mkfs_msdos()
735 mk4(img + MINBPS - 20, bpb.bpbRootClust); in mkfs_msdos()
737 } else if (lsn >= bpb.bpbResSectors && lsn < dir && in mkfs_msdos()
738 !((lsn - bpb.bpbResSectors) % in mkfs_msdos()
739 (bpb.bpbFATsecs ? bpb.bpbFATsecs : in mkfs_msdos()
740 bpb.bpbBigFATsecs))) { in mkfs_msdos()
741 mk1(img[0], bpb.bpbMedia); in mkfs_msdos()
757 if ((n = write(fd, img, bpb.bpbBytesPerSec)) == -1) { in mkfs_msdos()
761 if ((unsigned)n != bpb.bpbBytesPerSec) { in mkfs_msdos()
817 getstdfmt(const char *fmt, struct bpb *bpb) in getstdfmt() argument
827 *bpb = stdfmt[i].bpb; in getstdfmt()
836 __unused int oflag, struct bpb *bpb) in getdiskinfo() argument
838 if (ioctl(fd, BLKSSZGET, &bpb->bpbBytesPerSec)) { in getdiskinfo()
842 if (ckgeom(fname, bpb->bpbBytesPerSec, "bytes/sector") == -1) return -1; in getdiskinfo()
853 bpb->bpbHugeSectors = (u_int)block_size; in getdiskinfo()
855 bpb->bpbSecPerTrack = 63; in getdiskinfo()
856 if (ckgeom(fname, bpb->bpbSecPerTrack, "sectors/track") == -1) return -1; in getdiskinfo()
858 bpb->bpbHeads = 64; in getdiskinfo()
859 if (ckgeom(fname, bpb->bpbHeads, "drive heads") == -1) return -1; in getdiskinfo()
866 struct bpb *bpb) { in getdiskinfo() argument
872 struct bpb *bpb) in getdiskinfo() argument
910 if (bpb->bpbBytesPerSec) in getdiskinfo()
911 dlp.d_secsize = bpb->bpbBytesPerSec; in getdiskinfo()
912 if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, in getdiskinfo()
918 if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, in getdiskinfo()
923 if (bpb->bpbHeads == 0 && in getdiskinfo()
938 if (bpb->bpbBytesPerSec == 0) { in getdiskinfo()
941 bpb->bpbBytesPerSec = lp->d_secsize; in getdiskinfo()
943 if (bpb->bpbSecPerTrack == 0) { in getdiskinfo()
946 bpb->bpbSecPerTrack = lp->d_nsectors; in getdiskinfo()
948 if (bpb->bpbHeads == 0) { in getdiskinfo()
951 bpb->bpbHeads = lp->d_ntracks; in getdiskinfo()
953 if (bpb->bpbHugeSectors == 0) in getdiskinfo()
954 bpb->bpbHugeSectors = lp->d_secperunit; in getdiskinfo()
955 if (bpb->bpbHiddenSecs == 0) in getdiskinfo()
956 bpb->bpbHiddenSecs = hs; in getdiskinfo()
965 print_bpb(struct bpb *bpb) in print_bpb() argument
968 bpb->bpbBytesPerSec, bpb->bpbSecPerClust, bpb->bpbResSectors, in print_bpb()
969 bpb->bpbFATs); in print_bpb()
970 if (bpb->bpbRootDirEnts) in print_bpb()
971 printf(" RootDirEnts=%u", bpb->bpbRootDirEnts); in print_bpb()
972 if (bpb->bpbSectors) in print_bpb()
973 printf(" Sectors=%u", bpb->bpbSectors); in print_bpb()
974 printf(" Media=%#x", bpb->bpbMedia); in print_bpb()
975 if (bpb->bpbFATsecs) in print_bpb()
976 printf(" FATsecs=%u", bpb->bpbFATsecs); in print_bpb()
977 printf(" SecPerTrack=%u Heads=%u HiddenSecs=%u", bpb->bpbSecPerTrack, in print_bpb()
978 bpb->bpbHeads, bpb->bpbHiddenSecs); in print_bpb()
979 if (bpb->bpbHugeSectors) in print_bpb()
980 printf(" HugeSectors=%u", bpb->bpbHugeSectors); in print_bpb()
981 if (!bpb->bpbFATsecs) { in print_bpb()
982 printf(" FATsecs=%u RootCluster=%u", bpb->bpbBigFATsecs, in print_bpb()
983 bpb->bpbRootClust); in print_bpb()
985 printf(bpb->bpbFSInfo == MAXU16 ? "%#x" : "%u", bpb->bpbFSInfo); in print_bpb()
987 printf(bpb->bpbBackup == MAXU16 ? "%#x" : "%u", bpb->bpbBackup); in print_bpb()