test_io.c revision f20d0d57f73f7eb7fc801b85921cff4a3d90e385
119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * test_io.c --- This is the Test I/O interface.
319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1996 Theodore Ts'o.
519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header%
719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * This file may be redistributed under the terms of the GNU Public
819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * License.
919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header%
1019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
1119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
1219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdio.h>
1319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <string.h>
144cbe8af4b0d0c72fb28bb500c1bd8a46b00fdde3Theodore Ts'o#if HAVE_UNISTD_H
1519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <unistd.h>
164cbe8af4b0d0c72fb28bb500c1bd8a46b00fdde3Theodore Ts'o#endif
1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <fcntl.h>
1819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <time.h>
191d2ff46ae7533ffd038534b189f272d2a4122e4eTheodore Ts'o#if HAVE_SYS_STAT_H
2019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <sys/stat.h>
211d2ff46ae7533ffd038534b189f272d2a4122e4eTheodore Ts'o#endif
221d2ff46ae7533ffd038534b189f272d2a4122e4eTheodore Ts'o#if HAVE_SYS_TYPES_H
2319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <sys/types.h>
241d2ff46ae7533ffd038534b189f272d2a4122e4eTheodore Ts'o#endif
2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
26b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o#if EXT2_FLAT_INCLUDES
27b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o#include "ext2_fs.h"
28b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o#else
297b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o#include <linux/ext2_fs.h>
30b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o#endif
317b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o
327b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o#include "ext2fs.h"
3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
3519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * For checking structure magic numbers...
3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define EXT2_CHECK_MAGIC(struct, code) \
3919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	  if ((struct)->magic != (code)) return (code)
4019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct test_private_data {
4219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	magic;
4319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io_channel real;
4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*read_blk)(unsigned long block, int count, errcode_t err);
4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*write_blk)(unsigned long block, int count, errcode_t err);
4619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*set_blksize)(int blksize, errcode_t err);
47c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	void (*write_byte)(unsigned long block, int count, errcode_t err);
4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
5019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_open(const char *name, int flags, io_channel *channel);
5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_close(io_channel channel);
5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_set_blksize(io_channel channel, int blksize);
5319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_read_blk(io_channel channel, unsigned long block,
5419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, void *data);
5519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_write_blk(io_channel channel, unsigned long block,
5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o				int count, const void *data);
5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_flush(io_channel channel);
5819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
5919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic struct struct_io_manager struct_test_manager = {
6019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_ET_MAGIC_IO_MANAGER,
6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	"Test I/O Manager",
6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_open,
6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_close,
6419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_set_blksize,
6519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_read_blk,
6619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_write_blk,
6719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_flush
6819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
6919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
7019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oio_manager test_io_manager = &struct_test_manager;
7119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
7219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
7319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * These global variable can be set by the test program as
7419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * necessary *before* calling test_open
7519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
7619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oio_manager test_io_backing_manager = 0;
7719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_read_blk)
7819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(unsigned long block, int count, errcode_t err) = 0;
7919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_write_blk)
8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(unsigned long block, int count, errcode_t err) = 0;
8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_set_blksize)
8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(int blksize, errcode_t err) = 0;
83c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'ovoid (*test_io_cb_write_byte)
84c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	(unsigned long block, int count, errcode_t err) = 0;
8519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_open(const char *name, int flags, io_channel *channel)
8719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
8819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io_channel	io = NULL;
8919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data = NULL;
9019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval;
9119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
9219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (name == 0)
9319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return EXT2_ET_BAD_DEVICE_NAME;
947b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	retval = ext2fs_get_mem(sizeof(struct struct_io_channel),
957b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o				(void **) &io);
967b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	if (retval)
977b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o		return retval;
9819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	memset(io, 0, sizeof(struct struct_io_channel));
9919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
1007b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	retval = ext2fs_get_mem(sizeof(struct test_private_data),
1017b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o				(void **) &data);
1027b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	if (retval) {
1031f0b6c1f895d189fea6999d0c07a7fee936a4baaTheodore Ts'o		retval = EXT2_ET_NO_MEMORY;
10419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		goto cleanup;
10519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
10619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->manager = test_io_manager;
1077b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	retval = ext2fs_get_mem(strlen(name)+1, (void **) &io->name);
1087b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	if (retval)
10919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		goto cleanup;
1107b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o
11119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	strcpy(io->name, name);
11219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->private_data = data;
11319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->block_size = 1024;
11419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->read_error = 0;
11519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->write_error = 0;
116a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	io->refcount = 1;
11719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
11819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	memset(data, 0, sizeof(struct test_private_data));
11919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->magic = EXT2_ET_MAGIC_TEST_IO_CHANNEL;
12019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (test_io_backing_manager) {
12119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = test_io_backing_manager->open(name, flags,
12219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o						       &data->real);
12319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval)
12419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			goto cleanup;
12519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	} else
12619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->real = 0;
12719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->read_blk = 	test_io_cb_read_blk;
12819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->write_blk = 	test_io_cb_write_blk;
12919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->set_blksize = 	test_io_cb_set_blksize;
130c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	data->write_byte = 	test_io_cb_write_byte;
13119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
13219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	*channel = io;
13319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 0;
13419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
13519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ocleanup:
13619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (io)
1377b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o		ext2fs_free_mem((void **) &io);
13819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data)
1397b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o		ext2fs_free_mem((void **) &data);
14019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
14119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
14219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
14319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_close(io_channel channel)
14419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
14519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
14619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
14719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
14819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
14919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
15019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
15119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
152a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	if (--channel->refcount > 0)
153a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o		return 0;
154a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o
15519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
15619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_close(data->real);
15719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
15819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (channel->private_data)
1597b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o		ext2fs_free_mem((void **) &channel->private_data);
16019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (channel->name)
1617b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o		ext2fs_free_mem((void **) &channel->name);
1627b4e4534f9361b21d3fafdd88a58f133decee38cTheodore Ts'o	ext2fs_free_mem((void **) &channel);
16319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
16419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
16519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
16619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_set_blksize(io_channel channel, int blksize)
16719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
16819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
16919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
17019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
17119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
17219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
17319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
17419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
17519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
17619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_set_blksize(data->real, blksize);
17719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->set_blksize)
17819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->set_blksize(blksize, retval);
17919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
18019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Test_io: set_blksize(%d) returned %s\n",
18119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       blksize, retval ? error_message(retval) : "OK");
18219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
18319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
18419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_read_blk(io_channel channel, unsigned long block,
18719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, void *buf)
18819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
18919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
19019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
19119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
19219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
19319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
19419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
19519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
19619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
19719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_read_blk(data->real, block, count, buf);
19819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->read_blk)
19919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->read_blk(block, count, retval);
20019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
20119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Test_io: read_blk(%lu, %d) returned %s\n",
20219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       block, count, retval ? error_message(retval) : "OK");
20319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
20419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
20519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
20619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_write_blk(io_channel channel, unsigned long block,
20719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, const void *buf)
20819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
20919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
21019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
21119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
21219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
21319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
21419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
21519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
21619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
21719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_write_blk(data->real, block, count, buf);
218f20d0d57f73f7eb7fc801b85921cff4a3d90e385Theodore Ts'o	if (data->write_blk)
219f20d0d57f73f7eb7fc801b85921cff4a3d90e385Theodore Ts'o		data->write_blk(block, count, retval);
22019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
221f20d0d57f73f7eb7fc801b85921cff4a3d90e385Theodore Ts'o		printf("Test_io: write_blk(%lu, %d) returned %s\n",
22219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       block, count, retval ? error_message(retval) : "OK");
22319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
22419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
22519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
226c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'ostatic errcode_t test_write_byte(io_channel channel, unsigned long offset,
227c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o			       int count, const void *buf)
228c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o{
229c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	struct test_private_data *data;
230c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	errcode_t	retval = 0;
231c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o
232c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
233c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	data = (struct test_private_data *) channel->private_data;
234c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
235c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o
236c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	if (data->real && data->real->manager->write_byte)
237c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o		retval = io_channel_write_byte(data->real, offset, count, buf);
238c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	if (data->write_byte)
239c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o		data->write_byte(offset, count, retval);
240c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	else
241f20d0d57f73f7eb7fc801b85921cff4a3d90e385Theodore Ts'o		printf("Test_io: write_byte(%lu, %d) returned %s\n",
242c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o		       offset, count, retval ? error_message(retval) : "OK");
243c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o	return retval;
244c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o}
245c180ac86533bcbfb1560bd4aa01464785a760f70Theodore Ts'o
24619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
24719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Flush data buffers to disk.
24819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
24919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_flush(io_channel channel)
25019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
25119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
2529abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o	errcode_t	retval = 0;
25319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
25419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
25519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
25619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
25719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
25819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
2599abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o		retval = io_channel_flush(data->real);
2609abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o
2619abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o	printf("Test_io: flush() returned %s\n",
2629abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o		       retval ? error_message(retval) : "OK");
2639abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o
2649abd2ce914f9373fb676f0bb620ffba3a0e3c49eTheodore Ts'o	return retval;
26519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
26619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
267