2 * mountopts.c --- convert between default mount options and strings
4 * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu>
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
27 static struct mntopt mntopt_list[] = {
28 { EXT2_DEFM_DEBUG, "debug" },
29 { EXT2_DEFM_BSDGROUPS, "bsdgroups" },
30 { EXT2_DEFM_XATTR_USER, "user_xattr" },
31 { EXT2_DEFM_ACL, "acl" },
32 { EXT2_DEFM_UID16, "uid16" },
33 { EXT3_DEFM_JMODE_DATA, "journal_data" },
34 { EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" },
35 { EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" },
36 { EXT4_DEFM_NOBARRIER, "nobarrier" },
37 { EXT4_DEFM_BLOCK_VALIDITY, "block_validity" },
38 { EXT4_DEFM_DISCARD, "discard"},
39 { EXT4_DEFM_NODELALLOC, "nodelalloc"},
43 const char *e2p_mntopt2string(unsigned int mask)
49 for (f = mntopt_list; f->string; f++) {
53 for (fnum = 0; mask >>= 1; fnum++);
54 sprintf(buf, "MNTOPT_%d", fnum);
58 int e2p_string2mntopt(char *string, unsigned int *mask)
64 for (f = mntopt_list; f->string; f++) {
65 if (!strcasecmp(string, f->string)) {
70 if (strncasecmp(string, "MNTOPT_", 7))
75 num = strtol(string+8, &eptr, 10);
76 if (num > 31 || num < 0)
84 static char *skip_over_blanks(char *cp)
86 while (*cp && isspace(*cp))
91 static char *skip_over_word(char *cp)
93 while (*cp && !isspace(*cp) && *cp != ',')
99 * Edit a mntopt set array as requested by the user. The ok
100 * parameter, if non-zero, allows the application to limit what
101 * mntopts the user is allowed to set or clear using this function.
103 int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
105 char *cp, *buf, *next;
110 buf = malloc(strlen(str)+1);
117 cp = skip_over_blanks(cp);
118 next = skip_over_word(cp);
132 if (e2p_string2mntopt(cp, &mask)) {
136 if (ok && !(ok & mask)) {
140 if (mask & EXT3_DEFM_JMODE)
141 *mntopts &= ~EXT3_DEFM_JMODE;
146 cp = next ? next+1 : 0;