This change adds support for maximum mount count and interval checking of
ext2/ext3 file systems. The -i option however doesn't support d/w/m
suffixes.

Signed-off-by: Richard Braun <[email protected]>
---
This second version uses xatoi_range() and xatou_range(), and isn't verbose
about what it's doing.

 e2fsprogs/tune2fs.c |   32 +++++++++++++++++++++++++++-----
 include/usage.src.h |    6 ++++--
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c
index 311349f..89e00bb 100644
--- a/e2fsprogs/tune2fs.c
+++ b/e2fsprogs/tune2fs.c
@@ -27,25 +27,40 @@ do { \
 #define FETCH_LE32(field) \
        (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
 
+#define SECONDS_PER_DAY 86400
+#define MAX_CHECK_INTERVAL ((unsigned)0xffffffff / SECONDS_PER_DAY)
+
 enum {
        OPT_L = 1 << 0, // label
+       OPT_c = 1 << 1, // max mount count
+       OPT_i = 1 << 2, // check interval
 };
 
 int tune2fs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int tune2fs_main(int argc UNUSED_PARAM, char **argv)
 {
-       unsigned opts;
-       const char *label;
+       unsigned opts, check_interval;
+       const char *label, *max_mnt_count_str, *check_interval_str;
        struct ext2_super_block *sb;
-       int fd;
+       int fd, max_mnt_count;
 
        opt_complementary = "=1";
-       opts = getopt32(argv, "L:", &label);
+       opts = getopt32(argv, "L:c:i:", &label, &max_mnt_count_str, 
&check_interval_str);
        argv += optind; // argv[0] -- device
 
        if (!opts)
                bb_show_usage();
 
+       if (opts & OPT_c) {
+               max_mnt_count = xatoi_range(max_mnt_count_str, -1, 0xfffe);
+
+               if (max_mnt_count == 0)
+                       max_mnt_count = -1;
+       }
+
+       if (opts & OPT_i)
+               check_interval = xatou_range(check_interval_str, 0, 
MAX_CHECK_INTERVAL) * SECONDS_PER_DAY;
+
        // read superblock
        fd = xopen(argv[0], O_RDWR);
        xlseek(fd, 1024, SEEK_SET);
@@ -55,8 +70,15 @@ int tune2fs_main(int argc UNUSED_PARAM, char **argv)
        // mangle superblock
        //STORE_LE(sb->s_wtime, time(NULL)); - why bother?
        // set the label
-       if (1 /*opts & OPT_L*/)
+       if (opts & OPT_L)
                safe_strncpy((char *)sb->s_volume_name, label, 
sizeof(sb->s_volume_name));
+
+       if (opts & OPT_c)
+               STORE_LE(sb->s_max_mnt_count, (unsigned)max_mnt_count);
+
+       if (opts & OPT_i)
+               STORE_LE(sb->s_checkinterval, check_interval);
+
        // write superblock
        xlseek(fd, 1024, SEEK_SET);
        xwrite(fd, sb, 1024);
diff --git a/include/usage.src.h b/include/usage.src.h
index e7e9269..f2b1c99 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -4460,8 +4460,10 @@ INSERT
        "# tunctl -d tun0\n"
 
 #define tune2fs_trivial_usage \
-/*     "[-c max-mounts-count] [-e errors-behavior] [-g group] " */ \
-/*     "[-i interval[d|m|w]] [-j] [-J journal-options] [-l] [-s sparse-flag] " 
*/ \
+       "[-c max-mounts-count] " \
+/*     "[-e errors-behavior] [-g group] " */ \
+       "[-i interval] " \
+/*     "[-j] [-J journal-options] [-l] [-s sparse-flag] " */ \
 /*     "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] " */ \
 /*     "[-r reserved-blocks-count] [-u user] [-C mount-count] " */ \
        "[-L LABEL] " \
-- 
1.5.6.5

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to