test_io.c revision a29f4d30f24d68f1f1c75548e020689ede532c05
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>
1419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <unistd.h>
1519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdlib.h>
1619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <fcntl.h>
1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <time.h>
1819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <sys/stat.h>
1919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <sys/types.h>
2019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#if HAVE_ERRNO_H
2119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <errno.h>
2219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#endif
2319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include "et/com_err.h"
2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include "ext2fs/ext2_err.h"
2619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include "io.h"
2719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
2919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * For checking structure magic numbers...
3019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
3119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define EXT2_CHECK_MAGIC(struct, code) \
3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	  if ((struct)->magic != (code)) return (code)
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct test_private_data {
3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	magic;
3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io_channel real;
3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*read_blk)(unsigned long block, int count, errcode_t err);
3919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*write_blk)(unsigned long block, int count, errcode_t err);
4019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	void (*set_blksize)(int blksize, errcode_t err);
4119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
4219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_open(const char *name, int flags, io_channel *channel);
4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_close(io_channel channel);
4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_set_blksize(io_channel channel, int blksize);
4619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_read_blk(io_channel channel, unsigned long block,
4719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, void *data);
4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_write_blk(io_channel channel, unsigned long block,
4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o				int count, const void *data);
5019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_flush(io_channel channel);
5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic struct struct_io_manager struct_test_manager = {
5319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_ET_MAGIC_IO_MANAGER,
5419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	"Test I/O Manager",
5519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_open,
5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_close,
5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_set_blksize,
5819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_read_blk,
5919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_write_blk,
6019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	test_flush
6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oio_manager test_io_manager = &struct_test_manager;
6419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
6619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * These global variable can be set by the test program as
6719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * necessary *before* calling test_open
6819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
6919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oio_manager test_io_backing_manager = 0;
7019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_read_blk)
7119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(unsigned long block, int count, errcode_t err) = 0;
7219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_write_blk)
7319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(unsigned long block, int count, errcode_t err) = 0;
7419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid (*test_io_cb_set_blksize)
7519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(int blksize, errcode_t err) = 0;
7619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
7719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_open(const char *name, int flags, io_channel *channel)
7819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
7919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io_channel	io = NULL;
8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data = NULL;
8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval;
8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (name == 0)
8419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return EXT2_ET_BAD_DEVICE_NAME;
8519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io = (io_channel) malloc(sizeof(struct struct_io_channel));
8619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (!io)
8719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return ENOMEM;
8819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	memset(io, 0, sizeof(struct struct_io_channel));
8919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
9019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *)
9119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		malloc(sizeof(struct test_private_data));
9219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (!data) {
9319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ENOMEM;
9419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		goto cleanup;
9519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
9619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->manager = test_io_manager;
9719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->name = malloc(strlen(name)+1);
9819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (!io->name) {
9919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ENOMEM;
10019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		goto cleanup;
10119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
10219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	strcpy(io->name, name);
10319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->private_data = data;
10419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->block_size = 1024;
10519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->read_error = 0;
10619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	io->write_error = 0;
107a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	io->refcount = 1;
10819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
10919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	memset(data, 0, sizeof(struct test_private_data));
11019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->magic = EXT2_ET_MAGIC_TEST_IO_CHANNEL;
11119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (test_io_backing_manager) {
11219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = test_io_backing_manager->open(name, flags,
11319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o						       &data->real);
11419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval)
11519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			goto cleanup;
11619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	} else
11719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->real = 0;
11819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->read_blk = 	test_io_cb_read_blk;
11919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->write_blk = 	test_io_cb_write_blk;
12019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data->set_blksize = 	test_io_cb_set_blksize;
12119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
12219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	*channel = io;
12319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 0;
12419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
12519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ocleanup:
12619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (io)
12719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		free(io);
12819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data)
12919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		free(data);
13019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
13119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
13219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
13319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_close(io_channel channel)
13419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
13519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
13619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
13719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
13819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
13919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
14019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
14119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
142a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	if (--channel->refcount > 0)
143a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o		return 0;
144a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o
14519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
14619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_close(data->real);
14719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
14819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (channel->private_data)
14919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		free(channel->private_data);
15019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (channel->name)
15119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		free(channel->name);
15219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	free(channel);
15319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
15419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
15519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
15619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_set_blksize(io_channel channel, int blksize)
15719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
15819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
15919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
16019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
16119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
16219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
16319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
16419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
16519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
16619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_set_blksize(data->real, blksize);
16719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->set_blksize)
16819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->set_blksize(blksize, retval);
16919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
17019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Test_io: set_blksize(%d) returned %s\n",
17119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       blksize, retval ? error_message(retval) : "OK");
17219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
17319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
17419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
17519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
17619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_read_blk(io_channel channel, unsigned long block,
17719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, void *buf)
17819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
17919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
18019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
18119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
18319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
18419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
18519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
18719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_read_blk(data->real, block, count, buf);
18819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->read_blk)
18919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->read_blk(block, count, retval);
19019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
19119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Test_io: read_blk(%lu, %d) returned %s\n",
19219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       block, count, retval ? error_message(retval) : "OK");
19319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
19419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
19519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
19619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_write_blk(io_channel channel, unsigned long block,
19719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int count, const void *buf)
19819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
19919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
20019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval = 0;
20119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
20219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
20319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
20419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
20519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
20619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
20719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = io_channel_write_blk(data->real, block, count, buf);
20819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->write_blk)
20919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		data->write_blk(block, count, retval);
21019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else
21119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Test_io: write_blk(%lu, %d) returned %s\n",
21219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       block, count, retval ? error_message(retval) : "OK");
21319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return retval;
21419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
21519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
21619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
21719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Flush data buffers to disk.
21819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
21919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic errcode_t test_flush(io_channel channel)
22019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
22119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct test_private_data *data;
22219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
22319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
22419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	data = (struct test_private_data *) channel->private_data;
22519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
22619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
22719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (data->real)
22819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return io_channel_flush(data->real);
22919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 0;
23019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
23119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
232