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;
30 #define CHANNEL_FLAGS_WRITETHROUGH 0x01
32 struct struct_io_channel {
37 errcode_t (*read_error)(io_channel channel,
42 int actual_bytes_read,
44 errcode_t (*write_error)(io_channel channel,
49 int actual_bytes_written,
58 struct struct_io_manager {
61 errcode_t (*open)(const char *name, int flags, io_channel *channel);
62 errcode_t (*close)(io_channel channel);
63 errcode_t (*set_blksize)(io_channel channel, int blksize);
64 errcode_t (*read_blk)(io_channel channel, unsigned long block,
65 int count, void *data);
66 errcode_t (*write_blk)(io_channel channel, unsigned long block,
67 int count, const void *data);
68 errcode_t (*flush)(io_channel channel);
69 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
70 int count, const void *data);
71 errcode_t (*set_option)(io_channel channel, const char *option,
76 #define IO_FLAG_RW 0x0001
77 #define IO_FLAG_EXCLUSIVE 0x0002
80 * Convenience functions....
82 #define io_channel_close(c) ((c)->manager->close((c)))
83 #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
84 #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
85 #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
86 #define io_channel_flush(c) ((c)->manager->flush((c)))
87 #define io_channel_bumpcount(c) ((c)->refcount++)
90 extern errcode_t io_channel_set_options(io_channel channel,
92 extern errcode_t io_channel_write_byte(io_channel channel,
94 int count, const void *data);
97 extern io_manager unix_io_manager;
100 extern io_manager test_io_manager, test_io_backing_manager;
101 extern void (*test_io_cb_read_blk)
102 (unsigned long block, int count, errcode_t err);
103 extern void (*test_io_cb_write_blk)
104 (unsigned long block, int count, errcode_t err);
105 extern void (*test_io_cb_set_blksize)
106 (int blksize, errcode_t err);
108 #endif /* _EXT2FS_EXT2_IO_H */