From owner-freebsd-current@FreeBSD.ORG Fri Jun 12 16:50:44 2009 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 CA769106566B; Fri, 12 Jun 2009 16:50:44 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id A76E18FC14; Fri, 12 Jun 2009 16:50:43 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id TAA11796; Fri, 12 Jun 2009 19:50:41 +0300 (EEST) (envelope-from avg@freebsd.org) Message-ID: <4A328760.40301@freebsd.org> Date: Fri, 12 Jun 2009 19:50:40 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.21 (X11/20090406) MIME-Version: 1.0 To: Ulf Lilleengen , freebsd-current@freebsd.org X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Subject: fstat patch (64-bit os, zfs or devfs) 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, 12 Jun 2009 16:50:45 -0000 What do you think about the following change? commit c6d04723027dbc493376b6fd058bd7875ec8a888 Author: Andriy Gapon Date: Fri Jun 12 19:16:45 2009 +0300 fstat: fix fsid comparison when executed on a file on 64-bit system This affects only fstat on zfs and devfs, only on 64-bit systems and only when fsid is greater than 2^31 - 1. When fstat examines a file via stat(2) it takes uint32_t st_dev and assigns to (signed) (64-bit) long fsid, this results in a positive value. When fstat examines opened files it takes int32_t f_fsid.val[0] and assigns to (signed) (64-bit) long fsid, this results in a negative value. So, while initially st_dev and f_fsid.val[0] have the same bit values they get promoted to different 64-bit values because of the signed-vs-unsigned difference. A fix is to use "more natural" positive numbers by introducing intermediate unsigned cast for f_fsid.val[0]. diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 0907c49..dc728e5 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -649,7 +649,7 @@ devfs_filestat(struct vnode *vp, struct filestat *fsp) (void *)devfs_dirent.de_vnode, Pid); return 0; } - fsp->fsid = (long)mount.mnt_stat.f_fsid.val[0]; + fsp->fsid = (long)(uint32_t)mount.mnt_stat.f_fsid.val[0]; fsp->fileid = devfs_dirent.de_inode; fsp->mode = (devfs_dirent.de_mode & ~S_IFMT) | S_IFCHR; fsp->size = 0; diff --git a/usr.bin/fstat/zfs.c b/usr.bin/fstat/zfs.c index f611b1c..f654e79 100644 --- a/usr.bin/fstat/zfs.c +++ b/usr.bin/fstat/zfs.c @@ -117,7 +117,7 @@ zfs_filestat(struct vnode *vp, struct filestat *fsp) goto bad; } - fsp->fsid = (long)mount.mnt_stat.f_fsid.val[0]; + fsp->fsid = (long)(uint32_t)mount.mnt_stat.f_fsid.val[0]; fsp->fileid = *zid; /* * XXX: Shows up wrong in output, but UFS has this error too. Could -- Andriy Gapon