dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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