Add statvfs to Linux LibC#1029
Conversation
| public int[] _f_unused = new int[PADDING_SIZE]; // 0 on 64-bit systems | ||
| public NativeLong fsMountFlags; | ||
| public NativeLong fsMaxFilenameLength; | ||
| public int[] _fSpare = new int[6]; |
There was a problem hiding this comment.
Could you please describe where the C structure is from? The linux manpage has this to say:
struct statvfs {
unsigned long f_bsize; /* Filesystem block size */
unsigned long f_frsize; /* Fragment size */
fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */
fsblkcnt_t f_bfree; /* Number of free blocks */
fsblkcnt_t f_bavail; /* Number of free blocks for
unprivileged users */
fsfilcnt_t f_files; /* Number of inodes */
fsfilcnt_t f_ffree; /* Number of free inodes */
fsfilcnt_t f_favail; /* Number of free inodes for
unprivileged users */
unsigned long f_fsid; /* Filesystem ID */
unsigned long f_flag; /* Mount flags */
unsigned long f_namemax; /* Maximum filename length */
};.
// Here the types fsblkcnt_t and fsfilcnt_t are defined in <sys/types.h>.
// Both used to be unsigned longThis would indicate, that a mapping with all elements mapped as NativeLong and no padding would be correct. I'm also wondering about the ints used as padding. Are you sure that are not byte[]?
There was a problem hiding this comment.
The manpage defines the structure "approximately as follows". The header of sys/statvfs.h imports from bits/statvfs.h where the structure is defined. The relevant padding is a single 32-bit int:
#ifdef _STATVFSBUF_F_UNUSED
int __f_unused;
#endif
That conditional define is based on having 32-bit wordsize:
#if (__WORDSIZE == 32 \
&& (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
#define _STATVFSBUF_F_UNUSED
#endif
I've tested this both on 32-bit and 64-bit Linux VMs (Ubuntu 14 out-of-the box) and got sane values (255) for f_namemax on both systems.
There was a problem hiding this comment.
Related but not relevant to this PR, the statvfs manpage on FreeBSD is rather amusing.
There was a problem hiding this comment.
Thanks for the explanation. I should really now better to check the headers (I routinely pointed people to base windows bindings not on MSDN doc, but on the headers ...).
For _f_unused please bind it as a plain int. The field logic (taking it out of the field to be considered) still works. Then the padding calculation can be removed also.
For the structure names - I see why you named them how they are named. One thing you might want to consider is, that googling for the structures "header" names is easier when the original name is used. You could move the "speaking" names into javadoc.
There was a problem hiding this comment.
Will do. My thought with the array was hoping for future zero-length array compatibility. :)
|
Thank you. I merged the change via c2c3c09. The things I changed prior to merging:
|
|
That'll teach me to think "oh I'm just using the refactoring these names, nothing can go wrong." At some point I got out of sync and thought I fixed it. Guess not. |
Iterating
mountsmay be overkill, could probably just test/...