Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * tune2fs: utility to modify EXT2 filesystem |
| 4 | * |
| 5 | * Busybox'ed (2009) by Vladimir Dronnikov <dronnikov@gmail.com> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 8 | */ |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 9 | //config:config TUNE2FS |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 10 | //config: bool "tune2fs (4.4 kb)" |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 11 | //config: default n # off: it is too limited compared to upstream version |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: tune2fs allows the system administrator to adjust various tunable |
| 14 | //config: filesystem parameters on Linux ext2/ext3 filesystems. |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 15 | |
Denys Vlasenko | 99125c0 | 2017-08-05 20:38:04 +0200 | [diff] [blame] | 16 | //applet:IF_TUNE2FS(APPLET_NOEXEC(tune2fs, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, tune2fs)) |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 17 | |
Denys Vlasenko | 5bbee27 | 2016-11-23 21:51:11 +0100 | [diff] [blame] | 18 | //TODO alias to "tune2fs -L LABEL": //applet:IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, e2label)) |
| 19 | |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 20 | //kbuild:lib-$(CONFIG_TUNE2FS) += tune2fs.o |
| 21 | |
| 22 | //usage:#define tune2fs_trivial_usage |
| 23 | //usage: "[-c MAX_MOUNT_COUNT] " |
| 24 | ////usage: "[-e errors-behavior] [-g group] " |
| 25 | //usage: "[-i DAYS] " |
| 26 | ////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] " |
| 27 | ////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] " |
| 28 | ////usage: "[-r reserved-blocks-count] [-u user] " |
| 29 | //usage: "[-C MOUNT_COUNT] " |
| 30 | //usage: "[-L LABEL] " |
| 31 | ////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] " |
| 32 | ////usage: "[-T last-check-time] [-U UUID] " |
| 33 | //usage: "BLOCKDEV" |
| 34 | //usage: |
| 35 | //usage:#define tune2fs_full_usage "\n\n" |
| 36 | //usage: "Adjust filesystem options on ext[23] filesystems" |
| 37 | |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 38 | #include "libbb.h" |
| 39 | #include <linux/fs.h> |
Denys Vlasenko | 176bc34 | 2012-04-17 15:06:55 +0200 | [diff] [blame] | 40 | #include "bb_e2fs_defs.h" |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 41 | |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 42 | enum { |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 43 | OPT_L = 1 << 0, // label |
Richard Braun | 5aa4d53 | 2010-10-05 00:39:46 +0200 | [diff] [blame] | 44 | OPT_c = 1 << 1, // max mount count |
| 45 | OPT_i = 1 << 2, // check interval |
Denys Vlasenko | 46aa5e0 | 2011-09-11 20:08:12 +0200 | [diff] [blame] | 46 | OPT_C = 1 << 3, // current mount count |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | int tune2fs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 50 | int tune2fs_main(int argc UNUSED_PARAM, char **argv) |
| 51 | { |
| 52 | unsigned opts; |
Denys Vlasenko | 46aa5e0 | 2011-09-11 20:08:12 +0200 | [diff] [blame] | 53 | const char *label, *str_c, *str_i, *str_C; |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 54 | struct ext2_super_block *sb; |
| 55 | int fd; |
| 56 | |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame] | 57 | opts = getopt32(argv, "^" "L:c:i:C:" "\0" "=1", &label, &str_c, &str_i, &str_C); |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 58 | if (!opts) |
| 59 | bb_show_usage(); |
Richard Braun | 5aa4d53 | 2010-10-05 00:39:46 +0200 | [diff] [blame] | 60 | argv += optind; // argv[0] -- device |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 61 | |
| 62 | // read superblock |
| 63 | fd = xopen(argv[0], O_RDWR); |
| 64 | xlseek(fd, 1024, SEEK_SET); |
| 65 | sb = xzalloc(1024); |
| 66 | xread(fd, sb, 1024); |
| 67 | |
| 68 | // mangle superblock |
| 69 | //STORE_LE(sb->s_wtime, time(NULL)); - why bother? |
Richard Braun | 5aa4d53 | 2010-10-05 00:39:46 +0200 | [diff] [blame] | 70 | |
Denys Vlasenko | 46aa5e0 | 2011-09-11 20:08:12 +0200 | [diff] [blame] | 71 | if (opts & OPT_C) { |
| 72 | int n = xatoi_range(str_C, 1, 0xfffe); |
| 73 | STORE_LE(sb->s_mnt_count, (unsigned)n); |
| 74 | } |
| 75 | |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 76 | // set the label |
Richard Braun | 5aa4d53 | 2010-10-05 00:39:46 +0200 | [diff] [blame] | 77 | if (opts & OPT_L) |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 78 | safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name)); |
Richard Braun | 5aa4d53 | 2010-10-05 00:39:46 +0200 | [diff] [blame] | 79 | |
| 80 | if (opts & OPT_c) { |
| 81 | int n = xatoi_range(str_c, -1, 0xfffe); |
| 82 | if (n == 0) |
| 83 | n = -1; |
| 84 | STORE_LE(sb->s_max_mnt_count, (unsigned)n); |
| 85 | } |
| 86 | |
| 87 | if (opts & OPT_i) { |
| 88 | unsigned n = xatou_range(str_i, 0, (unsigned)0xffffffff / (24*60*60)) * 24*60*60; |
| 89 | STORE_LE(sb->s_checkinterval, n); |
| 90 | } |
| 91 | |
Denys Vlasenko | 3945bc1 | 2009-10-22 00:55:55 +0200 | [diff] [blame] | 92 | // write superblock |
| 93 | xlseek(fd, 1024, SEEK_SET); |
| 94 | xwrite(fd, sb, 1024); |
| 95 | |
| 96 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 97 | free(sb); |
| 98 | } |
| 99 | |
| 100 | xclose(fd); |
| 101 | return EXIT_SUCCESS; |
| 102 | } |