Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 May 2001 03:20:05 -0700 (PDT)
From:      Jan Conrad <conrad@th.physik.uni-bonn.de>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/27232: On NFSv3 mounted filesystems, stat returns st_blksize=512
Message-ID:  <200105101020.f4AAK5065603@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/27232; it has been noted by GNATS.

From: Jan Conrad <conrad@th.physik.uni-bonn.de>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: <freebsd-gnats-submit@FreeBSD.ORG>
Subject: Re: kern/27232: On NFSv3 mounted filesystems, stat returns st_blksize=512
Date: Thu, 10 May 2001 12:18:18 +0200 (CEST)

 On Wed, 9 May 2001, Garrett Wollman wrote:
 
 > <<On Wed, 9 May 2001 10:11:55 -0700 (PDT), conrad@th.physik.uni-bonn.de said:
 >
 > > On NFSv3 mounts, stat returns st_blksize=512 for every regular file.
 > > This in turn is used by libc routines as a default buffer size, as it
 > > should be the 'optimal' io blocksize.
 >
 > No.  It should be the block size used by the underlying filesystem's
 > block allocator, and in which the file's `st_blocks' size-on-disk is
 > reported.  While SUS describes it as a ``preferred'' block size, and
 > the FreeBSD manual pages describe it as ``optimal ... for I/O'', the
 > most important meaning of this field is as a multiplier of st_blocks
 > to determine the file's size.
 
 Hmm - I am sorry, but I can't believe your answer.
 
 If I stat the following file on /var/tmp (newfs'd with -b 8192 -f 1024)
 (all with FreeBSD 4.3R)
 
 -rw-r--r--  1 root  wheel  33398 Mar 13 17:40 /var/tmp/dev.out
 
 # my little stat checker (appended to the message) gives me
 ./stat
 /var/tmp/dev.out:
 st_mode = 100644
 st_blksize = 8192
 st_size = 33398
 st_blocks = 66
 
 As you can see st_blocks measures the size of the file in 512byte blocks
 independent of st_blksize!
 
 And the source of this is ufs_getattr in sys/ufs/ufs/ufs_vnops.c
 (this is present in HEAD!)
 
 	vap->va_flags = ip->i_flags;
 	vap->va_gen = ip->i_gen;
 	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 	vap->va_bytes = dbtob((u_quad_t)ip->i_blocks);
 	vap->va_type = IFTOVT(ip->i_mode);
 
 So either ufs or nfs is wrong (or both!)
 
 
 -Jan
 
 
 
 The output is from the following little program
 
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
 #define FILE1 "/milles/home/conrad/src/stat/stat.c"
 #define FILE2 "/.amd_mnt/avz109/users/Math_Dictionary/readme.htm"
 #define FILE3 "/var/tmp/dev.out"
 
 
 main()
 {
   struct stat sb;
   char *file = FILE3;
 
   if (stat(file, &sb) < 0) {
     printf ("fail\n");
   } else {
     printf ("%s:\n", file);
     printf ("st_mode = %o\n", sb.st_mode);
     printf ("st_blksize = %u\n", sb.st_blksize);
     printf ("st_size = %u\n", sb.st_size);
     printf ("st_blocks = %U\n", sb.st_blocks);
   };
 }
 
 
 
 
 >
 > -GAWollman
 >
 > --
 > Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
 > wollman@lcs.mit.edu  | O Siem / The fires of freedom
 > Opinions not those of| Dance in the burning flame
 > MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
 >
 
 -- 
 Physikalisches Institut der Universitaet Bonn
 Nussallee 12
 D-53115 Bonn
 GERMANY
 
 
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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