Whamcloud - gitweb
libext2fs: fix Direct I/O fallback code so it implements RMW correctly
[tools/e2fsprogs.git] / lib / ext2fs / io_manager.c
index 6d0e234..34e4859 100644 (file)
@@ -2,6 +2,7 @@
  * io_manager.c --- the I/O manager abstraction
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
@@ -99,3 +100,31 @@ errcode_t io_channel_write_blk64(io_channel channel, unsigned long long block,
        return (channel->manager->write_blk)(channel, (unsigned long) block,
                                             count, data);
 }
+
+errcode_t io_channel_discard(io_channel channel, unsigned long long block,
+                            unsigned long long count)
+{
+       EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+
+       if (channel->manager->discard)
+               return (channel->manager->discard)(channel, block, count);
+
+       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);
+}