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 Public
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
33 struct struct_io_channel {
38 errcode_t (*read_error)(io_channel channel,
43 int actual_bytes_read,
45 errcode_t (*write_error)(io_channel channel,
50 int actual_bytes_written,
59 struct struct_io_stats {
62 unsigned long long bytes_read;
63 unsigned long long bytes_written;
66 struct struct_io_manager {
69 errcode_t (*open)(const char *name, int flags, io_channel *channel);
70 errcode_t (*close)(io_channel channel);
71 errcode_t (*set_blksize)(io_channel channel, int blksize);
72 errcode_t (*read_blk)(io_channel channel, unsigned long block,
73 int count, void *data);
74 errcode_t (*write_blk)(io_channel channel, unsigned long block,
75 int count, const void *data);
76 errcode_t (*flush)(io_channel channel);
77 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
78 int count, const void *data);
79 errcode_t (*set_option)(io_channel channel, const char *option,
81 errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
82 errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
83 int count, void *data);
84 errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
85 int count, const void *data);
89 #define IO_FLAG_RW 0x0001
90 #define IO_FLAG_EXCLUSIVE 0x0002
93 * Convenience functions....
95 #define io_channel_close(c) ((c)->manager->close((c)))
96 #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
97 #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
98 #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
99 #define io_channel_flush(c) ((c)->manager->flush((c)))
100 #define io_channel_bumpcount(c) ((c)->refcount++)
103 extern errcode_t io_channel_set_options(io_channel channel,
104 const char *options);
105 extern errcode_t io_channel_write_byte(io_channel channel,
106 unsigned long offset,
107 int count, const void *data);
108 extern errcode_t io_channel_read_blk64(io_channel channel,
109 unsigned long long block,
110 int count, void *data);
111 extern errcode_t io_channel_write_blk64(io_channel channel,
112 unsigned long long block,
113 int count, const void *data);
116 extern io_manager unix_io_manager;
119 extern io_manager undo_io_manager;
120 extern errcode_t set_undo_io_backing_manager(io_manager manager);
121 extern errcode_t set_undo_io_backup_file(char *file_name);
124 extern io_manager test_io_manager, test_io_backing_manager;
125 extern void (*test_io_cb_read_blk)
126 (unsigned long block, int count, errcode_t err);
127 extern void (*test_io_cb_write_blk)
128 (unsigned long block, int count, errcode_t err);
129 extern void (*test_io_cb_set_blksize)
130 (int blksize, errcode_t err);
132 #endif /* _EXT2FS_EXT2_IO_H */