admin管理员组

文章数量:1123776

Is the value of st_blksize field of struct stat type filled inside function stat()'s output parameter, hard coded in some system config file? If it is, can somebody tell me the system config file path?

Is the value of st_blksize field of struct stat type filled inside function stat()'s output parameter, hard coded in some system config file? If it is, can somebody tell me the system config file path?

Share Improve this question asked yesterday HarryHarry 2,8051 gold badge22 silver badges46 bronze badges 5
  • 4 No — it depends on the file system, etc. – Jonathan Leffler Commented yesterday
  • 2 In one sense, yes. Unlike most of the other members of struct stat, the st_blksize is a property of the filesystem, not of the individual file. Generally, there's not a config file for this per se, but you can determine the filesystem type and some details from files, and, if that's not enough, with sufficient privilege you can read filesystem details from the host device. But I don't that, especially the last bit, is what you really meant. – John Bollinger Commented yesterday
  • @JonathanLeffler how to get that info non programmatically? – Harry Commented yesterday
  • 7 Substantially, you can't — certainly not portably between Linux and non-Linux systems. There's the POSIX statvfs() function, but it provides minimal reliable information. The various stat() functions may provide more, but that's all programmatic because the answer depends on which file system a given file resides on. You can't rely on a value derived at compile time. – Jonathan Leffler Commented yesterday
  • Define 'non-programmatically'. Do you mean via a command line? – user207421 Commented 2 hours ago
Add a comment  | 

1 Answer 1

Reset to default 1

Converting my comments into an answer.

The preferred block size may vary by file system type, so there's no easy way to determine one size at compile time for all files on a system — let alone if the executable will be copied across systems.

Can you get that information non-programmatically?

No — certainly not portably between Linux and non-Linux systems. There's the POSIX statvfs() function, but it provides minimal reliable information. The various stat() functions may provide more information, but that's all programmatic because the answer depends on which file system a given file resides on. You can't rely on a value derived at compile time.

本文标签: cpreferred block size for efficient file IOStack Overflow