1 /* vi: set sw=4 ts=4: */
3 * tune2fs: utility to modify EXT2 filesystem
5 * Busybox'ed (2009) by Vladimir Dronnikov <dronnikov@gmail.com>
7 * Licensed under GPLv2, see file LICENSE in this source tree.
11 #include "bb_e2fs_defs.h"
14 char BUG_wrong_field_size(void);
15 #define STORE_LE(field, value) \
17 if (sizeof(field) == 4) \
18 field = SWAP_LE32(value); \
19 else if (sizeof(field) == 2) \
20 field = SWAP_LE16(value); \
21 else if (sizeof(field) == 1) \
24 BUG_wrong_field_size(); \
27 #define FETCH_LE32(field) \
28 (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
30 //usage:#define tune2fs_trivial_usage
31 //usage: "[-c MAX_MOUNT_COUNT] "
32 ////usage: "[-e errors-behavior] [-g group] "
34 ////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] "
35 ////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] "
36 ////usage: "[-r reserved-blocks-count] [-u user] "
37 //usage: "[-C MOUNT_COUNT] "
38 //usage: "[-L LABEL] "
39 ////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] "
40 ////usage: "[-T last-check-time] [-U UUID] "
43 //usage:#define tune2fs_full_usage "\n\n"
44 //usage: "Adjust filesystem options on ext[23] filesystems"
47 OPT_L = 1 << 0, // label
48 OPT_c = 1 << 1, // max mount count
49 OPT_i = 1 << 2, // check interval
50 OPT_C = 1 << 3, // current mount count
53 int tune2fs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
54 int tune2fs_main(int argc UNUSED_PARAM, char **argv)
57 const char *label, *str_c, *str_i, *str_C;
58 struct ext2_super_block *sb;
61 opt_complementary = "=1";
62 opts = getopt32(argv, "L:c:i:C:", &label, &str_c, &str_i, &str_C);
65 argv += optind; // argv[0] -- device
68 fd = xopen(argv[0], O_RDWR);
69 xlseek(fd, 1024, SEEK_SET);
74 //STORE_LE(sb->s_wtime, time(NULL)); - why bother?
77 int n = xatoi_range(str_C, 1, 0xfffe);
78 STORE_LE(sb->s_mnt_count, (unsigned)n);
83 safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name));
86 int n = xatoi_range(str_c, -1, 0xfffe);
89 STORE_LE(sb->s_max_mnt_count, (unsigned)n);
93 unsigned n = xatou_range(str_i, 0, (unsigned)0xffffffff / (24*60*60)) * 24*60*60;
94 STORE_LE(sb->s_checkinterval, n);
98 xlseek(fd, 1024, SEEK_SET);
101 if (ENABLE_FEATURE_CLEAN_UP) {