Whamcloud - gitweb
mke2fs: clean up error handling in mke2fs_setup_tdb()
[tools/e2fsprogs.git] / misc / badblocks.c
index 528bc22..549a339 100644 (file)
@@ -203,6 +203,9 @@ static void print_status(void)
                       calc_percent((unsigned long) currently_testing,
                                    (unsigned long) num_blocks), 
                       time_diff_format(&time_end, &time_start, diff_buf));
+#ifdef HAVE_MBSTOWCS
+       len = mbstowcs(NULL, line_buf, sizeof(line_buf));
+#endif
        fputs(line_buf, stderr);
        memset(line_buf, '\b', len);
        line_buf[len] = 0;
@@ -223,6 +226,10 @@ static void *terminate_addr = NULL;
 
 static void terminate_intr(int signo EXT2FS_ATTR((unused)))
 {
+       fflush(out);
+       fprintf(stderr, "\n\nInterrupted at block %llu\n", 
+               (unsigned long long) currently_testing);
+       fflush(stderr);
        if (terminate_addr)
                longjmp(terminate_addr,1);
        exit(1);
@@ -434,6 +441,9 @@ static unsigned int test_ro (int dev, blk_t last_block,
        unsigned int bb_count = 0;
        errcode_t errcode;
 
+       /* set up abend handler */
+       capture_terminate(NULL);
+
        errcode = ext2fs_badblocks_list_iterate_begin(bb_list,&bb_iter);
        if (errcode) {
                com_err (program_name, errcode,
@@ -531,6 +541,8 @@ static unsigned int test_ro (int dev, blk_t last_block,
 
        ext2fs_badblocks_list_iterate_end(bb_iter);
 
+       uncapture_terminate();
+
        return bb_count;
 }
 
@@ -544,6 +556,9 @@ static unsigned int test_rw (int dev, blk_t last_block,
        int i, try, got, nr_pattern, pat_idx;
        unsigned int bb_count = 0;
 
+       /* set up abend handler */
+       capture_terminate(NULL);
+
        buffer = allocate_buffer(2 * blocks_at_once * block_size);
        read_buffer = buffer + blocks_at_once * block_size;
 
@@ -969,7 +984,7 @@ int main (int argc, char ** argv)
        FILE * in = NULL;
        int block_size = 1024;
        unsigned int blocks_at_once = 64;
-       blk_t last_block, first_block;
+       blk64_t last_block, first_block;
        int num_passes = 0;
        int passes_clean = 0;
        int dev;
@@ -1010,11 +1025,6 @@ int main (int argc, char ** argv)
                switch (c) {
                case 'b':
                        block_size = parse_uint(optarg, "block size");
-                       if (block_size > 4096) {
-                               com_err (program_name, 0,
-                                        _("bad block size - %s"), optarg);
-                               exit (1);
-                       }
                        break;
                case 'f':
                        force++;
@@ -1109,7 +1119,7 @@ int main (int argc, char ** argv)
                usage();
        device_name = argv[optind++];
        if (optind > argc - 1) {
-               errcode = ext2fs_get_device_size(device_name,
+               errcode = ext2fs_get_device_size2(device_name,
                                                 block_size,
                                                 &last_block);
                if (errcode == EXT2_ET_UNIMPLEMENTED) {