ext2_io.h 4.6 KB
Newer Older
Theodore Ts'o's avatar
Theodore Ts'o committed
1 2
/*
 * io.h --- the I/O manager abstraction
3
 *
Theodore Ts'o's avatar
Theodore Ts'o committed
4 5 6
 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
 *
 * %Begin-Header%
7 8
 * This file may be redistributed under the terms of the GNU Library
 * General Public License, version 2.
Theodore Ts'o's avatar
Theodore Ts'o committed
9
 * %End-Header%
Theodore Ts'o's avatar
Theodore Ts'o committed
10 11
 */

12 13 14
#ifndef _EXT2FS_EXT2_IO_H
#define _EXT2FS_EXT2_IO_H

Theodore Ts'o's avatar
Theodore Ts'o committed
15 16 17 18 19 20 21 22 23 24
/*
 * ext2_loff_t is defined here since unix_io.c needs it.
 */
#if defined(__GNUC__) || defined(HAS_LONG_LONG)
typedef long long	ext2_loff_t;
#else
typedef long		ext2_loff_t;
#endif

/* llseek.c */
25
ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
Theodore Ts'o's avatar
Theodore Ts'o committed
26

Theodore Ts'o's avatar
Theodore Ts'o committed
27 28
typedef struct struct_io_manager *io_manager;
typedef struct struct_io_channel *io_channel;
Theodore Ts'o's avatar
Theodore Ts'o committed
29
typedef struct struct_io_stats *io_stats;
Theodore Ts'o's avatar
Theodore Ts'o committed
30

31
#define CHANNEL_FLAGS_WRITETHROUGH	0x01
32 33 34 35
#define CHANNEL_FLAGS_DISCARD_ZEROES	0x02
#define CHANNEL_FLAGS_BLOCK_DEVICE	0x04

#define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
36

Theodore Ts'o's avatar
Theodore Ts'o committed
37
struct struct_io_channel {
Theodore Ts'o's avatar
Theodore Ts'o committed
38
	errcode_t	magic;
Theodore Ts'o's avatar
Theodore Ts'o committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
	io_manager	manager;
	char		*name;
	int		block_size;
	errcode_t	(*read_error)(io_channel channel,
				      unsigned long block,
				      int count,
				      void *data,
				      size_t size,
				      int actual_bytes_read,
				      errcode_t	error);
	errcode_t	(*write_error)(io_channel channel,
				       unsigned long block,
				       int count,
				       const void *data,
				       size_t size,
				       int actual_bytes_written,
				       errcode_t error);
Theodore Ts'o's avatar
Theodore Ts'o committed
56
	int		refcount;
57
	int		flags;
58
	long		reserved[14];
Theodore Ts'o's avatar
Theodore Ts'o committed
59
	void		*private_data;
60
	void		*app_data;
61
	int		align;
Theodore Ts'o's avatar
Theodore Ts'o committed
62 63
};

Theodore Ts'o's avatar
Theodore Ts'o committed
64 65 66 67 68 69 70
struct struct_io_stats {
	int			num_fields;
	int			reserved;
	unsigned long long	bytes_read;
	unsigned long long	bytes_written;
};

Theodore Ts'o's avatar
Theodore Ts'o committed
71
struct struct_io_manager {
Theodore Ts'o's avatar
Theodore Ts'o committed
72
	errcode_t magic;
Theodore Ts'o's avatar
Theodore Ts'o committed
73 74 75 76 77 78 79 80 81
	const char *name;
	errcode_t (*open)(const char *name, int flags, io_channel *channel);
	errcode_t (*close)(io_channel channel);
	errcode_t (*set_blksize)(io_channel channel, int blksize);
	errcode_t (*read_blk)(io_channel channel, unsigned long block,
			      int count, void *data);
	errcode_t (*write_blk)(io_channel channel, unsigned long block,
			       int count, const void *data);
	errcode_t (*flush)(io_channel channel);
Theodore Ts'o's avatar
Theodore Ts'o committed
82 83
	errcode_t (*write_byte)(io_channel channel, unsigned long offset,
				int count, const void *data);
84
	errcode_t (*set_option)(io_channel channel, const char *option,
85
				const char *arg);
Theodore Ts'o's avatar
Theodore Ts'o committed
86
	errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
87 88 89 90
	errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
					int count, void *data);
	errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
					int count, const void *data);
91 92
	errcode_t (*discard)(io_channel channel, unsigned long long block,
			     unsigned long long count);
93
	long	reserved[16];
Theodore Ts'o's avatar
Theodore Ts'o committed
94 95
};

96 97
#define IO_FLAG_RW		0x0001
#define IO_FLAG_EXCLUSIVE	0x0002
98
#define IO_FLAG_DIRECT_IO	0x0004
Theodore Ts'o's avatar
Theodore Ts'o committed
99 100 101 102 103 104 105 106 107

/*
 * Convenience functions....
 */
#define io_channel_close(c) 		((c)->manager->close((c)))
#define io_channel_set_blksize(c,s)	((c)->manager->set_blksize((c),s))
#define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
#define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
#define io_channel_flush(c) 		((c)->manager->flush((c)))
Theodore Ts'o's avatar
Theodore Ts'o committed
108
#define io_channel_bumpcount(c)		((c)->refcount++)
109

110
/* io_manager.c */
111
extern errcode_t io_channel_set_options(io_channel channel,
112
					const char *options);
113
extern errcode_t io_channel_write_byte(io_channel channel,
114 115
				       unsigned long offset,
				       int count, const void *data);
116 117 118 119 120 121
extern errcode_t io_channel_read_blk64(io_channel channel,
				       unsigned long long block,
				       int count, void *data);
extern errcode_t io_channel_write_blk64(io_channel channel,
					unsigned long long block,
					int count, const void *data);
122 123 124 125 126
extern errcode_t io_channel_discard(io_channel channel,
				    unsigned long long block,
				    unsigned long long count);
extern errcode_t io_channel_alloc_buf(io_channel channel,
				      int count, void *ptr);
127

Theodore Ts'o's avatar
Theodore Ts'o committed
128
/* unix_io.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
129 130
extern io_manager unix_io_manager;

131 132 133 134 135
/* undo_io.c */
extern io_manager undo_io_manager;
extern errcode_t set_undo_io_backing_manager(io_manager manager);
extern errcode_t set_undo_io_backup_file(char *file_name);

Theodore Ts'o's avatar
Theodore Ts'o committed
136 137 138 139 140 141
/* test_io.c */
extern io_manager test_io_manager, test_io_backing_manager;
extern void (*test_io_cb_read_blk)
	(unsigned long block, int count, errcode_t err);
extern void (*test_io_cb_write_blk)
	(unsigned long block, int count, errcode_t err);
142 143 144 145
extern void (*test_io_cb_read_blk64)
	(unsigned long long block, int count, errcode_t err);
extern void (*test_io_cb_write_blk64)
	(unsigned long long block, int count, errcode_t err);
Theodore Ts'o's avatar
Theodore Ts'o committed
146 147
extern void (*test_io_cb_set_blksize)
	(int blksize, errcode_t err);
148 149

#endif /* _EXT2FS_EXT2_IO_H */
150