1 /* vi: set sw=4 ts=4: */
3 * mountopts.c --- convert between default mount options and strings
5 * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu>
7 * This file can be redistributed under the terms of the GNU Library General
25 static const struct mntopt mntopt_list
[] = {
26 { EXT2_DEFM_DEBUG
, "debug" },
27 { EXT2_DEFM_BSDGROUPS
, "bsdgroups" },
28 { EXT2_DEFM_XATTR_USER
, "user_xattr" },
29 { EXT2_DEFM_ACL
, "acl" },
30 { EXT2_DEFM_UID16
, "uid16" },
31 { EXT3_DEFM_JMODE_DATA
, "journal_data" },
32 { EXT3_DEFM_JMODE_ORDERED
, "journal_data_ordered" },
33 { EXT3_DEFM_JMODE_WBACK
, "journal_data_writeback" },
37 const char *e2p_mntopt2string(unsigned int mask
)
39 const struct mntopt
*f
;
43 for (f
= mntopt_list
; f
->string
; f
++) {
47 for (fnum
= 0; mask
>>= 1; fnum
++);
48 sprintf(buf
, "MNTOPT_%d", fnum
);
52 int e2p_string2mntopt(char *string
, unsigned int *mask
)
54 const struct mntopt
*f
;
58 for (f
= mntopt_list
; f
->string
; f
++) {
59 if (!strcasecmp(string
, f
->string
)) {
64 if (strncasecmp(string
, "MNTOPT_", 8))
69 num
= strtol(string
+8, &eptr
, 10);
70 if (num
> 32 || num
< 0)
78 static char *skip_over_blanks(char *cp
)
80 while (*cp
&& isspace(*cp
))
85 static char *skip_over_word(char *cp
)
87 while (*cp
&& !isspace(*cp
) && *cp
!= ',')
93 * Edit a mntopt set array as requested by the user. The ok
94 * parameter, if non-zero, allows the application to limit what
95 * mntopts the user is allowed to set or clear using this function.
97 int e2p_edit_mntopts(const char *str
, __u32
*mntopts
, __u32 ok
)
99 char *cp
, *buf
, *next
;
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;