View | Details | Raw Unified | Return to bug 151850 | Differences between
and this patch

Collapse All | Expand All

(-)newfs_msdos.c (-12 / +21 lines)
Lines 55-60 Link Here
55
#define NPB	  2		/* nibbles per byte */
55
#define NPB	  2		/* nibbles per byte */
56
56
57
#define DOSMAGIC  0xaa55	/* DOS magic number */
57
#define DOSMAGIC  0xaa55	/* DOS magic number */
58
#define MAXBPS    4096		/* maximum bytes per sector */
58
#define MINBPS	  512		/* minimum bytes per sector */
59
#define MINBPS	  512		/* minimum bytes per sector */
59
#define MAXSPC	  128		/* maximum sectors per cluster */
60
#define MAXSPC	  128		/* maximum sectors per cluster */
60
#define MAXNFT	  16		/* maximum number of FATs */
61
#define MAXNFT	  16		/* maximum number of FATs */
Lines 406-429 Link Here
406
		(int)delta, bpb.bpbSecPerTrack);
407
		(int)delta, bpb.bpbSecPerTrack);
407
	    bpb.bpbHugeSectors -= delta;
408
	    bpb.bpbHugeSectors -= delta;
408
	}
409
	}
409
	if (bpb.bpbSecPerClust == 0) {	/* set defaults */
410
    else
410
	    if (bpb.bpbHugeSectors <= 6000)	/* about 3MB -> 512 bytes */
411
	bpb.bpbSecPerClust /= (bpb.bpbBytesPerSec / MINBPS);
411
		bpb.bpbSecPerClust = 1;
412
    }
412
	    else if (bpb.bpbHugeSectors <= (1<<17)) /* 64M -> 4k */
413
    if (bpb.bpbSecPerClust == 0) {	/* set defaults */
413
		bpb.bpbSecPerClust = 8;
414
	if (bpb.bpbHugeSectors <= 6000)	/* about 3MB -> 512 bytes */
414
	    else if (bpb.bpbHugeSectors <= (1<<19)) /* 256M -> 8k */
415
	    bpb.bpbSecPerClust = 1;
415
		bpb.bpbSecPerClust = 16;
416
	else if (bpb.bpbHugeSectors <= (1<<17)) /* 64M -> 4k */
416
	    else if (bpb.bpbHugeSectors <= (1<<21)) /* 1G -> 16k */
417
	    bpb.bpbSecPerClust = 8;
417
		bpb.bpbSecPerClust = 32;
418
	else if (bpb.bpbHugeSectors <= (1<<19)) /* 256M -> 8k */
418
	    else
419
	    bpb.bpbSecPerClust = 16;
419
		bpb.bpbSecPerClust = 64;		/* otherwise 32k */
420
	else if (bpb.bpbHugeSectors <= (1<<21)) /* 1G -> 16k */
420
	}
421
	    bpb.bpbSecPerClust = 32;
422
	else
423
	    bpb.bpbSecPerClust = 64;		/* otherwise 32k */
421
    }
424
    }
422
    if (!powerof2(bpb.bpbBytesPerSec))
425
    if (!powerof2(bpb.bpbBytesPerSec))
423
	errx(1, "bytes/sector (%u) is not a power of 2", bpb.bpbBytesPerSec);
426
	errx(1, "bytes/sector (%u) is not a power of 2", bpb.bpbBytesPerSec);
424
    if (bpb.bpbBytesPerSec < MINBPS)
427
    if (bpb.bpbBytesPerSec < MINBPS)
425
	errx(1, "bytes/sector (%u) is too small; minimum is %u",
428
	errx(1, "bytes/sector (%u) is too small; minimum is %u",
426
	     bpb.bpbBytesPerSec, MINBPS);
429
	     bpb.bpbBytesPerSec, MINBPS);
430
    if (bpb.bpbBytesPerSec > MAXBPS)
431
        printf( "WARNING: bytes/sector (%u) is bigger than %u",
432
	       bpb.bpbBytesPerSec, MAXBPS);
427
    if (!(fat = opt_F)) {
433
    if (!(fat = opt_F)) {
428
	if (opt_f)
434
	if (opt_f)
429
	    fat = 12;
435
	    fat = 12;
Lines 447-452 Link Here
447
		 opt_b, bpb.bpbBytesPerSec * MAXSPC);
453
		 opt_b, bpb.bpbBytesPerSec * MAXSPC);
448
	bpb.bpbSecPerClust = opt_b / bpb.bpbBytesPerSec;
454
	bpb.bpbSecPerClust = opt_b / bpb.bpbBytesPerSec;
449
    }
455
    }
456
    if (bpb.bpbSecPerClust * bpb.bpbBytesPerSec > 32 * 1024)
457
        printf("WARNING: bytes per sector (%u) is greater than 32K",
458
	     bpb.bpbSecPerClust * bpb.bpbBytesPerSec);
450
    if (opt_c) {
459
    if (opt_c) {
451
	if (!powerof2(opt_c))
460
	if (!powerof2(opt_c))
452
	    errx(1, "sectors/cluster (%u) is not a power of 2", opt_c);
461
	    errx(1, "sectors/cluster (%u) is not a power of 2", opt_c);

Return to bug 151850