Whamcloud - gitweb
Fix superblock field s_blocks_count for bigalloc file systems
[tools/e2fsprogs.git] / lib / ext2fs / undo_io.c
index e1e6458..454f3b6 100644 (file)
@@ -6,8 +6,8 @@
  * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
+#ifdef __GNUC__
+#define ATTR(x) __attribute__(x)
+#else
+#define ATTR(x)
+#endif
+
 /*
  * For checking structure magic numbers...
  */
@@ -67,6 +73,10 @@ struct undo_private_data {
 static errcode_t undo_open(const char *name, int flags, io_channel *channel);
 static errcode_t undo_close(io_channel channel);
 static errcode_t undo_set_blksize(io_channel channel, int blksize);
+static errcode_t undo_read_blk64(io_channel channel, unsigned long long block,
+                                int count, void *data);
+static errcode_t undo_write_blk64(io_channel channel, unsigned long long block,
+                                 int count, const void *data);
 static errcode_t undo_read_blk(io_channel channel, unsigned long block,
                               int count, void *data);
 static errcode_t undo_write_blk(io_channel channel, unsigned long block,
@@ -76,6 +86,7 @@ static errcode_t undo_write_byte(io_channel channel, unsigned long offset,
                                int size, const void *data);
 static errcode_t undo_set_option(io_channel channel, const char *option,
                                 const char *arg);
+static errcode_t undo_get_stats(io_channel channel, io_stats *stats);
 
 static struct struct_io_manager struct_undo_manager = {
        EXT2_ET_MAGIC_IO_MANAGER,
@@ -87,7 +98,10 @@ static struct struct_io_manager struct_undo_manager = {
        undo_write_blk,
        undo_flush,
        undo_write_byte,
-       undo_set_option
+       undo_set_option,
+       undo_get_stats,
+       undo_read_blk64,
+       undo_write_blk64,
 };
 
 io_manager undo_io_manager = &struct_undo_manager;
@@ -95,6 +109,10 @@ static io_manager undo_io_backing_manager ;
 static char *tdb_file;
 static int actual_size;
 
+static unsigned char mtime_key[] = "filesystem MTIME";
+static unsigned char blksize_key[] = "filesystem BLKSIZE";
+static unsigned char uuid_key[] = "filesystem UUID";
+
 errcode_t set_undo_io_backing_manager(io_manager manager)
 {
        /*
@@ -130,13 +148,13 @@ static errcode_t write_file_system_identity(io_channel undo_channel,
        block_size = channel->block_size;
 
        io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
-       retval = io_channel_read_blk(channel, 1, -SUPERBLOCK_SIZE, &super);
+       retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super);
        if (retval)
                goto err_out;
 
        /* Write to tdb file in the file system byte order */
-       tdb_key.dptr = "filesystem MTIME";
-       tdb_key.dsize = sizeof("filesystem MTIME");
+       tdb_key.dptr = mtime_key;
+       tdb_key.dsize = sizeof(mtime_key);
        tdb_data.dptr = (unsigned char *) &(super.s_mtime);
        tdb_data.dsize = sizeof(super.s_mtime);
 
@@ -146,8 +164,8 @@ static errcode_t write_file_system_identity(io_channel undo_channel,
                goto err_out;
        }
 
-       tdb_key.dptr = "filesystem UUID";
-       tdb_key.dsize = sizeof("filesystem UUID");
+       tdb_key.dptr = uuid_key;
+       tdb_key.dsize = sizeof(uuid_key);
        tdb_data.dptr = (unsigned char *)&(super.s_uuid);
        tdb_data.dsize = sizeof(super.s_uuid);
 
@@ -166,8 +184,8 @@ static errcode_t write_block_size(TDB_CONTEXT *tdb, int block_size)
        errcode_t retval;
        TDB_DATA tdb_key, tdb_data;
 
-       tdb_key.dptr = "filesystem BLKSIZE";
-       tdb_key.dsize = sizeof("filesystem BLKSIZE");
+       tdb_key.dptr = blksize_key;
+       tdb_key.dsize = sizeof(blksize_key);
        tdb_data.dptr = (unsigned char *)&(block_size);
        tdb_data.dsize = sizeof(block_size);
 
@@ -180,17 +198,17 @@ static errcode_t write_block_size(TDB_CONTEXT *tdb, int block_size)
 }
 
 static errcode_t undo_write_tdb(io_channel channel,
-                               unsigned long block, int count)
+                               unsigned long long block, int count)
 
 {
-       int size, i, sz;
-       unsigned long block_num, backing_blk_num;
+       int size, sz;
+       unsigned long long block_num, backing_blk_num;
        errcode_t retval = 0;
        ext2_loff_t offset;
        struct undo_private_data *data;
        TDB_DATA tdb_key, tdb_data;
-       char *read_ptr;
-       unsigned long end_block;
+       unsigned char *read_ptr;
+       unsigned long long end_block;
 
        data = (struct undo_private_data *) channel->private_data;
 
@@ -256,7 +274,7 @@ static errcode_t undo_write_tdb(io_channel channel,
                        sz = count / channel->block_size;
                else
                        sz = -count;
-               retval = io_channel_read_blk(data->real, backing_blk_num,
+               retval = io_channel_read_blk64(data->real, backing_blk_num,
                                             sz, read_ptr);
                if (retval) {
                        if (retval != EXT2_ET_SHORT_READ) {
@@ -275,7 +293,7 @@ static errcode_t undo_write_tdb(io_channel channel,
                tdb_data.dptr = read_ptr +
                                ((offset - data->offset) % channel->block_size);
 #ifdef DEBUG
-               printf("Printing with key %ld data %x and size %d\n",
+               printf("Printing with key %lld data %x and size %d\n",
                       block_num,
                       tdb_data.dptr,
                       tdb_data.dsize);
@@ -312,9 +330,13 @@ static errcode_t undo_write_tdb(io_channel channel,
        return retval;
 }
 
-static errcode_t undo_io_read_error(io_channel channel,
-                       unsigned long block, int count, void *data,
-                       size_t size, int actual, errcode_t error)
+static errcode_t undo_io_read_error(io_channel channel ATTR((unused)),
+                                   unsigned long block ATTR((unused)),
+                                   int count ATTR((unused)),
+                                   void *data ATTR((unused)),
+                                   size_t size ATTR((unused)),
+                                   int actual,
+                                   errcode_t error ATTR((unused)))
 {
        actual_size = actual;
        return error;
@@ -330,8 +352,6 @@ static errcode_t undo_open(const char *name, int flags, io_channel *channel)
        io_channel      io = NULL;
        struct undo_private_data *data = NULL;
        errcode_t       retval;
-       int             open_flags;
-       struct stat     st;
 
        if (name == 0)
                return EXT2_ET_BAD_DEVICE_NAME;
@@ -425,7 +445,7 @@ static errcode_t undo_close(io_channel channel)
 static errcode_t undo_set_blksize(io_channel channel, int blksize)
 {
        struct undo_private_data *data;
-       errcode_t               retval;
+       errcode_t               retval = 0;
 
        EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
        data = (struct undo_private_data *) channel->private_data;
@@ -443,10 +463,10 @@ static errcode_t undo_set_blksize(io_channel channel, int blksize)
        return retval;
 }
 
-static errcode_t undo_read_blk(io_channel channel, unsigned long block,
+static errcode_t undo_read_blk64(io_channel channel, unsigned long long block,
                               int count, void *buf)
 {
-       errcode_t       retval;
+       errcode_t       retval = 0;
        struct undo_private_data *data;
 
        EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
@@ -454,12 +474,18 @@ static errcode_t undo_read_blk(io_channel channel, unsigned long block,
        EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
 
        if (data->real)
-               retval = io_channel_read_blk(data->real, block, count, buf);
+               retval = io_channel_read_blk64(data->real, block, count, buf);
 
        return retval;
 }
 
-static errcode_t undo_write_blk(io_channel channel, unsigned long block,
+static errcode_t undo_read_blk(io_channel channel, unsigned long block,
+                              int count, void *buf)
+{
+       return undo_read_blk64(channel, block, count, buf);
+}
+
+static errcode_t undo_write_blk64(io_channel channel, unsigned long long block,
                                int count, const void *buf)
 {
        struct undo_private_data *data;
@@ -475,17 +501,22 @@ static errcode_t undo_write_blk(io_channel channel, unsigned long block,
        if (retval)
                 return retval;
        if (data->real)
-               retval = io_channel_write_blk(data->real, block, count, buf);
+               retval = io_channel_write_blk64(data->real, block, count, buf);
 
        return retval;
 }
 
+static errcode_t undo_write_blk(io_channel channel, unsigned long block,
+                               int count, const void *buf)
+{
+       return undo_write_blk64(channel, block, count, buf);
+}
+
 static errcode_t undo_write_byte(io_channel channel, unsigned long offset,
                                 int size, const void *buf)
 {
        struct undo_private_data *data;
        errcode_t       retval = 0;
-       ssize_t         actual;
        ext2_loff_t     location;
        unsigned long blk_num, count;;
 
@@ -573,3 +604,18 @@ static errcode_t undo_set_option(io_channel channel, const char *option,
        }
        return retval;
 }
+
+static errcode_t undo_get_stats(io_channel channel, io_stats *stats)
+{
+       errcode_t       retval = 0;
+       struct undo_private_data *data;
+
+       EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+       data = (struct undo_private_data *) channel->private_data;
+       EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+
+       if (data->real)
+               retval = (data->real->manager->get_stats)(data->real, stats);
+
+       return retval;
+}