Whamcloud - gitweb
libext2fs: allocate clusters to files in expand_dir.c and mkjournal.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 Library
8  * General Public License, version 2.
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 typedef struct struct_io_stats *io_stats;
30
31 #define CHANNEL_FLAGS_WRITETHROUGH      0x01
32 #define CHANNEL_FLAGS_DISCARD_ZEROES    0x02
33
34 #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
35
36 struct struct_io_channel {
37         errcode_t       magic;
38         io_manager      manager;
39         char            *name;
40         int             block_size;
41         errcode_t       (*read_error)(io_channel channel,
42                                       unsigned long block,
43                                       int count,
44                                       void *data,
45                                       size_t size,
46                                       int actual_bytes_read,
47                                       errcode_t error);
48         errcode_t       (*write_error)(io_channel channel,
49                                        unsigned long block,
50                                        int count,
51                                        const void *data,
52                                        size_t size,
53                                        int actual_bytes_written,
54                                        errcode_t error);
55         int             refcount;
56         int             flags;
57         long            reserved[14];
58         void            *private_data;
59         void            *app_data;
60 };
61
62 struct struct_io_stats {
63         int                     num_fields;
64         int                     reserved;
65         unsigned long long      bytes_read;
66         unsigned long long      bytes_written;
67 };
68
69 struct struct_io_manager {
70         errcode_t magic;
71         const char *name;
72         errcode_t (*open)(const char *name, int flags, io_channel *channel);
73         errcode_t (*close)(io_channel channel);
74         errcode_t (*set_blksize)(io_channel channel, int blksize);
75         errcode_t (*read_blk)(io_channel channel, unsigned long block,
76                               int count, void *data);
77         errcode_t (*write_blk)(io_channel channel, unsigned long block,
78                                int count, const void *data);
79         errcode_t (*flush)(io_channel channel);
80         errcode_t (*write_byte)(io_channel channel, unsigned long offset,
81                                 int count, const void *data);
82         errcode_t (*set_option)(io_channel channel, const char *option,
83                                 const char *arg);
84         errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
85         errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
86                                         int count, void *data);
87         errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
88                                         int count, const void *data);
89         errcode_t (*discard)(io_channel channel, unsigned long long block,
90                              unsigned long long count);
91         long    reserved[16];
92 };
93
94 #define IO_FLAG_RW              0x0001
95 #define IO_FLAG_EXCLUSIVE       0x0002
96 #define IO_FLAG_DIRECT_IO       0x0004
97
98 /*
99  * Convenience functions....
100  */
101 #define io_channel_close(c)             ((c)->manager->close((c)))
102 #define io_channel_set_blksize(c,s)     ((c)->manager->set_blksize((c),s))
103 #define io_channel_read_blk(c,b,n,d)    ((c)->manager->read_blk((c),b,n,d))
104 #define io_channel_write_blk(c,b,n,d)   ((c)->manager->write_blk((c),b,n,d))
105 #define io_channel_flush(c)             ((c)->manager->flush((c)))
106 #define io_channel_bumpcount(c)         ((c)->refcount++)
107
108 /* io_manager.c */
109 extern errcode_t io_channel_set_options(io_channel channel,
110                                         const char *options);
111 extern errcode_t io_channel_write_byte(io_channel channel,
112                                        unsigned long offset,
113                                        int count, const void *data);
114 extern errcode_t io_channel_read_blk64(io_channel channel,
115                                        unsigned long long block,
116                                        int count, void *data);
117 extern errcode_t io_channel_write_blk64(io_channel channel,
118                                         unsigned long long block,
119                                         int count, const void *data);
120 extern errcode_t io_channel_discard(io_channel channel,
121                                     unsigned long long block,
122                                     unsigned long long count);
123
124 /* unix_io.c */
125 extern io_manager unix_io_manager;
126
127 /* undo_io.c */
128 extern io_manager undo_io_manager;
129 extern errcode_t set_undo_io_backing_manager(io_manager manager);
130 extern errcode_t set_undo_io_backup_file(char *file_name);
131
132 /* test_io.c */
133 extern io_manager test_io_manager, test_io_backing_manager;
134 extern void (*test_io_cb_read_blk)
135         (unsigned long block, int count, errcode_t err);
136 extern void (*test_io_cb_write_blk)
137         (unsigned long block, int count, errcode_t err);
138 extern void (*test_io_cb_read_blk64)
139         (unsigned long long block, int count, errcode_t err);
140 extern void (*test_io_cb_write_blk64)
141         (unsigned long long block, int count, errcode_t err);
142 extern void (*test_io_cb_set_blksize)
143         (int blksize, errcode_t err);
144
145 #endif /* _EXT2FS_EXT2_IO_H */
146