Whamcloud - gitweb
ChangeLog, bitops.h, ext2fs.h, icount.c, version.c:
[tools/e2fsprogs.git] / lib / ext2fs / ext2_io.h
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 Public
8  * License.
9  * %End-Header%
10  */
11
12 /*
13  * ext2_loff_t is defined here since unix_io.c needs it.
14  */
15 #if defined(__GNUC__) || defined(HAS_LONG_LONG)
16 typedef long long       ext2_loff_t;
17 #else
18 typedef long            ext2_loff_t;
19 #endif
20
21 /* llseek.c */
22 ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
23
24 typedef struct struct_io_manager *io_manager;
25 typedef struct struct_io_channel *io_channel;
26
27 struct struct_io_channel {
28         errcode_t       magic;
29         io_manager      manager;
30         char            *name;
31         int             block_size;
32         errcode_t       (*read_error)(io_channel channel,
33                                       unsigned long block,
34                                       int count,
35                                       void *data,
36                                       size_t size,
37                                       int actual_bytes_read,
38                                       errcode_t error);
39         errcode_t       (*write_error)(io_channel channel,
40                                        unsigned long block,
41                                        int count,
42                                        const void *data,
43                                        size_t size,
44                                        int actual_bytes_written,
45                                        errcode_t error);
46         int             refcount;
47         int             reserved[15];
48         void            *private_data;
49         void            *app_data;
50 };
51
52 struct struct_io_manager {
53         errcode_t magic;
54         const char *name;
55         errcode_t (*open)(const char *name, int flags, io_channel *channel);
56         errcode_t (*close)(io_channel channel);
57         errcode_t (*set_blksize)(io_channel channel, int blksize);
58         errcode_t (*read_blk)(io_channel channel, unsigned long block,
59                               int count, void *data);
60         errcode_t (*write_blk)(io_channel channel, unsigned long block,
61                                int count, const void *data);
62         errcode_t (*flush)(io_channel channel);
63         int             reserved[16];
64 };
65
66 #define IO_FLAG_RW      1
67
68 /*
69  * Convenience functions....
70  */
71 #define io_channel_close(c)             ((c)->manager->close((c)))
72 #define io_channel_set_blksize(c,s)     ((c)->manager->set_blksize((c),s))
73 #define io_channel_read_blk(c,b,n,d)    ((c)->manager->read_blk((c),b,n,d))
74 #define io_channel_write_blk(c,b,n,d)   ((c)->manager->write_blk((c),b,n,d))
75 #define io_channel_flush(c)             ((c)->manager->flush((c)))
76 #define io_channel_bumpcount(c)         ((c)->refcount++)
77         
78 /* unix_io.c */
79 extern io_manager unix_io_manager;
80
81 /* test_io.c */
82 extern io_manager test_io_manager, test_io_backing_manager;
83 extern void (*test_io_cb_read_blk)
84         (unsigned long block, int count, errcode_t err);
85 extern void (*test_io_cb_write_blk)
86         (unsigned long block, int count, errcode_t err);
87 extern void (*test_io_cb_set_blksize)
88         (int blksize, errcode_t err);