`truncate --io-blocks`はどのサイズのブロックを使用しますか?

`truncate --io-blocks`はどのサイズのブロックを使用しますか?

GNUのブロックサイズはいくらですか?truncate --io-blocks使用?

      -o, --io-blocks
             treat SIZE as number of IO blocks instead of bytes
  • 512バイト
  • blockdev --getbsz
  • blockdev --getpbsz

ベストアンサー1

上記のいずれもありません。

ブロックサイズは、mkfsを使用するときに選択したファイルシステムパラメータに関連付けられており、ファイルを実行して見つけることがstat()できます。ファイルシステムが保存されている基本ブロックデバイス(存在する場合)とは何の関係もありません。

たとえば、GNUを使用すると、次のようになりますstat

$ /usr/bin/stat . | grep IO.Block       
  Size: 71680           Blocks: 144        IO Block: 2048   directory

よりプログラミング的なビューを好む場合は、stat()次のコマンドを使用してシステムコールを実行できますperl

$ perl -e '@x=stat("."); print $x[11]'
2048

どちらの場合も、そのファイルシステムに対する答えとして「2048」を取得します。

私達はこれを確認できます:

$ truncate -o -s 1 foo      
$ ls -l foo
-rw-r--r-- 1 sweh sweh 2048 Sep 17 10:28 foo

ファイルシステムごとにブロックサイズが異なる場合があります。たとえば、私のコンピュータでは、/newsディスクはほとんど小さなファイルを保存するので、より小さいブロックサイズを使用するようにします。

$ perl -e '@x=stat("/"); print $x[11]'
4096

$ perl -e '@x=stat("/news"); print $x[11]'
2048

Linuxファイルシステムでは、これは次のフラグを使用して行われます。extxmke2fs-b

   -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.

おすすめ記事