]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - misc/tune2fs.c
3e1269717237e3ba14b19aba7c07601844af2921
[thirdparty/e2fsprogs.git] / misc / tune2fs.c
1 /*
2 * tune2fs.c - Change the file system parameters on an ext2 file system
3 *
4 * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
7 *
8 * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o.
9 *
10 * %Begin-Header%
11 * This file may be redistributed under the terms of the GNU Public
12 * License.
13 * %End-Header%
14 */
15
16 /*
17 * History:
18 * 93/06/01 - Creation
19 * 93/10/31 - Added the -c option to change the maximal mount counts
20 * 93/12/14 - Added -l flag to list contents of superblock
21 * M.J.E. Mol (marcel@duteca.et.tudelft.nl)
22 * F.W. ten Wolde (franky@duteca.et.tudelft.nl)
23 * 93/12/29 - Added the -e option to change errors behavior
24 * 94/02/27 - Ported to use the ext2fs library
25 * 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de)
26 */
27
28 #define _XOPEN_SOURCE 600 /* for inclusion of strptime() */
29 #define _BSD_SOURCE /* for inclusion of strcasecmp() */
30 #include "config.h"
31 #include <fcntl.h>
32 #include <grp.h>
33 #ifdef HAVE_GETOPT_H
34 #include <getopt.h>
35 #else
36 extern char *optarg;
37 extern int optind;
38 #endif
39 #include <pwd.h>
40 #include <stdio.h>
41 #ifdef HAVE_STDLIB_H
42 #include <stdlib.h>
43 #endif
44 #include <string.h>
45 #include <time.h>
46 #include <unistd.h>
47 #include <sys/types.h>
48 #include <libgen.h>
49 #include <limits.h>
50
51 #include "ext2fs/ext2_fs.h"
52 #include "ext2fs/ext2fs.h"
53 #include "et/com_err.h"
54 #include "uuid/uuid.h"
55 #include "e2p/e2p.h"
56 #include "jfs_user.h"
57 #include "util.h"
58 #include "blkid/blkid.h"
59 #include "quota/mkquota.h"
60
61 #include "../version.h"
62 #include "nls-enable.h"
63
64 #define QOPT_ENABLE (1)
65 #define QOPT_DISABLE (-1)
66
67 extern int ask_yn(const char *string, int def);
68
69 const char *program_name = "tune2fs";
70 char *device_name;
71 char *new_label, *new_last_mounted, *new_UUID;
72 char *io_options;
73 static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
74 static int m_flag, M_flag, Q_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag;
75 static int I_flag;
76 static time_t last_check_time;
77 static int print_label;
78 static int max_mount_count, mount_count, mount_flags;
79 static unsigned long interval;
80 static blk64_t reserved_blocks;
81 static double reserved_ratio;
82 static unsigned long resgid, resuid;
83 static unsigned short errors;
84 static int open_flag;
85 static char *features_cmd;
86 static char *mntopts_cmd;
87 static int stride, stripe_width;
88 static int stride_set, stripe_width_set;
89 static char *extended_cmd;
90 static unsigned long new_inode_size;
91 static char *ext_mount_opts;
92 static int usrquota, grpquota;
93
94 int journal_size, journal_flags;
95 char *journal_device;
96
97 static struct list_head blk_move_list;
98
99 struct blk_move {
100 struct list_head list;
101 blk64_t old_loc;
102 blk64_t new_loc;
103 };
104
105
106 static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
107
108 #ifdef CONFIG_BUILD_FINDFS
109 void do_findfs(int argc, char **argv);
110 #endif
111
112 static void usage(void)
113 {
114 fprintf(stderr,
115 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
116 "[-g group]\n"
117 "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
118 "\t[-m reserved_blocks_percent] "
119 "[-o [^]mount_options[,...]] \n"
120 "\t[-r reserved_blocks_count] [-u user] [-C mount_count] "
121 "[-L volume_label]\n"
122 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
123 "\t[-E extended-option[,...]] [-T last_check_time] "
124 "[-U UUID]\n\t[ -I new_inode_size ] device\n"), program_name);
125 exit(1);
126 }
127
128 static __u32 ok_features[3] = {
129 /* Compat */
130 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
131 EXT2_FEATURE_COMPAT_DIR_INDEX,
132 /* Incompat */
133 EXT2_FEATURE_INCOMPAT_FILETYPE |
134 EXT3_FEATURE_INCOMPAT_EXTENTS |
135 EXT4_FEATURE_INCOMPAT_FLEX_BG,
136 /* R/O compat */
137 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
138 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
139 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
140 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
141 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
142 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
143 EXT4_FEATURE_RO_COMPAT_QUOTA
144 };
145
146 static __u32 clear_ok_features[3] = {
147 /* Compat */
148 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
149 EXT2_FEATURE_COMPAT_RESIZE_INODE |
150 EXT2_FEATURE_COMPAT_DIR_INDEX,
151 /* Incompat */
152 EXT2_FEATURE_INCOMPAT_FILETYPE |
153 EXT4_FEATURE_INCOMPAT_FLEX_BG,
154 /* R/O compat */
155 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
156 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
157 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
158 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
159 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
160 EXT4_FEATURE_RO_COMPAT_QUOTA
161 };
162
163 /*
164 * Remove an external journal from the filesystem
165 */
166 static void remove_journal_device(ext2_filsys fs)
167 {
168 char *journal_path;
169 ext2_filsys jfs;
170 char buf[1024];
171 journal_superblock_t *jsb;
172 int i, nr_users;
173 errcode_t retval;
174 int commit_remove_journal = 0;
175 io_manager io_ptr;
176
177 if (f_flag)
178 commit_remove_journal = 1; /* force removal even if error */
179
180 uuid_unparse(fs->super->s_journal_uuid, buf);
181 journal_path = blkid_get_devname(NULL, "UUID", buf);
182
183 if (!journal_path) {
184 journal_path =
185 ext2fs_find_block_device(fs->super->s_journal_dev);
186 if (!journal_path)
187 return;
188 }
189
190 #ifdef CONFIG_TESTIO_DEBUG
191 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
192 io_ptr = test_io_manager;
193 test_io_backing_manager = unix_io_manager;
194 } else
195 #endif
196 io_ptr = unix_io_manager;
197 retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
198 EXT2_FLAG_JOURNAL_DEV_OK, 0,
199 fs->blocksize, io_ptr, &jfs);
200 if (retval) {
201 com_err(program_name, retval,
202 _("while trying to open external journal"));
203 goto no_valid_journal;
204 }
205 if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
206 fprintf(stderr, _("%s is not a journal device.\n"),
207 journal_path);
208 goto no_valid_journal;
209 }
210
211 /* Get the journal superblock */
212 if ((retval = io_channel_read_blk64(jfs->io, 1, -1024, buf))) {
213 com_err(program_name, retval,
214 _("while reading journal superblock"));
215 goto no_valid_journal;
216 }
217
218 jsb = (journal_superblock_t *) buf;
219 if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
220 (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) {
221 fputs(_("Journal superblock not found!\n"), stderr);
222 goto no_valid_journal;
223 }
224
225 /* Find the filesystem UUID */
226 nr_users = ntohl(jsb->s_nr_users);
227 for (i = 0; i < nr_users; i++) {
228 if (memcmp(fs->super->s_uuid,
229 &jsb->s_users[i*16], 16) == 0)
230 break;
231 }
232 if (i >= nr_users) {
233 fputs(_("Filesystem's UUID not found on journal device.\n"),
234 stderr);
235 commit_remove_journal = 1;
236 goto no_valid_journal;
237 }
238 nr_users--;
239 for (i = 0; i < nr_users; i++)
240 memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16);
241 jsb->s_nr_users = htonl(nr_users);
242
243 /* Write back the journal superblock */
244 if ((retval = io_channel_write_blk64(jfs->io, 1, -1024, buf))) {
245 com_err(program_name, retval,
246 "while writing journal superblock.");
247 goto no_valid_journal;
248 }
249
250 commit_remove_journal = 1;
251
252 no_valid_journal:
253 if (commit_remove_journal == 0) {
254 fputs(_("Journal NOT removed\n"), stderr);
255 exit(1);
256 }
257 fs->super->s_journal_dev = 0;
258 uuid_clear(fs->super->s_journal_uuid);
259 ext2fs_mark_super_dirty(fs);
260 fputs(_("Journal removed\n"), stdout);
261 free(journal_path);
262 }
263
264 /* Helper function for remove_journal_inode */
265 static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
266 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
267 blk64_t ref_block EXT2FS_ATTR((unused)),
268 int ref_offset EXT2FS_ATTR((unused)),
269 void *private EXT2FS_ATTR((unused)))
270 {
271 blk64_t block;
272 int group;
273
274 block = *blocknr;
275 ext2fs_unmark_block_bitmap2(fs->block_map, block);
276 group = ext2fs_group_of_blk2(fs, block);
277 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
278 ext2fs_group_desc_csum_set(fs, group);
279 ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs));
280 return 0;
281 }
282
283 /*
284 * Remove the journal inode from the filesystem
285 */
286 static void remove_journal_inode(ext2_filsys fs)
287 {
288 struct ext2_inode inode;
289 errcode_t retval;
290 ino_t ino = fs->super->s_journal_inum;
291
292 retval = ext2fs_read_inode(fs, ino, &inode);
293 if (retval) {
294 com_err(program_name, retval,
295 _("while reading journal inode"));
296 exit(1);
297 }
298 if (ino == EXT2_JOURNAL_INO) {
299 retval = ext2fs_read_bitmaps(fs);
300 if (retval) {
301 com_err(program_name, retval,
302 _("while reading bitmaps"));
303 exit(1);
304 }
305 retval = ext2fs_block_iterate3(fs, ino,
306 BLOCK_FLAG_READ_ONLY, NULL,
307 release_blocks_proc, NULL);
308 if (retval) {
309 com_err(program_name, retval,
310 _("while clearing journal inode"));
311 exit(1);
312 }
313 memset(&inode, 0, sizeof(inode));
314 ext2fs_mark_bb_dirty(fs);
315 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
316 } else
317 inode.i_flags &= ~EXT2_IMMUTABLE_FL;
318 retval = ext2fs_write_inode(fs, ino, &inode);
319 if (retval) {
320 com_err(program_name, retval,
321 _("while writing journal inode"));
322 exit(1);
323 }
324 fs->super->s_journal_inum = 0;
325 ext2fs_mark_super_dirty(fs);
326 }
327
328 /*
329 * Update the default mount options
330 */
331 static void update_mntopts(ext2_filsys fs, char *mntopts)
332 {
333 struct ext2_super_block *sb = fs->super;
334
335 if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
336 fprintf(stderr, _("Invalid mount option set: %s\n"),
337 mntopts);
338 exit(1);
339 }
340 ext2fs_mark_super_dirty(fs);
341 }
342
343 static void request_fsck_afterwards(ext2_filsys fs)
344 {
345 static int requested = 0;
346
347 if (requested++)
348 return;
349 fs->super->s_state &= ~EXT2_VALID_FS;
350 printf("\n%s\n", _(please_fsck));
351 if (mount_flags & EXT2_MF_READONLY)
352 printf(_("(and reboot afterwards!)\n"));
353 }
354
355 /*
356 * Update the feature set as provided by the user.
357 */
358 static void update_feature_set(ext2_filsys fs, char *features)
359 {
360 struct ext2_super_block *sb = fs->super;
361 struct ext2_group_desc *gd;
362 __u32 old_features[3];
363 int i, type_err;
364 unsigned int mask_err;
365
366 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
367 ((&sb->s_feature_compat)[(type)] & (mask)))
368 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
369 !((&sb->s_feature_compat)[(type)] & (mask)))
370 #define FEATURE_CHANGED(type, mask) ((mask) & \
371 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
372
373 old_features[E2P_FEATURE_COMPAT] = sb->s_feature_compat;
374 old_features[E2P_FEATURE_INCOMPAT] = sb->s_feature_incompat;
375 old_features[E2P_FEATURE_RO_INCOMPAT] = sb->s_feature_ro_compat;
376
377 if (e2p_edit_feature2(features, &sb->s_feature_compat,
378 ok_features, clear_ok_features,
379 &type_err, &mask_err)) {
380 if (!mask_err)
381 fprintf(stderr,
382 _("Invalid filesystem option set: %s\n"),
383 features);
384 else if (type_err & E2P_FEATURE_NEGATE_FLAG)
385 fprintf(stderr, _("Clearing filesystem feature '%s' "
386 "not supported.\n"),
387 e2p_feature2string(type_err &
388 E2P_FEATURE_TYPE_MASK,
389 mask_err));
390 else
391 fprintf(stderr, _("Setting filesystem feature '%s' "
392 "not supported.\n"),
393 e2p_feature2string(type_err, mask_err));
394 exit(1);
395 }
396
397 if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
398 if ((mount_flags & EXT2_MF_MOUNTED) &&
399 !(mount_flags & EXT2_MF_READONLY)) {
400 fputs(_("The has_journal feature may only be "
401 "cleared when the filesystem is\n"
402 "unmounted or mounted "
403 "read-only.\n"), stderr);
404 exit(1);
405 }
406 if (sb->s_feature_incompat &
407 EXT3_FEATURE_INCOMPAT_RECOVER) {
408 fputs(_("The needs_recovery flag is set. "
409 "Please run e2fsck before clearing\n"
410 "the has_journal flag.\n"), stderr);
411 exit(1);
412 }
413 if (sb->s_journal_inum) {
414 remove_journal_inode(fs);
415 }
416 if (sb->s_journal_dev) {
417 remove_journal_device(fs);
418 }
419 }
420
421 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
422 /*
423 * If adding a journal flag, let the create journal
424 * code below handle setting the flag and creating the
425 * journal. We supply a default size if necessary.
426 */
427 if (!journal_size)
428 journal_size = -1;
429 sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
430 }
431
432 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
433 if (!sb->s_def_hash_version)
434 sb->s_def_hash_version = EXT2_HASH_HALF_MD4;
435 if (uuid_is_null((unsigned char *) sb->s_hash_seed))
436 uuid_generate((unsigned char *) sb->s_hash_seed);
437 }
438
439 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
440 if (ext2fs_check_desc(fs)) {
441 fputs(_("Clearing the flex_bg flag would "
442 "cause the the filesystem to be\n"
443 "inconsistent.\n"), stderr);
444 exit(1);
445 }
446 }
447
448 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
449 EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
450 if ((mount_flags & EXT2_MF_MOUNTED) &&
451 !(mount_flags & EXT2_MF_READONLY)) {
452 fputs(_("The huge_file feature may only be "
453 "cleared when the filesystem is\n"
454 "unmounted or mounted "
455 "read-only.\n"), stderr);
456 exit(1);
457 }
458 }
459
460 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
461 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
462 for (i = 0; i < fs->group_desc_count; i++) {
463 gd = ext2fs_group_desc(fs, fs->group_desc, i);
464 gd->bg_itable_unused = 0;
465 gd->bg_flags = EXT2_BG_INODE_ZEROED;
466 ext2fs_group_desc_csum_set(fs, i);
467 }
468 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
469 }
470
471 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
472 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
473 for (i = 0; i < fs->group_desc_count; i++) {
474 gd = ext2fs_group_desc(fs, fs->group_desc, i);
475 if ((gd->bg_flags & EXT2_BG_INODE_ZEROED) == 0) {
476 /*
477 * XXX what we really should do is zap
478 * uninitialized inode tables instead.
479 */
480 request_fsck_afterwards(fs);
481 break;
482 }
483 gd->bg_itable_unused = 0;
484 gd->bg_flags = 0;
485 gd->bg_checksum = 0;
486 }
487 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
488 }
489
490 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
491 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
492 /*
493 * Set the Q_flag here and handle the quota options in the code
494 * below.
495 */
496 if (!Q_flag) {
497 Q_flag = 1;
498 /* Enable both user quota and group quota by default */
499 usrquota = QOPT_ENABLE;
500 grpquota = QOPT_ENABLE;
501 }
502 sb->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
503 }
504
505 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
506 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
507 /*
508 * Set the Q_flag here and handle the quota options in the code
509 * below.
510 */
511 if (Q_flag)
512 fputs(_("\nWarning: '^quota' option overrides '-Q'"
513 "arguments.\n"), stderr);
514 Q_flag = 1;
515 /* Disable both user quota and group quota by default */
516 usrquota = QOPT_DISABLE;
517 grpquota = QOPT_DISABLE;
518 }
519
520 if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
521 (sb->s_feature_compat || sb->s_feature_ro_compat ||
522 sb->s_feature_incompat))
523 ext2fs_update_dynamic_rev(fs);
524
525 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT,
526 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
527 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
528 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
529 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT,
530 EXT2_FEATURE_INCOMPAT_FILETYPE) ||
531 FEATURE_CHANGED(E2P_FEATURE_COMPAT,
532 EXT2_FEATURE_COMPAT_RESIZE_INODE) ||
533 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
534 EXT2_FEATURE_RO_COMPAT_LARGE_FILE))
535 request_fsck_afterwards(fs);
536
537 if ((old_features[E2P_FEATURE_COMPAT] != sb->s_feature_compat) ||
538 (old_features[E2P_FEATURE_INCOMPAT] != sb->s_feature_incompat) ||
539 (old_features[E2P_FEATURE_RO_INCOMPAT] != sb->s_feature_ro_compat))
540 ext2fs_mark_super_dirty(fs);
541 }
542
543 /*
544 * Add a journal to the filesystem.
545 */
546 static void add_journal(ext2_filsys fs)
547 {
548 unsigned long journal_blocks;
549 errcode_t retval;
550 ext2_filsys jfs;
551 io_manager io_ptr;
552
553 if (fs->super->s_feature_compat &
554 EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
555 fputs(_("The filesystem already has a journal.\n"), stderr);
556 goto err;
557 }
558 if (journal_device) {
559 check_plausibility(journal_device);
560 check_mount(journal_device, 0, _("journal"));
561 #ifdef CONFIG_TESTIO_DEBUG
562 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
563 io_ptr = test_io_manager;
564 test_io_backing_manager = unix_io_manager;
565 } else
566 #endif
567 io_ptr = unix_io_manager;
568 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
569 EXT2_FLAG_JOURNAL_DEV_OK, 0,
570 fs->blocksize, io_ptr, &jfs);
571 if (retval) {
572 com_err(program_name, retval,
573 _("\n\twhile trying to open journal on %s\n"),
574 journal_device);
575 goto err;
576 }
577 printf(_("Creating journal on device %s: "),
578 journal_device);
579 fflush(stdout);
580
581 retval = ext2fs_add_journal_device(fs, jfs);
582 ext2fs_close(jfs);
583 if (retval) {
584 com_err(program_name, retval,
585 _("while adding filesystem to journal on %s"),
586 journal_device);
587 goto err;
588 }
589 fputs(_("done\n"), stdout);
590 } else if (journal_size) {
591 fputs(_("Creating journal inode: "), stdout);
592 fflush(stdout);
593 journal_blocks = figure_journal_size(journal_size, fs);
594
595 retval = ext2fs_add_journal_inode(fs, journal_blocks,
596 journal_flags);
597 if (retval) {
598 fprintf(stderr, "\n");
599 com_err(program_name, retval,
600 _("\n\twhile trying to create journal file"));
601 exit(1);
602 } else
603 fputs(_("done\n"), stdout);
604 /*
605 * If the filesystem wasn't mounted, we need to force
606 * the block group descriptors out.
607 */
608 if ((mount_flags & EXT2_MF_MOUNTED) == 0)
609 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
610 }
611 print_check_message(fs->super->s_max_mnt_count,
612 fs->super->s_checkinterval);
613 return;
614
615 err:
616 free(journal_device);
617 exit(1);
618 }
619
620 void handle_quota_options(ext2_filsys fs)
621 {
622 quota_ctx_t qctx;
623 errcode_t retval;
624 ext2_ino_t qf_ino;
625
626 if (!usrquota && !grpquota)
627 /* Nothing to do. */
628 return;
629
630 init_quota_context(&qctx, fs, -1);
631
632 if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
633 if ((qf_ino = quota_file_exists(fs, USRQUOTA, QFMT_VFS_V1)) > 0)
634 set_sb_quota_inum(fs, qf_ino, USRQUOTA);
635 else
636 write_quota_inode(qctx, USRQUOTA);
637 } else if (usrquota == QOPT_DISABLE) {
638 remove_quota_inode(fs, USRQUOTA);
639 }
640
641 if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
642 if ((qf_ino = quota_file_exists(fs, GRPQUOTA, QFMT_VFS_V1)) > 0)
643 set_sb_quota_inum(fs, qf_ino, GRPQUOTA);
644 else
645 write_quota_inode(qctx, GRPQUOTA);
646 } else if (grpquota == QOPT_DISABLE) {
647 remove_quota_inode(fs, GRPQUOTA);
648 }
649
650 release_quota_context(&qctx);
651
652 if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
653 fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
654 ext2fs_mark_super_dirty(fs);
655 } else if ((usrquota == QOPT_DISABLE) && (grpquota == QOPT_DISABLE)) {
656 fs->super->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
657 ext2fs_mark_super_dirty(fs);
658 }
659
660 return;
661 }
662
663 void parse_quota_opts(const char *opts)
664 {
665 char *buf, *token, *next, *p, *arg;
666 int len;
667
668 len = strlen(opts);
669 buf = malloc(len+1);
670 if (!buf) {
671 fputs(_("Couldn't allocate memory to parse quota "
672 "options!\n"), stderr);
673 exit(1);
674 }
675 strcpy(buf, opts);
676 for (token = buf; token && *token; token = next) {
677 p = strchr(token, ',');
678 next = 0;
679 if (p) {
680 *p = 0;
681 next = p+1;
682 }
683
684 if (strcmp(token, "usrquota") == 0) {
685 usrquota = QOPT_ENABLE;
686 } else if (strcmp(token, "^usrquota") == 0) {
687 usrquota = QOPT_DISABLE;
688 } else if (strcmp(token, "grpquota") == 0) {
689 grpquota = QOPT_ENABLE;
690 } else if (strcmp(token, "^grpquota") == 0) {
691 grpquota = QOPT_DISABLE;
692 } else {
693 fputs(_("\nBad quota options specified.\n\n"
694 "Following valid quota options are available "
695 "(pass by separating with comma):\n"
696 "\t[^]usrquota\n"
697 "\t[^]grpquota\n"
698 "\n\n"), stderr);
699 free(buf);
700 exit(1);
701 }
702 }
703 free(buf);
704 }
705
706
707
708 static void parse_e2label_options(int argc, char ** argv)
709 {
710 if ((argc < 2) || (argc > 3)) {
711 fputs(_("Usage: e2label device [newlabel]\n"), stderr);
712 exit(1);
713 }
714 io_options = strchr(argv[1], '?');
715 if (io_options)
716 *io_options++ = 0;
717 device_name = blkid_get_devname(NULL, argv[1], NULL);
718 if (!device_name) {
719 com_err("e2label", 0, _("Unable to resolve '%s'"),
720 argv[1]);
721 exit(1);
722 }
723 open_flag = EXT2_FLAG_JOURNAL_DEV_OK;
724 if (argc == 3) {
725 open_flag |= EXT2_FLAG_RW;
726 L_flag = 1;
727 new_label = argv[2];
728 } else
729 print_label++;
730 }
731
732 static time_t parse_time(char *str)
733 {
734 struct tm ts;
735
736 if (strcmp(str, "now") == 0) {
737 return (time(0));
738 }
739 memset(&ts, 0, sizeof(ts));
740 #ifdef HAVE_STRPTIME
741 strptime(str, "%Y%m%d%H%M%S", &ts);
742 #else
743 sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
744 &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
745 ts.tm_year -= 1900;
746 ts.tm_mon -= 1;
747 if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
748 ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
749 ts.tm_min > 59 || ts.tm_sec > 61)
750 ts.tm_mday = 0;
751 #endif
752 if (ts.tm_mday == 0) {
753 com_err(program_name, 0,
754 _("Couldn't parse date/time specifier: %s"),
755 str);
756 usage();
757 }
758 ts.tm_isdst = -1;
759 return (mktime(&ts));
760 }
761
762 static void parse_tune2fs_options(int argc, char **argv)
763 {
764 int c;
765 char *tmp;
766 struct group *gr;
767 struct passwd *pw;
768
769 open_flag = 0;
770
771 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
772 while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:Q:T:U:")) != EOF)
773 switch (c) {
774 case 'c':
775 max_mount_count = strtol(optarg, &tmp, 0);
776 if (*tmp || max_mount_count > 16000) {
777 com_err(program_name, 0,
778 _("bad mounts count - %s"),
779 optarg);
780 usage();
781 }
782 if (max_mount_count == 0)
783 max_mount_count = -1;
784 c_flag = 1;
785 open_flag = EXT2_FLAG_RW;
786 break;
787 case 'C':
788 mount_count = strtoul(optarg, &tmp, 0);
789 if (*tmp || mount_count > 16000) {
790 com_err(program_name, 0,
791 _("bad mounts count - %s"),
792 optarg);
793 usage();
794 }
795 C_flag = 1;
796 open_flag = EXT2_FLAG_RW;
797 break;
798 case 'e':
799 if (strcmp(optarg, "continue") == 0)
800 errors = EXT2_ERRORS_CONTINUE;
801 else if (strcmp(optarg, "remount-ro") == 0)
802 errors = EXT2_ERRORS_RO;
803 else if (strcmp(optarg, "panic") == 0)
804 errors = EXT2_ERRORS_PANIC;
805 else {
806 com_err(program_name, 0,
807 _("bad error behavior - %s"),
808 optarg);
809 usage();
810 }
811 e_flag = 1;
812 open_flag = EXT2_FLAG_RW;
813 break;
814 case 'E':
815 extended_cmd = optarg;
816 open_flag |= EXT2_FLAG_RW;
817 break;
818 case 'f': /* Force */
819 f_flag = 1;
820 break;
821 case 'g':
822 resgid = strtoul(optarg, &tmp, 0);
823 if (*tmp) {
824 gr = getgrnam(optarg);
825 if (gr == NULL)
826 tmp = optarg;
827 else {
828 resgid = gr->gr_gid;
829 *tmp = 0;
830 }
831 }
832 if (*tmp) {
833 com_err(program_name, 0,
834 _("bad gid/group name - %s"),
835 optarg);
836 usage();
837 }
838 g_flag = 1;
839 open_flag = EXT2_FLAG_RW;
840 break;
841 case 'i':
842 interval = strtoul(optarg, &tmp, 0);
843 switch (*tmp) {
844 case 's':
845 tmp++;
846 break;
847 case '\0':
848 case 'd':
849 case 'D': /* days */
850 interval *= 86400;
851 if (*tmp != '\0')
852 tmp++;
853 break;
854 case 'm':
855 case 'M': /* months! */
856 interval *= 86400 * 30;
857 tmp++;
858 break;
859 case 'w':
860 case 'W': /* weeks */
861 interval *= 86400 * 7;
862 tmp++;
863 break;
864 }
865 if (*tmp) {
866 com_err(program_name, 0,
867 _("bad interval - %s"), optarg);
868 usage();
869 }
870 i_flag = 1;
871 open_flag = EXT2_FLAG_RW;
872 break;
873 case 'j':
874 if (!journal_size)
875 journal_size = -1;
876 open_flag = EXT2_FLAG_RW;
877 break;
878 case 'J':
879 parse_journal_opts(optarg);
880 open_flag = EXT2_FLAG_RW;
881 break;
882 case 'l':
883 l_flag = 1;
884 break;
885 case 'L':
886 new_label = optarg;
887 L_flag = 1;
888 open_flag |= EXT2_FLAG_RW |
889 EXT2_FLAG_JOURNAL_DEV_OK;
890 break;
891 case 'm':
892 reserved_ratio = strtod(optarg, &tmp);
893 if (*tmp || reserved_ratio > 50 ||
894 reserved_ratio < 0) {
895 com_err(program_name, 0,
896 _("bad reserved block ratio - %s"),
897 optarg);
898 usage();
899 }
900 m_flag = 1;
901 open_flag = EXT2_FLAG_RW;
902 break;
903 case 'M':
904 new_last_mounted = optarg;
905 M_flag = 1;
906 open_flag = EXT2_FLAG_RW;
907 break;
908 case 'o':
909 if (mntopts_cmd) {
910 com_err(program_name, 0,
911 _("-o may only be specified once"));
912 usage();
913 }
914 mntopts_cmd = optarg;
915 open_flag = EXT2_FLAG_RW;
916 break;
917
918 case 'O':
919 if (features_cmd) {
920 com_err(program_name, 0,
921 _("-O may only be specified once"));
922 usage();
923 }
924 features_cmd = optarg;
925 open_flag = EXT2_FLAG_RW;
926 break;
927 case 'Q':
928 Q_flag = 1;
929 parse_quota_opts(optarg);
930 open_flag = EXT2_FLAG_RW;
931 break;
932 case 'r':
933 reserved_blocks = strtoul(optarg, &tmp, 0);
934 if (*tmp) {
935 com_err(program_name, 0,
936 _("bad reserved blocks count - %s"),
937 optarg);
938 usage();
939 }
940 r_flag = 1;
941 open_flag = EXT2_FLAG_RW;
942 break;
943 case 's': /* Deprecated */
944 s_flag = atoi(optarg);
945 open_flag = EXT2_FLAG_RW;
946 break;
947 case 'T':
948 T_flag = 1;
949 last_check_time = parse_time(optarg);
950 open_flag = EXT2_FLAG_RW;
951 break;
952 case 'u':
953 resuid = strtoul(optarg, &tmp, 0);
954 if (*tmp) {
955 pw = getpwnam(optarg);
956 if (pw == NULL)
957 tmp = optarg;
958 else {
959 resuid = pw->pw_uid;
960 *tmp = 0;
961 }
962 }
963 if (*tmp) {
964 com_err(program_name, 0,
965 _("bad uid/user name - %s"),
966 optarg);
967 usage();
968 }
969 u_flag = 1;
970 open_flag = EXT2_FLAG_RW;
971 break;
972 case 'U':
973 new_UUID = optarg;
974 U_flag = 1;
975 open_flag = EXT2_FLAG_RW |
976 EXT2_FLAG_JOURNAL_DEV_OK;
977 break;
978 case 'I':
979 new_inode_size = strtoul(optarg, &tmp, 0);
980 if (*tmp) {
981 com_err(program_name, 0,
982 _("bad inode size - %s"),
983 optarg);
984 usage();
985 }
986 if (!((new_inode_size &
987 (new_inode_size - 1)) == 0)) {
988 com_err(program_name, 0,
989 _("Inode size must be a "
990 "power of two- %s"),
991 optarg);
992 usage();
993 }
994 open_flag = EXT2_FLAG_RW;
995 I_flag = 1;
996 break;
997 default:
998 usage();
999 }
1000 if (optind < argc - 1 || optind == argc)
1001 usage();
1002 if (!open_flag && !l_flag)
1003 usage();
1004 io_options = strchr(argv[optind], '?');
1005 if (io_options)
1006 *io_options++ = 0;
1007 device_name = blkid_get_devname(NULL, argv[optind], NULL);
1008 if (!device_name) {
1009 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
1010 argv[optind]);
1011 exit(1);
1012 }
1013 }
1014
1015 #ifdef CONFIG_BUILD_FINDFS
1016 void do_findfs(int argc, char **argv)
1017 {
1018 char *dev;
1019
1020 if ((argc != 2) ||
1021 (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
1022 fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
1023 exit(2);
1024 }
1025 dev = blkid_get_devname(NULL, argv[1], NULL);
1026 if (!dev) {
1027 com_err("findfs", 0, _("Unable to resolve '%s'"),
1028 argv[1]);
1029 exit(1);
1030 }
1031 puts(dev);
1032 exit(0);
1033 }
1034 #endif
1035
1036 static void parse_extended_opts(ext2_filsys fs, const char *opts)
1037 {
1038 char *buf, *token, *next, *p, *arg;
1039 int len, hash_alg;
1040 int r_usage = 0;
1041
1042 len = strlen(opts);
1043 buf = malloc(len+1);
1044 if (!buf) {
1045 fprintf(stderr,
1046 _("Couldn't allocate memory to parse options!\n"));
1047 exit(1);
1048 }
1049 strcpy(buf, opts);
1050 for (token = buf; token && *token; token = next) {
1051 p = strchr(token, ',');
1052 next = 0;
1053 if (p) {
1054 *p = 0;
1055 next = p+1;
1056 }
1057 arg = strchr(token, '=');
1058 if (arg) {
1059 *arg = 0;
1060 arg++;
1061 }
1062 if (!strcmp(token, "test_fs")) {
1063 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
1064 printf("Setting test filesystem flag\n");
1065 ext2fs_mark_super_dirty(fs);
1066 } else if (!strcmp(token, "^test_fs")) {
1067 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
1068 printf("Clearing test filesystem flag\n");
1069 ext2fs_mark_super_dirty(fs);
1070 } else if (strcmp(token, "stride") == 0) {
1071 if (!arg) {
1072 r_usage++;
1073 continue;
1074 }
1075 stride = strtoul(arg, &p, 0);
1076 if (*p) {
1077 fprintf(stderr,
1078 _("Invalid RAID stride: %s\n"),
1079 arg);
1080 r_usage++;
1081 continue;
1082 }
1083 stride_set = 1;
1084 } else if (strcmp(token, "stripe-width") == 0 ||
1085 strcmp(token, "stripe_width") == 0) {
1086 if (!arg) {
1087 r_usage++;
1088 continue;
1089 }
1090 stripe_width = strtoul(arg, &p, 0);
1091 if (*p) {
1092 fprintf(stderr,
1093 _("Invalid RAID stripe-width: %s\n"),
1094 arg);
1095 r_usage++;
1096 continue;
1097 }
1098 stripe_width_set = 1;
1099 } else if (strcmp(token, "hash_alg") == 0 ||
1100 strcmp(token, "hash-alg") == 0) {
1101 if (!arg) {
1102 r_usage++;
1103 continue;
1104 }
1105 hash_alg = e2p_string2hash(arg);
1106 if (hash_alg < 0) {
1107 fprintf(stderr,
1108 _("Invalid hash algorithm: %s\n"),
1109 arg);
1110 r_usage++;
1111 continue;
1112 }
1113 fs->super->s_def_hash_version = hash_alg;
1114 printf(_("Setting default hash algorithm "
1115 "to %s (%d)\n"),
1116 arg, hash_alg);
1117 ext2fs_mark_super_dirty(fs);
1118 } else if (!strcmp(token, "mount_opts")) {
1119 if (!arg) {
1120 r_usage++;
1121 continue;
1122 }
1123 if (strlen(arg) >= sizeof(fs->super->s_mount_opts)) {
1124 fprintf(stderr,
1125 "Extended mount options too long\n");
1126 continue;
1127 }
1128 ext_mount_opts = strdup(arg);
1129 } else
1130 r_usage++;
1131 }
1132 if (r_usage) {
1133 fprintf(stderr, _("\nBad options specified.\n\n"
1134 "Extended options are separated by commas, "
1135 "and may take an argument which\n"
1136 "\tis set off by an equals ('=') sign.\n\n"
1137 "Valid extended options are:\n"
1138 "\thash_alg=<hash algorithm>\n"
1139 "\tmount_opts=<extended default mount options>\n"
1140 "\tstride=<RAID per-disk chunk size in blocks>\n"
1141 "\tstripe_width=<RAID stride*data disks in blocks>\n"
1142 "\ttest_fs\n"
1143 "\t^test_fs\n"));
1144 free(buf);
1145 exit(1);
1146 }
1147 free(buf);
1148 }
1149
1150 /*
1151 * Fill in the block bitmap bmap with the information regarding the
1152 * blocks to be moved
1153 */
1154 static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
1155 ext2fs_block_bitmap bmap)
1156 {
1157 dgrp_t i;
1158 int retval;
1159 ext2_badblocks_list bb_list = 0;
1160 blk64_t j, needed_blocks = 0;
1161 blk64_t start_blk, end_blk;
1162
1163 retval = ext2fs_read_bb_inode(fs, &bb_list);
1164 if (retval)
1165 return retval;
1166
1167 for (i = 0; i < fs->group_desc_count; i++) {
1168 start_blk = ext2fs_inode_table_loc(fs, i) +
1169 fs->inode_blocks_per_group;
1170
1171 end_blk = ext2fs_inode_table_loc(fs, i) +
1172 new_ino_blks_per_grp;
1173
1174 for (j = start_blk; j < end_blk; j++) {
1175 if (ext2fs_test_block_bitmap2(fs->block_map, j)) {
1176 /*
1177 * IF the block is a bad block we fail
1178 */
1179 if (ext2fs_badblocks_list_test(bb_list, j)) {
1180 ext2fs_badblocks_list_free(bb_list);
1181 return ENOSPC;
1182 }
1183
1184 ext2fs_mark_block_bitmap2(bmap, j);
1185 } else {
1186 /*
1187 * We are going to use this block for
1188 * inode table. So mark them used.
1189 */
1190 ext2fs_mark_block_bitmap2(fs->block_map, j);
1191 }
1192 }
1193 needed_blocks += end_blk - start_blk;
1194 }
1195
1196 ext2fs_badblocks_list_free(bb_list);
1197 if (needed_blocks > ext2fs_free_blocks_count(fs->super))
1198 return ENOSPC;
1199
1200 return 0;
1201 }
1202
1203 static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
1204 {
1205 dgrp_t group;
1206 group = ext2fs_group_of_blk(fs, blk);
1207 if (ext2fs_block_bitmap_loc(fs, group) == blk)
1208 return 1;
1209 if (ext2fs_inode_bitmap_loc(fs, group) == blk)
1210 return 1;
1211 return 0;
1212 }
1213
1214 static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk_t blk)
1215 {
1216 blk_t start_blk, end_blk;
1217 start_blk = fs->super->s_first_data_block +
1218 EXT2_BLOCKS_PER_GROUP(fs->super) * group;
1219 /*
1220 * We cannot get new block beyond end_blk for for the last block group
1221 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1222 */
1223 end_blk = start_blk + EXT2_BLOCKS_PER_GROUP(fs->super);
1224 if (blk >= start_blk && blk <= end_blk)
1225 return 1;
1226 return 0;
1227 }
1228
1229 static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
1230 {
1231
1232 char *buf;
1233 dgrp_t group = 0;
1234 errcode_t retval;
1235 int meta_data = 0;
1236 blk64_t blk, new_blk, goal;
1237 struct blk_move *bmv;
1238
1239 retval = ext2fs_get_mem(fs->blocksize, &buf);
1240 if (retval)
1241 return retval;
1242
1243 for (new_blk = blk = fs->super->s_first_data_block;
1244 blk < ext2fs_blocks_count(fs->super); blk++) {
1245 if (!ext2fs_test_block_bitmap2(bmap, blk))
1246 continue;
1247
1248 if (ext2fs_is_meta_block(fs, blk)) {
1249 /*
1250 * If the block is mapping a fs meta data block
1251 * like group desc/block bitmap/inode bitmap. We
1252 * should find a block in the same group and fix
1253 * the respective fs metadata pointers. Otherwise
1254 * fail
1255 */
1256 group = ext2fs_group_of_blk(fs, blk);
1257 goal = ext2fs_group_first_block2(fs, group);
1258 meta_data = 1;
1259
1260 } else {
1261 goal = new_blk;
1262 }
1263 retval = ext2fs_new_block2(fs, goal, NULL, &new_blk);
1264 if (retval)
1265 goto err_out;
1266
1267 /* new fs meta data block should be in the same group */
1268 if (meta_data && !ext2fs_is_block_in_group(fs, group, new_blk)) {
1269 retval = ENOSPC;
1270 goto err_out;
1271 }
1272
1273 /* Mark this block as allocated */
1274 ext2fs_mark_block_bitmap2(fs->block_map, new_blk);
1275
1276 /* Add it to block move list */
1277 retval = ext2fs_get_mem(sizeof(struct blk_move), &bmv);
1278 if (retval)
1279 goto err_out;
1280
1281 bmv->old_loc = blk;
1282 bmv->new_loc = new_blk;
1283
1284 list_add(&(bmv->list), &blk_move_list);
1285
1286 retval = io_channel_read_blk64(fs->io, blk, 1, buf);
1287 if (retval)
1288 goto err_out;
1289
1290 retval = io_channel_write_blk64(fs->io, new_blk, 1, buf);
1291 if (retval)
1292 goto err_out;
1293 }
1294
1295 err_out:
1296 ext2fs_free_mem(&buf);
1297 return retval;
1298 }
1299
1300 static blk64_t translate_block(blk64_t blk)
1301 {
1302 struct list_head *entry;
1303 struct blk_move *bmv;
1304
1305 list_for_each(entry, &blk_move_list) {
1306 bmv = list_entry(entry, struct blk_move, list);
1307 if (bmv->old_loc == blk)
1308 return bmv->new_loc;
1309 }
1310
1311 return 0;
1312 }
1313
1314 static int process_block(ext2_filsys fs EXT2FS_ATTR((unused)),
1315 blk64_t *block_nr,
1316 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
1317 blk64_t ref_block EXT2FS_ATTR((unused)),
1318 int ref_offset EXT2FS_ATTR((unused)),
1319 void *priv_data)
1320 {
1321 int ret = 0;
1322 blk64_t new_blk;
1323 ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data;
1324
1325 if (!ext2fs_test_block_bitmap2(bmap, *block_nr))
1326 return 0;
1327 new_blk = translate_block(*block_nr);
1328 if (new_blk) {
1329 *block_nr = new_blk;
1330 /*
1331 * This will force the ext2fs_write_inode in the iterator
1332 */
1333 ret |= BLOCK_CHANGED;
1334 }
1335
1336 return ret;
1337 }
1338
1339 static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1340 {
1341 errcode_t retval = 0;
1342 ext2_ino_t ino;
1343 blk64_t blk;
1344 char *block_buf = 0;
1345 struct ext2_inode inode;
1346 ext2_inode_scan scan = NULL;
1347
1348 retval = ext2fs_get_mem(fs->blocksize * 3, &block_buf);
1349 if (retval)
1350 return retval;
1351
1352 retval = ext2fs_open_inode_scan(fs, 0, &scan);
1353 if (retval)
1354 goto err_out;
1355
1356 while (1) {
1357 retval = ext2fs_get_next_inode(scan, &ino, &inode);
1358 if (retval)
1359 goto err_out;
1360
1361 if (!ino)
1362 break;
1363
1364 if (inode.i_links_count == 0)
1365 continue; /* inode not in use */
1366
1367 /* FIXME!!
1368 * If we end up modifying the journal inode
1369 * the sb->s_jnl_blocks will differ. But a
1370 * subsequent e2fsck fixes that.
1371 * Do we need to fix this ??
1372 */
1373
1374 if (ext2fs_file_acl_block(&inode) &&
1375 ext2fs_test_block_bitmap2(bmap,
1376 ext2fs_file_acl_block(&inode))) {
1377 blk = translate_block(ext2fs_file_acl_block(&inode));
1378 if (!blk)
1379 continue;
1380
1381 ext2fs_file_acl_block_set(&inode, blk);
1382
1383 /*
1384 * Write the inode to disk so that inode table
1385 * resizing can work
1386 */
1387 retval = ext2fs_write_inode(fs, ino, &inode);
1388 if (retval)
1389 goto err_out;
1390 }
1391
1392 if (!ext2fs_inode_has_valid_blocks(&inode))
1393 continue;
1394
1395 retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
1396 process_block, bmap);
1397 if (retval)
1398 goto err_out;
1399
1400 }
1401
1402 err_out:
1403 ext2fs_free_mem(&block_buf);
1404
1405 return retval;
1406 }
1407
1408 /*
1409 * We need to scan for inode and block bitmaps that may need to be
1410 * moved. This can take place if the filesystem was formatted for
1411 * RAID arrays using the mke2fs's extended option "stride".
1412 */
1413 static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1414 {
1415 dgrp_t i;
1416 blk_t blk, new_blk;
1417
1418 for (i = 0; i < fs->group_desc_count; i++) {
1419 blk = ext2fs_block_bitmap_loc(fs, i);
1420 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1421 new_blk = translate_block(blk);
1422 if (!new_blk)
1423 continue;
1424 ext2fs_block_bitmap_loc_set(fs, i, new_blk);
1425 }
1426
1427 blk = ext2fs_inode_bitmap_loc(fs, i);
1428 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1429 new_blk = translate_block(blk);
1430 if (!new_blk)
1431 continue;
1432 ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
1433 }
1434 }
1435 return 0;
1436 }
1437
1438 static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size)
1439 {
1440 dgrp_t i;
1441 blk64_t blk;
1442 errcode_t retval;
1443 int new_ino_blks_per_grp;
1444 unsigned int j;
1445 char *old_itable = NULL, *new_itable = NULL;
1446 char *tmp_old_itable = NULL, *tmp_new_itable = NULL;
1447 unsigned long old_ino_size;
1448 int old_itable_size, new_itable_size;
1449
1450 old_itable_size = fs->inode_blocks_per_group * fs->blocksize;
1451 old_ino_size = EXT2_INODE_SIZE(fs->super);
1452
1453 new_ino_blks_per_grp = ext2fs_div_ceil(
1454 EXT2_INODES_PER_GROUP(fs->super) *
1455 new_ino_size,
1456 fs->blocksize);
1457
1458 new_itable_size = new_ino_blks_per_grp * fs->blocksize;
1459
1460 retval = ext2fs_get_mem(old_itable_size, &old_itable);
1461 if (retval)
1462 return retval;
1463
1464 retval = ext2fs_get_mem(new_itable_size, &new_itable);
1465 if (retval)
1466 goto err_out;
1467
1468 tmp_old_itable = old_itable;
1469 tmp_new_itable = new_itable;
1470
1471 for (i = 0; i < fs->group_desc_count; i++) {
1472 blk = ext2fs_inode_table_loc(fs, i);
1473 retval = io_channel_read_blk64(fs->io, blk,
1474 fs->inode_blocks_per_group, old_itable);
1475 if (retval)
1476 goto err_out;
1477
1478 for (j = 0; j < EXT2_INODES_PER_GROUP(fs->super); j++) {
1479 memcpy(new_itable, old_itable, old_ino_size);
1480
1481 memset(new_itable+old_ino_size, 0,
1482 new_ino_size - old_ino_size);
1483
1484 new_itable += new_ino_size;
1485 old_itable += old_ino_size;
1486 }
1487
1488 /* reset the pointer */
1489 old_itable = tmp_old_itable;
1490 new_itable = tmp_new_itable;
1491
1492 retval = io_channel_write_blk64(fs->io, blk,
1493 new_ino_blks_per_grp, new_itable);
1494 if (retval)
1495 goto err_out;
1496 }
1497
1498 /* Update the meta data */
1499 fs->inode_blocks_per_group = new_ino_blks_per_grp;
1500 fs->super->s_inode_size = new_ino_size;
1501
1502 err_out:
1503 if (old_itable)
1504 ext2fs_free_mem(&old_itable);
1505
1506 if (new_itable)
1507 ext2fs_free_mem(&new_itable);
1508
1509 return retval;
1510 }
1511
1512 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
1513 {
1514 blk64_t blk;
1515 ext2_ino_t ino;
1516 unsigned int group = 0;
1517 unsigned int count = 0;
1518 int total_free = 0;
1519 int group_free = 0;
1520
1521 /*
1522 * First calculate the block statistics
1523 */
1524 for (blk = fs->super->s_first_data_block;
1525 blk < ext2fs_blocks_count(fs->super); blk++) {
1526 if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) {
1527 group_free++;
1528 total_free++;
1529 }
1530 count++;
1531 if ((count == fs->super->s_blocks_per_group) ||
1532 (blk == ext2fs_blocks_count(fs->super)-1)) {
1533 ext2fs_bg_free_blocks_count_set(fs, group++,
1534 group_free);
1535 count = 0;
1536 group_free = 0;
1537 }
1538 }
1539 total_free = EXT2FS_C2B(fs, total_free);
1540 ext2fs_free_blocks_count_set(fs->super, total_free);
1541
1542 /*
1543 * Next, calculate the inode statistics
1544 */
1545 group_free = 0;
1546 total_free = 0;
1547 count = 0;
1548 group = 0;
1549
1550 /* Protect loop from wrap-around if s_inodes_count maxed */
1551 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
1552 if (!ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) {
1553 group_free++;
1554 total_free++;
1555 }
1556 count++;
1557 if ((count == fs->super->s_inodes_per_group) ||
1558 (ino == fs->super->s_inodes_count)) {
1559 ext2fs_bg_free_inodes_count_set(fs, group++,
1560 group_free);
1561 count = 0;
1562 group_free = 0;
1563 }
1564 }
1565 fs->super->s_free_inodes_count = total_free;
1566 ext2fs_mark_super_dirty(fs);
1567 return 0;
1568 }
1569
1570 #define list_for_each_safe(pos, pnext, head) \
1571 for (pos = (head)->next, pnext = pos->next; pos != (head); \
1572 pos = pnext, pnext = pos->next)
1573
1574 static void free_blk_move_list(void)
1575 {
1576 struct list_head *entry, *tmp;
1577 struct blk_move *bmv;
1578
1579 list_for_each_safe(entry, tmp, &blk_move_list) {
1580 bmv = list_entry(entry, struct blk_move, list);
1581 list_del(entry);
1582 ext2fs_free_mem(&bmv);
1583 }
1584 return;
1585 }
1586
1587 static int resize_inode(ext2_filsys fs, unsigned long new_size)
1588 {
1589 errcode_t retval;
1590 int new_ino_blks_per_grp;
1591 ext2fs_block_bitmap bmap;
1592
1593 retval = ext2fs_read_inode_bitmap(fs);
1594 if (retval) {
1595 fputs(_("Failed to read inode bitmap\n"), stderr);
1596 return retval;
1597 }
1598 retval = ext2fs_read_block_bitmap(fs);
1599 if (retval) {
1600 fputs(_("Failed to read blockbitmap\n"), stderr);
1601 return retval;
1602 }
1603 INIT_LIST_HEAD(&blk_move_list);
1604
1605
1606 new_ino_blks_per_grp = ext2fs_div_ceil(
1607 EXT2_INODES_PER_GROUP(fs->super)*
1608 new_size,
1609 fs->blocksize);
1610
1611 /* We may change the file system.
1612 * Mark the file system as invalid so that
1613 * the user is prompted to run fsck.
1614 */
1615 fs->super->s_state &= ~EXT2_VALID_FS;
1616
1617 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
1618 &bmap);
1619 if (retval) {
1620 fputs(_("Failed to allocate block bitmap when "
1621 "increasing inode size\n"), stderr);
1622 return retval;
1623 }
1624 retval = get_move_bitmaps(fs, new_ino_blks_per_grp, bmap);
1625 if (retval) {
1626 fputs(_("Not enough space to increase inode size \n"), stderr);
1627 goto err_out;
1628 }
1629 retval = move_block(fs, bmap);
1630 if (retval) {
1631 fputs(_("Failed to relocate blocks during inode resize \n"),
1632 stderr);
1633 goto err_out;
1634 }
1635 retval = inode_scan_and_fix(fs, bmap);
1636 if (retval)
1637 goto err_out_undo;
1638
1639 retval = group_desc_scan_and_fix(fs, bmap);
1640 if (retval)
1641 goto err_out_undo;
1642
1643 retval = expand_inode_table(fs, new_size);
1644 if (retval)
1645 goto err_out_undo;
1646
1647 ext2fs_calculate_summary_stats(fs);
1648
1649 fs->super->s_state |= EXT2_VALID_FS;
1650 /* mark super block and block bitmap as dirty */
1651 ext2fs_mark_super_dirty(fs);
1652 ext2fs_mark_bb_dirty(fs);
1653
1654 err_out:
1655 free_blk_move_list();
1656 ext2fs_free_block_bitmap(bmap);
1657
1658 return retval;
1659
1660 err_out_undo:
1661 free_blk_move_list();
1662 ext2fs_free_block_bitmap(bmap);
1663 fputs(_("Error in resizing the inode size.\n"
1664 "Run e2undo to undo the "
1665 "file system changes. \n"), stderr);
1666
1667 return retval;
1668 }
1669
1670 static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
1671 {
1672 errcode_t retval = 0;
1673 const char *tdb_dir;
1674 char *tdb_file;
1675 char *dev_name, *tmp_name;
1676
1677 #if 0 /* FIXME!! */
1678 /*
1679 * Configuration via a conf file would be
1680 * nice
1681 */
1682 profile_get_string(profile, "scratch_files",
1683 "directory", 0, 0,
1684 &tdb_dir);
1685 #endif
1686 tmp_name = strdup(name);
1687 if (!tmp_name) {
1688 alloc_fn_fail:
1689 com_err(program_name, ENOMEM,
1690 _("Couldn't allocate memory for tdb filename\n"));
1691 return ENOMEM;
1692 }
1693 dev_name = basename(tmp_name);
1694
1695 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
1696 if (!tdb_dir)
1697 tdb_dir = "/var/lib/e2fsprogs";
1698
1699 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
1700 access(tdb_dir, W_OK))
1701 return 0;
1702
1703 tdb_file = malloc(strlen(tdb_dir) + 9 + strlen(dev_name) + 7 + 1);
1704 if (!tdb_file)
1705 goto alloc_fn_fail;
1706 sprintf(tdb_file, "%s/tune2fs-%s.e2undo", tdb_dir, dev_name);
1707
1708 if (!access(tdb_file, F_OK)) {
1709 if (unlink(tdb_file) < 0) {
1710 retval = errno;
1711 com_err(program_name, retval,
1712 _("while trying to delete %s"),
1713 tdb_file);
1714 free(tdb_file);
1715 return retval;
1716 }
1717 }
1718
1719 set_undo_io_backing_manager(*io_ptr);
1720 *io_ptr = undo_io_manager;
1721 set_undo_io_backup_file(tdb_file);
1722 printf(_("To undo the tune2fs operation please run "
1723 "the command\n e2undo %s %s\n\n"),
1724 tdb_file, name);
1725 free(tdb_file);
1726 free(tmp_name);
1727 return retval;
1728 }
1729
1730 int main(int argc, char **argv)
1731 {
1732 errcode_t retval;
1733 ext2_filsys fs;
1734 struct ext2_super_block *sb;
1735 io_manager io_ptr, io_ptr_orig = NULL;
1736
1737 #ifdef ENABLE_NLS
1738 setlocale(LC_MESSAGES, "");
1739 setlocale(LC_CTYPE, "");
1740 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1741 textdomain(NLS_CAT_NAME);
1742 #endif
1743 if (argc && *argv)
1744 program_name = *argv;
1745 add_error_table(&et_ext2_error_table);
1746
1747 #ifdef CONFIG_BUILD_FINDFS
1748 if (strcmp(get_progname(argv[0]), "findfs") == 0)
1749 do_findfs(argc, argv);
1750 #endif
1751 if (strcmp(get_progname(argv[0]), "e2label") == 0)
1752 parse_e2label_options(argc, argv);
1753 else
1754 parse_tune2fs_options(argc, argv);
1755
1756 #ifdef CONFIG_TESTIO_DEBUG
1757 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
1758 io_ptr = test_io_manager;
1759 test_io_backing_manager = unix_io_manager;
1760 } else
1761 #endif
1762 io_ptr = unix_io_manager;
1763
1764 retry_open:
1765 retval = ext2fs_open2(device_name, io_options, open_flag,
1766 0, 0, io_ptr, &fs);
1767 if (retval) {
1768 com_err(program_name, retval,
1769 _("while trying to open %s"),
1770 device_name);
1771 fprintf(stderr,
1772 _("Couldn't find valid filesystem superblock.\n"));
1773 exit(1);
1774 }
1775
1776 if (I_flag && !io_ptr_orig) {
1777 /*
1778 * Check the inode size is right so we can issue an
1779 * error message and bail before setting up the tdb
1780 * file.
1781 */
1782 if (new_inode_size == EXT2_INODE_SIZE(fs->super)) {
1783 fprintf(stderr, _("The inode size is already %lu\n"),
1784 new_inode_size);
1785 exit(1);
1786 }
1787 if (new_inode_size < EXT2_INODE_SIZE(fs->super)) {
1788 fprintf(stderr, _("Shrinking the inode size is "
1789 "not supported\n"));
1790 exit(1);
1791 }
1792
1793 /*
1794 * If inode resize is requested use the
1795 * Undo I/O manager
1796 */
1797 io_ptr_orig = io_ptr;
1798 retval = tune2fs_setup_tdb(device_name, &io_ptr);
1799 if (retval)
1800 exit(1);
1801 if (io_ptr != io_ptr_orig) {
1802 ext2fs_close(fs);
1803 goto retry_open;
1804 }
1805 }
1806
1807 sb = fs->super;
1808 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1809
1810 if (print_label) {
1811 /* For e2label emulation */
1812 printf("%.*s\n", (int) sizeof(sb->s_volume_name),
1813 sb->s_volume_name);
1814 remove_error_table(&et_ext2_error_table);
1815 exit(0);
1816 }
1817
1818 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
1819 if (retval) {
1820 com_err("ext2fs_check_if_mount", retval,
1821 _("while determining whether %s is mounted."),
1822 device_name);
1823 exit(1);
1824 }
1825 /* Normally we only need to write out the superblock */
1826 fs->flags |= EXT2_FLAG_SUPER_ONLY;
1827
1828 if (c_flag) {
1829 sb->s_max_mnt_count = max_mount_count;
1830 ext2fs_mark_super_dirty(fs);
1831 printf(_("Setting maximal mount count to %d\n"),
1832 max_mount_count);
1833 }
1834 if (C_flag) {
1835 sb->s_mnt_count = mount_count;
1836 ext2fs_mark_super_dirty(fs);
1837 printf(_("Setting current mount count to %d\n"), mount_count);
1838 }
1839 if (e_flag) {
1840 sb->s_errors = errors;
1841 ext2fs_mark_super_dirty(fs);
1842 printf(_("Setting error behavior to %d\n"), errors);
1843 }
1844 if (g_flag) {
1845 sb->s_def_resgid = resgid;
1846 ext2fs_mark_super_dirty(fs);
1847 printf(_("Setting reserved blocks gid to %lu\n"), resgid);
1848 }
1849 if (i_flag) {
1850 if (interval >= (1ULL << 32)) {
1851 com_err(program_name, 0,
1852 _("interval between checks is too big (%lu)"),
1853 interval);
1854 exit(1);
1855 }
1856 sb->s_checkinterval = interval;
1857 ext2fs_mark_super_dirty(fs);
1858 printf(_("Setting interval between checks to %lu seconds\n"),
1859 interval);
1860 }
1861 if (m_flag) {
1862 ext2fs_r_blocks_count_set(sb, reserved_ratio *
1863 ext2fs_blocks_count(sb) / 100.0);
1864 ext2fs_mark_super_dirty(fs);
1865 printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
1866 reserved_ratio, ext2fs_r_blocks_count(sb));
1867 }
1868 if (r_flag) {
1869 if (reserved_blocks > ext2fs_blocks_count(sb)/2) {
1870 com_err(program_name, 0,
1871 _("reserved blocks count is too big (%llu)"),
1872 reserved_blocks);
1873 exit(1);
1874 }
1875 ext2fs_r_blocks_count_set(sb, reserved_blocks);
1876 ext2fs_mark_super_dirty(fs);
1877 printf(_("Setting reserved blocks count to %llu\n"),
1878 reserved_blocks);
1879 }
1880 if (s_flag == 1) {
1881 if (sb->s_feature_ro_compat &
1882 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
1883 fputs(_("\nThe filesystem already has sparse "
1884 "superblocks.\n"), stderr);
1885 else {
1886 sb->s_feature_ro_compat |=
1887 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1888 sb->s_state &= ~EXT2_VALID_FS;
1889 ext2fs_mark_super_dirty(fs);
1890 printf(_("\nSparse superblock flag set. %s"),
1891 _(please_fsck));
1892 }
1893 }
1894 if (s_flag == 0) {
1895 fputs(_("\nClearing the sparse superflag not supported.\n"),
1896 stderr);
1897 exit(1);
1898 }
1899 if (T_flag) {
1900 sb->s_lastcheck = last_check_time;
1901 ext2fs_mark_super_dirty(fs);
1902 printf(_("Setting time filesystem last checked to %s\n"),
1903 ctime(&last_check_time));
1904 }
1905 if (u_flag) {
1906 sb->s_def_resuid = resuid;
1907 ext2fs_mark_super_dirty(fs);
1908 printf(_("Setting reserved blocks uid to %lu\n"), resuid);
1909 }
1910 if (L_flag) {
1911 if (strlen(new_label) > sizeof(sb->s_volume_name))
1912 fputs(_("Warning: label too long, truncating.\n"),
1913 stderr);
1914 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
1915 strncpy(sb->s_volume_name, new_label,
1916 sizeof(sb->s_volume_name));
1917 ext2fs_mark_super_dirty(fs);
1918 }
1919 if (M_flag) {
1920 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
1921 strncpy(sb->s_last_mounted, new_last_mounted,
1922 sizeof(sb->s_last_mounted));
1923 ext2fs_mark_super_dirty(fs);
1924 }
1925 if (mntopts_cmd)
1926 update_mntopts(fs, mntopts_cmd);
1927 if (features_cmd)
1928 update_feature_set(fs, features_cmd);
1929 if (extended_cmd)
1930 parse_extended_opts(fs, extended_cmd);
1931 if (journal_size || journal_device)
1932 add_journal(fs);
1933
1934 if (Q_flag) {
1935 if (mount_flags & EXT2_MF_MOUNTED) {
1936 fputs(_("The quota feature may only be changed when "
1937 "the filesystem is unmounted.\n"), stderr);
1938 exit(1);
1939 }
1940 handle_quota_options(fs);
1941 }
1942
1943 if (U_flag) {
1944 int set_csum = 0;
1945 dgrp_t i;
1946
1947 if (sb->s_feature_ro_compat &
1948 EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
1949 /*
1950 * Determine if the block group checksums are
1951 * correct so we know whether or not to set
1952 * them later on.
1953 */
1954 for (i = 0; i < fs->group_desc_count; i++)
1955 if (!ext2fs_group_desc_csum_verify(fs, i))
1956 break;
1957 if (i >= fs->group_desc_count)
1958 set_csum = 1;
1959 }
1960 if ((strcasecmp(new_UUID, "null") == 0) ||
1961 (strcasecmp(new_UUID, "clear") == 0)) {
1962 uuid_clear(sb->s_uuid);
1963 } else if (strcasecmp(new_UUID, "time") == 0) {
1964 uuid_generate_time(sb->s_uuid);
1965 } else if (strcasecmp(new_UUID, "random") == 0) {
1966 uuid_generate(sb->s_uuid);
1967 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
1968 com_err(program_name, 0, _("Invalid UUID format\n"));
1969 exit(1);
1970 }
1971 if (set_csum) {
1972 for (i = 0; i < fs->group_desc_count; i++)
1973 ext2fs_group_desc_csum_set(fs, i);
1974 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
1975 }
1976 ext2fs_mark_super_dirty(fs);
1977 }
1978 if (I_flag) {
1979 if (mount_flags & EXT2_MF_MOUNTED) {
1980 fputs(_("The inode size may only be "
1981 "changed when the filesystem is "
1982 "unmounted.\n"), stderr);
1983 exit(1);
1984 }
1985 if (fs->super->s_feature_incompat &
1986 EXT4_FEATURE_INCOMPAT_FLEX_BG) {
1987 fputs(_("Changing the inode size not supported for "
1988 "filesystems with the flex_bg\n"
1989 "feature enabled.\n"),
1990 stderr);
1991 exit(1);
1992 }
1993 /*
1994 * We want to update group descriptor also
1995 * with the new free inode count
1996 */
1997 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
1998 if (resize_inode(fs, new_inode_size) == 0) {
1999 printf(_("Setting inode size %lu\n"),
2000 new_inode_size);
2001 } else {
2002 printf(_("Failed to change inode size\n"));
2003 exit(1);
2004 }
2005 }
2006
2007 if (l_flag)
2008 list_super(sb);
2009 if (stride_set) {
2010 sb->s_raid_stride = stride;
2011 ext2fs_mark_super_dirty(fs);
2012 printf(_("Setting stride size to %d\n"), stride);
2013 }
2014 if (stripe_width_set) {
2015 sb->s_raid_stripe_width = stripe_width;
2016 ext2fs_mark_super_dirty(fs);
2017 printf(_("Setting stripe width to %d\n"), stripe_width);
2018 }
2019 if (ext_mount_opts) {
2020 strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
2021 sizeof(fs->super->s_mount_opts));
2022 fs->super->s_mount_opts[sizeof(fs->super->s_mount_opts)-1] = 0;
2023 ext2fs_mark_super_dirty(fs);
2024 printf(_("Setting extended default mount options to '%s'\n"),
2025 ext_mount_opts);
2026 free(ext_mount_opts);
2027 }
2028 free(device_name);
2029 remove_error_table(&et_ext2_error_table);
2030 return (ext2fs_close(fs) ? 1 : 0);
2031 }