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

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