1
2
3
4
5
6
7
8
9#include "libbb.h"
10#include <linux/fs.h>
11#include <linux/ext2_fs.h>
12
13
14char BUG_wrong_field_size(void);
15#define STORE_LE(field, value) \
16do { \
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) \
22 field = (value); \
23 else \
24 BUG_wrong_field_size(); \
25} while (0)
26
27#define FETCH_LE32(field) \
28 (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45enum {
46 OPT_L = 1 << 0,
47 OPT_c = 1 << 1,
48 OPT_i = 1 << 2,
49};
50
51int tune2fs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
52int tune2fs_main(int argc UNUSED_PARAM, char **argv)
53{
54 unsigned opts;
55 const char *label, *str_c, *str_i;
56 struct ext2_super_block *sb;
57 int fd;
58
59 opt_complementary = "=1";
60 opts = getopt32(argv, "L:c:i:", &label, &str_c, &str_i);
61 if (!opts)
62 bb_show_usage();
63 argv += optind;
64
65
66 fd = xopen(argv[0], O_RDWR);
67 xlseek(fd, 1024, SEEK_SET);
68 sb = xzalloc(1024);
69 xread(fd, sb, 1024);
70
71
72
73
74
75 if (opts & OPT_L)
76 safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name));
77
78 if (opts & OPT_c) {
79 int n = xatoi_range(str_c, -1, 0xfffe);
80 if (n == 0)
81 n = -1;
82 STORE_LE(sb->s_max_mnt_count, (unsigned)n);
83 }
84
85 if (opts & OPT_i) {
86 unsigned n = xatou_range(str_i, 0, (unsigned)0xffffffff / (24*60*60)) * 24*60*60;
87 STORE_LE(sb->s_checkinterval, n);
88 }
89
90
91 xlseek(fd, 1024, SEEK_SET);
92 xwrite(fd, sb, 1024);
93
94 if (ENABLE_FEATURE_CLEAN_UP) {
95 free(sb);
96 }
97
98 xclose(fd);
99 return EXIT_SUCCESS;
100}
101