Date: Sat, 9 Jan 2010 15:54:41 GMT From: Pedro Giffuni <giffunip@tutopia.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/142526: Cleanups and updates to newfs_msdos Message-ID: <201001091554.o09FsfJ0084778@www.freebsd.org> Resent-Message-ID: <201001091600.o09G0Del073556@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 142526 >Category: bin >Synopsis: Cleanups and updates to newfs_msdos >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Jan 09 16:00:12 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Pedro Giffuni >Release: 8.0-RELEASE >Organization: >Environment: FreeBSD mogwai.giffuni.net 8.0-RELEASE FreeBSD 8.0-RELEASE #12: Tue Dec 1 23:31:27 UTC 2009 pedro@mogwai.giffuni.net:/usr/src/sys/i386/compile/GENERIC i386 >Description: Some cleanups from NetBSD: - c99 initializers - snprintf instead of sprintf - Change the default volume label from "NO NAME" to "NO_NAME". And others for compatibility: - Limit Bytes per Sector to max. 4096 to remain in spec. - Set OEM String to "BSD4.4 " following the unnamed spacing convention in that other OS that suggests "MSWIN4.1" >How-To-Repeat: >Fix: diff -ru newfs_msdos.orig/newfs_msdos.8 newfs_msdos/newfs_msdos.8 --- newfs_msdos.orig/newfs_msdos.8 2010-01-06 11:06:02.000000000 +0000 +++ newfs_msdos/newfs_msdos.8 2010-01-09 10:25:12.000000000 +0000 @@ -116,7 +116,7 @@ .It Fl S Ar sector-size Number of bytes per sector. Acceptable values are powers of 2 -in the range 128 through 32768. +in the range 512 through 4096. .It Fl a Ar FAT-size Number of sectors per FAT. .It Fl b Ar block-size diff -ru newfs_msdos.orig/newfs_msdos.c newfs_msdos/newfs_msdos.c --- newfs_msdos.orig/newfs_msdos.c 2010-01-06 11:06:02.000000000 +0000 +++ newfs_msdos/newfs_msdos.c 2010-01-09 10:31:00.000000000 +0000 @@ -56,6 +56,7 @@ #define DOSMAGIC 0xaa55 /* DOS magic number */ #define MINBPS 512 /* minimum bytes per sector */ +#define MAXBPS 4096 /* maximum bytes per sector */ #define MAXSPC 128 /* maximum sectors per cluster */ #define MAXNFT 16 /* maximum number of FATs */ #define DEFBLK 4096 /* default block size */ @@ -165,20 +166,23 @@ #define BPBGAP 0, 0, 0, 0, 0, 0 +#define INIT(a, b, c, d, e, f, g, h, i, j) \ + { .bps = a, .spc = b, .res = c, .nft = d, .rde = e, \ + .sec = f, .mid = g, .spf = h, .spt = i, .hds = j, } static struct { const char *name; struct bpb bpb; } const stdfmt[] = { - {"160", {512, 1, 1, 2, 64, 320, 0xfe, 1, 8, 1, BPBGAP}}, - {"180", {512, 1, 1, 2, 64, 360, 0xfc, 2, 9, 1, BPBGAP}}, - {"320", {512, 2, 1, 2, 112, 640, 0xff, 1, 8, 2, BPBGAP}}, - {"360", {512, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2, BPBGAP}}, - {"640", {512, 2, 1, 2, 112, 1280, 0xfb, 2, 8, 2, BPBGAP}}, - {"720", {512, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2, BPBGAP}}, - {"1200", {512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2, BPBGAP}}, - {"1232", {1024,1, 1, 2, 192, 1232, 0xfe, 2, 8, 2, BPBGAP}}, - {"1440", {512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2, BPBGAP}}, - {"2880", {512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2, BPBGAP}} + {"160", INIT(512, 1, 1, 2, 64, 320, 0xfe, 1, 8, 1)}, + {"180", INIT(512, 1, 1, 2, 64, 360, 0xfc, 2, 9, 1)}, + {"320", INIT(512, 2, 1, 2, 112, 640, 0xff, 1, 8, 2)}, + {"360", INIT(512, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2)}, + {"640", INIT(512, 2, 1, 2, 112, 1280, 0xfb, 2, 8, 2)}, + {"720", INIT(512, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2)}, + {"1200", INIT(512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2)}, + {"1232", INIT(1024,1, 1, 2, 192, 1232, 0xfe, 2, 8, 2)}, + {"1440", INIT(512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2)}, + {"2880", INIT(512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2)} }; static const u_int8_t bootcode[] = { @@ -424,6 +428,9 @@ if (bpb.bps < MINBPS) errx(1, "bytes/sector (%u) is too small; minimum is %u", bpb.bps, MINBPS); + else if (bpb.bps > MAXBPS) + errx(1, "bytes/sector (%u) is too big; maximum is %u", + bpb.bps, MAXBPS); if (!(fat = opt_F)) { if (opt_f) fat = 12; @@ -533,7 +540,7 @@ if (!bpb.res) bpb.res = fat == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x; else if (bpb.res < x) - errx(1, "too few reserved sectors"); + errx(1, "too few reserved sectors (need %d have %d)", x, bpb.res); if (fat != 32 && !bpb.rde) bpb.rde = DEFRDE; rds = howmany(bpb.rde, bpb.bps / sizeof(struct de)); @@ -657,8 +664,8 @@ ((u_int)tm->tm_hour << 8 | (u_int)tm->tm_min)); mk4(bsx->volid, x); - mklabel(bsx->label, opt_L ? opt_L : "NO NAME"); - sprintf(buf, "FAT%u", fat); + mklabel(bsx->label, opt_L ? opt_L : "NO_NAME"); + snprintf(buf, sizeof(buf), "FAT%u", fat); setstr(bsx->type, buf, sizeof(bsx->type)); if (!opt_B) { x1 += sizeof(struct bsx); @@ -666,7 +673,7 @@ mk1(bs->jmp[0], 0xeb); mk1(bs->jmp[1], x1 - 2); mk1(bs->jmp[2], 0x90); - setstr(bs->oem, opt_O ? opt_O : "BSD 4.4", + setstr(bs->oem, opt_O ? opt_O : "BSD4.4 ", sizeof(bs->oem)); memcpy(img + x1, bootcode, sizeof(bootcode)); mk2(img + MINBPS - 2, DOSMAGIC); >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001091554.o09FsfJ0084778>