Skip to content

Conversation

@LaurentChardon
Copy link

Fixes garbled output when -vv parameter is used and a bad block is found.

Output from test with bad blocks 1024 and 2048.
Before:

$ sudo misc/badblocks -vv /dev/sda1
Checking blocks 0 to 204799
Checking for bad blocks (read-only test): 102450% done, 0:00 elapsed. (0/0/0 errors)
204800% done, 0:00 elapsed. (1/0/0 errors)
done                                                 
Pass completed, 2 bad blocks found. (2/0/0 errors)

After:

$ sudo misc/badblocks -vv /dev/sda1
Checking blocks 0 to 204799
Checking for bad blocks (read-only test): 1024                                                                                                                           
2048                                                                                                                           
done                                                 
Pass completed, 2 bad blocks found. (2/0/0 errors)

I moved the function bb_output because it uses print_status that was defined later. The changes in it are where the if (v_flag > 1) blocks are, lines 464-470 and 475-476.

I could have added a function prototype for print_status instead of moving bb_output but that's not done for any other function. I could have added prototypes for all functions instead. I didn't do it so as not to modify the code too much, but let me know if you prefer that I do that.

Fixes garbled output when -vv parameter is used and a bad block is found.

Signed-off-by: Laurent Chardon <laurent.chardon@gmail.com>
@linuxCowboy
Copy link

This is also with no -v parameter at all, but -s

s=4000797358
 # $B -b 512 -c 1 -s -f -n -t 0x66 /dev/sdb $((s+(3*1))) $s
/dev/sdb is apparently in use by the system; badblocks forced anyway.
Checking for bad blocks (non-destructive read-write test)
Testing with pattern 0x66: 4000797360ne, 0:00 elapsed. (0/0/0 errors)
/tmp/fork: Invalid argument during seek
4000797361
done 

or with -v

 # /tmp/fork -b 512 -c 1 -sv -f -n -t 0x66 /dev/sdb $((s+(5*1))) $s
/dev/sdb is apparently in use by the system; badblocks forced anyway.
Checking for bad blocks in non-destructive read-write mode
From block 4000797358 to 4000797363
Checking for bad blocks (non-destructive read-write test)
Testing with pattern 0x66: 4000797360ne, 0:00 elapsed. (0/0/0 errors)
/tmp/fork: Invalid argument during seek
4000797361
/tmp/fork: Invalid argument during seek
4000797362
/tmp/fork: Invalid argument during seek
4000797363
done                                                 
Pass completed, 4 bad blocks found. (4/0/0 errors)

or beyond device

 # /tmp/fork -b 512 -c 1 -sv -f -n -t 0x66 /dev/sdb $((s+(3*1))) $s
/dev/sdb is apparently in use by the system; badblocks forced anyway.
Checking for bad blocks in non-destructive read-write mode
From block 4000797362 to 4000797365
Checking for bad blocks (non-destructive read-write test)
Testing with pattern 0x66: /tmp/fork: Invalid argument during seekrs)  <== remain
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
4000797362
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
4000797363
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
4000797364
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
/tmp/fork: Invalid argument during seek
4000797365
/tmp/fork: Invalid argument during seek
done                                                 
Pass completed, 4 bad blocks found. (0/0/4 errors)

my quick solution: XTerm Control Sequences

https://github.com/linuxCowboy/badblocks/commit/7c63fbdc44c5d6a8eda7de1d58d63d30c879769b

 # $B -b 512 -c 1 -s -f -n -t 0x66 /dev/sdb $((s+(3*1))) $s
/dev/sdb is apparently in use by the system; badblocks forced anyway.
Checking for bad blocks (non-destructive read-write test)
Testing with pattern 0x66: 4000797360
/tmp/fix: Invalid argument during seek
4000797361
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants