• 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 
37 #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
38 
39 struct 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 
66 struct struct_io_stats {
67 	int			num_fields;
68 	int			reserved;
69 	unsigned long long	bytes_read;
70 	unsigned long long	bytes_written;
71 };
72 
73 struct 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 #define IO_FLAG_FORCE_BOUNCE	0x0008
107 
108 /*
109  * Convenience functions....
110  */
111 #define io_channel_close(c) 		((c)->manager->close((c)))
112 #define io_channel_set_blksize(c,s)	((c)->manager->set_blksize((c),s))
113 #define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
114 #define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
115 #define io_channel_flush(c) 		((c)->manager->flush((c)))
116 #define io_channel_bumpcount(c)		((c)->refcount++)
117 
118 /* io_manager.c */
119 extern errcode_t io_channel_set_options(io_channel channel,
120 					const char *options);
121 extern errcode_t io_channel_write_byte(io_channel channel,
122 				       unsigned long offset,
123 				       int count, const void *data);
124 extern errcode_t io_channel_read_blk64(io_channel channel,
125 				       unsigned long long block,
126 				       int count, void *data);
127 extern errcode_t io_channel_write_blk64(io_channel channel,
128 					unsigned long long block,
129 					int count, const void *data);
130 extern errcode_t io_channel_discard(io_channel channel,
131 				    unsigned long long block,
132 				    unsigned long long count);
133 extern errcode_t io_channel_zeroout(io_channel channel,
134 				    unsigned long long block,
135 				    unsigned long long count);
136 extern errcode_t io_channel_alloc_buf(io_channel channel,
137 				      int count, void *ptr);
138 extern errcode_t io_channel_cache_readahead(io_channel io,
139 					    unsigned long long block,
140 					    unsigned long long count);
141 
142 /* unix_io.c */
143 extern io_manager unix_io_manager;
144 extern io_manager unixfd_io_manager;
145 
146 /* sparse_io.c */
147 extern io_manager sparse_io_manager;
148 extern io_manager sparsefd_io_manager;
149 
150 /* undo_io.c */
151 extern io_manager undo_io_manager;
152 extern errcode_t set_undo_io_backing_manager(io_manager manager);
153 extern errcode_t set_undo_io_backup_file(char *file_name);
154 
155 /* test_io.c */
156 extern io_manager test_io_manager, test_io_backing_manager;
157 extern void (*test_io_cb_read_blk)
158 	(unsigned long block, int count, errcode_t err);
159 extern void (*test_io_cb_write_blk)
160 	(unsigned long block, int count, errcode_t err);
161 extern void (*test_io_cb_read_blk64)
162 	(unsigned long long block, int count, errcode_t err);
163 extern void (*test_io_cb_write_blk64)
164 	(unsigned long long block, int count, errcode_t err);
165 extern void (*test_io_cb_set_blksize)
166 	(int blksize, errcode_t err);
167 
168 #endif /* _EXT2FS_EXT2_IO_H */
169 
170