unix_io.c: Add #ifdef NO_IO_CACHE which disables all userspace
caching by the unix_io layer. Not enabled, only for
debugging.
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index ae498da..b2deb70 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -278,6 +278,7 @@
}
}
+#ifndef NO_IO_CACHE
/*
* Try to find a block in the cache. If the block is not found, and
* eldest is a non-zero pointer, then fill in eldest with the cache
@@ -358,6 +359,7 @@
}
return retval2;
}
+#endif /* NO_IO_CACHE */
static errcode_t unix_open(const char *name, int flags, io_channel *channel)
{
@@ -471,7 +473,9 @@
if (--channel->refcount > 0)
return 0;
+#ifndef NO_IO_CACHE
retval = flush_cached_blocks(channel, data, 0);
+#endif
if (close(data->dev) < 0)
retval = errno;
@@ -494,8 +498,10 @@
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
if (channel->block_size != blksize) {
+#ifndef NO_IO_CACHE
if ((retval = flush_cached_blocks(channel, data, 0)))
return retval;
+#endif
channel->block_size = blksize;
free_cache(channel, data);
@@ -519,6 +525,9 @@
data = (struct unix_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+#ifdef NO_IO_CACHE
+ return raw_read_blk(channel, data, block, count, buf);
+#else
/*
* If we're doing an odd-sized read or a very large read,
* flush out the cache and then do a direct read.
@@ -567,6 +576,7 @@
}
}
return 0;
+#endif /* NO_IO_CACHE */
}
static errcode_t unix_write_blk(io_channel channel, unsigned long block,
@@ -582,6 +592,9 @@
data = (struct unix_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+#ifdef NO_IO_CACHE
+ return raw_write_blk(channel, data, block, count, buf);
+#else
/*
* If we're doing an odd-sized write or a very large write,
* flush out the cache completely and then do a direct write.
@@ -615,6 +628,7 @@
cp += channel->block_size;
}
return retval;
+#endif /* NO_IO_CACHE */
}
static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
@@ -628,11 +642,13 @@
data = (struct unix_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+#ifndef NO_IO_CACHE
/*
* Flush out the cache completely
*/
if ((retval = flush_cached_blocks(channel, data, 1)))
return retval;
+#endif
if (lseek(data->dev, offset, SEEK_SET) < 0)
return errno;
@@ -656,7 +672,9 @@
data = (struct unix_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+#ifndef NO_IO_CACHE
retval = flush_cached_blocks(channel, data, 0);
+#endif
fsync(data->dev);
return retval;
}