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_COMPAT, EXT2_FEATURE_COMPAT_LAZY_BG,
41 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
43 { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE,
45 { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_HUGE_FILE,
47 { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_GDT_CSUM,
49 { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_DIR_NLINK,
51 { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE,
54 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION,
56 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE,
58 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER,
60 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
62 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS,
64 { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG,
66 { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS,
68 { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_64BIT,
73 const char *e2p_feature2string(int compat, unsigned int mask)
80 for (f = feature_list; f->string; f++) {
81 if ((compat == f->compat) &&
86 case E2P_FEATURE_COMPAT:
89 case E2P_FEATURE_INCOMPAT:
92 case E2P_FEATURE_RO_INCOMPAT:
99 for (fnum = 0; mask >>= 1; fnum++);
100 sprintf(buf, "FEATURE_%c%d", fchar, fnum);
104 int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
110 for (f = feature_list; f->string; f++) {
111 if (!strcasecmp(string, f->string)) {
112 *compat_type = f->compat;
117 if (strncasecmp(string, "FEATURE_", 8))
123 *compat_type = E2P_FEATURE_COMPAT;
127 *compat_type = E2P_FEATURE_INCOMPAT;
131 *compat_type = E2P_FEATURE_RO_INCOMPAT;
138 num = strtol(string+9, &eptr, 10);
139 if (num > 32 || num < 0)
147 static char *skip_over_blanks(char *cp)
149 while (*cp && isspace(*cp))
154 static char *skip_over_word(char *cp)
156 while (*cp && !isspace(*cp) && *cp != ',')
162 * Edit a feature set array as requested by the user. The ok_array,
163 * if set, allows the application to limit what features the user is
164 * allowed to set or clear using this function.
166 int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
168 char *cp, *buf, *next;
174 buf = malloc(strlen(str)+1);
178 for (cp = buf; cp && *cp; cp = next ? next+1 : 0) {
180 cp = skip_over_blanks(cp);
181 next = skip_over_word(cp);
188 if ((strcasecmp(cp, "none") == 0) ||
189 (strcasecmp(cp, "clear") == 0)) {
204 if (e2p_string2feature(cp, &compat_type, &mask)) {
208 if (ok_array && !(ok_array[compat_type] & mask)) {
213 compat_array[compat_type] &= ~mask;
215 compat_array[compat_type] |= mask;