Created
May 14, 2021 07:53
-
-
Save ilovezfs/bbca7ffb7f9c319df898f5d6fee5e126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <strings.h> | |
#include <sys/mount.h> | |
int append_option(uint32_t flag, char *option_yes, char *option_no, uint32_t mntflags, char *options, | |
size_t buflen) | |
{ | |
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); | |
} | |
return 0; | |
} | |
int main(int argc, char** argv) { | |
size_t buflen = (_POSIX_MAX_INPUT+1) * 2; | |
char options[buflen]; | |
options[0] = '\0'; | |
struct statfs* mounts; | |
int num_mounts = getmntinfo(&mounts, MNT_WAIT); | |
for (int i = 0; i < num_mounts; i++) { | |
uint32_t fflags = mounts[i].f_flags; | |
append_option(MNT_LOCAL, "local", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_RDONLY, "ro", "rw", mounts[i].f_flags, options, buflen); | |
append_option(MNT_JOURNALED, "journaled", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_NOEXEC, "noexec", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_NOSUID, "nosuid", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_NODEV, "nodev", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_DONTBROWSE, "nobrowse", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_IGNORE_OWNERSHIP, "noowners", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_NOUSERXATTR, "noxattr", NULL, mounts[i].f_flags, options, buflen); | |
append_option(MNT_NOATIME, "noatime", NULL, mounts[i].f_flags, options, buflen); | |
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'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment