Re: newfs broken in -CURRENT after 204654

From: Jayachandran C. <c.jayachandran_at_gmail.com>
Date: Mon, 8 Mar 2010 18:08:05 +0530
On Mon, Mar 08, 2010 at 11:58:39AM +0000, Poul-Henning Kamp wrote:
> In message <20100308125643.1ac0be0f_at_ernst.jennejohn.org>, Gary Jennejohn writes
> :
> >On Mon, 8 Mar 2010 14:17:17 +0530
> 
> >> I'm trying this one more time, since the issue is still unresolved.
> >> 
> >> newfs(8) broke for big-endian systems since revision 204654. This change
> >> made sectorsize variable int64_t, and now it cannot be passed to the ioctl
> >> DIOCGSECTORSIZE.
> 
> This patch is correct, DIOCGSECTORSIZE takes an unsigned argument, see
> <sys/disk.h>:
> 
> #define DIOCGSECTORSIZE _IOR('d', 128, u_int)
>         /*-
>          * Get the sectorsize of the device in bytes.  The sectorsize is the
>          * smallest unit of data which can be transfered from this device.
>          * Usually this is a power of two but it may not be. (ie: CDROM audio)
>          */
> 
> 
> >I can't say whether this is correct, but the logic could definitely be
> >simplified like this, since sectorsize is known to be 0 already:
> >	    if (sectorsize == 0)
> >		if (ioctl(disk.d_fd, DIOCGSECTORSIZE, &tsecsize) >= 0)
> >		    sectorsize = tsecsize;
> 
> I'm not sure that is a valid assumption.

I think I missed this one. Probably we could do ioctl(...) != -1 and be equivalent.
Thanks for the comments.  New patch below.


Index: sbin/newfs/newfs.c
===================================================================
--- sbin/newfs/newfs.c	(revision 204858)
+++ sbin/newfs/newfs.c	(working copy)
_at__at_ -132,6 +132,7 _at__at_
 	char *cp, *special;
 	intmax_t reserved;
 	int ch, i, rval;
+	u_int tsecsize;
 	off_t mediasize;
 	char part_name;		/* partition name, default to full disk */
 
_at__at_ -328,8 +329,8 _at__at_
 		/* set fssize from the partition */
 	} else {
 	    if (sectorsize == 0)
-		if (ioctl(disk.d_fd, DIOCGSECTORSIZE, &sectorsize) == -1)
-		    sectorsize = 0;	/* back out on error for safety */
+		if (ioctl(disk.d_fd, DIOCGSECTORSIZE, &tsecsize) != -1)
+		    sectorsize = tsecsize;
 	    if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1)
 		getfssize(&fssize, special, mediasize / sectorsize, reserved);
 	}



Regards,
JC.
Received on Mon Mar 08 2010 - 11:34:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:01 UTC