aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ext2fs/io_manager.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2012-05-07 14:41:49 -0400
committerTheodore Ts'o <tytso@mit.edu>2012-05-07 14:41:49 -0400
commitfd1c5a0622a9578b86f695d2f60df7d4f8b21875 (patch)
treea10fcc8c682038a203e59c511fe09752e9284dad /lib/ext2fs/io_manager.c
parent07d120848d143c40feb55be31f0f0bb1ad1ec6f9 (diff)
downloadandroid_external_e2fsprogs-fd1c5a0622a9578b86f695d2f60df7d4f8b21875.tar.gz
android_external_e2fsprogs-fd1c5a0622a9578b86f695d2f60df7d4f8b21875.tar.bz2
android_external_e2fsprogs-fd1c5a0622a9578b86f695d2f60df7d4f8b21875.zip
libext2fs: factor out I/O buffer allocation
Create a new function, io_channel_alloc_buf() which allocates I/O buffers with appropriate alignment if we are using direct I/O. The original code was sometimes using a larger alignment factor than necessary, and would always request an aligned memory buffer even when it was not necessary since the block device was not opened with O_DIRECT. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/io_manager.c')
-rw-r--r--lib/ext2fs/io_manager.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/ext2fs/io_manager.c b/lib/ext2fs/io_manager.c
index 25df59ec..34e48592 100644
--- a/lib/ext2fs/io_manager.c
+++ b/lib/ext2fs/io_manager.c
@@ -111,3 +111,20 @@ errcode_t io_channel_discard(io_channel channel, unsigned long long block,
return EXT2_ET_UNIMPLEMENTED;
}
+
+errcode_t io_channel_alloc_buf(io_channel io, int count, void *ptr)
+{
+ size_t size;
+
+ if (count == 0)
+ size = io->block_size;
+ else if (count > 0)
+ size = io->block_size * count;
+ else
+ size = -count;
+
+ if (io->align)
+ return ext2fs_get_memalign(size, io->align, ptr);
+ else
+ return ext2fs_get_mem(size, ptr);
+}