Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * io.h --- the I/O manager abstraction |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 3 | * |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 */ |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 25 | /* ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int); */ |
| 26 | #ifdef CONFIG_LFS |
| 27 | # define ext2fs_llseek lseek64 |
| 28 | #else |
| 29 | # define ext2fs_llseek lseek |
| 30 | #endif |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 31 | |
| 32 | typedef struct struct_io_manager *io_manager; |
| 33 | typedef struct struct_io_channel *io_channel; |
| 34 | |
| 35 | #define CHANNEL_FLAGS_WRITETHROUGH 0x01 |
| 36 | |
| 37 | struct struct_io_channel { |
| 38 | errcode_t magic; |
| 39 | io_manager manager; |
| 40 | char *name; |
| 41 | int block_size; |
| 42 | errcode_t (*read_error)(io_channel channel, |
| 43 | unsigned long block, |
| 44 | int count, |
| 45 | void *data, |
| 46 | size_t size, |
| 47 | int actual_bytes_read, |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 48 | errcode_t error); |
| 49 | errcode_t (*write_error)(io_channel channel, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 50 | unsigned long block, |
| 51 | int count, |
| 52 | const void *data, |
| 53 | size_t size, |
| 54 | int actual_bytes_written, |
| 55 | errcode_t error); |
| 56 | int refcount; |
| 57 | int flags; |
| 58 | int reserved[14]; |
| 59 | void *private_data; |
| 60 | void *app_data; |
| 61 | }; |
| 62 | |
| 63 | struct struct_io_manager { |
| 64 | errcode_t magic; |
| 65 | const char *name; |
| 66 | errcode_t (*open)(const char *name, int flags, io_channel *channel); |
| 67 | errcode_t (*close)(io_channel channel); |
| 68 | errcode_t (*set_blksize)(io_channel channel, int blksize); |
| 69 | errcode_t (*read_blk)(io_channel channel, unsigned long block, |
| 70 | int count, void *data); |
| 71 | errcode_t (*write_blk)(io_channel channel, unsigned long block, |
| 72 | int count, const void *data); |
| 73 | errcode_t (*flush)(io_channel channel); |
| 74 | errcode_t (*write_byte)(io_channel channel, unsigned long offset, |
| 75 | int count, const void *data); |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 76 | errcode_t (*set_option)(io_channel channel, const char *option, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 77 | const char *arg); |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 78 | int reserved[14]; |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | #define IO_FLAG_RW 1 |
| 82 | |
| 83 | /* |
| 84 | * Convenience functions.... |
| 85 | */ |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 86 | #define io_channel_close(c) ((c)->manager->close((c))) |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 87 | #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s)) |
| 88 | #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d)) |
| 89 | #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d)) |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 90 | #define io_channel_flush(c) ((c)->manager->flush((c))) |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 91 | #define io_channel_bumpcount(c) ((c)->refcount++) |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 92 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 93 | /* io_manager.c */ |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 94 | extern errcode_t io_channel_set_options(io_channel channel, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 95 | const char *options); |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 96 | extern errcode_t io_channel_write_byte(io_channel channel, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 97 | unsigned long offset, |
| 98 | int count, const void *data); |
| 99 | |
| 100 | /* unix_io.c */ |
| 101 | extern io_manager unix_io_manager; |
| 102 | |
| 103 | /* test_io.c */ |
| 104 | extern io_manager test_io_manager, test_io_backing_manager; |
| 105 | extern void (*test_io_cb_read_blk) |
| 106 | (unsigned long block, int count, errcode_t err); |
| 107 | extern void (*test_io_cb_write_blk) |
| 108 | (unsigned long block, int count, errcode_t err); |
| 109 | extern void (*test_io_cb_set_blksize) |
| 110 | (int blksize, errcode_t err); |
| 111 | |
| 112 | #endif /* _EXT2FS_EXT2_IO_H */ |
"Vladimir N. Oleynik" | b71e602 | 2005-09-19 13:48:39 +0000 | [diff] [blame] | 113 | |