Whamcloud - gitweb
git://git.whamcloud.com
/
tools
/
e2fsprogs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ChangeLog, fsck.c:
[tools/e2fsprogs.git]
/
misc
/
badblocks.c
diff --git
a/misc/badblocks.c
b/misc/badblocks.c
index
8c72885
..
8de08f7
100644
(file)
--- a/
misc/badblocks.c
+++ b/
misc/badblocks.c
@@
-47,13
+47,9
@@
extern int optind;
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/types.h>
-#if HAVE_LINUX_FS_H
-#include <linux/fd.h>
-#endif
-
#include "et/com_err.h"
#include "ext2fs/ext2_io.h"
#include "et/com_err.h"
#include "ext2fs/ext2_io.h"
-#include
<linux/ext2_fs.h>
+#include
"ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
#include "nls-enable.h"
#include "ext2fs/ext2fs.h"
#include "nls-enable.h"
@@
-68,7
+64,7
@@
static int force = 0; /* force check of mounted device */
static void usage(void)
{
static void usage(void)
{
- fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwnf]\n [-c blocks_at_once] [-p num_passes] device [
blocks_count
[start_count]]\n"),
+ fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwnf]\n [-c blocks_at_once] [-p num_passes] device [
last_block
[start_count]]\n"),
program_name);
exit (1);
}
program_name);
exit (1);
}
@@
-214,25
+210,16
@@
static long do_write (int dev, char * buffer, int try, int block_size,
static int host_dev;
static int host_dev;
-static void flush_bufs
(int dev
)
+static void flush_bufs
(void
)
{
{
-#ifdef HAVE_FDATASYNC
- if (fdatasync (dev) == -1)
- com_err (program_name, errno, _("during fdatasync"));
-#else
- if (fsync (dev) == -1)
- com_err (program_name, errno, _("during fsync"));
-#endif
+ errcode_t retval;
-#ifdef BLKFLSBUF
- ioctl (host_dev, BLKFLSBUF, 0); /* In case this is a HD */
-#endif
-#ifdef FDFLUSH
- ioctl (host_dev, FDFLUSH, 0); /* In case this is floppy */
-#endif
+ retval = ext2fs_sync_device(host_dev, 1);
+ if (retval)
+ com_err(program_name, retval, _("during ext2fs_sync_device"));
}
}
-static unsigned int test_ro (int dev, unsigned long
blocks_count
,
+static unsigned int test_ro (int dev, unsigned long
last_block
,
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
@@
-258,22
+245,22
@@
static unsigned int test_ro (int dev, unsigned long blocks_count,
com_err (program_name, ENOMEM, _("while allocating buffers"));
exit (1);
}
com_err (program_name, ENOMEM, _("while allocating buffers"));
exit (1);
}
- flush_bufs(
dev
);
+ flush_bufs();
if (v_flag) {
fprintf(stderr, _("Checking for bad blocks in read-only mode\n"));
fprintf (stderr, _("From block %lu to %lu\n"), from_count,
if (v_flag) {
fprintf(stderr, _("Checking for bad blocks in read-only mode\n"));
fprintf (stderr, _("From block %lu to %lu\n"), from_count,
-
blocks_count
);
+
last_block
);
}
try = blocks_at_once;
currently_testing = from_count;
}
try = blocks_at_once;
currently_testing = from_count;
- num_blocks =
blocks_count
;
+ num_blocks =
last_block
;
if (s_flag || v_flag > 1) {
fprintf(stderr,
_("Checking for bad blocks (read-only test): "));
if (v_flag <= 1)
alarm_intr(SIGALRM);
}
if (s_flag || v_flag > 1) {
fprintf(stderr,
_("Checking for bad blocks (read-only test): "));
if (v_flag <= 1)
alarm_intr(SIGALRM);
}
- while (currently_testing <
blocks_count
)
+ while (currently_testing <
last_block
)
{
if (next_bad) {
if (currently_testing == next_bad) {
{
if (next_bad) {
if (currently_testing == next_bad) {
@@
-285,8
+272,8
@@
static unsigned int test_ro (int dev, unsigned long blocks_count,
else if (currently_testing + try > next_bad)
try = next_bad - currently_testing;
}
else if (currently_testing + try > next_bad)
try = next_bad - currently_testing;
}
- if (currently_testing + try >
blocks_count
)
- try =
blocks_count
- currently_testing;
+ if (currently_testing + try >
last_block
)
+ try =
last_block
- currently_testing;
got = do_read (dev, blkbuf, try, block_size, currently_testing);
currently_testing += got;
if (got == try) {
got = do_read (dev, blkbuf, try, block_size, currently_testing);
currently_testing += got;
if (got == try) {
@@
-312,7
+299,7
@@
static unsigned int test_ro (int dev, unsigned long blocks_count,
return bb_count;
}
return bb_count;
}
-static unsigned int test_rw (int dev, unsigned long
blocks_count
,
+static unsigned int test_rw (int dev, unsigned long
last_block
,
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
@@
-328,25
+315,25
@@
static unsigned int test_rw (int dev, unsigned long blocks_count,
exit (1);
}
exit (1);
}
- flush_bufs(
dev
);
+ flush_bufs();
if (v_flag) {
fprintf(stderr,
_("Checking for bad blocks in read-write mode\n"));
fprintf(stderr, _("From block %lu to %lu\n"),
if (v_flag) {
fprintf(stderr,
_("Checking for bad blocks in read-write mode\n"));
fprintf(stderr, _("From block %lu to %lu\n"),
- from_count,
blocks_count
);
+ from_count,
last_block
);
}
for (i = 0; i < sizeof (pattern); i++) {
memset (buffer, pattern[i], block_size);
if (s_flag | v_flag)
fprintf (stderr, _("Writing pattern 0x%08x: "),
*((int *) buffer));
}
for (i = 0; i < sizeof (pattern); i++) {
memset (buffer, pattern[i], block_size);
if (s_flag | v_flag)
fprintf (stderr, _("Writing pattern 0x%08x: "),
*((int *) buffer));
- num_blocks =
blocks_count
;
+ num_blocks =
last_block
;
currently_testing = from_count;
if (s_flag && v_flag <= 1)
alarm_intr(SIGALRM);
for (;
currently_testing = from_count;
if (s_flag && v_flag <= 1)
alarm_intr(SIGALRM);
for (;
- currently_testing <
blocks_count
;
+ currently_testing <
last_block
;
currently_testing++)
{
if (ext2fs_llseek (dev, (ext2_loff_t) currently_testing *
currently_testing++)
{
if (ext2fs_llseek (dev, (ext2_loff_t) currently_testing *
@@
-363,15
+350,15
@@
static unsigned int test_rw (int dev, unsigned long blocks_count,
alarm (0);
if (s_flag | v_flag)
fprintf(stderr, _(done_string));
alarm (0);
if (s_flag | v_flag)
fprintf(stderr, _(done_string));
- flush_bufs(
dev
);
+ flush_bufs();
if (s_flag | v_flag)
fprintf (stderr, _("Reading and comparing: "));
if (s_flag | v_flag)
fprintf (stderr, _("Reading and comparing: "));
- num_blocks =
blocks_count
;
+ num_blocks =
last_block
;
currently_testing = from_count;
if (s_flag && v_flag <= 1)
alarm_intr(SIGALRM);
for (;
currently_testing = from_count;
if (s_flag && v_flag <= 1)
alarm_intr(SIGALRM);
for (;
- currently_testing <
blocks_count
;
+ currently_testing <
last_block
;
currently_testing++)
{
if (ext2fs_llseek (dev, (ext2_loff_t) currently_testing *
currently_testing++)
{
if (ext2fs_llseek (dev, (ext2_loff_t) currently_testing *
@@
-391,7
+378,7
@@
static unsigned int test_rw (int dev, unsigned long blocks_count,
alarm (0);
if (s_flag | v_flag)
fprintf(stderr, _(done_string));
alarm (0);
if (s_flag | v_flag)
fprintf(stderr, _(done_string));
- flush_bufs(
dev
);
+ flush_bufs();
}
return bb_count;
}
return bb_count;
@@
-402,7
+389,7
@@
struct saved_blk_record {
int num;
};
int num;
};
-static unsigned int test_nd (int dev, unsigned long
blocks_count
,
+static unsigned int test_nd (int dev, unsigned long
last_block
,
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
int block_size, unsigned long from_count,
unsigned long blocks_at_once)
{
@@
-446,11
+433,11
@@
static unsigned int test_nd (int dev, unsigned long blocks_count,
(*ptr) = random() % (1 << sizeof(char));
}
(*ptr) = random() % (1 << sizeof(char));
}
- flush_bufs(
dev
);
+ flush_bufs();
if (v_flag) {
fprintf (stderr,
_("Checking for bad blocks in non-destructive read-write mode\n"));
if (v_flag) {
fprintf (stderr,
_("Checking for bad blocks in non-destructive read-write mode\n"));
- fprintf (stderr, _("From block %lu to %lu\n"), from_count,
blocks_count
);
+ fprintf (stderr, _("From block %lu to %lu\n"), from_count,
last_block
);
}
if (s_flag || v_flag > 1) {
fprintf(stderr, _("Checking for bad blocks (non-destructive read-write test): "));
}
if (s_flag || v_flag > 1) {
fprintf(stderr, _("Checking for bad blocks (non-destructive read-write test): "));
@@
-482,9
+469,9
@@
static unsigned int test_nd (int dev, unsigned long blocks_count,
save_ptr = blkbuf;
test_ptr = blkbuf + (blocks_at_once * block_size);
currently_testing = from_count;
save_ptr = blkbuf;
test_ptr = blkbuf + (blocks_at_once * block_size);
currently_testing = from_count;
- num_blocks =
blocks_count
;
+ num_blocks =
last_block
;
- while (currently_testing <
blocks_count
) {
+ while (currently_testing <
last_block
) {
try = blocks_at_once - buf_used;
if (next_bad) {
if (currently_testing == next_bad) {
try = blocks_at_once - buf_used;
if (next_bad) {
if (currently_testing == next_bad) {
@@
-496,8
+483,8
@@
static unsigned int test_nd (int dev, unsigned long blocks_count,
else if (currently_testing + try > next_bad)
try = next_bad - currently_testing;
}
else if (currently_testing + try > next_bad)
try = next_bad - currently_testing;
}
- if (currently_testing + try >
blocks_count
)
- try =
blocks_count
- currently_testing;
+ if (currently_testing + try >
last_block
)
+ try =
last_block
- currently_testing;
got = do_read (dev, save_ptr, try, block_size,
currently_testing);
if (got == 0) {
got = do_read (dev, save_ptr, try, block_size,
currently_testing);
if (got == 0) {
@@
-536,10
+523,10
@@
static unsigned int test_nd (int dev, unsigned long blocks_count,
* back and get some more blocks.
*/
if ((buf_used != blocks_at_once) &&
* back and get some more blocks.
*/
if ((buf_used != blocks_at_once) &&
- (currently_testing <
blocks_count
))
+ (currently_testing <
last_block
))
continue;
continue;
- flush_bufs(
dev
);
+ flush_bufs();
save_currently_testing = currently_testing;
/*
save_currently_testing = currently_testing;
/*
@@
-651,7
+638,7
@@
int main (int argc, char ** argv)
FILE * in = NULL;
int block_size = 1024;
unsigned long blocks_at_once = 16;
FILE * in = NULL;
int block_size = 1024;
unsigned long blocks_at_once = 16;
- blk_t
blocks_count
, from_count;
+ blk_t
last_block
, from_count;
int num_passes = 0;
int passes_clean = 0;
int dev;
int num_passes = 0;
int passes_clean = 0;
int dev;
@@
-668,7
+655,7
@@
int main (int argc, char ** argv)
textdomain(NLS_CAT_NAME);
#endif
test_func = test_ro;
textdomain(NLS_CAT_NAME);
#endif
test_func = test_ro;
-
+
if (argc && *argv)
program_name = *argv;
while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:")) != EOF) {
if (argc && *argv)
program_name = *argv;
while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:")) != EOF) {
@@
-737,7
+724,7
@@
int main (int argc, char ** argv)
if (optind > argc - 1) {
errcode = ext2fs_get_device_size(device_name,
block_size,
if (optind > argc - 1) {
errcode = ext2fs_get_device_size(device_name,
block_size,
- &
blocks_count
);
+ &
last_block
);
if (errcode == EXT2_ET_UNIMPLEMENTED) {
com_err(program_name, 0,
_("Couldn't determine device size; you "
if (errcode == EXT2_ET_UNIMPLEMENTED) {
com_err(program_name, 0,
_("Couldn't determine device size; you "
@@
-750,7
+737,7
@@
int main (int argc, char ** argv)
exit(1);
}
} else {
exit(1);
}
} else {
-
blocks_count
= strtoul (argv[optind], &tmp, 0);
+
last_block
= strtoul (argv[optind], &tmp, 0);
if (*tmp) {
com_err (program_name, 0, _("bad blocks count - %s"),
argv[optind]);
if (*tmp) {
com_err (program_name, 0, _("bad blocks count - %s"),
argv[optind]);
@@
-766,9
+753,9
@@
int main (int argc, char ** argv)
exit (1);
}
} else from_count = 0;
exit (1);
}
} else from_count = 0;
- if (from_count >=
blocks_count
) {
+ if (from_count >=
last_block
) {
com_err (program_name, 0, _("bad blocks range: %lu-%lu"),
com_err (program_name, 0, _("bad blocks range: %lu-%lu"),
- from_count,
blocks_count
);
+ from_count,
last_block
);
exit (1);
}
if (w_flag)
exit (1);
}
if (w_flag)
@@
-852,7
+839,7
@@
int main (int argc, char ** argv)
do {
unsigned int bb_count;
do {
unsigned int bb_count;
- bb_count = test_func(dev,
blocks_count
, block_size,
+ bb_count = test_func(dev,
last_block
, block_size,
from_count, blocks_at_once);
if (bb_count)
passes_clean = 0;
from_count, blocks_at_once);
if (bb_count)
passes_clean = 0;