1997-04-29 20:17:09 +04:00
|
|
|
/*
|
|
|
|
* test_io.c --- This is the Test I/O interface.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
1997-04-29 20:17:09 +04:00
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#if HAVE_SYS_STAT_H
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <sys/stat.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <sys/types.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#endif
|
2005-04-06 22:44:16 +04:00
|
|
|
#ifdef HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#else
|
|
|
|
#define PR_GET_DUMPABLE 3
|
|
|
|
#endif
|
|
|
|
#if (!defined(HAVE_PRCTL) && defined(linux))
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
#include "ext2_fs.h"
|
1997-10-26 06:41:24 +03:00
|
|
|
#include "ext2fs.h"
|
1997-04-29 20:17:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For checking structure magic numbers...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EXT2_CHECK_MAGIC(struct, code) \
|
|
|
|
if ((struct)->magic != (code)) return (code)
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
struct test_private_data {
|
|
|
|
int magic;
|
|
|
|
io_channel real;
|
2003-05-05 20:08:47 +04:00
|
|
|
int flags;
|
|
|
|
FILE *outfile;
|
|
|
|
unsigned long block;
|
2004-05-27 05:04:07 +04:00
|
|
|
int read_abort_count, write_abort_count;
|
1997-04-29 20:17:09 +04:00
|
|
|
void (*read_blk)(unsigned long block, int count, errcode_t err);
|
|
|
|
void (*write_blk)(unsigned long block, int count, errcode_t err);
|
|
|
|
void (*set_blksize)(int blksize, errcode_t err);
|
2000-10-27 00:24:43 +04:00
|
|
|
void (*write_byte)(unsigned long block, int count, errcode_t err);
|
2008-05-25 03:17:01 +04:00
|
|
|
void (*read_blk64)(unsigned long long block, int count, errcode_t err);
|
|
|
|
void (*write_blk64)(unsigned long long block, int count, errcode_t err);
|
1997-04-29 20:17:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static errcode_t test_open(const char *name, int flags, io_channel *channel);
|
|
|
|
static errcode_t test_close(io_channel channel);
|
|
|
|
static errcode_t test_set_blksize(io_channel channel, int blksize);
|
|
|
|
static errcode_t test_read_blk(io_channel channel, unsigned long block,
|
|
|
|
int count, void *data);
|
|
|
|
static errcode_t test_write_blk(io_channel channel, unsigned long block,
|
|
|
|
int count, const void *data);
|
2008-05-25 03:17:01 +04:00
|
|
|
static errcode_t test_read_blk64(io_channel channel, unsigned long long block,
|
|
|
|
int count, void *data);
|
|
|
|
static errcode_t test_write_blk64(io_channel channel, unsigned long long block,
|
|
|
|
int count, const void *data);
|
1997-04-29 20:17:09 +04:00
|
|
|
static errcode_t test_flush(io_channel channel);
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
static errcode_t test_write_byte(io_channel channel, unsigned long offset,
|
|
|
|
int count, const void *buf);
|
2008-08-28 07:07:54 +04:00
|
|
|
static errcode_t test_set_option(io_channel channel, const char *option,
|
2004-11-30 22:07:11 +03:00
|
|
|
const char *arg);
|
2007-08-04 04:07:09 +04:00
|
|
|
static errcode_t test_get_stats(io_channel channel, io_stats *stats);
|
2010-11-18 06:38:36 +03:00
|
|
|
static errcode_t test_discard(io_channel channel, unsigned long long block,
|
|
|
|
unsigned long long count);
|
1997-04-29 20:17:09 +04:00
|
|
|
|
|
|
|
static struct struct_io_manager struct_test_manager = {
|
|
|
|
EXT2_ET_MAGIC_IO_MANAGER,
|
|
|
|
"Test I/O Manager",
|
|
|
|
test_open,
|
|
|
|
test_close,
|
|
|
|
test_set_blksize,
|
|
|
|
test_read_blk,
|
|
|
|
test_write_blk,
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
test_flush,
|
2004-11-30 22:07:11 +03:00
|
|
|
test_write_byte,
|
2007-08-04 04:07:09 +04:00
|
|
|
test_set_option,
|
|
|
|
test_get_stats,
|
2008-05-25 03:17:01 +04:00
|
|
|
test_read_blk64,
|
|
|
|
test_write_blk64,
|
2010-11-18 06:38:36 +03:00
|
|
|
test_discard,
|
1997-04-29 20:17:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
io_manager test_io_manager = &struct_test_manager;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These global variable can be set by the test program as
|
|
|
|
* necessary *before* calling test_open
|
|
|
|
*/
|
|
|
|
io_manager test_io_backing_manager = 0;
|
|
|
|
void (*test_io_cb_read_blk)
|
|
|
|
(unsigned long block, int count, errcode_t err) = 0;
|
|
|
|
void (*test_io_cb_write_blk)
|
|
|
|
(unsigned long block, int count, errcode_t err) = 0;
|
2008-05-25 03:17:01 +04:00
|
|
|
void (*test_io_cb_read_blk64)
|
|
|
|
(unsigned long long block, int count, errcode_t err) = 0;
|
|
|
|
void (*test_io_cb_write_blk64)
|
|
|
|
(unsigned long long block, int count, errcode_t err) = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
void (*test_io_cb_set_blksize)
|
|
|
|
(int blksize, errcode_t err) = 0;
|
2000-10-27 00:24:43 +04:00
|
|
|
void (*test_io_cb_write_byte)
|
|
|
|
(unsigned long block, int count, errcode_t err) = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
|
2003-05-05 20:08:47 +04:00
|
|
|
/*
|
|
|
|
* Test flags
|
|
|
|
*/
|
|
|
|
#define TEST_FLAG_READ 0x01
|
|
|
|
#define TEST_FLAG_WRITE 0x02
|
|
|
|
#define TEST_FLAG_SET_BLKSIZE 0x04
|
|
|
|
#define TEST_FLAG_FLUSH 0x08
|
2004-05-27 05:04:07 +04:00
|
|
|
#define TEST_FLAG_DUMP 0x10
|
2004-11-30 22:07:11 +03:00
|
|
|
#define TEST_FLAG_SET_OPTION 0x20
|
2010-11-18 06:38:36 +03:00
|
|
|
#define TEST_FLAG_DISCARD 0x40
|
2003-05-05 20:08:47 +04:00
|
|
|
|
|
|
|
static void test_dump_block(io_channel channel,
|
|
|
|
struct test_private_data *data,
|
2003-07-06 08:36:48 +04:00
|
|
|
unsigned long block, const void *buf)
|
2003-05-05 20:08:47 +04:00
|
|
|
{
|
|
|
|
const unsigned char *cp;
|
|
|
|
FILE *f = data->outfile;
|
|
|
|
int i;
|
|
|
|
unsigned long cksum = 0;
|
|
|
|
|
|
|
|
for (i=0, cp = buf; i < channel->block_size; i++, cp++) {
|
|
|
|
cksum += *cp;
|
|
|
|
}
|
2003-07-06 08:36:48 +04:00
|
|
|
fprintf(f, "Contents of block %lu, checksum %08lu: \n", block, cksum);
|
2003-05-05 20:08:47 +04:00
|
|
|
for (i=0, cp = buf; i < channel->block_size; i++, cp++) {
|
|
|
|
if ((i % 16) == 0)
|
|
|
|
fprintf(f, "%04x: ", i);
|
|
|
|
fprintf(f, "%02x%c", *cp, ((i % 16) == 15) ? '\n' : ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
static void test_abort(io_channel channel, unsigned long block)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
f = data->outfile;
|
|
|
|
test_flush(channel);
|
|
|
|
|
|
|
|
fprintf(f, "Aborting due to I/O to block %lu\n", block);
|
|
|
|
fflush(f);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2005-04-06 22:44:16 +04:00
|
|
|
static char *safe_getenv(const char *arg)
|
|
|
|
{
|
2005-04-16 21:56:03 +04:00
|
|
|
if ((getuid() != geteuid()) || (getgid() != getegid()))
|
2005-04-06 22:44:16 +04:00
|
|
|
return NULL;
|
|
|
|
#if HAVE_PRCTL
|
2005-07-25 20:36:43 +04:00
|
|
|
if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
|
2005-04-06 22:44:16 +04:00
|
|
|
return NULL;
|
|
|
|
#else
|
|
|
|
#if (defined(linux) && defined(SYS_prctl))
|
2005-07-25 20:36:43 +04:00
|
|
|
if (syscall(SYS_prctl, PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
|
2005-04-06 22:44:16 +04:00
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE___SECURE_GETENV
|
2005-05-08 10:15:02 +04:00
|
|
|
return __secure_getenv(arg);
|
2005-04-06 22:44:16 +04:00
|
|
|
#else
|
2005-05-08 10:15:02 +04:00
|
|
|
return getenv(arg);
|
2005-04-06 22:44:16 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
static errcode_t test_open(const char *name, int flags, io_channel *channel)
|
|
|
|
{
|
|
|
|
io_channel io = NULL;
|
|
|
|
struct test_private_data *data = NULL;
|
|
|
|
errcode_t retval;
|
2004-05-27 05:04:07 +04:00
|
|
|
char *value;
|
1997-04-29 20:17:09 +04:00
|
|
|
|
|
|
|
if (name == 0)
|
|
|
|
return EXT2_ET_BAD_DEVICE_NAME;
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
1997-04-29 20:17:09 +04:00
|
|
|
memset(io, 0, sizeof(struct struct_io_channel));
|
|
|
|
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(sizeof(struct test_private_data), &data);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval) {
|
1997-10-31 09:07:47 +03:00
|
|
|
retval = EXT2_ET_NO_MEMORY;
|
1997-04-29 20:17:09 +04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
io->manager = test_io_manager;
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(strlen(name)+1, &io->name);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
1997-04-29 20:17:09 +04:00
|
|
|
goto cleanup;
|
1997-10-26 06:41:24 +03:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
strcpy(io->name, name);
|
|
|
|
io->private_data = data;
|
|
|
|
io->block_size = 1024;
|
|
|
|
io->read_error = 0;
|
|
|
|
io->write_error = 0;
|
1997-04-30 01:26:48 +04:00
|
|
|
io->refcount = 1;
|
1997-04-29 20:17:09 +04:00
|
|
|
|
|
|
|
memset(data, 0, sizeof(struct test_private_data));
|
|
|
|
data->magic = EXT2_ET_MAGIC_TEST_IO_CHANNEL;
|
|
|
|
if (test_io_backing_manager) {
|
|
|
|
retval = test_io_backing_manager->open(name, flags,
|
|
|
|
&data->real);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
} else
|
|
|
|
data->real = 0;
|
|
|
|
data->read_blk = test_io_cb_read_blk;
|
|
|
|
data->write_blk = test_io_cb_write_blk;
|
|
|
|
data->set_blksize = test_io_cb_set_blksize;
|
2000-10-27 00:24:43 +04:00
|
|
|
data->write_byte = test_io_cb_write_byte;
|
2008-05-25 03:17:01 +04:00
|
|
|
data->read_blk64 = test_io_cb_read_blk64;
|
|
|
|
data->write_blk64 = test_io_cb_write_blk64;
|
2003-05-05 20:08:47 +04:00
|
|
|
|
|
|
|
data->outfile = NULL;
|
2005-04-06 22:44:16 +04:00
|
|
|
if ((value = safe_getenv("TEST_IO_LOGFILE")) != NULL)
|
2004-05-27 05:04:07 +04:00
|
|
|
data->outfile = fopen(value, "w");
|
2003-05-05 20:08:47 +04:00
|
|
|
if (!data->outfile)
|
|
|
|
data->outfile = stderr;
|
|
|
|
|
|
|
|
data->flags = 0;
|
2005-04-06 22:44:16 +04:00
|
|
|
if ((value = safe_getenv("TEST_IO_FLAGS")) != NULL)
|
2004-05-27 05:04:07 +04:00
|
|
|
data->flags = strtoul(value, NULL, 0);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2003-05-05 20:08:47 +04:00
|
|
|
data->block = 0;
|
2005-04-06 22:44:16 +04:00
|
|
|
if ((value = safe_getenv("TEST_IO_BLOCK")) != NULL)
|
2004-05-27 05:04:07 +04:00
|
|
|
data->block = strtoul(value, NULL, 0);
|
|
|
|
|
|
|
|
data->read_abort_count = 0;
|
2005-04-06 22:44:16 +04:00
|
|
|
if ((value = safe_getenv("TEST_IO_READ_ABORT")) != NULL)
|
2004-05-27 05:04:07 +04:00
|
|
|
data->read_abort_count = strtoul(value, NULL, 0);
|
|
|
|
|
|
|
|
data->write_abort_count = 0;
|
2005-04-06 22:44:16 +04:00
|
|
|
if ((value = safe_getenv("TEST_IO_WRITE_ABORT")) != NULL)
|
2004-05-27 05:04:07 +04:00
|
|
|
data->write_abort_count = strtoul(value, NULL, 0);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
*channel = io;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (io)
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&io);
|
1997-04-29 20:17:09 +04:00
|
|
|
if (data)
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&data);
|
1997-04-29 20:17:09 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t test_close(io_channel channel)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
1997-04-30 01:26:48 +04:00
|
|
|
if (--channel->refcount > 0)
|
|
|
|
return 0;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_close(data->real);
|
2003-05-05 20:08:47 +04:00
|
|
|
|
2003-05-06 03:50:49 +04:00
|
|
|
if (data->outfile && data->outfile != stderr)
|
2003-05-05 20:08:47 +04:00
|
|
|
fclose(data->outfile);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&channel->private_data);
|
1997-04-29 20:17:09 +04:00
|
|
|
if (channel->name)
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&channel->name);
|
|
|
|
ext2fs_free_mem(&channel);
|
1997-04-29 20:17:09 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t test_set_blksize(io_channel channel, int blksize)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_set_blksize(data->real, blksize);
|
|
|
|
if (data->set_blksize)
|
|
|
|
data->set_blksize(blksize, retval);
|
2003-05-05 20:08:47 +04:00
|
|
|
if (data->flags & TEST_FLAG_SET_BLKSIZE)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: set_blksize(%d) returned %s\n",
|
|
|
|
blksize, retval ? error_message(retval) : "OK");
|
|
|
|
channel->block_size = blksize;
|
1997-04-29 20:17:09 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static errcode_t test_read_blk(io_channel channel, unsigned long block,
|
|
|
|
int count, void *buf)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_read_blk(data->real, block, count, buf);
|
|
|
|
if (data->read_blk)
|
|
|
|
data->read_blk(block, count, retval);
|
2003-05-05 20:08:47 +04:00
|
|
|
if (data->flags & TEST_FLAG_READ)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: read_blk(%lu, %d) returned %s\n",
|
|
|
|
block, count, retval ? error_message(retval) : "OK");
|
2004-05-27 05:04:07 +04:00
|
|
|
if (data->block && data->block == block) {
|
|
|
|
if (data->flags & TEST_FLAG_DUMP)
|
|
|
|
test_dump_block(channel, data, block, buf);
|
|
|
|
if (--data->read_abort_count == 0)
|
|
|
|
test_abort(channel, block);
|
2008-08-28 07:07:54 +04:00
|
|
|
}
|
1997-04-29 20:17:09 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t test_write_blk(io_channel channel, unsigned long block,
|
|
|
|
int count, const void *buf)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_write_blk(data->real, block, count, buf);
|
2000-12-05 06:53:41 +03:00
|
|
|
if (data->write_blk)
|
|
|
|
data->write_blk(block, count, retval);
|
2003-05-05 20:08:47 +04:00
|
|
|
if (data->flags & TEST_FLAG_WRITE)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: write_blk(%lu, %d) returned %s\n",
|
|
|
|
block, count, retval ? error_message(retval) : "OK");
|
2004-05-27 05:04:07 +04:00
|
|
|
if (data->block && data->block == block) {
|
|
|
|
if (data->flags & TEST_FLAG_DUMP)
|
|
|
|
test_dump_block(channel, data, block, buf);
|
|
|
|
if (--data->write_abort_count == 0)
|
|
|
|
test_abort(channel, block);
|
|
|
|
}
|
1997-04-29 20:17:09 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-05-25 03:17:01 +04:00
|
|
|
static errcode_t test_read_blk64(io_channel channel, unsigned long long block,
|
|
|
|
int count, void *buf)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_read_blk64(data->real, block, count, buf);
|
|
|
|
if (data->read_blk64)
|
|
|
|
data->read_blk64(block, count, retval);
|
|
|
|
if (data->flags & TEST_FLAG_READ)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: read_blk64(%llu, %d) returned %s\n",
|
|
|
|
block, count, retval ? error_message(retval) : "OK");
|
|
|
|
if (data->block && data->block == block) {
|
|
|
|
if (data->flags & TEST_FLAG_DUMP)
|
|
|
|
test_dump_block(channel, data, block, buf);
|
|
|
|
if (--data->read_abort_count == 0)
|
|
|
|
test_abort(channel, block);
|
2008-08-28 07:07:54 +04:00
|
|
|
}
|
2008-05-25 03:17:01 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t test_write_blk64(io_channel channel, unsigned long long block,
|
|
|
|
int count, const void *buf)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_write_blk64(data->real, block, count, buf);
|
|
|
|
if (data->write_blk64)
|
|
|
|
data->write_blk64(block, count, retval);
|
|
|
|
if (data->flags & TEST_FLAG_WRITE)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: write_blk64(%llu, %d) returned %s\n",
|
|
|
|
block, count, retval ? error_message(retval) : "OK");
|
|
|
|
if (data->block && data->block == block) {
|
|
|
|
if (data->flags & TEST_FLAG_DUMP)
|
|
|
|
test_dump_block(channel, data, block, buf);
|
|
|
|
if (--data->write_abort_count == 0)
|
|
|
|
test_abort(channel, block);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-10-27 00:24:43 +04:00
|
|
|
static errcode_t test_write_byte(io_channel channel, unsigned long offset,
|
|
|
|
int count, const void *buf)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real && data->real->manager->write_byte)
|
|
|
|
retval = io_channel_write_byte(data->real, offset, count, buf);
|
|
|
|
if (data->write_byte)
|
|
|
|
data->write_byte(offset, count, retval);
|
2003-05-05 20:08:47 +04:00
|
|
|
if (data->flags & TEST_FLAG_WRITE)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: write_byte(%lu, %d) returned %s\n",
|
|
|
|
offset, count, retval ? error_message(retval) : "OK");
|
2000-10-27 00:24:43 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
/*
|
|
|
|
* Flush data buffers to disk.
|
|
|
|
*/
|
|
|
|
static errcode_t test_flush(io_channel channel)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
1998-02-17 01:00:37 +03:00
|
|
|
errcode_t retval = 0;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real)
|
1998-02-17 01:00:37 +03:00
|
|
|
retval = io_channel_flush(data->real);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2003-05-05 20:08:47 +04:00
|
|
|
if (data->flags & TEST_FLAG_FLUSH)
|
|
|
|
fprintf(data->outfile, "Test_io: flush() returned %s\n",
|
|
|
|
retval ? error_message(retval) : "OK");
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1998-02-17 01:00:37 +03:00
|
|
|
return retval;
|
1997-04-29 20:17:09 +04:00
|
|
|
}
|
|
|
|
|
2008-08-28 07:07:54 +04:00
|
|
|
static errcode_t test_set_option(io_channel channel, const char *option,
|
2004-11-30 22:07:11 +03:00
|
|
|
const char *arg)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
|
|
|
|
if (data->flags & TEST_FLAG_SET_OPTION)
|
2008-08-28 07:07:54 +04:00
|
|
|
fprintf(data->outfile, "Test_io: set_option(%s, %s) ",
|
2004-11-30 22:07:11 +03:00
|
|
|
option, arg);
|
|
|
|
if (data->real && data->real->manager->set_option) {
|
2008-08-28 07:07:54 +04:00
|
|
|
retval = (data->real->manager->set_option)(data->real,
|
2004-11-30 22:07:11 +03:00
|
|
|
option, arg);
|
|
|
|
if (data->flags & TEST_FLAG_SET_OPTION)
|
|
|
|
fprintf(data->outfile, "returned %s\n",
|
|
|
|
retval ? error_message(retval) : "OK");
|
|
|
|
} else {
|
|
|
|
if (data->flags & TEST_FLAG_SET_OPTION)
|
|
|
|
fprintf(data->outfile, "not implemented\n");
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2007-08-04 04:07:09 +04:00
|
|
|
|
|
|
|
static errcode_t test_get_stats(io_channel channel, io_stats *stats)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
|
|
|
if (data->real && data->real->manager->get_stats) {
|
|
|
|
retval = (data->real->manager->get_stats)(data->real, stats);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2010-11-18 06:38:36 +03:00
|
|
|
|
|
|
|
static errcode_t test_discard(io_channel channel, unsigned long long block,
|
|
|
|
unsigned long long count)
|
|
|
|
{
|
|
|
|
struct test_private_data *data;
|
|
|
|
errcode_t retval = 0;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
|
|
|
data = (struct test_private_data *) channel->private_data;
|
|
|
|
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
|
|
|
|
|
2010-11-18 06:38:38 +03:00
|
|
|
if (data->real)
|
|
|
|
retval = io_channel_discard(data->real, block, count);
|
2010-11-18 06:38:36 +03:00
|
|
|
if (data->flags & TEST_FLAG_DISCARD)
|
|
|
|
fprintf(data->outfile,
|
|
|
|
"Test_io: discard(%llu, %llu) returned %s\n",
|
|
|
|
block, count, retval ? error_message(retval) : "OK");
|
|
|
|
return retval;
|
|
|
|
}
|