2 * mountopts.c --- convert between default mount options and strings
4 * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu>
6 * This file can be redistributed under the terms of the GNU Library General
24 static struct mntopt mntopt_list[] = {
25 { EXT2_DEFM_DEBUG, "debug" },
26 { EXT2_DEFM_BSDGROUPS, "bsdgroups" },
27 { EXT2_DEFM_XATTR_USER, "user_xattr" },
28 { EXT2_DEFM_ACL, "acl" },
29 { EXT2_DEFM_UID16, "uid16" },
30 { EXT3_DEFM_JMODE_DATA, "journal_data" },
31 { EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" },
32 { EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" },
36 const char *e2p_mntopt2string(unsigned int mask)
42 for (f = mntopt_list; f->string; f++) {
46 for (fnum = 0; mask >>= 1; fnum++);
47 sprintf(buf, "MNTOPT_%d", fnum);
51 int e2p_string2mntopt(char *string, unsigned int *mask)
57 for (f = mntopt_list; f->string; f++) {
58 if (!strcasecmp(string, f->string)) {
63 if (strncasecmp(string, "MNTOPT_", 8))
68 num = strtol(string+8, &eptr, 10);
69 if (num > 32 || num < 0)
77 static char *skip_over_blanks(char *cp)
79 while (*cp && isspace(*cp))
84 static char *skip_over_word(char *cp)
86 while (*cp && !isspace(*cp) && *cp != ',')
92 * Edit a mntopt set array as requested by the user. The ok
93 * parameter, if non-zero, allows the application to limit what
94 * mntopts the user is allowed to set or clear using this function.
96 int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
98 char *cp, *buf, *next;
102 buf = xmalloc(strlen(str)+1);
107 cp = skip_over_blanks(cp);
108 next = skip_over_word(cp);
121 if (e2p_string2mntopt(cp, &mask))
123 if (ok && !(ok & mask))
125 if (mask & EXT3_DEFM_JMODE)
126 *mntopts &= ~EXT3_DEFM_JMODE;
131 cp = next ? next+1 : 0;