2 * set_fields.c --- set a superblock value
4 * Copyright (C) 2000, 2001, 2002, 2003, 2004 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 #define _XOPEN_SOURCE 600 /* for inclusion of strptime() and strtoull */
15 #define STRTOULL strtoull
17 #define STRTOULL strtoul
28 #include <sys/types.h>
40 #include "uuid/uuid.h"
42 #include "quota/quotaio.h"
44 static struct ext2_super_block set_sb;
45 static struct ext2_inode_large set_inode;
46 static struct ext2_group_desc set_gd;
47 static struct ext4_group_desc set_gd4;
48 static struct mmp_struct set_mmp;
50 static ext2_ino_t set_ino;
53 #define FLAG_ARRAY 0x0001
55 struct field_set_info {
60 errcode_t (*func)(struct field_set_info *info, char *field, char *arg);
65 static errcode_t parse_uint(struct field_set_info *info, char *field, char *arg);
66 static errcode_t parse_int(struct field_set_info *info, char *field, char *arg);
67 static errcode_t parse_string(struct field_set_info *info, char *field, char *arg);
68 static errcode_t parse_uuid(struct field_set_info *info, char *field, char *arg);
69 static errcode_t parse_hashalg(struct field_set_info *info, char *field, char *arg);
70 static errcode_t parse_time(struct field_set_info *info, char *field, char *arg);
71 static errcode_t parse_bmap(struct field_set_info *info, char *field, char *arg);
72 static errcode_t parse_gd_csum(struct field_set_info *info, char *field, char *arg);
73 static errcode_t parse_mmp_clear(struct field_set_info *info, char *field,
76 static struct field_set_info super_fields[] = {
77 { "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
78 { "blocks_count", &set_sb.s_blocks_count, &set_sb.s_blocks_count_hi,
80 { "r_blocks_count", &set_sb.s_r_blocks_count,
81 &set_sb.s_r_blocks_count_hi, 4, parse_uint },
82 { "free_blocks_count", &set_sb.s_free_blocks_count,
83 &set_sb.s_free_blocks_hi, 4, parse_uint },
84 { "free_inodes_count", &set_sb.s_free_inodes_count, NULL, 4, parse_uint },
85 { "first_data_block", &set_sb.s_first_data_block, NULL, 4, parse_uint },
86 { "log_block_size", &set_sb.s_log_block_size, NULL, 4, parse_uint },
87 { "log_cluster_size", &set_sb.s_log_cluster_size, NULL, 4, parse_int },
88 { "blocks_per_group", &set_sb.s_blocks_per_group, NULL, 4, parse_uint },
89 { "clusters_per_group", &set_sb.s_clusters_per_group, NULL, 4, parse_uint },
90 { "inodes_per_group", &set_sb.s_inodes_per_group, NULL, 4, parse_uint },
91 { "mtime", &set_sb.s_mtime, NULL, 4, parse_time },
92 { "wtime", &set_sb.s_wtime, NULL, 4, parse_time },
93 { "mnt_count", &set_sb.s_mnt_count, NULL, 2, parse_uint },
94 { "max_mnt_count", &set_sb.s_max_mnt_count, NULL, 2, parse_int },
96 { "state", &set_sb.s_state, NULL, 2, parse_uint },
97 { "errors", &set_sb.s_errors, NULL, 2, parse_uint },
98 { "minor_rev_level", &set_sb.s_minor_rev_level, NULL, 2, parse_uint },
99 { "lastcheck", &set_sb.s_lastcheck, NULL, 4, parse_time },
100 { "checkinterval", &set_sb.s_checkinterval, NULL, 4, parse_uint },
101 { "creator_os", &set_sb.s_creator_os, NULL, 4, parse_uint },
102 { "rev_level", &set_sb.s_rev_level, NULL, 4, parse_uint },
103 { "def_resuid", &set_sb.s_def_resuid, NULL, 2, parse_uint },
104 { "def_resgid", &set_sb.s_def_resgid, NULL, 2, parse_uint },
105 { "first_ino", &set_sb.s_first_ino, NULL, 4, parse_uint },
106 { "inode_size", &set_sb.s_inode_size, NULL, 2, parse_uint },
107 { "block_group_nr", &set_sb.s_block_group_nr, NULL, 2, parse_uint },
108 { "feature_compat", &set_sb.s_feature_compat, NULL, 4, parse_uint },
109 { "feature_incompat", &set_sb.s_feature_incompat, NULL, 4, parse_uint },
110 { "feature_ro_compat", &set_sb.s_feature_ro_compat, NULL, 4, parse_uint },
111 { "uuid", &set_sb.s_uuid, NULL, 16, parse_uuid },
112 { "volume_name", &set_sb.s_volume_name, NULL, 16, parse_string },
113 { "last_mounted", &set_sb.s_last_mounted, NULL, 64, parse_string },
114 { "lastcheck", &set_sb.s_lastcheck, NULL, 4, parse_uint },
115 { "algorithm_usage_bitmap", &set_sb.s_algorithm_usage_bitmap, NULL,
117 { "prealloc_blocks", &set_sb.s_prealloc_blocks, NULL, 1, parse_uint },
118 { "prealloc_dir_blocks", &set_sb.s_prealloc_dir_blocks, NULL, 1,
120 { "reserved_gdt_blocks", &set_sb.s_reserved_gdt_blocks, NULL, 2,
122 { "journal_uuid", &set_sb.s_journal_uuid, NULL, 16, parse_uuid },
123 { "journal_inum", &set_sb.s_journal_inum, NULL, 4, parse_uint },
124 { "journal_dev", &set_sb.s_journal_dev, NULL, 4, parse_uint },
125 { "last_orphan", &set_sb.s_last_orphan, NULL, 4, parse_uint },
126 { "hash_seed", &set_sb.s_hash_seed, NULL, 16, parse_uuid },
127 { "def_hash_version", &set_sb.s_def_hash_version, NULL, 1, parse_hashalg },
128 { "jnl_backup_type", &set_sb.s_jnl_backup_type, NULL, 1, parse_uint },
129 { "desc_size", &set_sb.s_desc_size, NULL, 2, parse_uint },
130 { "default_mount_opts", &set_sb.s_default_mount_opts, NULL, 4, parse_uint },
131 { "first_meta_bg", &set_sb.s_first_meta_bg, NULL, 4, parse_uint },
132 { "mkfs_time", &set_sb.s_mkfs_time, NULL, 4, parse_time },
133 { "jnl_blocks", &set_sb.s_jnl_blocks[0], NULL, 4, parse_uint, FLAG_ARRAY,
135 { "min_extra_isize", &set_sb.s_min_extra_isize, NULL, 2, parse_uint },
136 { "want_extra_isize", &set_sb.s_want_extra_isize, NULL, 2, parse_uint },
137 { "flags", &set_sb.s_flags, NULL, 4, parse_uint },
138 { "raid_stride", &set_sb.s_raid_stride, NULL, 2, parse_uint },
139 { "min_extra_isize", &set_sb.s_min_extra_isize, NULL, 4, parse_uint },
140 { "mmp_interval", &set_sb.s_mmp_update_interval, NULL, 2, parse_uint },
141 { "mmp_block", &set_sb.s_mmp_block, NULL, 8, parse_uint },
142 { "raid_stripe_width", &set_sb.s_raid_stripe_width, NULL, 4, parse_uint },
143 { "log_groups_per_flex", &set_sb.s_log_groups_per_flex, NULL, 1, parse_uint },
144 { "kbytes_written", &set_sb.s_kbytes_written, NULL, 8, parse_uint },
145 { "snapshot_inum", &set_sb.s_snapshot_inum, NULL, 4, parse_uint },
146 { "snapshot_id", &set_sb.s_snapshot_id, NULL, 4, parse_uint },
147 { "snapshot_r_blocks_count", &set_sb.s_snapshot_r_blocks_count,
148 NULL, 8, parse_uint },
149 { "snapshot_list", &set_sb.s_snapshot_list, NULL, 4, parse_uint },
150 { "mount_opts", &set_sb.s_mount_opts, NULL, 64, parse_string },
151 { "usr_quota_inum", &set_sb.s_usr_quota_inum, NULL, 4, parse_uint },
152 { "grp_quota_inum", &set_sb.s_grp_quota_inum, NULL, 4, parse_uint },
153 { "prj_quota_inum", &set_sb.s_prj_quota_inum, NULL, 4, parse_uint },
154 { "overhead_blocks", &set_sb.s_overhead_blocks, NULL, 4, parse_uint },
155 { "backup_bgs", &set_sb.s_backup_bgs[0], NULL, 4, parse_uint,
157 { "checksum", &set_sb.s_checksum, NULL, 4, parse_uint },
158 { "error_count", &set_sb.s_error_count, NULL, 4, parse_uint },
159 { "first_error_time", &set_sb.s_first_error_time, NULL, 4, parse_time },
160 { "first_error_ino", &set_sb.s_first_error_ino, NULL, 4, parse_uint },
161 { "first_error_block", &set_sb.s_first_error_block, NULL, 8, parse_uint },
162 { "first_error_func", &set_sb.s_first_error_func, NULL, 32, parse_string },
163 { "first_error_line", &set_sb.s_first_error_ino, NULL, 4, parse_uint },
164 { "last_error_time", &set_sb.s_last_error_time, NULL, 4, parse_time },
165 { "last_error_ino", &set_sb.s_last_error_ino, NULL, 4, parse_uint },
166 { "last_error_block", &set_sb.s_last_error_block, NULL, 8, parse_uint },
167 { "last_error_func", &set_sb.s_last_error_func, NULL, 32, parse_string },
168 { "last_error_line", &set_sb.s_last_error_ino, NULL, 4, parse_uint },
172 static struct field_set_info inode_fields[] = {
173 { "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
174 { "mode", &set_inode.i_mode, NULL, 2, parse_uint },
175 { "uid", &set_inode.i_uid, &set_inode.osd2.linux2.l_i_uid_high,
177 { "size", &set_inode.i_size, &set_inode.i_size_high, 4, parse_uint },
178 { "atime", &set_inode.i_atime, NULL, 4, parse_time },
179 { "ctime", &set_inode.i_ctime, NULL, 4, parse_time },
180 { "mtime", &set_inode.i_mtime, NULL, 4, parse_time },
181 { "dtime", &set_inode.i_dtime, NULL, 4, parse_time },
182 { "gid", &set_inode.i_gid, &set_inode.osd2.linux2.l_i_gid_high,
184 { "links_count", &set_inode.i_links_count, NULL, 2, parse_uint },
185 /* Special case: i_blocks is 4 bytes, i_blocks_high is 2 bytes */
186 { "blocks", &set_inode.i_blocks, &set_inode.osd2.linux2.l_i_blocks_hi,
188 { "flags", &set_inode.i_flags, NULL, 4, parse_uint },
189 { "version", &set_inode.osd1.linux1.l_i_version,
190 &set_inode.i_version_hi, 4, parse_uint },
191 { "translator", &set_inode.osd1.hurd1.h_i_translator, NULL, 4, parse_uint },
192 { "block", &set_inode.i_block[0], NULL, 4, parse_uint, FLAG_ARRAY,
194 { "block[IND]", &set_inode.i_block[EXT2_IND_BLOCK], NULL, 4, parse_uint },
195 { "block[DIND]", &set_inode.i_block[EXT2_DIND_BLOCK], NULL, 4, parse_uint },
196 { "block[TIND]", &set_inode.i_block[EXT2_TIND_BLOCK], NULL, 4, parse_uint },
197 { "generation", &set_inode.i_generation, NULL, 4, parse_uint },
198 /* Special case: i_file_acl_high is 2 bytes */
199 { "file_acl", &set_inode.i_file_acl,
200 &set_inode.osd2.linux2.l_i_file_acl_high, 6, parse_uint },
201 { "dir_acl", &set_inode.i_dir_acl, NULL, 4, parse_uint },
202 { "faddr", &set_inode.i_faddr, NULL, 4, parse_uint },
203 { "frag", &set_inode.osd2.hurd2.h_i_frag, NULL, 1, parse_uint },
204 { "fsize", &set_inode.osd2.hurd2.h_i_fsize, NULL, 1, parse_uint },
205 { "checksum", &set_inode.osd2.linux2.l_i_checksum_lo,
206 &set_inode.i_checksum_hi, 2, parse_uint },
207 { "author", &set_inode.osd2.hurd2.h_i_author, NULL,
209 { "extra_isize", &set_inode.i_extra_isize, NULL,
211 { "ctime_extra", &set_inode.i_ctime_extra, NULL,
213 { "mtime_extra", &set_inode.i_mtime_extra, NULL,
215 { "atime_extra", &set_inode.i_atime_extra, NULL,
217 { "crtime", &set_inode.i_crtime, NULL, 4, parse_uint },
218 { "crtime_extra", &set_inode.i_crtime_extra, NULL,
220 { "projid", &set_inode.i_projid, NULL, 4, parse_uint },
221 { "bmap", NULL, NULL, 4, parse_bmap, FLAG_ARRAY },
225 static struct field_set_info ext2_bg_fields[] = {
226 { "block_bitmap", &set_gd.bg_block_bitmap, NULL, 4, parse_uint },
227 { "inode_bitmap", &set_gd.bg_inode_bitmap, NULL, 4, parse_uint },
228 { "inode_table", &set_gd.bg_inode_table, NULL, 4, parse_uint },
229 { "free_blocks_count", &set_gd.bg_free_blocks_count, NULL, 2, parse_uint },
230 { "free_inodes_count", &set_gd.bg_free_inodes_count, NULL, 2, parse_uint },
231 { "used_dirs_count", &set_gd.bg_used_dirs_count, NULL, 2, parse_uint },
232 { "flags", &set_gd.bg_flags, NULL, 2, parse_uint },
233 { "itable_unused", &set_gd.bg_itable_unused, NULL, 2, parse_uint },
234 { "checksum", &set_gd.bg_checksum, NULL, 2, parse_gd_csum },
238 static struct field_set_info ext4_bg_fields[] = {
239 { "block_bitmap", &set_gd4.bg_block_bitmap,
240 &set_gd4.bg_block_bitmap_hi, 4, parse_uint },
241 { "inode_bitmap", &set_gd4.bg_inode_bitmap,
242 &set_gd4.bg_inode_bitmap_hi, 4, parse_uint },
243 { "inode_table", &set_gd4.bg_inode_table,
244 &set_gd4.bg_inode_table_hi, 4, parse_uint },
245 { "free_blocks_count", &set_gd4.bg_free_blocks_count,
246 &set_gd4.bg_free_blocks_count_hi, 2, parse_uint },
247 { "free_inodes_count", &set_gd4.bg_free_inodes_count,
248 &set_gd4.bg_free_inodes_count_hi, 2, parse_uint },
249 { "used_dirs_count", &set_gd4.bg_used_dirs_count,
250 &set_gd4.bg_used_dirs_count_hi, 2, parse_uint },
251 { "flags", &set_gd4.bg_flags, NULL, 2, parse_uint },
252 { "exclude_bitmap", &set_gd4.bg_exclude_bitmap_lo,
253 &set_gd4.bg_exclude_bitmap_hi, 4, parse_uint },
254 { "block_bitmap_csum", &set_gd4.bg_block_bitmap_csum_lo,
255 &set_gd4.bg_block_bitmap_csum_hi, 2, parse_uint },
256 { "inode_bitmap_csum", &set_gd4.bg_inode_bitmap_csum_lo,
257 &set_gd4.bg_inode_bitmap_csum_hi, 2, parse_uint },
258 { "itable_unused", &set_gd4.bg_itable_unused,
259 &set_gd4.bg_itable_unused_hi, 2, parse_uint },
260 { "checksum", &set_gd4.bg_checksum, NULL, 2, parse_gd_csum },
264 static struct field_set_info mmp_fields[] = {
265 { "clear", &set_mmp.mmp_magic, NULL, sizeof(set_mmp), parse_mmp_clear },
266 { "magic", &set_mmp.mmp_magic, NULL, 4, parse_uint },
267 { "seq", &set_mmp.mmp_seq, NULL, 4, parse_uint },
268 { "time", &set_mmp.mmp_time, NULL, 8, parse_uint },
269 { "nodename", &set_mmp.mmp_nodename, NULL, sizeof(set_mmp.mmp_nodename),
271 { "bdevname", &set_mmp.mmp_bdevname, NULL, sizeof(set_mmp.mmp_bdevname),
273 { "check_interval", &set_mmp.mmp_check_interval, NULL, 2, parse_uint },
276 static int check_suffix(const char *field)
278 int len = strlen(field);
283 if (!strcmp(field, "_lo"))
285 if (!strcmp(field, "_hi"))
290 static struct field_set_info *find_field(struct field_set_info *fields,
293 struct field_set_info *ss;
295 char *arg, *delim, *idx, *tmp;
296 int suffix, prefix_len;
298 if (fields == super_fields)
300 else if (fields == inode_fields)
304 prefix_len = strlen(prefix);
305 if (strncmp(field, prefix, prefix_len) == 0)
308 arg = malloc(strlen(field)+1);
313 idx = strchr(arg, '[');
316 delim = idx + strlen(idx) - 1;
317 if (!*idx || *delim != ']')
323 * Can we parse the number?
326 array_idx = strtol(idx, &tmp, 0);
335 * If there is a valid _hi or a _lo suffix, strip it off
337 suffix = check_suffix(arg);
339 arg[strlen(arg)-3] = 0;
341 for (ss = fields ; ss->name ; ss++) {
342 if (suffix && ss->ptr2 == 0)
344 if (ss->flags & FLAG_ARRAY) {
345 if (!idx || (strcmp(ss->name, arg) != 0))
347 if (ss->max_idx > 0 && array_idx >= ss->max_idx)
350 if (strcmp(ss->name, arg) != 0)
361 * Note: info->size == 6 is special; this means a base size 4 bytes,
362 * and secondiory (high) size of 2 bytes. This is needed for the
363 * special case of i_blocks_high and i_file_acl_high.
365 static errcode_t parse_uint(struct field_set_info *info, char *field,
368 unsigned long long n, num, mask, limit;
369 int suffix = check_suffix(field);
371 void *field1 = info->ptr, *field2 = info->ptr2;
372 int size = (info->size == 6) ? 4 : info->size;
387 u.ptr8 = (__u8 *) field1;
388 if (info->flags & FLAG_ARRAY)
389 u.ptr8 += array_idx * info->size;
392 num = STRTOULL(arg, &tmp, 0);
394 fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
398 mask = ~0ULL >> ((8 - size) * 8);
399 limit = ~0ULL >> ((8 - info->size) * 8);
400 if (field2 && info->size != 6)
401 limit = ~0ULL >> ((8 - info->size*2) * 8);
404 fprintf(stderr, "Value '%s' exceeds field %s maximum %llu.\n",
405 arg, info->name, limit);
411 /* Should never get here */
412 fprintf(stderr, "64-bit field %s has a second 64-bit field\n"
413 "defined; BUG?!?\n", info->name);
429 u.ptr8 = (__u8 *) field2;
449 static errcode_t parse_int(struct field_set_info *info,
450 char *field EXT2FS_ATTR((unused)), char *arg)
458 num = strtol(arg, &tmp, 0);
460 fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
464 switch (info->size) {
466 ptr32 = (__s32 *) info->ptr;
470 ptr16 = (__s16 *) info->ptr;
474 ptr8 = (__s8 *) info->ptr;
481 static errcode_t parse_string(struct field_set_info *info,
482 char *field EXT2FS_ATTR((unused)), char *arg)
484 char *cp = (char *) info->ptr;
486 if (strlen(arg) >= info->size) {
487 fprintf(stderr, "Error maximum size for %s is %d.\n",
488 info->name, info->size);
495 static errcode_t parse_time(struct field_set_info *info,
496 char *field EXT2FS_ATTR((unused)), char *arg)
501 ptr32 = (__u32 *) info->ptr;
503 t = string_to_time(arg);
505 if (t == ((time_t) -1)) {
506 fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
514 static errcode_t parse_uuid(struct field_set_info *info,
515 char *field EXT2FS_ATTR((unused)), char *arg)
517 unsigned char * p = (unsigned char *) info->ptr;
519 if ((strcasecmp(arg, "null") == 0) ||
520 (strcasecmp(arg, "clear") == 0)) {
522 } else if (strcasecmp(arg, "time") == 0) {
523 uuid_generate_time(p);
524 } else if (strcasecmp(arg, "random") == 0) {
526 } else if (uuid_parse(arg, p)) {
527 fprintf(stderr, "Invalid UUID format: %s\n", arg);
533 static errcode_t parse_hashalg(struct field_set_info *info,
534 char *field EXT2FS_ATTR((unused)), char *arg)
537 unsigned char *p = (unsigned char *) info->ptr;
539 hashv = e2p_string2hash(arg);
541 fprintf(stderr, "Invalid hash algorithm: %s\n", arg);
548 static errcode_t parse_bmap(struct field_set_info *info,
549 char *field EXT2FS_ATTR((unused)), char *arg)
555 blk = strtoull(arg, &tmp, 0);
557 fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
562 retval = ext2fs_bmap2(current_fs, set_ino,
563 (struct ext2_inode *) &set_inode,
564 NULL, BMAP_ALLOC | BMAP_SET, array_idx, NULL,
567 com_err("set_inode", retval, "while setting block map");
572 static errcode_t parse_gd_csum(struct field_set_info *info, char *field,
576 if (strcmp(arg, "calc") == 0) {
577 ext2fs_group_desc_csum_set(current_fs, set_bg);
578 memcpy(&set_gd, ext2fs_group_desc(current_fs,
579 current_fs->group_desc,
582 printf("Checksum set to 0x%04x\n",
583 ext2fs_bg_checksum(current_fs, set_bg));
587 return parse_uint(info, field, arg);
590 static void print_possible_fields(struct field_set_info *fields)
592 struct field_set_info *ss;
593 const char *type, *cmd;
595 char name[40], idx[40];
597 if (fields == super_fields) {
599 cmd = "set_super_value";
600 } else if (fields == inode_fields) {
603 } else if (fields == mmp_fields) {
605 cmd = "set_mmp_value";
607 type = "Block group descriptor";
608 cmd = "set_block_group";
612 fprintf(f, "%s fields supported by the %s command:\n", type, cmd);
614 for (ss = fields ; ss->name ; ss++) {
616 if (ss->func == parse_string)
618 else if (ss->func == parse_int)
620 else if (ss->func == parse_uint)
621 type = "unsigned integer";
622 else if (ss->func == parse_uuid)
624 else if (ss->func == parse_hashalg)
625 type = "hash algorithm";
626 else if (ss->func == parse_time)
628 else if (ss->func == parse_bmap)
629 type = "set physical->logical block map";
630 else if (ss->func == parse_gd_csum)
631 type = "unsigned integer OR \"calc\"";
632 strcpy(name, ss->name);
633 if (ss->flags & FLAG_ARRAY) {
635 sprintf(idx, "[%d]", ss->max_idx);
641 strcat(name, "[_hi|_lo]");
642 fprintf(f, "\t%-25s\t%s\n", name, type);
648 void do_set_super(int argc, char *argv[])
650 const char *usage = "<field> <value>\n"
651 "\t\"set_super_value -l\" will list the names of "
652 "superblock fields\n\twhich can be set.";
653 static struct field_set_info *ss;
655 if ((argc == 2) && !strcmp(argv[1], "-l")) {
656 print_possible_fields(super_fields);
660 if (common_args_process(argc, argv, 3, 3, "set_super_value",
664 if ((ss = find_field(super_fields, argv[1])) == 0) {
665 com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
668 set_sb = *current_fs->super;
669 if (ss->func(ss, argv[1], argv[2]) == 0) {
670 *current_fs->super = set_sb;
671 ext2fs_mark_super_dirty(current_fs);
675 void do_set_inode(int argc, char *argv[])
677 const char *usage = "<inode> <field> <value>\n"
678 "\t\"set_inode_field -l\" will list the names of "
679 "the fields in an ext2 inode\n\twhich can be set.";
680 static struct field_set_info *ss;
682 if ((argc == 2) && !strcmp(argv[1], "-l")) {
683 print_possible_fields(inode_fields);
687 if (common_args_process(argc, argv, 4, 4, "set_inode",
691 if ((ss = find_field(inode_fields, argv[2])) == 0) {
692 com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
696 set_ino = string_to_inode(argv[1]);
700 if (debugfs_read_inode_full(set_ino,
701 (struct ext2_inode *) &set_inode, argv[1],
705 if (ss->func(ss, argv[2], argv[3]) == 0) {
706 if (debugfs_write_inode_full(set_ino,
707 (struct ext2_inode *) &set_inode,
708 argv[1], sizeof(set_inode)))
713 void do_set_block_group_descriptor(int argc, char *argv[])
715 const char *usage = "<bg number> <field> <value>\n"
716 "\t\"set_block_group_descriptor -l\" will list the names of "
717 "the fields in a block group descriptor\n\twhich can be set.";
718 struct field_set_info *table;
719 struct field_set_info *ss;
725 * Determine whether we are editing an ext2 or ext4 block group
726 * descriptor. Descriptors larger than ext4_group_desc cannot
727 * have their fields edited yet, because they do not have any
728 * names assigned. When that happens, this function needs to
729 * be updated for the new descriptor struct and fields.
732 EXT2_DESC_SIZE(current_fs->super) >= EXT2_MIN_DESC_SIZE_64BIT) {
733 table = ext4_bg_fields;
735 size = sizeof(set_gd4);
737 table = ext2_bg_fields;
739 size = sizeof(set_gd);
742 if ((argc == 2) && !strcmp(argv[1], "-l")) {
743 print_possible_fields(table);
747 if (common_args_process(argc, argv, 4, 4, "set_block_group_descriptor",
751 set_bg = strtoul(argv[1], &end, 0);
753 com_err(argv[0], 0, "invalid block group number: %s", argv[1]);
757 if (set_bg >= current_fs->group_desc_count) {
758 com_err(argv[0], 0, "block group number too big: %d", set_bg);
762 if ((ss = find_field(table, argv[2])) == 0) {
763 com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
767 target = ext2fs_group_desc(current_fs, current_fs->group_desc, set_bg);
768 memcpy(edit, target, size);
769 if (ss->func(ss, argv[2], argv[3]) == 0) {
770 memcpy(target, edit, size);
771 ext2fs_mark_super_dirty(current_fs);
775 static errcode_t parse_mmp_clear(struct field_set_info *info,
776 char *field EXT2FS_ATTR((unused)),
777 char *arg EXT2FS_ATTR((unused)))
781 retval = ext2fs_mmp_clear(current_fs);
783 com_err("set_mmp_value", retval, "while clearing MMP block\n");
785 memcpy(info->ptr, current_fs->mmp_buf, info->size);
787 return 1; /* we don't need the MMP block written again */
790 void do_set_mmp_value(int argc, char *argv[])
792 const char *usage = "<field> <value>\n"
793 "\t\"set_mmp_value -l\" will list the names of "
794 "MMP fields\n\twhich can be set.";
795 static struct field_set_info *smmp;
796 struct mmp_struct *mmp_s;
799 if (argc == 2 && strcmp(argv[1], "-l") == 0) {
800 print_possible_fields(mmp_fields);
804 if (check_fs_open(argv[0]))
807 if (current_fs->super->s_mmp_block == 0) {
808 com_err(argv[0], 0, "no MMP block allocated\n");
812 if (common_args_process(argc, argv, 2, 3, "set_mmp_value",
816 mmp_s = current_fs->mmp_buf;
818 retval = ext2fs_get_mem(current_fs->blocksize, &mmp_s);
820 com_err(argv[0], retval, "allocating MMP buffer\n");
823 retval = ext2fs_mmp_read(current_fs,
824 current_fs->super->s_mmp_block, mmp_s);
826 com_err(argv[0], retval, "reading MMP block %llu.\n",
827 (long long)current_fs->super->s_mmp_block);
828 ext2fs_free_mem(&mmp_s);
831 current_fs->mmp_buf = mmp_s;
834 smmp = find_field(mmp_fields, argv[1]);
836 com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
841 if (smmp->func(smmp, argv[1], argv[2]) == 0) {
842 ext2fs_mmp_write(current_fs, current_fs->super->s_mmp_block,