OT: multi-platform *nix blocksize detection
Bill Vermillion
fp at wjv.com
Wed Oct 20 06:45:26 PDT 2004
On Tue, Oct 19 23:15 Fairlight said 'Who you talkin' to? You talkin'
to Fairlight? I didn't do nuttin'. I said:
> Decidedly OT, but we have some people with *nix expertise here...
> Anyone know how to standardly detect the block size on a *nix
> filesystem, independant of platform type?
> I know, for instance, that linux ext2 uses 512-byte blocks...at
> least on most systems with SCSI drives that I've seen.
> However, I know FBSD has like a 4K or 8K block size, and
> Solaris has a 4K block size on the system I just checked.
Don't confuse physical block size with filesystem block size.
Almost all systems will be using a 512-byte block size on the hard
disk. The exceptions will be those that include ECC in the block
and those will be in the 560 byte range.
I've just looked at mkfs.ext2 and Linus also allocates in
1024, 2048 or 4096 byte blocks. So you can not depend
on the file system allocation size being the same on all system -
but the default will the 1024.
Any system using 512 byte file system allocation sizes will
have performance losses - and increased performance is why
the FFS system in BSD was developed and has since migrated
to a great many OSes. SCO's file system are all based on FFS
or enhanced versions - with a lot of work being done original
by Acer with the AFFS [or AFS?] which is as I recall the heart
of the HTFS in SCO.
I know of no Unix[like] system that uses 512 bytes in the file
system.
The S51 - the original Unix file system - and in this group most
seen in Xenix - had logical allocations of 1024K bytes - eg
two physical blocks.
In an effort to improve performance the AT&T SysV2 brought forth
the S52 file system. That allocated 4 blocks at a time - or
2048 bytes.
BSD has always used a 512 byte physical block size and used to
use eight 512 physical byte block allocations for 4096 byte
file-system blocks.
The older BSD systems used to use 4096 filesystem blocks - with
1024 fragments, but now the filesystem block size defaults
to 16384 byte long file system blocks. Minimum file size
allocations is 4096 - but with today's larger files for almost
everything the larger size improves performance.
> I need to do something conditionally based on the block
> size--alter some calculations, actually.
> Anyone know of a standard way to find out automatically in
> -any- kind of code? I can extrapolate. I thought of using
> stat on a file and checking st_blksize, but that's actually
> the desired I/O block size it wants, not how it really stores
> it--at least not in reality on this system I'm working on
> at the moment. It says 4096. I guarantee these are 512-byte
> blocks.
I can almost guarantee that at almost 100% of the systems you will
see are using 512-byte blocks [and I'm lumbing in those with
the 560+ byte physical blocks in that group].
> Checking manually with fdisk isn't something I'd like to suggest to an
> end-user, ya know? :)
And I'm curious as to why you need to know this, and why a user
would need this. Unless you are working at the lowest OS level
you are going to be constrained by the allocation sizes imposed
by the file system.
Bill
--
Bill Vermillion - bv @ wjv . com
More information about the Filepro-list
mailing list