• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
21 typedef long long	ext2_loff_t;
22 #else
23 typedef long		ext2_loff_t;
24 #endif
25 
26 /* llseek.c */
27 ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
28 
29 typedef struct struct_io_manager *io_manager;
30 typedef struct struct_io_channel *io_channel;
31 typedef 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 #define CHANNEL_FLAGS_THREADS		0x08
37 
38 #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
39 
40 struct struct_io_channel {
41 	errcode_t	magic;
42 	io_manager	manager;
43 	char		*name;
44 	int		block_size;
45 	errcode_t	(*read_error)(io_channel channel,
46 				      unsigned long block,
47 				      int count,
48 				      void *data,
49 				      size_t size,
50 				      int actual_bytes_read,
51 				      errcode_t	error);
52 	errcode_t	(*write_error)(io_channel channel,
53 				       unsigned long block,
54 				       int count,
55 				       const void *data,
56 				       size_t size,
57 				       int actual_bytes_written,
58 				       errcode_t error);
59 	int		refcount;
60 	int		flags;
61 	long		reserved[14];
62 	void		*private_data;
63 	void		*app_data;
64 	int		align;
65 };
66 
67 struct struct_io_stats {
68 	int			num_fields;
69 	int			reserved;
70 	unsigned long long	bytes_read;
71 	unsigned long long	bytes_written;
72 };
73 
74 struct struct_io_manager {
75 	errcode_t magic;
76 	const char *name;
77 	errcode_t (*open)(const char *name, int flags, io_channel *channel);
78 	errcode_t (*close)(io_channel channel);
79 	errcode_t (*set_blksize)(io_channel channel, int blksize);
80 	errcode_t (*read_blk)(io_channel channel, unsigned long block,
81 			      int count, void *data);
82 	errcode_t (*write_blk)(io_channel channel, unsigned long block,
83 			       int count, const void *data);
84 	errcode_t (*flush)(io_channel channel);
85 	errcode_t (*write_byte)(io_channel channel, unsigned long offset,
86 				int count, const void *data);
87 	errcode_t (*set_option)(io_channel channel, const char *option,
88 				const char *arg);
89 	errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
90 	errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
91 					int count, void *data);
92 	errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
93 					int count, const void *data);
94 	errcode_t (*discard)(io_channel channel, unsigned long long block,
95 			     unsigned long long count);
96 	errcode_t (*cache_readahead)(io_channel channel,
97 				     unsigned long long block,
98 				     unsigned long long count);
99 	errcode_t (*zeroout)(io_channel channel, unsigned long long block,
100 			     unsigned long long count);
101 	long	reserved[14];
102 };
103 
104 #define IO_FLAG_RW		0x0001
105 #define IO_FLAG_EXCLUSIVE	0x0002
106 #define IO_FLAG_DIRECT_IO	0x0004
107 #define IO_FLAG_FORCE_BOUNCE	0x0008
108 #define IO_FLAG_THREADS		0x0010
109 #define IO_FLAG_NOCACHE		0x0020
110 
111 /*
112  * Convenience functions....
113  */
114 #define io_channel_close(c) 		((c)->manager->close((c)))
115 #define io_channel_set_blksize(c,s)	((c)->manager->set_blksize((c),s))
116 #define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
117 #define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
118 #define io_channel_flush(c) 		((c)->manager->flush((c)))
119 #define io_channel_bumpcount(c)		((c)->refcount++)
120 
121 /* io_manager.c */
122 extern errcode_t io_channel_set_options(io_channel channel,
123 					const char *options);
124 extern errcode_t io_channel_write_byte(io_channel channel,
125 				       unsigned long offset,
126 				       int count, const void *data);
127 extern errcode_t io_channel_read_blk64(io_channel channel,
128 				       unsigned long long block,
129 				       int count, void *data);
130 extern errcode_t io_channel_write_blk64(io_channel channel,
131 					unsigned long long block,
132 					int count, const void *data);
133 extern errcode_t io_channel_discard(io_channel channel,
134 				    unsigned long long block,
135 				    unsigned long long count);
136 extern errcode_t io_channel_zeroout(io_channel channel,
137 				    unsigned long long block,
138 				    unsigned long long count);
139 extern errcode_t io_channel_alloc_buf(io_channel channel,
140 				      int count, void *ptr);
141 extern errcode_t io_channel_cache_readahead(io_channel io,
142 					    unsigned long long block,
143 					    unsigned long long count);
144 
145 #ifdef _WIN32
146 /* windows_io.c */
147 extern io_manager windows_io_manager;
148 #else
149 /* unix_io.c */
150 extern io_manager unix_io_manager;
151 extern io_manager unixfd_io_manager;
152 #endif
153 
154 /* sparse_io.c */
155 extern io_manager sparse_io_manager;
156 extern io_manager sparsefd_io_manager;
157 
158 /* undo_io.c */
159 extern io_manager undo_io_manager;
160 extern errcode_t set_undo_io_backing_manager(io_manager manager);
161 extern errcode_t set_undo_io_backup_file(char *file_name);
162 
163 /* test_io.c */
164 extern io_manager test_io_manager, test_io_backing_manager;
165 extern void (*test_io_cb_read_blk)
166 	(unsigned long block, int count, errcode_t err);
167 extern void (*test_io_cb_write_blk)
168 	(unsigned long block, int count, errcode_t err);
169 extern void (*test_io_cb_read_blk64)
170 	(unsigned long long block, int count, errcode_t err);
171 extern void (*test_io_cb_write_blk64)
172 	(unsigned long long block, int count, errcode_t err);
173 extern void (*test_io_cb_set_blksize)
174 	(int blksize, errcode_t err);
175 
176 #endif /* _EXT2FS_EXT2_IO_H */
177 
178