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_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
34 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE,
36 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_BTREE_DIR,
38 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION,
40 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE,
42 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER,
47 const char *e2p_feature2string(int compat, unsigned int mask)
54 for (f = feature_list; f->string; f++) {
55 if ((compat == f->compat) &&
60 case E2P_FEATURE_COMPAT:
63 case E2P_FEATURE_INCOMPAT:
66 case E2P_FEATURE_RO_INCOMPAT:
73 for (fnum = 0; mask >>= 1; fnum++);
74 sprintf(buf, "FEATURE_%c%d", fchar, fnum);
78 int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
84 for (f = feature_list; f->string; f++) {
85 if (!strcasecmp(string, f->string)) {
86 *compat_type = f->compat;
91 if (strncasecmp(string, "FEATURE_", 8))
97 *compat_type = E2P_FEATURE_COMPAT;
101 *compat_type = E2P_FEATURE_INCOMPAT;
105 *compat_type = E2P_FEATURE_RO_INCOMPAT;
112 num = strtol(string+9, &eptr, 10);
113 if (num > 32 || num < 0)
121 static char *skip_over_blanks(char *cp)
123 while (*cp && isspace(*cp))
128 static char *skip_over_word(char *cp)
130 while (*cp && !isspace(*cp) && *cp != ',')
136 * Edit a feature set array as requested by the user. The ok_array,
137 * if set, allows the application to limit what features the user is
138 * allowed to set or clear using this function.
140 int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
142 char *cp, *buf, *next;
147 buf = malloc(strlen(str)+1);
154 cp = skip_over_blanks(cp);
155 next = skip_over_word(cp);
168 if (e2p_string2feature(cp, &compat_type, &mask))
170 if (ok_array && !(ok_array[compat_type] & mask))
173 compat_array[compat_type] &= ~mask;
175 compat_array[compat_type] |= mask;
176 cp = next ? next+1 : 0;