From owner-freebsd-current@FreeBSD.ORG Fri Apr 8 19:35:15 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F18A41065674 for ; Fri, 8 Apr 2011 19:35:15 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe02.c2i.net [212.247.154.34]) by mx1.freebsd.org (Postfix) with ESMTP id 802138FC16 for ; Fri, 8 Apr 2011 19:35:15 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=oR3+9dOmPeF3nZCt5Gxyvf/bIpfj8bfjGZkkfp/xES8= c=1 sm=1 a=IU0TiZmyZPMA:10 a=Iba5Pj8TEUkA:10 a=WQU8e4WWZSUA:10 a=kj9zAlcOel0A:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=I9e8OeI0s8YJDl6_EUwA:9 a=YQQ5uAi0Li113Qy5L50A:7 a=CjuIK1q_8ugA:10 a=VRswk_N_Q0jjV6_B:21 a=jx-RxEBJv90FUxRe:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe02.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 111869573 for freebsd-current@freebsd.org; Fri, 08 Apr 2011 21:35:13 +0200 From: Hans Petter Selasky To: "freebsd-current@FreeBSD.org" Date: Fri, 8 Apr 2011 21:34:15 +0200 User-Agent: KMail/1.13.5 (FreeBSD/8.2-PRERELEASE; KDE/4.4.5; amd64; ; ) X-Face: *nPdTl_}RuAI6^PVpA02T?$%Xa^>@hE0uyUIoiha$pC:9TVgl.Oq, NwSZ4V"|LR.+tj}g5 %V,x^qOs~mnU3]Gn; cQLv&.N>TrxmSFf+p6(30a/{)KUU!s}w\IhQBj}[g}bj0I3^glmC( :AuzV9:.hESm-x4h240C`9=w MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201104082134.15674.hselasky@c2i.net> Subject: Fdisk formatting of disk having bs=1K fails X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2011 19:35:16 -0000 Hi, It appears that src/sbin/fdisk.c can only read the MBR of disks having a blocksize different than 512 bytes. When writing a new MBR, the below check fails. Can someone having knowledge into fdisk, fix this issue and MFC to 8- stable? Also I'm curious about the #ifdef __ia64__ . if ((mboot.bootinst_size = sb.st_size) % secsize != 0) secsize = 1024; sb.st_size = sizeof(/boot/mbr) = 512; --HPS My attempt to fix this issue: --- fdisk.c (revision 220305) +++ fdisk.c (local) @@ -508,22 +508,29 @@ const char *fname; int fdesc, n; struct stat sb; + off_t align_size; fname = b_flag ? b_flag : "/boot/mbr"; if ((fdesc = open(fname, O_RDONLY)) == -1 || fstat(fdesc, &sb) == -1) err(1, "%s", fname); - if ((mboot.bootinst_size = sb.st_size) % secsize != 0) - errx(1, "%s: length must be a multiple of sector size", fname); + + align_size = (sb.st_size + secsize - 1); + align_size -= align_size % secsize; + if (align_size == 0) + errx(1, "%s: length must be non-zero", fname); + mboot.bootinst_size = align_size; if (mboot.bootinst != NULL) free(mboot.bootinst); - if ((mboot.bootinst = malloc(mboot.bootinst_size = sb.st_size)) == NULL) + if ((mboot.bootinst = malloc(align_size)) == NULL) errx(1, "%s: unable to allocate read buffer", fname); - if ((n = read(fdesc, mboot.bootinst, mboot.bootinst_size)) == -1 || + if ((n = read(fdesc, mboot.bootinst, sb.st_size)) == -1 || close(fdesc)) err(1, "%s", fname); - if (n != mboot.bootinst_size) + if (n != sb.st_size) errx(1, "%s: short read", fname); + if (align_size != n) + memset(mboot.bootinst + sb.st_size, 0, align_size - sb.st_size); #else if (mboot.bootinst != NULL) free(mboot.bootinst);