newfs_msdos.c (42261) | newfs_msdos.c (48954) |
---|---|
1/* 2 * Copyright (c) 1998 Robert Nordier 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#ifndef lint 29static const char rcsid[] = | 1/* 2 * Copyright (c) 1998 Robert Nordier 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#ifndef lint 29static const char rcsid[] = |
30 "$Id: newfs_msdos.c,v 1.6 1998/12/07 14:09:17 rnordier Exp $"; | 30 "$Id: newfs_msdos.c,v 1.7 1999/01/03 02:18:57 jkh Exp $"; |
31#endif /* not lint */ 32 33#include <sys/param.h> 34#include <sys/stat.h> 35#include <sys/diskslice.h> 36#include <sys/disklabel.h> 37#include <sys/mount.h> 38 --- 329 unchanged lines hidden (view full) --- 368 bpb.hid = opt_o; 369 if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) 370 getdiskinfo(fd, fname, dtype, oflag, &bpb); 371 if (!powerof2(bpb.bps)) 372 errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps); 373 if (bpb.bps < MINBPS) 374 errx(1, "bytes/sector (%u) is too small; minimum is %u", 375 bpb.bps, MINBPS); | 31#endif /* not lint */ 32 33#include <sys/param.h> 34#include <sys/stat.h> 35#include <sys/diskslice.h> 36#include <sys/disklabel.h> 37#include <sys/mount.h> 38 --- 329 unchanged lines hidden (view full) --- 368 bpb.hid = opt_o; 369 if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) 370 getdiskinfo(fd, fname, dtype, oflag, &bpb); 371 if (!powerof2(bpb.bps)) 372 errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps); 373 if (bpb.bps < MINBPS) 374 errx(1, "bytes/sector (%u) is too small; minimum is %u", 375 bpb.bps, MINBPS); |
376 if (!(fat = opt_F)) | 376 if (!(fat = opt_F)) { |
377 if (opt_f) 378 fat = 12; 379 else if (!opt_e && (opt_i || opt_k)) 380 fat = 32; | 377 if (opt_f) 378 fat = 12; 379 else if (!opt_e && (opt_i || opt_k)) 380 fat = 32; |
381 } |
|
381 if ((fat == 32 && opt_e) || (fat != 32 && (opt_i || opt_k))) 382 errx(1, "-%c is not a legal FAT%s option", 383 fat == 32 ? 'e' : opt_i ? 'i' : 'k', 384 fat == 32 ? "32" : "12/16"); 385 if (opt_f && fat == 32) 386 bpb.rde = 0; 387 if (opt_b) { 388 if (!powerof2(opt_b)) --- 46 unchanged lines hidden (view full) --- 435 err(1, "%s", bname); 436 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bps || 437 sb.st_size < bpb.bps || sb.st_size > bpb.bps * MAXU16) 438 errx(1, "%s: inappropriate file type or format", bname); 439 bss = sb.st_size / bpb.bps; 440 } 441 if (!bpb.nft) 442 bpb.nft = 2; | 382 if ((fat == 32 && opt_e) || (fat != 32 && (opt_i || opt_k))) 383 errx(1, "-%c is not a legal FAT%s option", 384 fat == 32 ? 'e' : opt_i ? 'i' : 'k', 385 fat == 32 ? "32" : "12/16"); 386 if (opt_f && fat == 32) 387 bpb.rde = 0; 388 if (opt_b) { 389 if (!powerof2(opt_b)) --- 46 unchanged lines hidden (view full) --- 436 err(1, "%s", bname); 437 if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bps || 438 sb.st_size < bpb.bps || sb.st_size > bpb.bps * MAXU16) 439 errx(1, "%s: inappropriate file type or format", bname); 440 bss = sb.st_size / bpb.bps; 441 } 442 if (!bpb.nft) 443 bpb.nft = 2; |
443 if (!fat) | 444 if (!fat) { |
444 if (bpb.bsec < (bpb.res ? bpb.res : bss) + 445 howmany((RESFTE + (bpb.spc ? MINCLS16 : MAXCLS12 + 1)) * 446 ((bpb.spc ? 16 : 12) / BPN), bpb.bps * NPB) * 447 bpb.nft + 448 howmany(bpb.rde ? bpb.rde : DEFRDE, 449 bpb.bps / sizeof(struct de)) + 450 (bpb.spc ? MINCLS16 : MAXCLS12 + 1) * 451 (bpb.spc ? bpb.spc : howmany(DEFBLK, bpb.bps))) 452 fat = 12; 453 else if (bpb.rde || bpb.bsec < 454 (bpb.res ? bpb.res : bss) + 455 howmany((RESFTE + MAXCLS16) * 2, bpb.bps) * bpb.nft + 456 howmany(DEFRDE, bpb.bps / sizeof(struct de)) + 457 (MAXCLS16 + 1) * 458 (bpb.spc ? bpb.spc : howmany(8192, bpb.bps))) 459 fat = 16; 460 else 461 fat = 32; | 445 if (bpb.bsec < (bpb.res ? bpb.res : bss) + 446 howmany((RESFTE + (bpb.spc ? MINCLS16 : MAXCLS12 + 1)) * 447 ((bpb.spc ? 16 : 12) / BPN), bpb.bps * NPB) * 448 bpb.nft + 449 howmany(bpb.rde ? bpb.rde : DEFRDE, 450 bpb.bps / sizeof(struct de)) + 451 (bpb.spc ? MINCLS16 : MAXCLS12 + 1) * 452 (bpb.spc ? bpb.spc : howmany(DEFBLK, bpb.bps))) 453 fat = 12; 454 else if (bpb.rde || bpb.bsec < 455 (bpb.res ? bpb.res : bss) + 456 howmany((RESFTE + MAXCLS16) * 2, bpb.bps) * bpb.nft + 457 howmany(DEFRDE, bpb.bps / sizeof(struct de)) + 458 (MAXCLS16 + 1) * 459 (bpb.spc ? bpb.spc : howmany(8192, bpb.bps))) 460 fat = 16; 461 else 462 fat = 32; |
463 } |
|
462 x = bss; 463 if (fat == 32) { 464 if (!bpb.infs) { 465 if (x == MAXU16 || x == bpb.bkbs) 466 errx(1, "no room for info sector"); 467 bpb.infs = x; 468 } 469 if (bpb.infs != MAXU16 && x <= bpb.infs) --- 290 unchanged lines hidden (view full) --- 760 s[s1 - fname] = 0; 761 if ((fd1 = open(s, O_RDONLY)) != -1) { 762 i = ioctl(fd1, DIOCGDINFO, lp); 763 close(fd1); 764 } 765 free(s); 766 errno = e; 767 } | 464 x = bss; 465 if (fat == 32) { 466 if (!bpb.infs) { 467 if (x == MAXU16 || x == bpb.bkbs) 468 errx(1, "no room for info sector"); 469 bpb.infs = x; 470 } 471 if (bpb.infs != MAXU16 && x <= bpb.infs) --- 290 unchanged lines hidden (view full) --- 762 s[s1 - fname] = 0; 763 if ((fd1 = open(s, O_RDONLY)) != -1) { 764 i = ioctl(fd1, DIOCGDINFO, lp); 765 close(fd1); 766 } 767 free(s); 768 errno = e; 769 } |
768 if (i == -1) | 770 if (i == -1) { |
769 if (!dtype) { 770 warn("ioctl (GDINFO)"); 771 errx(1, "%s: can't read disk label; " 772 "disk type must be specified", fname); 773 } else if (!(lp = getdiskbyname(dtype))) 774 errx(1, "%s: unknown disk type", dtype); | 771 if (!dtype) { 772 warn("ioctl (GDINFO)"); 773 errx(1, "%s: can't read disk label; " 774 "disk type must be specified", fname); 775 } else if (!(lp = getdiskbyname(dtype))) 776 errx(1, "%s: unknown disk type", dtype); |
777 } |
|
775 if (slice == -1 || part != -1) { 776 if (part == -1) 777 part = RAW_PART; 778 if (part >= lp->d_npartitions || 779 !lp->d_partitions[part].p_size) 780 errx(1, "%s: partition is unavailable", fname); 781 if (!oflag && part != -1) 782 bpb->hid += lp->d_partitions[part].p_offset; --- 142 unchanged lines hidden --- | 778 if (slice == -1 || part != -1) { 779 if (part == -1) 780 part = RAW_PART; 781 if (part >= lp->d_npartitions || 782 !lp->d_partitions[part].p_size) 783 errx(1, "%s: partition is unavailable", fname); 784 if (!oflag && part != -1) 785 bpb->hid += lp->d_partitions[part].p_offset; --- 142 unchanged lines hidden --- |