*
* This file is based on the minix file system programs fsck and mkfs
* written and copyrighted by Linus Torvalds <Linus.Torvalds@cs.helsinki.fi>
- *
+ *
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
* 99/06/30...99/07/26 - Added non-destructive write-testing,
* configurable blocks-at-once parameter,
* loading of badblocks list to avoid testing
- * blocks known to be bad, multiple passes to
+ * blocks known to be bad, multiple passes to
* make sure that no new blocks are added to the
* list. (Work done by David Beattie)
*/
static void exclusive_usage(void)
{
- fprintf(stderr,
- _("%s: The -n and -w options are mutually exclusive.\n\n"),
+ fprintf(stderr,
+ _("%s: The -n and -w options are mutually exclusive.\n\n"),
program_name);
exit(1);
}
static void *allocate_buffer(size_t size)
{
void *ret = 0;
-
+
#ifdef HAVE_POSIX_MEMALIGN
if (posix_memalign(&ret, sys_page_size, size) < 0)
ret = 0;
#ifdef HAVE_VALLOC
ret = valloc(size);
#endif /* HAVE_VALLOC */
-#endif /* HAVE_MEMALIGN */
+#endif /* HAVE_MEMALIGN */
#endif /* HAVE_POSIX_MEMALIGN */
if (!ret)
}
/* kludge:
- increment the iteration through the bb_list if
+ increment the iteration through the bb_list if
an element was just added before the current iteration
position. This should not cause next_bad to change. */
if (bb_iter && bad < next_bad)
static void print_status(void)
{
- fprintf(stderr, "%15lu/%15lu", (unsigned long) currently_testing,
+ fprintf(stderr, "%15lu/%15lu", (unsigned long) currently_testing,
(unsigned long) num_blocks);
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", stderr);
fflush (stderr);
#ifdef O_DIRECT
int new_flag = O_DIRECT;
int flag;
-
+
if ((((unsigned long) buffer & (sys_page_size - 1)) != 0) ||
((size & (sys_page_size - 1)) != 0) ||
((current_block & ((sys_page_size >> 9)-1)) != 0))
{
unsigned int i, nb;
unsigned char bpattern[sizeof(pattern)], *ptr;
-
+
if (pattern == (unsigned int) ~0) {
for (ptr = buffer; ptr < buffer + n; ptr++) {
(*ptr) = random() % (1 << (8 * sizeof(char)));
if (d_flag)
gettimeofday(&tv2, NULL);
if (got < 0)
- got = 0;
+ got = 0;
if (got & 511)
fprintf(stderr, _("Weird value (%ld) in do_read\n"), got);
got /= block_size;
/* Try the write */
got = write (dev, buffer, try * block_size);
if (got < 0)
- got = 0;
+ got = 0;
if (got & 511)
fprintf(stderr, "Weird value (%ld) in do_write\n", got);
got /= block_size;
exit (1);
}
if (v_flag) {
- fprintf (stderr, _("Checking blocks %lu to %lu\n"),
- (unsigned long) first_block,
+ fprintf (stderr, _("Checking blocks %lu to %lu\n"),
+ (unsigned long) first_block,
(unsigned long) last_block - 1);
}
if (t_flag) {
if ( (blocks_at_once >= sys_page_size >> 9)
&& (currently_testing % (sys_page_size >> 9)!= 0))
try -= (sys_page_size >> 9)
- - (currently_testing
+ - (currently_testing
% (sys_page_size >> 9));
continue;
}
buffer = allocate_buffer(2 * blocks_at_once * block_size);
read_buffer = buffer + blocks_at_once * block_size;
-
+
if (!buffer) {
com_err (program_name, ENOMEM, _("while allocating buffers"));
exit (1);
flush_bufs();
if (v_flag) {
- fputs(_("Checking for bad blocks in read-write mode\n"),
+ fputs(_("Checking for bad blocks in read-write mode\n"),
stderr);
fprintf(stderr, _("From block %lu to %lu\n"),
- (unsigned long) first_block,
+ (unsigned long) first_block,
(unsigned long) last_block - 1);
}
if (t_flag) {
try = blocks_at_once;
/* recover page-aligned offset for O_DIRECT */
if ( (blocks_at_once >= sys_page_size >> 9)
- && (currently_testing %
+ && (currently_testing %
(sys_page_size >> 9)!= 0))
try -= (sys_page_size >> 9)
- - (currently_testing
+ - (currently_testing
% (sys_page_size >> 9));
continue;
} else
bb_count += bb_output(currently_testing++);
}
}
-
+
num_blocks = 0;
alarm (0);
if (s_flag | v_flag)
if ( (blocks_at_once >= sys_page_size >> 9)
&& (currently_testing % (sys_page_size >> 9)!= 0))
try = blocks_at_once - (sys_page_size >> 9)
- - (currently_testing
+ - (currently_testing
% (sys_page_size >> 9));
else
try = blocks_at_once;
if (v_flag > 1)
print_status();
}
-
+
num_blocks = 0;
alarm (0);
if (s_flag | v_flag)
save_base = blkbuf;
test_base = blkbuf + (blocks_at_once * block_size);
read_base = blkbuf + (2 * blocks_at_once * block_size);
-
+
num_saved = 0;
flush_bufs();
if (v_flag) {
fputs(_("Checking for bad blocks in non-destructive read-write mode\n"), stderr);
- fprintf (stderr, _("From block %lu to %lu\n"),
+ fprintf (stderr, _("From block %lu to %lu\n"),
(unsigned long) first_block,
(unsigned long) last_block - 1);
}
fflush (out);
exit(1);
}
-
+
/* set up abend handler */
capture_terminate(terminate_env);
if (written != got)
com_err (program_name, errno,
_("during test data write, block %lu"),
- (unsigned long) currently_testing +
+ (unsigned long) currently_testing +
written);
buf_used += got;
try = test_record[used2].num;
used2++;
}
-
+
got = do_read (dev, read_ptr, try,
block_size, currently_testing);
bb_count += bb_output(currently_testing + got);
got++;
}
-
+
/* write back original data */
do_write (dev, save_ptr, got,
block_size, currently_testing);
{
char *tmp;
unsigned long ret;
-
+
errno = 0;
ret = strtoul(str, &tmp, 0);
if (*tmp || errno || (ret > UINT_MAX) ||
sys_page_size = sysval;
#endif /* _SC_PAGESIZE */
#endif /* HAVE_SYSCONF */
-
+
if (argc && *argv)
program_name = *argv;
while ((c = getopt (argc, argv, "b:d:e:fi:o:svwnc:p:h:t:X")) != EOF) {
d_flag = parse_uint(optarg, "read delay factor");
break;
case 'p':
- num_passes = parse_uint(optarg,
+ num_passes = parse_uint(optarg,
"number of clean passes");
break;
case 'h':
if (t_flag + 1 > t_max) {
unsigned int *t_patts_new;
- t_patts_new = realloc(t_patts, sizeof(int) *
+ t_patts_new = realloc(t_patts, sizeof(int) *
(t_max + T_INC));
if (!t_patts_new) {
com_err(program_name, ENOMEM,
}
if (w_flag)
check_mount(device_name);
-
+
open_flag = w_flag ? O_RDWR : O_RDONLY;
dev = open (device_name, open_flag);
if (dev == -1) {
passes_clean = 0;
else
++passes_clean;
-
+
if (v_flag)
fprintf(stderr,
- _("Pass completed, %u bad blocks found.\n"),
+ _("Pass completed, %u bad blocks found.\n"),
bb_count);
} while (passes_clean < num_passes);