Skip to content

Instantly share code, notes, and snippets.

@ilovezfs
Created May 14, 2021 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilovezfs/76f61c53b4a33f36bd4e039a95e2b03a to your computer and use it in GitHub Desktop.
Save ilovezfs/76f61c53b4a33f36bd4e039a95e2b03a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/mount.h>
char *options;
size_t buflen = (_POSIX_MAX_INPUT+1) * 2;
uint32_t mntflags;
void
append_option(uint32_t flag, char *option_yes, char *option_no)
{
if ((mntflags & flag) && option_yes != NULL) {
if (*options != '\0')
strlcat(options, ",", buflen);
strlcat(options, option_yes, buflen);
} else if (!(mntflags & flag) && option_no != NULL) {
if (*options != '\0')
strlcat(options, ",", buflen);
strlcat(options, option_no, buflen);
}
}
int main(int argc, char *argv[]) {
options = (char *)malloc(buflen);
options[0] = '\0';
struct statfs *mounts;
int num_mounts = getmntinfo(&mounts, MNT_WAIT);
for (int i = 0; i < num_mounts; i++) {
mntflags = mounts[i].f_flags;
append_option(MNT_LOCAL, "local", NULL);
append_option(MNT_RDONLY, "ro", "rw");
append_option(MNT_JOURNALED, "journaled", NULL);
append_option(MNT_NOEXEC, "noexec", NULL);
append_option(MNT_NOSUID, "nosuid", NULL);
append_option(MNT_NODEV, "nodev", NULL);
append_option(MNT_DONTBROWSE, "nobrowse", NULL);
append_option(MNT_IGNORE_OWNERSHIP, "noowners", NULL);
append_option(MNT_NOUSERXATTR, "noxattr", NULL);
append_option(MNT_NOATIME, "noatime", NULL);
printf("%s\t%s\t%s\t%s\n", mounts[i].f_mntfromname,
mounts[i].f_mntonname, mounts[i].f_fstypename, options);
options[0] = '\0';
}
free(options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment