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