2 * io.h --- the I/O manager abstraction
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
12 #ifndef _EXT2FS_EXT2_IO_H
13 #define _EXT2FS_EXT2_IO_H
16 * ext2_loff_t is defined here since unix_io.c needs it.
18 #if defined(__GNUC__) || defined(HAS_LONG_LONG)
19 typedef long long ext2_loff_t;
21 typedef long ext2_loff_t;
25 ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
27 typedef struct struct_io_manager *io_manager;
28 typedef struct struct_io_channel *io_channel;
29 typedef struct struct_io_stats *io_stats;
31 #define CHANNEL_FLAGS_WRITETHROUGH 0x01
32 #define CHANNEL_FLAGS_DISCARD_ZEROES 0x02
33 #define CHANNEL_FLAGS_BLOCK_DEVICE 0x04
35 #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
37 struct struct_io_channel {
42 errcode_t (*read_error)(io_channel channel,
47 int actual_bytes_read,
49 errcode_t (*write_error)(io_channel channel,
54 int actual_bytes_written,
64 struct struct_io_stats {
67 unsigned long long bytes_read;
68 unsigned long long bytes_written;
71 struct struct_io_manager {
74 errcode_t (*open)(const char *name, int flags, io_channel *channel);
75 errcode_t (*close)(io_channel channel);
76 errcode_t (*set_blksize)(io_channel channel, int blksize);
77 errcode_t (*read_blk)(io_channel channel, unsigned long block,
78 int count, void *data);
79 errcode_t (*write_blk)(io_channel channel, unsigned long block,
80 int count, const void *data);
81 errcode_t (*flush)(io_channel channel);
82 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
83 int count, const void *data);
84 errcode_t (*set_option)(io_channel channel, const char *option,
86 errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
87 errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
88 int count, void *data);
89 errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
90 int count, const void *data);
91 errcode_t (*discard)(io_channel channel, unsigned long long block,
92 unsigned long long count);
93 errcode_t (*cache_readahead)(io_channel channel,
94 unsigned long long block,
95 unsigned long long count);
96 errcode_t (*zeroout)(io_channel channel, unsigned long long block,
97 unsigned long long count);
101 #define IO_FLAG_RW 0x0001
102 #define IO_FLAG_EXCLUSIVE 0x0002
103 #define IO_FLAG_DIRECT_IO 0x0004
106 * Convenience functions....
108 #define io_channel_close(c) ((c)->manager->close((c)))
109 #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
110 #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
111 #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
112 #define io_channel_flush(c) ((c)->manager->flush((c)))
113 #define io_channel_bumpcount(c) ((c)->refcount++)
116 extern errcode_t io_channel_set_options(io_channel channel,
117 const char *options);
118 extern errcode_t io_channel_write_byte(io_channel channel,
119 unsigned long offset,
120 int count, const void *data);
121 extern errcode_t io_channel_read_blk64(io_channel channel,
122 unsigned long long block,
123 int count, void *data);
124 extern errcode_t io_channel_write_blk64(io_channel channel,
125 unsigned long long block,
126 int count, const void *data);
127 extern errcode_t io_channel_discard(io_channel channel,
128 unsigned long long block,
129 unsigned long long count);
130 extern errcode_t io_channel_zeroout(io_channel channel,
131 unsigned long long block,
132 unsigned long long count);
133 extern errcode_t io_channel_alloc_buf(io_channel channel,
134 int count, void *ptr);
135 extern errcode_t io_channel_cache_readahead(io_channel io,
136 unsigned long long block,
137 unsigned long long count);
140 extern io_manager unix_io_manager;
143 extern io_manager undo_io_manager;
144 extern errcode_t set_undo_io_backing_manager(io_manager manager);
145 extern errcode_t set_undo_io_backup_file(char *file_name);
148 extern io_manager test_io_manager, test_io_backing_manager;
149 extern void (*test_io_cb_read_blk)
150 (unsigned long block, int count, errcode_t err);
151 extern void (*test_io_cb_write_blk)
152 (unsigned long block, int count, errcode_t err);
153 extern void (*test_io_cb_read_blk64)
154 (unsigned long long block, int count, errcode_t err);
155 extern void (*test_io_cb_write_blk64)
156 (unsigned long long block, int count, errcode_t err);
157 extern void (*test_io_cb_set_blksize)
158 (int blksize, errcode_t err);
160 #endif /* _EXT2FS_EXT2_IO_H */