What size blocks does GNU truncate --io-blocks use?
-o, --io-blocks treat SIZE as number of IO blocks instead of bytes
- 512 bytes
blockdev --getbszblockdev --getpbsz
What size blocks does GNU truncate --io-blocks use?
-o, --io-blocks treat SIZE as number of IO blocks instead of bytes
blockdev --getbszblockdev --getpbszNone of the above.
The blocksize is related to the filesystem parameters chosen at mkfs time, and can be found by running stat() against the file. It has no relation to the underlying block device the file system is stored on (if any).
For example, with GNU stat:
$ /usr/bin/stat . | grep IO.Block
Size: 71680 Blocks: 144 IO Block: 2048 directory
If you prefer a more programmatic view, the stat() system call can be made in perl with:
$ perl -e '@x=stat("."); print $x[11]'
2048
In both cases we get "2048" as the answer for this filesystem.
We can verify this:
$ truncate -o -s 1 foo
$ ls -l foo
-rw-r--r-- 1 sweh sweh 2048 Sep 17 10:28 foo
Different filesystems can have different block sizes. eg on my machine I made the /news disk use smaller block sizes because it stores mostly smaller files
$ perl -e '@x=stat("/"); print $x[11]'
4096
$ perl -e '@x=stat("/news"); print $x[11]'
2048
For Linux extx file systems, this is done with mke2fs with the -b flag:
-b block-size
Specify the size of blocks in bytes. Valid block-size values
are 1024, 2048 and 4096 bytes per block. If omitted, block-size
is heuristically determined by the filesystem size and the
expected usage of the filesystem (see the -T option). If block-
size is preceded by a negative sign ('-'), then mke2fs will use
heuristics to determine the appropriate block size, with the
constraint that the block size will be at least block-size
bytes. This is useful for certain hardware devices which
require that the blocksize be a multiple of 2k.
rsize mount option, nevertheless the block size of the underlaying filesystem.
stat() against the file (which is what the code does) is required to get the right answer. And it should, really, be against the file and not the directory, because you can get different results there, as well.
truncate has that --io-block in the first place though (FreeBSD where that utility first came from in 2000) doesn't have it, nor why it's not implemented as a suffix for the size (like truncate -s1B). It's been there from the start apparently. I can't imagine it being a common use case.