Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / busybox / e2fsprogs / tune2fs.c
blob49773467880970efdae5f2b4177ecb2495994078
1 /* vi: set sw=4 ts=4: */
2 /*
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.
8 */
9 #include "libbb.h"
10 #include <linux/fs.h>
11 #include <linux/ext2_fs.h>
13 // storage helpers
14 char BUG_wrong_field_size(void);
15 #define STORE_LE(field, value) \
16 do { \
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)
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 MOUNT_CNT] "
32 //usage: "[-i DAYS] "
33 //usage: "[-L LABEL] "
34 //usage: "BLOCKDEV"
35 //usage:
36 //usage:#define tune2fs_full_usage "\n\n"
37 //usage: "Adjust filesystem options on ext[23] filesystems"
38 //applet:IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, tune2fs))
40 enum {
41 OPT_L = 1 << 0, // label
42 OPT_c = 1 << 1, // max mount count
43 OPT_i = 1 << 2, // check interval
46 int tune2fs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47 int tune2fs_main(int argc UNUSED_PARAM, char **argv)
49 unsigned opts;
50 const char *label, *str_c, *str_i;
51 struct ext2_super_block *sb;
52 int fd;
54 opt_complementary = "=1";
55 opts = getopt32(argv, "L:c:i:", &label, &str_c, &str_i);
56 if (!opts)
57 bb_show_usage();
58 argv += optind; // argv[0] -- device
60 // read superblock
61 fd = xopen(argv[0], O_RDWR);
62 xlseek(fd, 1024, SEEK_SET);
63 sb = xzalloc(1024);
64 xread(fd, sb, 1024);
66 // mangle superblock
67 //STORE_LE(sb->s_wtime, time(NULL)); - why bother?
69 // set the label
70 if (opts & OPT_L)
71 safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name));
73 if (opts & OPT_c) {
74 int n = xatoi_range(str_c, -1, 0xfffe);
75 if (n == 0)
76 n = -1;
77 STORE_LE(sb->s_max_mnt_count, (unsigned)n);
80 if (opts & OPT_i) {
81 unsigned n = xatou_range(str_i, 0, (unsigned)0xffffffff / (24*60*60)) * 24*60*60;
82 STORE_LE(sb->s_checkinterval, n);
85 // write superblock
86 xlseek(fd, 1024, SEEK_SET);
87 xwrite(fd, sb, 1024);
89 if (ENABLE_FEATURE_CLEAN_UP) {
90 free(sb);
93 xclose(fd);
94 return EXIT_SUCCESS;