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