source: MondoRescue/branches/stable/mindi-busybox/e2fsprogs/e2p/mntopts.c@ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 2.5 KB
Line 
1/*
2 * mountopts.c --- convert between default mount options and strings
3 *
4 * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu>
5 *
6 * This file can be redistributed under the terms of the GNU Library General
7 * Public License
8 *
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <ctype.h>
15#include <errno.h>
16
17#include "e2p.h"
18
19struct mntopt {
20 unsigned int mask;
21 const char *string;
22};
23
24static const 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" },
33 { 0, 0 },
34};
35
36const char *e2p_mntopt2string(unsigned int mask)
37{
38 const struct mntopt *f;
39 static char buf[20];
40 int fnum;
41
42 for (f = mntopt_list; f->string; f++) {
43 if (mask == f->mask)
44 return f->string;
45 }
46 for (fnum = 0; mask >>= 1; fnum++);
47 sprintf(buf, "MNTOPT_%d", fnum);
48 return buf;
49}
50
51int e2p_string2mntopt(char *string, unsigned int *mask)
52{
53 const struct mntopt *f;
54 char *eptr;
55 int num;
56
57 for (f = mntopt_list; f->string; f++) {
58 if (!strcasecmp(string, f->string)) {
59 *mask = f->mask;
60 return 0;
61 }
62 }
63 if (strncasecmp(string, "MNTOPT_", 8))
64 return 1;
65
66 if (string[8] == 0)
67 return 1;
68 num = strtol(string+8, &eptr, 10);
69 if (num > 32 || num < 0)
70 return 1;
71 if (*eptr)
72 return 1;
73 *mask = 1 << num;
74 return 0;
75}
76
77static char *skip_over_blanks(char *cp)
78{
79 while (*cp && isspace(*cp))
80 cp++;
81 return cp;
82}
83
84static char *skip_over_word(char *cp)
85{
86 while (*cp && !isspace(*cp) && *cp != ',')
87 cp++;
88 return cp;
89}
90
91/*
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.
95 */
96int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
97{
98 char *cp, *buf, *next;
99 int neg;
100 unsigned int mask;
101
102 buf = bb_xstrdup(str);
103 cp = buf;
104 while (cp && *cp) {
105 neg = 0;
106 cp = skip_over_blanks(cp);
107 next = skip_over_word(cp);
108 if (*next == 0)
109 next = 0;
110 else
111 *next = 0;
112 switch (*cp) {
113 case '-':
114 case '^':
115 neg++;
116 case '+':
117 cp++;
118 break;
119 }
120 if (e2p_string2mntopt(cp, &mask))
121 return 1;
122 if (ok && !(ok & mask))
123 return 1;
124 if (mask & EXT3_DEFM_JMODE)
125 *mntopts &= ~EXT3_DEFM_JMODE;
126 if (neg)
127 *mntopts &= ~mask;
128 else
129 *mntopts |= mask;
130 cp = next ? next+1 : 0;
131 }
132 return 0;
133}
Note: See TracBrowser for help on using the repository browser.