how can i get the mount point of a given device id which came from os.fstat()?

what i want is something like this:

> df ~/todo
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda3       51290592 23633044  25019724  49% /home

> findmnt --target ~/todo
/home  /dev/sda3 ext4   rw,relatime,lazytime,data=ordered

i found two ways to do that so far, but as i know little about c libs, i’m
still wondering if there are better or idiomatic ways.

  • std.ChildProcess.init(.{"df", "/"})
  • @cImport(@cInclude("fstab.h")) source

after read the fstab struct in fstab.h, the mntent struct in mntent.h, i started to know they are merely a string parser, so i implemented the parser in pure zig, and used /proc/mounts as the source.

1 Like

If you can afford linking against libc (apparently you can, as you’re using @cImport()) then you can use getmntent(). That parses /etc/fstab for you, but of course you can just parse it yourself if you want and skip the dependency :slight_smile:

thanks for the reply! i think the “import mntent.h” approach is a bit of overkill.