From owner-freebsd-bugs@FreeBSD.ORG Sat Jan 9 16:00:13 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E0831065692 for ; Sat, 9 Jan 2010 16:00:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 41E8D8FC24 for ; Sat, 9 Jan 2010 16:00:13 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o09G0DVM073557 for ; Sat, 9 Jan 2010 16:00:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o09G0Del073556; Sat, 9 Jan 2010 16:00:13 GMT (envelope-from gnats) Resent-Date: Sat, 9 Jan 2010 16:00:13 GMT Resent-Message-Id: <201001091600.o09G0Del073556@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pedro Giffuni Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B562106566B for ; Sat, 9 Jan 2010 15:54:42 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id ED9B98FC08 for ; Sat, 9 Jan 2010 15:54:41 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o09FsfLt084811 for ; Sat, 9 Jan 2010 15:54:41 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o09FsfJ0084778; Sat, 9 Jan 2010 15:54:41 GMT (envelope-from nobody) Message-Id: <201001091554.o09FsfJ0084778@www.freebsd.org> Date: Sat, 9 Jan 2010 15:54:41 GMT From: Pedro Giffuni To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/142526: Cleanups and updates to newfs_msdos X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jan 2010 16:00:13 -0000 >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: