Blame SOURCES/0169-xfs-Add-helpers-for-inode-size.patch

6b3c76
From bc7e3f1e508c91b9ad7d3459998c5cd31d1caca0 Mon Sep 17 00:00:00 2001
a85e8e
From: Jan Kara <jack@suse.cz>
a85e8e
Date: Mon, 1 Jun 2015 14:28:45 +0200
6b3c76
Subject: [PATCH 169/261] xfs: Add helpers for inode size
a85e8e
a85e8e
Add helpers to return size of XFS inode on disk and when loaded in
a85e8e
memory.
a85e8e
a85e8e
Signed-off-by: Jan Kara <jack@suse.cz>
a85e8e
---
a85e8e
 grub-core/fs/xfs.c | 35 ++++++++++++++++++++++++-----------
a85e8e
 1 file changed, 24 insertions(+), 11 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
6b3c76
index 0d704e9a4..26d8147a9 100644
a85e8e
--- a/grub-core/fs/xfs.c
a85e8e
+++ b/grub-core/fs/xfs.c
a85e8e
@@ -255,6 +255,24 @@ grub_xfs_inode_offset (struct grub_xfs_data *data,
a85e8e
 	  data->sblock.log2_inode);
a85e8e
 }
a85e8e
 
a85e8e
+static inline grub_size_t
a85e8e
+grub_xfs_inode_size(struct grub_xfs_data *data)
a85e8e
+{
a85e8e
+  return 1 << data->sblock.log2_inode;
a85e8e
+}
a85e8e
+
a85e8e
+/*
a85e8e
+ * Returns size occupied by XFS inode stored in memory - we store struct
a85e8e
+ * grub_fshelp_node there but on disk inode size may be actually larger than
a85e8e
+ * struct grub_xfs_inode so we need to account for that so that we can read
a85e8e
+ * from disk directly into in-memory structure.
a85e8e
+ */
a85e8e
+static inline grub_size_t
a85e8e
+grub_xfs_fshelp_size(struct grub_xfs_data *data)
a85e8e
+{
a85e8e
+  return sizeof (struct grub_fshelp_node) - sizeof (struct grub_xfs_inode)
a85e8e
+	       + grub_xfs_inode_size(data);
a85e8e
+}
a85e8e
 
a85e8e
 static grub_err_t
a85e8e
 grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino,
a85e8e
@@ -264,8 +282,8 @@ grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino,
a85e8e
   int offset = grub_xfs_inode_offset (data, ino);
a85e8e
 
a85e8e
   /* Read the inode.  */
a85e8e
-  if (grub_disk_read (data->disk, block, offset,
a85e8e
-		      1 << data->sblock.log2_inode, inode))
a85e8e
+  if (grub_disk_read (data->disk, block, offset, grub_xfs_inode_size(data),
a85e8e
+		      inode))
a85e8e
     return grub_errno;
a85e8e
 
a85e8e
   if (grub_strncmp ((char *) inode->magic, "IN", 2))
a85e8e
@@ -297,7 +315,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
a85e8e
       if (node->inode.fork_offset)
a85e8e
 	recoffset = (node->inode.fork_offset - 1) / 2;
a85e8e
       else
a85e8e
-	recoffset = ((1 << node->data->sblock.log2_inode)
a85e8e
+	recoffset = (grub_xfs_inode_size(node->data)
a85e8e
 		     - ((char *) &node->inode.data.btree.keys
a85e8e
 			- (char *) &node->inode))
a85e8e
 	  / (2 * sizeof (grub_uint64_t));
a85e8e
@@ -456,9 +474,7 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename,
a85e8e
   struct grub_fshelp_node *fdiro;
a85e8e
   grub_err_t err;
a85e8e
 
a85e8e
-  fdiro = grub_malloc (sizeof (struct grub_fshelp_node)
a85e8e
-		       - sizeof (struct grub_xfs_inode)
a85e8e
-		       + (1 << ctx->diro->data->sblock.log2_inode) + 1);
a85e8e
+  fdiro = grub_malloc (grub_xfs_fshelp_size(ctx->diro->data) + 1);
a85e8e
   if (!fdiro)
a85e8e
     {
a85e8e
       grub_print_error ();
a85e8e
@@ -682,7 +698,7 @@ grub_xfs_mount (grub_disk_t disk)
a85e8e
   data = grub_realloc (data,
a85e8e
 		       sizeof (struct grub_xfs_data)
a85e8e
 		       - sizeof (struct grub_xfs_inode)
a85e8e
-		       + (1 << data->sblock.log2_inode) + 1);
a85e8e
+		       + grub_xfs_inode_size(data) + 1);
a85e8e
 
a85e8e
   if (! data)
a85e8e
     goto fail;
a85e8e
@@ -797,10 +813,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
a85e8e
 
a85e8e
   if (fdiro != &data->diropen)
a85e8e
     {
a85e8e
-      grub_memcpy (&data->diropen, fdiro,
a85e8e
-		   sizeof (struct grub_fshelp_node)
a85e8e
-		   - sizeof (struct grub_xfs_inode)
a85e8e
-		   + (1 << data->sblock.log2_inode));
a85e8e
+      grub_memcpy (&data->diropen, fdiro, grub_xfs_fshelp_size(data));
a85e8e
       grub_free (fdiro);
a85e8e
     }
a85e8e
 
6b3c76
-- 
6b3c76
2.13.5
6b3c76