This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/11611] New: statvfs sign-extends lower 32 bits of f_fsid field, loses upper 32 bits


I'm running on CentOS 5.4 (but this bug appears to go back a long ways).

I have a file system mounted which has a 64-bit FSID, of which bit 31 is set:

  000486ba.a1297d6b

Note that the lower 32 bits of the FSID, if interpreted as a signed number, are negative.

If I apply fstatvfs() to this file system, I get an incorrect FSID, because the lower half is sign-extended into the upper half:

fstatvfs returns:
  ffffffff.a1297d6b

If I call fstatfs() instead, I get:
  000486ba.a1297d6b

I traced the problem down to the INTERNAL_STATVFS routine in glibc/sysdeps/unix/sysv/linux/internal_statvfs.c.  (This is not 
quite the newest version, as the source tree I had handy was dated 2009-09-09, but I don't see any recent changes in this 
area.)

The fsid is assigned here:

  if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
    buf->f_fsid = (fsbuf->f_fsid.__val[0]
		   | ((unsigned long int) fsbuf->f_fsid.__val[1]
		      << (8 * (sizeof (buf->f_fsid)
			       - sizeof (fsbuf->f_fsid.__val[0])))));

Note that ' fsbuf->f_fsid.__val[0] ' is not cast to an unsigned value.  f_fsid is defined in glibc/bits/typesizes.h as a structure of 
two 'int' values.

Thus f_fsid, which is a 64-bit value, gets assigned a 32-bit signed 'int' value which is ORed against the upper 32 bits.  If the 
lower half has its sign bit set, the f_fsid will be incorrect.

Luckily, there is an easy workaround, as the statfs() and fstatfs() calls don't suffer from this problem.  (But they're not POSIX, 
either.)

-- 
           Summary: statvfs sign-extends lower 32 bits of f_fsid field,
                    loses upper 32 bits
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: rang at me dot com
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: x86_64, Linux (CentOS 5.4)


http://sourceware.org/bugzilla/show_bug.cgi?id=11611

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]