This patch adds a "readahead" method to the io_manager interface Signed-off-by: Vladimir V. Saveliev vs@clusterfs.com Index: e2fsprogs-1.40.2/lib/ext2fs/ext2_io.h =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/ext2_io.h +++ e2fsprogs-1.40.2/lib/ext2fs/ext2_io.h @@ -68,6 +68,8 @@ struct struct_io_manager { errcode_t (*set_blksize)(io_channel channel, int blksize); errcode_t (*read_blk)(io_channel channel, unsigned long block, int count, void *data); + errcode_t (*readahead)(io_channel channel, unsigned long block, + int count); errcode_t (*write_blk)(io_channel channel, unsigned long block, int count, const void *data); errcode_t (*flush)(io_channel channel); @@ -89,6 +91,7 @@ struct struct_io_manager { #define io_channel_close(c) ((c)->manager->close((c))) #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s)) #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d)) +#define io_channel_readahead(c,b,n) ((c)->manager->readahead((c),b,n)) #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d)) #define io_channel_flush(c) ((c)->manager->flush((c))) #define io_channel_bumpcount(c) ((c)->refcount++) @@ -99,6 +102,8 @@ extern errcode_t io_channel_set_options( extern errcode_t io_channel_write_byte(io_channel channel, unsigned long offset, int count, const void *data); +extern errcode_t readahead_noop(io_channel channel, unsigned long block, + int count); /* unix_io.c */ extern io_manager unix_io_manager; Index: e2fsprogs-1.40.2/lib/ext2fs/unix_io.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/unix_io.c +++ e2fsprogs-1.40.2/lib/ext2fs/unix_io.c @@ -15,6 +15,8 @@ * %End-Header% */ +#define _XOPEN_SOURCE 600 +#define _FILE_OFFSET_BITS 64 #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE @@ -78,6 +80,8 @@ static errcode_t unix_close(io_channel c static errcode_t unix_set_blksize(io_channel channel, int blksize); static errcode_t unix_read_blk(io_channel channel, unsigned long block, int count, void *data); +static errcode_t unix_readahead(io_channel channel, unsigned long block, + int count); static errcode_t unix_write_blk(io_channel channel, unsigned long block, int count, const void *data); static errcode_t unix_flush(io_channel channel); @@ -106,6 +110,7 @@ static struct struct_io_manager struct_u unix_close, unix_set_blksize, unix_read_blk, + unix_readahead, unix_write_blk, unix_flush, #ifdef NEED_BOUNCE_BUFFER @@ -611,6 +616,18 @@ static errcode_t unix_read_blk(io_channe #endif /* NO_IO_CACHE */ } +static errcode_t unix_readahead(io_channel channel, unsigned long block, + int count) +{ + struct unix_private_data *data; + + data = (struct unix_private_data *)channel->private_data; + posix_fadvise(data->dev, (ext2_loff_t)block * channel->block_size, + (ext2_loff_t)count * channel->block_size, + POSIX_FADV_WILLNEED); + return 0; +} + static errcode_t unix_write_blk(io_channel channel, unsigned long block, int count, const void *buf) { Index: e2fsprogs-1.40.2/lib/ext2fs/inode_io.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/inode_io.c +++ e2fsprogs-1.40.2/lib/ext2fs/inode_io.c @@ -64,6 +64,7 @@ static struct struct_io_manager struct_i inode_close, inode_set_blksize, inode_read_blk, + readahead_noop, inode_write_blk, inode_flush, inode_write_byte Index: e2fsprogs-1.40.2/lib/ext2fs/dosio.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/dosio.c +++ e2fsprogs-1.40.2/lib/ext2fs/dosio.c @@ -64,6 +64,7 @@ static struct struct_io_manager struct_d dos_close, dos_set_blksize, dos_read_blk, + readahead_noop, dos_write_blk, dos_flush }; Index: e2fsprogs-1.40.2/lib/ext2fs/nt_io.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/nt_io.c +++ e2fsprogs-1.40.2/lib/ext2fs/nt_io.c @@ -236,6 +236,7 @@ static struct struct_io_manager struct_n nt_close, nt_set_blksize, nt_read_blk, + readahead_noop, nt_write_blk, nt_flush }; Index: e2fsprogs-1.40.2/lib/ext2fs/test_io.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/test_io.c +++ e2fsprogs-1.40.2/lib/ext2fs/test_io.c @@ -74,6 +74,7 @@ static struct struct_io_manager struct_t test_close, test_set_blksize, test_read_blk, + readahead_noop, test_write_blk, test_flush, test_write_byte, Index: e2fsprogs-1.40.2/lib/ext2fs/io_manager.c =================================================================== --- e2fsprogs-1.40.2.orig/lib/ext2fs/io_manager.c +++ e2fsprogs-1.40.2/lib/ext2fs/io_manager.c @@ -67,3 +67,9 @@ errcode_t io_channel_write_byte(io_chann return EXT2_ET_UNIMPLEMENTED; } + +errcode_t readahead_noop(io_channel channel, unsigned long block, + int count) +{ + return 0; +}