From owner-freebsd-bugs Thu May 10 3:20:13 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 3F04B37B423 for ; Thu, 10 May 2001 03:20:05 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f4AAK5065603; Thu, 10 May 2001 03:20:05 -0700 (PDT) (envelope-from gnats) Date: Thu, 10 May 2001 03:20:05 -0700 (PDT) Message-Id: <200105101020.f4AAK5065603@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jan Conrad Subject: Re: kern/27232: On NFSv3 mounted filesystems, stat returns st_blksize=512 Reply-To: Jan Conrad Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR kern/27232; it has been noted by GNATS. From: Jan Conrad To: Garrett Wollman Cc: 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 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 #include #include #include #include #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