1*6a54128fSAndroid Build Coastguard Worker /* 2*6a54128fSAndroid Build Coastguard Worker * io.h --- the I/O manager abstraction 3*6a54128fSAndroid Build Coastguard Worker * 4*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. 5*6a54128fSAndroid Build Coastguard Worker * 6*6a54128fSAndroid Build Coastguard Worker * %Begin-Header% 7*6a54128fSAndroid Build Coastguard Worker * This file may be redistributed under the terms of the GNU Library 8*6a54128fSAndroid Build Coastguard Worker * General Public License, version 2. 9*6a54128fSAndroid Build Coastguard Worker * %End-Header% 10*6a54128fSAndroid Build Coastguard Worker */ 11*6a54128fSAndroid Build Coastguard Worker 12*6a54128fSAndroid Build Coastguard Worker #ifndef _EXT2FS_EXT2_IO_H 13*6a54128fSAndroid Build Coastguard Worker #define _EXT2FS_EXT2_IO_H 14*6a54128fSAndroid Build Coastguard Worker 15*6a54128fSAndroid Build Coastguard Worker #include <ext2fs/ext2_types.h> 16*6a54128fSAndroid Build Coastguard Worker 17*6a54128fSAndroid Build Coastguard Worker /* 18*6a54128fSAndroid Build Coastguard Worker * ext2_loff_t is defined here since unix_io.c needs it. 19*6a54128fSAndroid Build Coastguard Worker */ 20*6a54128fSAndroid Build Coastguard Worker #if defined(__GNUC__) || defined(HAS_LONG_LONG) 21*6a54128fSAndroid Build Coastguard Worker typedef long long ext2_loff_t; 22*6a54128fSAndroid Build Coastguard Worker #else 23*6a54128fSAndroid Build Coastguard Worker typedef long ext2_loff_t; 24*6a54128fSAndroid Build Coastguard Worker #endif 25*6a54128fSAndroid Build Coastguard Worker 26*6a54128fSAndroid Build Coastguard Worker /* llseek.c */ 27*6a54128fSAndroid Build Coastguard Worker ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int); 28*6a54128fSAndroid Build Coastguard Worker 29*6a54128fSAndroid Build Coastguard Worker typedef struct struct_io_manager *io_manager; 30*6a54128fSAndroid Build Coastguard Worker typedef struct struct_io_channel *io_channel; 31*6a54128fSAndroid Build Coastguard Worker typedef struct struct_io_stats *io_stats; 32*6a54128fSAndroid Build Coastguard Worker 33*6a54128fSAndroid Build Coastguard Worker #define CHANNEL_FLAGS_WRITETHROUGH 0x01 34*6a54128fSAndroid Build Coastguard Worker #define CHANNEL_FLAGS_DISCARD_ZEROES 0x02 35*6a54128fSAndroid Build Coastguard Worker #define CHANNEL_FLAGS_BLOCK_DEVICE 0x04 36*6a54128fSAndroid Build Coastguard Worker #define CHANNEL_FLAGS_THREADS 0x08 37*6a54128fSAndroid Build Coastguard Worker 38*6a54128fSAndroid Build Coastguard Worker #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES) 39*6a54128fSAndroid Build Coastguard Worker 40*6a54128fSAndroid Build Coastguard Worker struct struct_io_channel { 41*6a54128fSAndroid Build Coastguard Worker errcode_t magic; 42*6a54128fSAndroid Build Coastguard Worker io_manager manager; 43*6a54128fSAndroid Build Coastguard Worker char *name; 44*6a54128fSAndroid Build Coastguard Worker int block_size; 45*6a54128fSAndroid Build Coastguard Worker errcode_t (*read_error)(io_channel channel, 46*6a54128fSAndroid Build Coastguard Worker unsigned long block, 47*6a54128fSAndroid Build Coastguard Worker int count, 48*6a54128fSAndroid Build Coastguard Worker void *data, 49*6a54128fSAndroid Build Coastguard Worker size_t size, 50*6a54128fSAndroid Build Coastguard Worker int actual_bytes_read, 51*6a54128fSAndroid Build Coastguard Worker errcode_t error); 52*6a54128fSAndroid Build Coastguard Worker errcode_t (*write_error)(io_channel channel, 53*6a54128fSAndroid Build Coastguard Worker unsigned long block, 54*6a54128fSAndroid Build Coastguard Worker int count, 55*6a54128fSAndroid Build Coastguard Worker const void *data, 56*6a54128fSAndroid Build Coastguard Worker size_t size, 57*6a54128fSAndroid Build Coastguard Worker int actual_bytes_written, 58*6a54128fSAndroid Build Coastguard Worker errcode_t error); 59*6a54128fSAndroid Build Coastguard Worker int refcount; 60*6a54128fSAndroid Build Coastguard Worker int flags; 61*6a54128fSAndroid Build Coastguard Worker long reserved[14]; 62*6a54128fSAndroid Build Coastguard Worker void *private_data; 63*6a54128fSAndroid Build Coastguard Worker void *app_data; 64*6a54128fSAndroid Build Coastguard Worker int align; 65*6a54128fSAndroid Build Coastguard Worker }; 66*6a54128fSAndroid Build Coastguard Worker 67*6a54128fSAndroid Build Coastguard Worker struct struct_io_stats { 68*6a54128fSAndroid Build Coastguard Worker int num_fields; 69*6a54128fSAndroid Build Coastguard Worker int reserved; 70*6a54128fSAndroid Build Coastguard Worker unsigned long long bytes_read; 71*6a54128fSAndroid Build Coastguard Worker unsigned long long bytes_written; 72*6a54128fSAndroid Build Coastguard Worker }; 73*6a54128fSAndroid Build Coastguard Worker 74*6a54128fSAndroid Build Coastguard Worker struct struct_io_manager { 75*6a54128fSAndroid Build Coastguard Worker errcode_t magic; 76*6a54128fSAndroid Build Coastguard Worker const char *name; 77*6a54128fSAndroid Build Coastguard Worker errcode_t (*open)(const char *name, int flags, io_channel *channel); 78*6a54128fSAndroid Build Coastguard Worker errcode_t (*close)(io_channel channel); 79*6a54128fSAndroid Build Coastguard Worker errcode_t (*set_blksize)(io_channel channel, int blksize); 80*6a54128fSAndroid Build Coastguard Worker errcode_t (*read_blk)(io_channel channel, unsigned long block, 81*6a54128fSAndroid Build Coastguard Worker int count, void *data); 82*6a54128fSAndroid Build Coastguard Worker errcode_t (*write_blk)(io_channel channel, unsigned long block, 83*6a54128fSAndroid Build Coastguard Worker int count, const void *data); 84*6a54128fSAndroid Build Coastguard Worker errcode_t (*flush)(io_channel channel); 85*6a54128fSAndroid Build Coastguard Worker errcode_t (*write_byte)(io_channel channel, unsigned long offset, 86*6a54128fSAndroid Build Coastguard Worker int count, const void *data); 87*6a54128fSAndroid Build Coastguard Worker errcode_t (*set_option)(io_channel channel, const char *option, 88*6a54128fSAndroid Build Coastguard Worker const char *arg); 89*6a54128fSAndroid Build Coastguard Worker errcode_t (*get_stats)(io_channel channel, io_stats *io_stats); 90*6a54128fSAndroid Build Coastguard Worker errcode_t (*read_blk64)(io_channel channel, unsigned long long block, 91*6a54128fSAndroid Build Coastguard Worker int count, void *data); 92*6a54128fSAndroid Build Coastguard Worker errcode_t (*write_blk64)(io_channel channel, unsigned long long block, 93*6a54128fSAndroid Build Coastguard Worker int count, const void *data); 94*6a54128fSAndroid Build Coastguard Worker errcode_t (*discard)(io_channel channel, unsigned long long block, 95*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 96*6a54128fSAndroid Build Coastguard Worker errcode_t (*cache_readahead)(io_channel channel, 97*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 98*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 99*6a54128fSAndroid Build Coastguard Worker errcode_t (*zeroout)(io_channel channel, unsigned long long block, 100*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 101*6a54128fSAndroid Build Coastguard Worker long reserved[14]; 102*6a54128fSAndroid Build Coastguard Worker }; 103*6a54128fSAndroid Build Coastguard Worker 104*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_RW 0x0001 105*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_EXCLUSIVE 0x0002 106*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_DIRECT_IO 0x0004 107*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_FORCE_BOUNCE 0x0008 108*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_THREADS 0x0010 109*6a54128fSAndroid Build Coastguard Worker #define IO_FLAG_NOCACHE 0x0020 110*6a54128fSAndroid Build Coastguard Worker 111*6a54128fSAndroid Build Coastguard Worker /* 112*6a54128fSAndroid Build Coastguard Worker * Convenience functions.... 113*6a54128fSAndroid Build Coastguard Worker */ 114*6a54128fSAndroid Build Coastguard Worker #define io_channel_close(c) ((c)->manager->close((c))) 115*6a54128fSAndroid Build Coastguard Worker #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s)) 116*6a54128fSAndroid Build Coastguard Worker #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d)) 117*6a54128fSAndroid Build Coastguard Worker #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d)) 118*6a54128fSAndroid Build Coastguard Worker #define io_channel_flush(c) ((c)->manager->flush((c))) 119*6a54128fSAndroid Build Coastguard Worker #define io_channel_bumpcount(c) ((c)->refcount++) 120*6a54128fSAndroid Build Coastguard Worker 121*6a54128fSAndroid Build Coastguard Worker /* io_manager.c */ 122*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_set_options(io_channel channel, 123*6a54128fSAndroid Build Coastguard Worker const char *options); 124*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_write_byte(io_channel channel, 125*6a54128fSAndroid Build Coastguard Worker unsigned long offset, 126*6a54128fSAndroid Build Coastguard Worker int count, const void *data); 127*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_read_blk64(io_channel channel, 128*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 129*6a54128fSAndroid Build Coastguard Worker int count, void *data); 130*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_write_blk64(io_channel channel, 131*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 132*6a54128fSAndroid Build Coastguard Worker int count, const void *data); 133*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_discard(io_channel channel, 134*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 135*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 136*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_zeroout(io_channel channel, 137*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 138*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 139*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_alloc_buf(io_channel channel, 140*6a54128fSAndroid Build Coastguard Worker int count, void *ptr); 141*6a54128fSAndroid Build Coastguard Worker extern errcode_t io_channel_cache_readahead(io_channel io, 142*6a54128fSAndroid Build Coastguard Worker unsigned long long block, 143*6a54128fSAndroid Build Coastguard Worker unsigned long long count); 144*6a54128fSAndroid Build Coastguard Worker 145*6a54128fSAndroid Build Coastguard Worker #ifdef _WIN32 146*6a54128fSAndroid Build Coastguard Worker /* windows_io.c */ 147*6a54128fSAndroid Build Coastguard Worker extern io_manager windows_io_manager; 148*6a54128fSAndroid Build Coastguard Worker #define default_io_manager windows_io_manager 149*6a54128fSAndroid Build Coastguard Worker #else 150*6a54128fSAndroid Build Coastguard Worker /* unix_io.c */ 151*6a54128fSAndroid Build Coastguard Worker extern io_manager unix_io_manager; 152*6a54128fSAndroid Build Coastguard Worker extern io_manager unixfd_io_manager; 153*6a54128fSAndroid Build Coastguard Worker #define default_io_manager unix_io_manager 154*6a54128fSAndroid Build Coastguard Worker #endif 155*6a54128fSAndroid Build Coastguard Worker 156*6a54128fSAndroid Build Coastguard Worker /* sparse_io.c */ 157*6a54128fSAndroid Build Coastguard Worker extern io_manager sparse_io_manager; 158*6a54128fSAndroid Build Coastguard Worker extern io_manager sparsefd_io_manager; 159*6a54128fSAndroid Build Coastguard Worker 160*6a54128fSAndroid Build Coastguard Worker /* undo_io.c */ 161*6a54128fSAndroid Build Coastguard Worker extern io_manager undo_io_manager; 162*6a54128fSAndroid Build Coastguard Worker extern errcode_t set_undo_io_backing_manager(io_manager manager); 163*6a54128fSAndroid Build Coastguard Worker extern errcode_t set_undo_io_backup_file(char *file_name); 164*6a54128fSAndroid Build Coastguard Worker 165*6a54128fSAndroid Build Coastguard Worker /* test_io.c */ 166*6a54128fSAndroid Build Coastguard Worker extern io_manager test_io_manager, test_io_backing_manager; 167*6a54128fSAndroid Build Coastguard Worker extern void (*test_io_cb_read_blk) 168*6a54128fSAndroid Build Coastguard Worker (unsigned long block, int count, errcode_t err); 169*6a54128fSAndroid Build Coastguard Worker extern void (*test_io_cb_write_blk) 170*6a54128fSAndroid Build Coastguard Worker (unsigned long block, int count, errcode_t err); 171*6a54128fSAndroid Build Coastguard Worker extern void (*test_io_cb_read_blk64) 172*6a54128fSAndroid Build Coastguard Worker (unsigned long long block, int count, errcode_t err); 173*6a54128fSAndroid Build Coastguard Worker extern void (*test_io_cb_write_blk64) 174*6a54128fSAndroid Build Coastguard Worker (unsigned long long block, int count, errcode_t err); 175*6a54128fSAndroid Build Coastguard Worker extern void (*test_io_cb_set_blksize) 176*6a54128fSAndroid Build Coastguard Worker (int blksize, errcode_t err); 177*6a54128fSAndroid Build Coastguard Worker 178*6a54128fSAndroid Build Coastguard Worker #endif /* _EXT2FS_EXT2_IO_H */ 179*6a54128fSAndroid Build Coastguard Worker 180