Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Aug 2009 11:04:32 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r196400 - stable/8/usr.bin/fstat
Message-ID:  <200908201104.n7KB4WkZ084364@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Aug 20 11:04:31 2009
New Revision: 196400
URL: http://svn.freebsd.org/changeset/base/196400

Log:
  MFC 196399: fstat: fix fsid comparison when executed on systems with 64-bit long
  
  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].
  
  Reviewed by:    jhb, lulf
  Approved by:    re (kib)
  MFC after:      1 week (to stable/7)

Modified:
  stable/8/usr.bin/fstat/   (props changed)
  stable/8/usr.bin/fstat/fstat.c
  stable/8/usr.bin/fstat/zfs.c

Modified: stable/8/usr.bin/fstat/fstat.c
==============================================================================
--- stable/8/usr.bin/fstat/fstat.c	Thu Aug 20 10:57:14 2009	(r196399)
+++ stable/8/usr.bin/fstat/fstat.c	Thu Aug 20 11:04:31 2009	(r196400)
@@ -658,7 +658,7 @@ devfs_filestat(struct vnode *vp, struct 
 		    (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;

Modified: stable/8/usr.bin/fstat/zfs.c
==============================================================================
--- stable/8/usr.bin/fstat/zfs.c	Thu Aug 20 10:57:14 2009	(r196399)
+++ stable/8/usr.bin/fstat/zfs.c	Thu Aug 20 11:04:31 2009	(r196400)
@@ -117,7 +117,7 @@ zfs_filestat(struct vnode *vp, struct fi
 		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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908201104.n7KB4WkZ084364>