2 * feature.c --- convert between features and strings
4 * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
6 * This file can be redistributed under the terms of the GNU Library General
25 static struct feature feature_list[] = {
26 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC,
28 { E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL,
30 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES,
32 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR,
34 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX,
36 { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE,
38 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
40 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE,
42 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION,
44 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE,
46 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER,
48 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
50 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS,
52 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG,
57 const char *e2p_feature2string(int compat, unsigned int mask)
64 for (f = feature_list; f->string; f++) {
65 if ((compat == f->compat) &&
70 case E2P_FEATURE_COMPAT:
73 case E2P_FEATURE_INCOMPAT:
76 case E2P_FEATURE_RO_INCOMPAT:
83 for (fnum = 0; mask >>= 1; fnum++);
84 sprintf(buf, "FEATURE_%c%d", fchar, fnum);
88 int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
94 for (f = feature_list; f->string; f++) {
95 if (!strcasecmp(string, f->string)) {
96 *compat_type = f->compat;
101 if (strncasecmp(string, "FEATURE_", 8))
107 *compat_type = E2P_FEATURE_COMPAT;
111 *compat_type = E2P_FEATURE_INCOMPAT;
115 *compat_type = E2P_FEATURE_RO_INCOMPAT;
122 num = strtol(string+9, &eptr, 10);
123 if (num > 32 || num < 0)
131 static inline char *skip_over_blanks(char *cp)
133 while (*cp && isspace(*cp))
138 static inline char *skip_over_word(char *cp)
140 while (*cp && !isspace(*cp) && *cp != ',')
146 * Edit a feature set array as requested by the user. The ok_array,
147 * if set, allows the application to limit what features the user is
148 * allowed to set or clear using this function.
150 int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
152 char *cp, *buf, *next;
157 buf = xmalloc(strlen(str)+1);
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;