#2261 closed enhancement (fixed)
Member named `st_blocks' is missing from struct stat in sys/stat.h
| Reported by: | kaoutsis | Owned by: | axeld |
|---|---|---|---|
| Priority: | normal | Milestone: | R1 |
| Component: | System/libroot.so | Version: | R1/pre-alpha1 |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: | ||
| Has a Patch: | no | Platform: | All |
Description
Change History (9)
comment:1 Changed 7 years ago by kaoutsis
comment:2 Changed 7 years ago by andreasf
This has been a common issue for ports, see some examples and workarounds at HaikuPorts (formerly BePorts). BeOS did not have it either.
comment:3 follow-up: ↓ 5 Changed 7 years ago by nielx
Git also assumes this st_blocks to exist.
comment:4 Changed 7 years ago by bonefish
- Component changed from - General to System
- Type changed from bug to enhancement
stat::st_blocks is actually part of the XSI extension.
comment:5 in reply to: ↑ 3 Changed 7 years ago by scottmc
comment:6 Changed 7 years ago by axeld
- Component changed from System to System/libroot.so
- Resolution set to fixed
- Status changed from new to closed
Fixed in hrev27791. What unit is used for st_blocks in the software that it uses besides WINE which assumes a block size of 512?
Currently, BFS uses its native block size for the computation of the value, but if it's always expressed in 512 blocks, then we should probably change this.
Also note that this is just another value that cannot be retrieved via BStatable::GetStat() due to binary compatibility.
comment:7 Changed 7 years ago by anevilyak
The POSIX spec seems to indicate that it's allowed to vary:
The unit for the st_blocks member of the stat structure is not defined within IEEE Std 1003.1-2001. In some implementations it is 512 bytes. It may differ on a file system basis. There is no correlation between values of the st_blocks and st_blksize, and the f_bsize (from <sys/statvfs.h>) structure members.
Source: http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html
comment:8 Changed 7 years ago by axeld
The POSIX spec is pretty stupid in this regard, as it makes the st_blocks field essentially useless. So if other platforms are using a consistent value, we should use that, too.
comment:9 Changed 7 years ago by anevilyak
Right, I was wondering about that as well, since I don't see from the spec how you would actually determine the block size on a particular platform.

Required by wine:
directory.c at line 947 +-1:
info->EndOfFile.QuadPart = st.st_size; info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512; info->FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;