Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * io.h --- the I/O manager abstraction |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 3 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. |
| 5 | * |
| 6 | * %Begin-Header% |
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 7 | * This file may be redistributed under the terms of the GNU Library |
| 8 | * General Public License, version 2. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Theodore Ts'o | 9abd2ce | 1998-02-16 22:00:37 +0000 | [diff] [blame] | 12 | #ifndef _EXT2FS_EXT2_IO_H |
| 13 | #define _EXT2FS_EXT2_IO_H |
| 14 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 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 */ |
Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 25 | ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 26 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 27 | typedef struct struct_io_manager *io_manager; |
| 28 | typedef struct struct_io_channel *io_channel; |
Theodore Ts'o | 6d96b00 | 2007-08-03 20:07:09 -0400 | [diff] [blame] | 29 | typedef struct struct_io_stats *io_stats; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 30 | |
Theodore Ts'o | adfc8c6 | 2000-10-18 19:22:24 +0000 | [diff] [blame] | 31 | #define CHANNEL_FLAGS_WRITETHROUGH 0x01 |
Lukas Czerner | d866599 | 2010-11-18 03:38:37 +0000 | [diff] [blame] | 32 | #define CHANNEL_FLAGS_DISCARD_ZEROES 0x02 |
Lukas Czerner | d2bfdc7 | 2011-09-15 23:44:59 -0400 | [diff] [blame] | 33 | #define CHANNEL_FLAGS_BLOCK_DEVICE 0x04 |
Lukas Czerner | d866599 | 2010-11-18 03:38:37 +0000 | [diff] [blame] | 34 | |
| 35 | #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES) |
Theodore Ts'o | adfc8c6 | 2000-10-18 19:22:24 +0000 | [diff] [blame] | 36 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 37 | struct struct_io_channel { |
Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 38 | errcode_t magic; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 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, |
| 48 | errcode_t error); |
| 49 | errcode_t (*write_error)(io_channel channel, |
| 50 | unsigned long block, |
| 51 | int count, |
| 52 | const void *data, |
| 53 | size_t size, |
| 54 | int actual_bytes_written, |
| 55 | errcode_t error); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 56 | int refcount; |
Theodore Ts'o | adfc8c6 | 2000-10-18 19:22:24 +0000 | [diff] [blame] | 57 | int flags; |
Theodore Ts'o | 4690e62 | 2008-08-27 21:46:26 -0400 | [diff] [blame] | 58 | long reserved[14]; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 59 | void *private_data; |
Theodore Ts'o | e9affb7 | 1997-08-24 02:57:55 +0000 | [diff] [blame] | 60 | void *app_data; |
Theodore Ts'o | 0a05b90 | 2012-05-07 12:56:07 -0400 | [diff] [blame] | 61 | int align; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Theodore Ts'o | 6d96b00 | 2007-08-03 20:07:09 -0400 | [diff] [blame] | 64 | struct struct_io_stats { |
| 65 | int num_fields; |
| 66 | int reserved; |
| 67 | unsigned long long bytes_read; |
| 68 | unsigned long long bytes_written; |
| 69 | }; |
| 70 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 71 | struct struct_io_manager { |
Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 72 | errcode_t magic; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 73 | const char *name; |
| 74 | errcode_t (*open)(const char *name, int flags, io_channel *channel); |
| 75 | errcode_t (*close)(io_channel channel); |
| 76 | errcode_t (*set_blksize)(io_channel channel, int blksize); |
| 77 | errcode_t (*read_blk)(io_channel channel, unsigned long block, |
| 78 | int count, void *data); |
| 79 | errcode_t (*write_blk)(io_channel channel, unsigned long block, |
| 80 | int count, const void *data); |
| 81 | errcode_t (*flush)(io_channel channel); |
Theodore Ts'o | c180ac8 | 2000-10-26 20:24:43 +0000 | [diff] [blame] | 82 | errcode_t (*write_byte)(io_channel channel, unsigned long offset, |
| 83 | int count, const void *data); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 84 | errcode_t (*set_option)(io_channel channel, const char *option, |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 85 | const char *arg); |
Theodore Ts'o | 6d96b00 | 2007-08-03 20:07:09 -0400 | [diff] [blame] | 86 | errcode_t (*get_stats)(io_channel channel, io_stats *io_stats); |
Jose R. Santos | 3154e1c | 2008-03-03 10:41:18 -0600 | [diff] [blame] | 87 | errcode_t (*read_blk64)(io_channel channel, unsigned long long block, |
| 88 | int count, void *data); |
| 89 | errcode_t (*write_blk64)(io_channel channel, unsigned long long block, |
| 90 | int count, const void *data); |
Lukas Czerner | e90a59e | 2010-11-18 03:38:36 +0000 | [diff] [blame] | 91 | errcode_t (*discard)(io_channel channel, unsigned long long block, |
| 92 | unsigned long long count); |
Theodore Ts'o | 4690e62 | 2008-08-27 21:46:26 -0400 | [diff] [blame] | 93 | long reserved[16]; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Theodore Ts'o | fa6c653 | 2006-03-18 18:57:44 -0500 | [diff] [blame] | 96 | #define IO_FLAG_RW 0x0001 |
| 97 | #define IO_FLAG_EXCLUSIVE 0x0002 |
Theodore Ts'o | 7f1a1fb | 2010-09-24 10:02:25 -0400 | [diff] [blame] | 98 | #define IO_FLAG_DIRECT_IO 0x0004 |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Convenience functions.... |
| 102 | */ |
| 103 | #define io_channel_close(c) ((c)->manager->close((c))) |
| 104 | #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s)) |
| 105 | #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d)) |
| 106 | #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d)) |
| 107 | #define io_channel_flush(c) ((c)->manager->flush((c))) |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 108 | #define io_channel_bumpcount(c) ((c)->refcount++) |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 109 | |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 110 | /* io_manager.c */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 111 | extern errcode_t io_channel_set_options(io_channel channel, |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 112 | const char *options); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 113 | extern errcode_t io_channel_write_byte(io_channel channel, |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 114 | unsigned long offset, |
| 115 | int count, const void *data); |
Theodore Ts'o | 4690e62 | 2008-08-27 21:46:26 -0400 | [diff] [blame] | 116 | extern errcode_t io_channel_read_blk64(io_channel channel, |
| 117 | unsigned long long block, |
| 118 | int count, void *data); |
| 119 | extern errcode_t io_channel_write_blk64(io_channel channel, |
| 120 | unsigned long long block, |
| 121 | int count, const void *data); |
Theodore Ts'o | aa07cb7 | 2011-02-27 20:09:54 -0500 | [diff] [blame] | 122 | extern errcode_t io_channel_discard(io_channel channel, |
| 123 | unsigned long long block, |
| 124 | unsigned long long count); |
Theodore Ts'o | fd1c5a0 | 2012-05-07 14:41:49 -0400 | [diff] [blame] | 125 | extern errcode_t io_channel_alloc_buf(io_channel channel, |
| 126 | int count, void *ptr); |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 127 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 128 | /* unix_io.c */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 129 | extern io_manager unix_io_manager; |
| 130 | |
Aneesh Kumar K.V | 72a168b | 2007-08-13 15:56:21 +0530 | [diff] [blame] | 131 | /* undo_io.c */ |
| 132 | extern io_manager undo_io_manager; |
| 133 | extern errcode_t set_undo_io_backing_manager(io_manager manager); |
| 134 | extern errcode_t set_undo_io_backup_file(char *file_name); |
| 135 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 136 | /* test_io.c */ |
| 137 | extern io_manager test_io_manager, test_io_backing_manager; |
| 138 | extern void (*test_io_cb_read_blk) |
| 139 | (unsigned long block, int count, errcode_t err); |
| 140 | extern void (*test_io_cb_write_blk) |
| 141 | (unsigned long block, int count, errcode_t err); |
Valerie Aurora Henson | 8f82ef9 | 2009-08-05 00:27:10 -0400 | [diff] [blame] | 142 | extern void (*test_io_cb_read_blk64) |
| 143 | (unsigned long long block, int count, errcode_t err); |
| 144 | extern void (*test_io_cb_write_blk64) |
| 145 | (unsigned long long block, int count, errcode_t err); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 146 | extern void (*test_io_cb_set_blksize) |
| 147 | (int blksize, errcode_t err); |
Theodore Ts'o | 9abd2ce | 1998-02-16 22:00:37 +0000 | [diff] [blame] | 148 | |
| 149 | #endif /* _EXT2FS_EXT2_IO_H */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 150 | |