Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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/ Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Change History (9)

comment:1 Changed 9 years ago by kaoutsis

Required by wine:

/Haiku1/packages/wine-1.0-rc1/dlls/ntdll> make
gcc -c -I. -I. -I../../include -I../../include  -D__WINESRC__ -D_NTSYSTEM_ -D_REENTRANT -fPIC -Wall -pipe -fno-strict-aliasing -Wwrite-strings -Wpointer-arith  -g -O2  -o directory.o directory.c
/Haiku1/packages/wine-1.0-rc1/dlls/ntdll/directory.c: In function `append_entry':
/Haiku1/packages/wine-1.0-rc1/dlls/ntdll/directory.c:947: structure has no member named `st_blocks'
make: *** [directory.o] Error 1

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;

comment:2 Changed 9 years ago by Andreas Färber

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 Changed 9 years ago by Niels Sascha Reedijk

Git also assumes this st_blocks to exist.

comment:4 Changed 9 years ago by Ingo Weinhold

Component: - GeneralSystem
Type: bugenhancement

stat::st_blocks is actually part of the XSI extension.

comment:5 in reply to:  3 Changed 9 years ago by scottmc

Replying to nielx:

Git also assumes this st_blocks to exist.

So does CVS 1-12-13...

comment:6 Changed 9 years ago by axeld

Component: SystemSystem/
Resolution: fixed
Status: newclosed

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 9 years ago by Rene Gollent

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.


comment:8 Changed 9 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 9 years ago by Rene Gollent

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.

Note: See TracTickets for help on using tickets.