Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: getmntinfo compatibility question



On Fri, Feb 14, 2025 at 09:22:54AM +0100, Thomas Klausner wrote:
> Perhaps we need to add code like FreeBSD has (to rust libc):
> https://github.com/rust-lang/libc/blob/2258bf0fb96767bcffbe3ed09b29a31ee54b549b/src/unix/bsd/freebsdlike/freebsd/mod.rs#L5340

Your rust binary calls __getvfsstat90 (according to ktrace), so the definition
in C is 

nt     getvfsstat(struct statvfs *, size_t, int)
    __RENAME(__getvfsstat90);

and the argument needs to be an array of struct statvfs. The equivalent C
code should be something like:

---
#include <stdio.h>
#include <sys/statvfs.h>

int main(int argc, char **argv)
{
        struct statvfs buf[20];
        int ret = getvfsstat(buf, sizeof buf, ST_WAIT);
        printf("ret %d\n", ret);
        return 0;
}
---

(at least ktrace shows the same syscall for this) and this returns:

(gdb) p buf[0]
$2 = {f_flag = 20480, f_bsize = 32768, f_frsize = 4096, f_iosize = 32768, 
  f_blocks = 116136549, f_bfree = 112048364, f_bavail = 106241537, 
  f_bresvd = 5806827, f_files = 29092606, f_ffree = 28605067, 
  f_favail = 28605067, f_fresvd = 0, f_syncreads = 267410, 
  f_syncwrites = 12497, f_asyncreads = 2, f_asyncwrites = 4423, f_fsidx = {
    __fsid_val = {43008, 1931}}, f_fsid = 43008, f_namemax = 255, f_owner = 0, 
  f_spare = {0, 0, 0, 0}, f_fstypename = "ffs", '\000' <repeats 28 times>, 
  f_mntonname = "/", '\000' <repeats 1022 times>, 
  f_mntfromname = "/dev/dk0", '\000' <repeats 1015 times>, 
  f_mntfromlabel = "G5root", '\000' <repeats 1017 times>}


so the problem must be with the rust libc definition of the struct.


Martin


Home | Main Index | Thread Index | Old Index