grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: grub-devel@gnu.org
Cc: Andrei Borzenkov <arvidjaar@gmail.com>, Jan Kara <jack@suse.cz>
Subject: [PATCH 1/2] xfs: Add helpers for inode size
Date: Wed, 13 May 2015 09:32:47 +0200	[thread overview]
Message-ID: <1431502368-29422-2-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1431502368-29422-1-git-send-email-jack@suse.cz>

Add helpers to return size of XFS inode on disk and when loaded in
memory.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 grub-core/fs/xfs.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index 0d704e9a4d4b..61b4125ef074 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -255,6 +255,24 @@ grub_xfs_inode_offset (struct grub_xfs_data *data,
 	  data->sblock.log2_inode);
 }
 
+static inline grub_size_t
+grub_xfs_inode_size(struct grub_xfs_data *data)
+{
+  return 1 << data->sblock.log2_inode;
+}
+
+/*
+ * Returns size occupied by XFS inode stored in memory - we store struct
+ * grub_fshelp_node there but on disk inode size may be actually larger than
+ * struct grub_xfs_inode so we need to account for that so that we can read
+ * from disk directly into in-memory structure.
+ */
+static inline grub_size_t
+grub_inmem_xfs_inode_size(struct grub_xfs_data *data)
+{
+  return sizeof (struct grub_fshelp_node) - sizeof (struct grub_xfs_inode)
+	       + grub_xfs_inode_size(data);
+}
 
 static grub_err_t
 grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino,
@@ -264,8 +282,8 @@ grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino,
   int offset = grub_xfs_inode_offset (data, ino);
 
   /* Read the inode.  */
-  if (grub_disk_read (data->disk, block, offset,
-		      1 << data->sblock.log2_inode, inode))
+  if (grub_disk_read (data->disk, block, offset, grub_xfs_inode_size(data),
+		      inode))
     return grub_errno;
 
   if (grub_strncmp ((char *) inode->magic, "IN", 2))
@@ -297,7 +315,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
       if (node->inode.fork_offset)
 	recoffset = (node->inode.fork_offset - 1) / 2;
       else
-	recoffset = ((1 << node->data->sblock.log2_inode)
+	recoffset = (grub_xfs_inode_size(node->data)
 		     - ((char *) &node->inode.data.btree.keys
 			- (char *) &node->inode))
 	  / (2 * sizeof (grub_uint64_t));
@@ -456,9 +474,7 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename,
   struct grub_fshelp_node *fdiro;
   grub_err_t err;
 
-  fdiro = grub_malloc (sizeof (struct grub_fshelp_node)
-		       - sizeof (struct grub_xfs_inode)
-		       + (1 << ctx->diro->data->sblock.log2_inode) + 1);
+  fdiro = grub_malloc (grub_inmem_xfs_inode_size(ctx->diro->data) + 1);
   if (!fdiro)
     {
       grub_print_error ();
@@ -682,7 +698,7 @@ grub_xfs_mount (grub_disk_t disk)
   data = grub_realloc (data,
 		       sizeof (struct grub_xfs_data)
 		       - sizeof (struct grub_xfs_inode)
-		       + (1 << data->sblock.log2_inode) + 1);
+		       + grub_xfs_inode_size(data) + 1);
 
   if (! data)
     goto fail;
@@ -797,10 +813,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
 
   if (fdiro != &data->diropen)
     {
-      grub_memcpy (&data->diropen, fdiro,
-		   sizeof (struct grub_fshelp_node)
-		   - sizeof (struct grub_xfs_inode)
-		   + (1 << data->sblock.log2_inode));
+      grub_memcpy (&data->diropen, fdiro, grub_inmem_xfs_inode_size(data));
       grub_free (fdiro);
     }
 
-- 
2.1.4



  reply	other threads:[~2015-05-13  7:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13  7:32 [PATCH 0/2 v2] Support for XFS v5 filesystem Jan Kara
2015-05-13  7:32 ` Jan Kara [this message]
2015-05-30  7:00   ` [PATCH 1/2] xfs: Add helpers for inode size Andrei Borzenkov
2015-06-01 12:22     ` Jan Kara
2015-05-13  7:32 ` [PATCH 2/2] xfs: V5 filesystem format support Jan Kara
2015-05-30  6:59   ` Andrei Borzenkov
2015-06-01 12:20     ` Jan Kara
  -- strict thread matches above, loose matches on Subject: below --
2015-06-01 12:28 [PATCH 0/2 v3] Support for XFS v5 filesystem Jan Kara
2015-06-01 12:28 ` [PATCH 1/2] xfs: Add helpers for inode size Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431502368-29422-2-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).