ext2_io.h revision f9e0f1d4a7cf32c4091eee7d2a1676cac1d17438
1/*
2 * io.h --- the I/O manager abstraction
3 *
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
9 * %End-Header%
10 */
11
12#ifndef _EXT2FS_EXT2_IO_H
13#define _EXT2FS_EXT2_IO_H
14
15#include <ext2fs/ext2_types.h>
16
17/*
18 * ext2_loff_t is defined here since unix_io.c needs it.
19 */
20#if defined(__GNUC__) || defined(HAS_LONG_LONG)
21typedef long long	ext2_loff_t;
22#else
23typedef long		ext2_loff_t;
24#endif
25
26/* llseek.c */
27ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
28
29typedef struct struct_io_manager *io_manager;
30typedef struct struct_io_channel *io_channel;
31typedef struct struct_io_stats *io_stats;
32
33#define CHANNEL_FLAGS_WRITETHROUGH	0x01
34#define CHANNEL_FLAGS_DISCARD_ZEROES	0x02
35#define CHANNEL_FLAGS_BLOCK_DEVICE	0x04
36
37#define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
38
39struct struct_io_channel {
40	errcode_t	magic;
41	io_manager	manager;
42	char		*name;
43	int		block_size;
44	errcode_t	(*read_error)(io_channel channel,
45				      unsigned long block,
46				      int count,
47				      void *data,
48				      size_t size,
49				      int actual_bytes_read,
50				      errcode_t	error);
51	errcode_t	(*write_error)(io_channel channel,
52				       unsigned long block,
53				       int count,
54				       const void *data,
55				       size_t size,
56				       int actual_bytes_written,
57				       errcode_t error);
58	int		refcount;
59	int		flags;
60	long		reserved[14];
61	void		*private_data;
62	void		*app_data;
63	int		align;
64};
65
66struct struct_io_stats {
67	int			num_fields;
68	int			reserved;
69	unsigned long long	bytes_read;
70	unsigned long long	bytes_written;
71};
72
73struct struct_io_manager {
74	errcode_t magic;
75	const char *name;
76	errcode_t (*open)(const char *name, int flags, io_channel *channel);
77	errcode_t (*close)(io_channel channel);
78	errcode_t (*set_blksize)(io_channel channel, int blksize);
79	errcode_t (*read_blk)(io_channel channel, unsigned long block,
80			      int count, void *data);
81	errcode_t (*write_blk)(io_channel channel, unsigned long block,
82			       int count, const void *data);
83	errcode_t (*flush)(io_channel channel);
84	errcode_t (*write_byte)(io_channel channel, unsigned long offset,
85				int count, const void *data);
86	errcode_t (*set_option)(io_channel channel, const char *option,
87				const char *arg);
88	errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
89	errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
90					int count, void *data);
91	errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
92					int count, const void *data);
93	errcode_t (*discard)(io_channel channel, unsigned long long block,
94			     unsigned long long count);
95	errcode_t (*cache_readahead)(io_channel channel,
96				     unsigned long long block,
97				     unsigned long long count);
98	errcode_t (*zeroout)(io_channel channel, unsigned long long block,
99			     unsigned long long count);
100	long	reserved[14];
101};
102
103#define IO_FLAG_RW		0x0001
104#define IO_FLAG_EXCLUSIVE	0x0002
105#define IO_FLAG_DIRECT_IO	0x0004
106
107/*
108 * Convenience functions....
109 */
110#define io_channel_close(c) 		((c)->manager->close((c)))
111#define io_channel_set_blksize(c,s)	((c)->manager->set_blksize((c),s))
112#define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
113#define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
114#define io_channel_flush(c) 		((c)->manager->flush((c)))
115#define io_channel_bumpcount(c)		((c)->refcount++)
116
117/* io_manager.c */
118extern errcode_t io_channel_set_options(io_channel channel,
119					const char *options);
120extern errcode_t io_channel_write_byte(io_channel channel,
121				       unsigned long offset,
122				       int count, const void *data);
123extern errcode_t io_channel_read_blk64(io_channel channel,
124				       unsigned long long block,
125				       int count, void *data);
126extern errcode_t io_channel_write_blk64(io_channel channel,
127					unsigned long long block,
128					int count, const void *data);
129extern errcode_t io_channel_discard(io_channel channel,
130				    unsigned long long block,
131				    unsigned long long count);
132extern errcode_t io_channel_zeroout(io_channel channel,
133				    unsigned long long block,
134				    unsigned long long count);
135extern errcode_t io_channel_alloc_buf(io_channel channel,
136				      int count, void *ptr);
137extern errcode_t io_channel_cache_readahead(io_channel io,
138					    unsigned long long block,
139					    unsigned long long count);
140
141/* unix_io.c */
142extern io_manager unix_io_manager;
143extern io_manager unixfd_io_manager;
144
145/* sparse_io.c */
146extern io_manager sparse_io_manager;
147extern io_manager sparsefd_io_manager;
148
149/* undo_io.c */
150extern io_manager undo_io_manager;
151extern errcode_t set_undo_io_backing_manager(io_manager manager);
152extern errcode_t set_undo_io_backup_file(char *file_name);
153
154/* test_io.c */
155extern io_manager test_io_manager, test_io_backing_manager;
156extern void (*test_io_cb_read_blk)
157	(unsigned long block, int count, errcode_t err);
158extern void (*test_io_cb_write_blk)
159	(unsigned long block, int count, errcode_t err);
160extern void (*test_io_cb_read_blk64)
161	(unsigned long long block, int count, errcode_t err);
162extern void (*test_io_cb_write_blk64)
163	(unsigned long long block, int count, errcode_t err);
164extern void (*test_io_cb_set_blksize)
165	(int blksize, errcode_t err);
166
167#endif /* _EXT2FS_EXT2_IO_H */
168
169