micro-utils/include/libmu/parse_mount.h

51 lines
1.1 KiB
C

#ifndef _PARSE_MOUNT_H
#define _PARSE_MOUNT_H
#include <string.h>
typedef struct {
char *opt;
char *notopt;
char *desc;
unsigned int val;
} MU_MOUNT_OPTS;
#if defined(__BSD__)
#define MS_RDONLY MNT_RDONLY
#define MS_REMOUNT 0
#define MS_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_NODEV MNT_NODEV
#endif
MU_MOUNT_OPTS mu_options[] = {
{"defaults", NULL, NULL, 0},
{"ro", "rw", "Read only / Read and write", MS_RDONLY},
{"remount", NULL, "Remount a mounted filesystem", MS_REMOUNT},
{"sync", "async", "Writes are [a]synchronous", MS_SYNCHRONOUS},
{"nodev", "dev", "(Dis)allow use of special device files", MS_NODEV}
};
unsigned long mu_parse_opts(char *str) {
unsigned long opt = 1;
char *token = strtok(str, ",");
while (token != NULL) {
for (size_t i = 0; i < sizeof(mu_options) / sizeof(mu_options[0]); i++) {
if (mu_options[i].opt && !strcmp(token, mu_options[i].opt)) {
opt |= mu_options[i].val;
break;
}
if (mu_options[i].notopt && !strcmp(token, mu_options[i].notopt)) {
opt &= ~mu_options[i].val;
break;
}
}
token = strtok(NULL, ",");
}
return opt;
}
#endif