• Home
  • Raw
  • Download

Lines Matching refs:bpb

161 struct bpb {  struct
184 struct bpb bpb; member
235 static int getstdfmt(const char *, struct bpb *);
236 static int getdiskinfo(int, const char *, const char *, int, struct bpb *);
237 static void print_bpb(struct bpb *);
250 struct bpb bpb; in mkfs_msdos() local
323 memset(&bpb, 0, sizeof(bpb)); in mkfs_msdos()
325 if (getstdfmt(o.floppy, &bpb) == -1) in mkfs_msdos()
327 bpb.bpbHugeSectors = bpb.bpbSectors; in mkfs_msdos()
328 bpb.bpbSectors = 0; in mkfs_msdos()
329 bpb.bpbBigFATsecs = bpb.bpbFATsecs; in mkfs_msdos()
330 bpb.bpbFATsecs = 0; in mkfs_msdos()
333 bpb.bpbHeads = o.drive_heads; in mkfs_msdos()
335 bpb.bpbSecPerTrack = o.sectors_per_track; in mkfs_msdos()
337 bpb.bpbBytesPerSec = o.bytes_per_sector; in mkfs_msdos()
339 bpb.bpbHugeSectors = o.size; in mkfs_msdos()
341 bpb.bpbHiddenSecs = o.hidden_sectors; in mkfs_msdos()
344 if (getdiskinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb) == -1) in mkfs_msdos()
346 bpb.bpbHugeSectors -= (o.offset / bpb.bpbBytesPerSec); in mkfs_msdos()
347 if (bpb.bpbSecPerClust == 0) { /* set defaults */ in mkfs_msdos()
348 if (bpb.bpbHugeSectors <= 6000) /* about 3MB -> 512 bytes */ in mkfs_msdos()
349 bpb.bpbSecPerClust = 1; in mkfs_msdos()
350 else if (bpb.bpbHugeSectors <= (1<<17)) /* 64M -> 4k */ in mkfs_msdos()
351 bpb.bpbSecPerClust = 8; in mkfs_msdos()
352 else if (bpb.bpbHugeSectors <= (1<<19)) /* 256M -> 8k */ in mkfs_msdos()
353 bpb.bpbSecPerClust = 16; in mkfs_msdos()
354 else if (bpb.bpbHugeSectors <= (1<<21)) /* 1G -> 16k */ in mkfs_msdos()
355 bpb.bpbSecPerClust = 32; in mkfs_msdos()
357 bpb.bpbSecPerClust = 64; /* otherwise 32k */ in mkfs_msdos()
360 if (bpb.bpbBytesPerSec < MINBPS || in mkfs_msdos()
361 bpb.bpbBytesPerSec > MAXBPS || in mkfs_msdos()
362 !powerof2(bpb.bpbBytesPerSec)) { in mkfs_msdos()
364 bpb.bpbBytesPerSec); in mkfs_msdos()
385 bpb.bpbRootDirEnts = 0; in mkfs_msdos()
396 if (o.block_size < bpb.bpbBytesPerSec) { in mkfs_msdos()
398 o.block_size, bpb.bpbBytesPerSec); in mkfs_msdos()
401 if (o.block_size > bpb.bpbBytesPerSec * MAXSPC) { in mkfs_msdos()
403 o.block_size, bpb.bpbBytesPerSec * MAXSPC); in mkfs_msdos()
406 bpb.bpbSecPerClust = o.block_size / bpb.bpbBytesPerSec; in mkfs_msdos()
414 bpb.bpbSecPerClust = o.sectors_per_cluster; in mkfs_msdos()
417 bpb.bpbResSectors = o.reserved_sectors; in mkfs_msdos()
424 bpb.bpbFATs = o.num_FAT; in mkfs_msdos()
427 bpb.bpbRootDirEnts = o.directory_entries; in mkfs_msdos()
433 bpb.bpbMedia = o.media_descriptor; in mkfs_msdos()
436 bpb.bpbBigFATsecs = o.sectors_per_fat; in mkfs_msdos()
438 bpb.bpbFSInfo = o.info_sector; in mkfs_msdos()
440 bpb.bpbBackup = o.backup_sector; in mkfs_msdos()
454 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bpbBytesPerSec || in mkfs_msdos()
455 sb.st_size < bpb.bpbBytesPerSec || in mkfs_msdos()
456 sb.st_size > bpb.bpbBytesPerSec * MAXU16) { in mkfs_msdos()
460 bss = sb.st_size / bpb.bpbBytesPerSec; in mkfs_msdos()
462 if (!bpb.bpbFATs) in mkfs_msdos()
463 bpb.bpbFATs = 2; in mkfs_msdos()
465 if (bpb.bpbHugeSectors < (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + in mkfs_msdos()
466 howmany((RESFTE + (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1)) * in mkfs_msdos()
467 (bpb.bpbSecPerClust ? 16 : 12) / BPN, in mkfs_msdos()
468 bpb.bpbBytesPerSec * NPB) * in mkfs_msdos()
469 bpb.bpbFATs + in mkfs_msdos()
470 howmany(bpb.bpbRootDirEnts ? bpb.bpbRootDirEnts : DEFRDE, in mkfs_msdos()
471 bpb.bpbBytesPerSec / sizeof(struct de)) + in mkfs_msdos()
472 (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1) * in mkfs_msdos()
473 (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : in mkfs_msdos()
474 howmany(DEFBLK, bpb.bpbBytesPerSec))) in mkfs_msdos()
476 else if (bpb.bpbRootDirEnts || bpb.bpbHugeSectors < in mkfs_msdos()
477 (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + in mkfs_msdos()
478 howmany((RESFTE + MAXCLS16) * 2, bpb.bpbBytesPerSec) * in mkfs_msdos()
479 bpb.bpbFATs + in mkfs_msdos()
480 howmany(DEFRDE, bpb.bpbBytesPerSec / sizeof(struct de)) + in mkfs_msdos()
482 (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : in mkfs_msdos()
483 howmany(8192, bpb.bpbBytesPerSec))) in mkfs_msdos()
490 if (!bpb.bpbFSInfo) { in mkfs_msdos()
491 if (x == MAXU16 || x == bpb.bpbBackup) { in mkfs_msdos()
495 bpb.bpbFSInfo = x; in mkfs_msdos()
497 if (bpb.bpbFSInfo != MAXU16 && x <= bpb.bpbFSInfo) in mkfs_msdos()
498 x = bpb.bpbFSInfo + 1; in mkfs_msdos()
499 if (!bpb.bpbBackup) { in mkfs_msdos()
504 bpb.bpbBackup = x; in mkfs_msdos()
505 } else if (bpb.bpbBackup != MAXU16 && bpb.bpbBackup == bpb.bpbFSInfo) { in mkfs_msdos()
509 if (bpb.bpbBackup != MAXU16 && x <= bpb.bpbBackup) in mkfs_msdos()
510 x = bpb.bpbBackup + 1; in mkfs_msdos()
515 set_res = (bpb.bpbResSectors == 0); in mkfs_msdos()
516 set_spf = (bpb.bpbBigFATsecs == 0); in mkfs_msdos()
517 set_spc = (bpb.bpbSecPerClust == 0); in mkfs_msdos()
532 bpb.bpbResSectors = ((fat == 32) ? in mkfs_msdos()
533 MAX(x, MAX(16384 / bpb.bpbBytesPerSec, 4)) : x) + extra_res; in mkfs_msdos()
534 else if (bpb.bpbResSectors < x) { in mkfs_msdos()
536 bpb.bpbResSectors); in mkfs_msdos()
539 if (fat != 32 && !bpb.bpbRootDirEnts) in mkfs_msdos()
540 bpb.bpbRootDirEnts = DEFRDE; in mkfs_msdos()
541 rds = howmany(bpb.bpbRootDirEnts, in mkfs_msdos()
542 bpb.bpbBytesPerSec / sizeof(struct de)); in mkfs_msdos()
544 for (bpb.bpbSecPerClust = howmany(fat == 16 ? DEFBLK16 : in mkfs_msdos()
545 DEFBLK, bpb.bpbBytesPerSec); in mkfs_msdos()
546 bpb.bpbSecPerClust < MAXSPC && (bpb.bpbResSectors + in mkfs_msdos()
548 bpb.bpbBytesPerSec * NPB) * bpb.bpbFATs + in mkfs_msdos()
550 (u_int64_t) (maxcls(fat) + 1) * bpb.bpbSecPerClust) <= in mkfs_msdos()
551 bpb.bpbHugeSectors; in mkfs_msdos()
552 bpb.bpbSecPerClust <<= 1) in mkfs_msdos()
556 if (fat != 32 && bpb.bpbBigFATsecs > MAXU16) { in mkfs_msdos()
560 x1 = bpb.bpbResSectors + rds; in mkfs_msdos()
561 x = bpb.bpbBigFATsecs ? bpb.bpbBigFATsecs : 1; in mkfs_msdos()
562 if (x1 + (u_int64_t)x * bpb.bpbFATs > bpb.bpbHugeSectors) { in mkfs_msdos()
566 x1 += x * bpb.bpbFATs; in mkfs_msdos()
567 x = (u_int64_t)(bpb.bpbHugeSectors - x1) * bpb.bpbBytesPerSec * NPB / in mkfs_msdos()
568 (bpb.bpbSecPerClust * bpb.bpbBytesPerSec * NPB + in mkfs_msdos()
569 fat / BPN * bpb.bpbFATs); in mkfs_msdos()
571 bpb.bpbBytesPerSec * NPB); in mkfs_msdos()
573 if (bpb.bpbBigFATsecs == 0) in mkfs_msdos()
574 bpb.bpbBigFATsecs = x2; in mkfs_msdos()
575 x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs; in mkfs_msdos()
579 alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs) % in mkfs_msdos()
580 bpb.bpbSecPerClust; in mkfs_msdos()
582 extra_res += bpb.bpbSecPerClust - alignment; in mkfs_msdos()
589 cls = (bpb.bpbHugeSectors - x1) / bpb.bpbSecPerClust; in mkfs_msdos()
590 x = (u_int64_t)bpb.bpbBigFATsecs * bpb.bpbBytesPerSec * NPB / (fat / BPN) - in mkfs_msdos()
594 if (bpb.bpbBigFATsecs < x2) in mkfs_msdos()
604 bpb.bpbHugeSectors = x1 + (cls + 1) * bpb.bpbSecPerClust - 1; in mkfs_msdos()
606 bpb.bpbHugeSectors); in mkfs_msdos()
609 "(%u bytes/cluster)\n", fname, cls * bpb.bpbSecPerClust, in mkfs_msdos()
610 cls * bpb.bpbSecPerClust == 1 ? "" : "s", cls, fat, in mkfs_msdos()
611 cls == 1 ? "" : "s", bpb.bpbBytesPerSec * bpb.bpbSecPerClust); in mkfs_msdos()
612 if (!bpb.bpbMedia) in mkfs_msdos()
613 bpb.bpbMedia = !bpb.bpbHiddenSecs ? 0xf0 : 0xf8; in mkfs_msdos()
615 bpb.bpbRootClust = RESFTE; in mkfs_msdos()
616 if (bpb.bpbHugeSectors <= MAXU16) { in mkfs_msdos()
617 bpb.bpbSectors = bpb.bpbHugeSectors; in mkfs_msdos()
618 bpb.bpbHugeSectors = 0; in mkfs_msdos()
621 bpb.bpbFATsecs = bpb.bpbBigFATsecs; in mkfs_msdos()
622 bpb.bpbBigFATsecs = 0; in mkfs_msdos()
624 print_bpb(&bpb); in mkfs_msdos()
645 dir = bpb.bpbResSectors + (bpb.bpbFATsecs ? bpb.bpbFATsecs : in mkfs_msdos()
646 bpb.bpbBigFATsecs) * bpb.bpbFATs; in mkfs_msdos()
656 for (lsn = 0; lsn < dir + (fat == 32 ? bpb.bpbSecPerClust : rds); lsn++) { in mkfs_msdos()
660 (dir + (fat == 32 ? bpb.bpbSecPerClust: rds)), in mkfs_msdos()
662 (fat == 32 ? bpb.bpbSecPerClust: rds))); in mkfs_msdos()
667 fat == 32 && bpb.bpbBackup != MAXU16 && in mkfs_msdos()
668 bss <= bpb.bpbBackup && x >= bpb.bpbBackup) { in mkfs_msdos()
669 x -= bpb.bpbBackup; in mkfs_msdos()
676 if ((n = read(fd1, img, bpb.bpbBytesPerSec)) == -1) { in mkfs_msdos()
680 if ((unsigned)n != bpb.bpbBytesPerSec) { in mkfs_msdos()
685 memset(img, 0, bpb.bpbBytesPerSec); in mkfs_msdos()
687 (fat == 32 && bpb.bpbBackup != MAXU16 && in mkfs_msdos()
688 lsn == bpb.bpbBackup)) { in mkfs_msdos()
691 mk2(bsbpb->bpbBytesPerSec, bpb.bpbBytesPerSec); in mkfs_msdos()
692 mk1(bsbpb->bpbSecPerClust, bpb.bpbSecPerClust); in mkfs_msdos()
693 mk2(bsbpb->bpbResSectors, bpb.bpbResSectors); in mkfs_msdos()
694 mk1(bsbpb->bpbFATs, bpb.bpbFATs); in mkfs_msdos()
695 mk2(bsbpb->bpbRootDirEnts, bpb.bpbRootDirEnts); in mkfs_msdos()
696 mk2(bsbpb->bpbSectors, bpb.bpbSectors); in mkfs_msdos()
697 mk1(bsbpb->bpbMedia, bpb.bpbMedia); in mkfs_msdos()
698 mk2(bsbpb->bpbFATsecs, bpb.bpbFATsecs); in mkfs_msdos()
699 mk2(bsbpb->bpbSecPerTrack, bpb.bpbSecPerTrack); in mkfs_msdos()
700 mk2(bsbpb->bpbHeads, bpb.bpbHeads); in mkfs_msdos()
701 mk4(bsbpb->bpbHiddenSecs, bpb.bpbHiddenSecs); in mkfs_msdos()
702 mk4(bsbpb->bpbHugeSectors, bpb.bpbHugeSectors); in mkfs_msdos()
706 mk4(bsxbpb->bpbBigFATsecs, bpb.bpbBigFATsecs); in mkfs_msdos()
709 mk4(bsxbpb->bpbRootClust, bpb.bpbRootClust); in mkfs_msdos()
710 mk2(bsxbpb->bpbFSInfo, bpb.bpbFSInfo); in mkfs_msdos()
711 mk2(bsxbpb->bpbBackup, bpb.bpbBackup); in mkfs_msdos()
741 } else if (fat == 32 && bpb.bpbFSInfo != MAXU16 && in mkfs_msdos()
742 (lsn == bpb.bpbFSInfo || in mkfs_msdos()
743 (bpb.bpbBackup != MAXU16 && in mkfs_msdos()
744 lsn == bpb.bpbBackup + bpb.bpbFSInfo))) { in mkfs_msdos()
750 } else if (lsn >= bpb.bpbResSectors && lsn < dir && in mkfs_msdos()
751 !((lsn - bpb.bpbResSectors) % in mkfs_msdos()
752 (bpb.bpbFATsecs ? bpb.bpbFATsecs : in mkfs_msdos()
753 bpb.bpbBigFATsecs))) { in mkfs_msdos()
754 mk1(img[0], bpb.bpbMedia); in mkfs_msdos()
774 img += bpb.bpbBytesPerSec; in mkfs_msdos()
893 getstdfmt(const char *fmt, struct bpb *bpb) in getstdfmt() argument
903 *bpb = stdfmt[i].bpb; in getstdfmt()
931 __unused int oflag, struct bpb *bpb) in getdiskinfo() argument
933 if (ioctl(fd, BLKSSZGET, &bpb->bpbBytesPerSec)) { in getdiskinfo()
937 if (ckgeom(fname, bpb->bpbBytesPerSec, "bytes/sector") == -1) return -1; in getdiskinfo()
944 u_int64_t sectors = device_size/bpb->bpbBytesPerSec; in getdiskinfo()
947 sectors, device_size, bpb->bpbBytesPerSec); in getdiskinfo()
949 bpb->bpbHugeSectors = sectors; in getdiskinfo()
951 bpb->bpbSecPerTrack = 63; in getdiskinfo()
952 if (ckgeom(fname, bpb->bpbSecPerTrack, "sectors/track") == -1) return -1; in getdiskinfo()
954 bpb->bpbHeads = 64; in getdiskinfo()
955 if (ckgeom(fname, bpb->bpbHeads, "drive heads") == -1) return -1; in getdiskinfo()
962 struct bpb *bpb) { in getdiskinfo() argument
968 struct bpb *bpb) in getdiskinfo() argument
1000 if (bpb->bpbBytesPerSec) in getdiskinfo()
1001 dlp.d_secsize = bpb->bpbBytesPerSec; in getdiskinfo()
1002 if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, in getdiskinfo()
1008 if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, in getdiskinfo()
1013 if (bpb->bpbHeads == 0 && in getdiskinfo()
1033 if (bpb->bpbBytesPerSec == 0) { in getdiskinfo()
1036 bpb->bpbBytesPerSec = lp->d_secsize; in getdiskinfo()
1038 if (bpb->bpbSecPerTrack == 0) { in getdiskinfo()
1041 bpb->bpbSecPerTrack = lp->d_nsectors; in getdiskinfo()
1043 if (bpb->bpbHeads == 0) { in getdiskinfo()
1046 bpb->bpbHeads = lp->d_ntracks; in getdiskinfo()
1048 if (bpb->bpbHugeSectors == 0) in getdiskinfo()
1049 bpb->bpbHugeSectors = lp->d_secperunit; in getdiskinfo()
1050 if (bpb->bpbHiddenSecs == 0) in getdiskinfo()
1051 bpb->bpbHiddenSecs = hs; in getdiskinfo()
1060 print_bpb(struct bpb *bpb) in print_bpb() argument
1063 bpb->bpbBytesPerSec, bpb->bpbSecPerClust, bpb->bpbResSectors, in print_bpb()
1064 bpb->bpbFATs); in print_bpb()
1065 if (bpb->bpbRootDirEnts) in print_bpb()
1066 printf(" RootDirEnts=%u", bpb->bpbRootDirEnts); in print_bpb()
1067 if (bpb->bpbSectors) in print_bpb()
1068 printf(" Sectors=%u", bpb->bpbSectors); in print_bpb()
1069 printf(" Media=%#x", bpb->bpbMedia); in print_bpb()
1070 if (bpb->bpbFATsecs) in print_bpb()
1071 printf(" FATsecs=%u", bpb->bpbFATsecs); in print_bpb()
1072 printf(" SecPerTrack=%u Heads=%u HiddenSecs=%u", bpb->bpbSecPerTrack, in print_bpb()
1073 bpb->bpbHeads, bpb->bpbHiddenSecs); in print_bpb()
1074 if (bpb->bpbHugeSectors) in print_bpb()
1075 printf(" HugeSectors=%u", bpb->bpbHugeSectors); in print_bpb()
1076 if (!bpb->bpbFATsecs) { in print_bpb()
1077 printf(" FATsecs=%u RootCluster=%u", bpb->bpbBigFATsecs, in print_bpb()
1078 bpb->bpbRootClust); in print_bpb()
1080 printf(bpb->bpbFSInfo == MAXU16 ? "%#x" : "%u", bpb->bpbFSInfo); in print_bpb()
1082 printf(bpb->bpbBackup == MAXU16 ? "%#x" : "%u", bpb->bpbBackup); in print_bpb()