1 /* vi: set sw=4 ts=4: */
3 * feature.c --- convert between features and strings
5 * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
7 * This file can be redistributed under the terms of the GNU Library General
26 static const struct feature feature_list[] = {
27 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC,
29 { E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL,
31 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES,
33 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR,
35 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX,
37 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE,
39 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
41 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE,
43 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION,
45 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE,
47 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER,
49 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
51 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS,
53 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG,
58 const char *e2p_feature2string(int compat, unsigned int mask)
60 const struct feature *f;
65 for (f = feature_list; f->string; f++) {
66 if ((compat == f->compat) &&
71 case E2P_FEATURE_COMPAT:
74 case E2P_FEATURE_INCOMPAT:
77 case E2P_FEATURE_RO_INCOMPAT:
84 for (fnum = 0; mask >>= 1; fnum++);
85 sprintf(buf, "FEATURE_%c%d", fchar, fnum);
89 int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
91 const struct feature *f;
95 for (f = feature_list; f->string; f++) {
96 if (!strcasecmp(string, f->string)) {
97 *compat_type = f->compat;
102 if (strncasecmp(string, "FEATURE_", 8))
108 *compat_type = E2P_FEATURE_COMPAT;
112 *compat_type = E2P_FEATURE_INCOMPAT;
116 *compat_type = E2P_FEATURE_RO_INCOMPAT;
123 num = strtol(string+9, &eptr, 10);
124 if (num > 32 || num < 0)
132 static inline char *skip_over_blanks(char *cp)
134 while (*cp && isspace(*cp))
139 static inline char *skip_over_word(char *cp)
141 while (*cp && !isspace(*cp) && *cp != ',')
147 * Edit a feature set array as requested by the user. The ok_array,
148 * if set, allows the application to limit what features the user is
149 * allowed to set or clear using this function.
151 int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
153 char *cp, *buf, *next;
158 buf = bb_xstrdup(str);
162 cp = skip_over_blanks(cp);
163 next = skip_over_word(cp);
176 if (e2p_string2feature(cp, &compat_type, &mask))
178 if (ok_array && !(ok_array[compat_type] & mask))
181 compat_array[compat_type] &= ~mask;
183 compat_array[compat_type] |= mask;
184 cp = next ? next+1 : 0;