grub2/0167-grub-core-fs-jfs.c-Remove-nested-functions.patch
2013-05-02 16:54:52 -04:00

189 lines
5.8 KiB
Diff
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From f360e6e4d10c7f304127c50e03fd1c84c226f65e Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Thu, 28 Feb 2013 10:51:32 +0100
Subject: [PATCH 167/364] * grub-core/fs/jfs.c: Remove nested functions.
---
ChangeLog | 4 ++
grub-core/fs/jfs.c | 113 +++++++++++++++++++++++++++--------------------------
2 files changed, 61 insertions(+), 56 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 056de9d..6601c42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2013-02-28 Vladimir Serbinenko <phcoder@gmail.com>
+ * grub-core/fs/jfs.c: Remove nested functions.
+
+2013-02-28 Vladimir Serbinenko <phcoder@gmail.com>
+
* grub-core/fs/minix.c: Remove nested functions.
2013-02-28 Vladimir Serbinenko <phcoder@gmail.com>
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
index 88b21ad..4122eff 100644
--- a/grub-core/fs/jfs.c
+++ b/grub-core/fs/jfs.c
@@ -255,60 +255,60 @@ static grub_dl_t my_mod;
static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino);
-/* Get the block number for the block BLK in the node INODE in the
- mounted filesystem DATA. */
static grub_int64_t
-grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
- grub_uint64_t blk)
+getblk (struct grub_jfs_treehead *treehead,
+ struct grub_jfs_tree_extent *extents,
+ struct grub_jfs_data *data,
+ grub_uint64_t blk)
{
- auto grub_int64_t getblk (struct grub_jfs_treehead *treehead,
- struct grub_jfs_tree_extent *extents);
+ int found = -1;
+ int i;
- grub_int64_t getblk (struct grub_jfs_treehead *treehead,
- struct grub_jfs_tree_extent *extents)
+ for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++)
{
- int found = -1;
- int i;
-
- for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++)
+ if (treehead->flags & GRUB_JFS_TREE_LEAF)
{
- if (treehead->flags & GRUB_JFS_TREE_LEAF)
- {
- /* Read the leafnode. */
- if (grub_le_to_cpu32 (extents[i].offset2) <= blk
- && ((grub_le_to_cpu16 (extents[i].extent.length))
- + (extents[i].extent.length2 << 16)
- + grub_le_to_cpu32 (extents[i].offset2)) > blk)
- return (blk - grub_le_to_cpu32 (extents[i].offset2)
- + grub_le_to_cpu32 (extents[i].extent.blk2));
- }
- else
- if (blk >= grub_le_to_cpu32 (extents[i].offset2))
- found = i;
+ /* Read the leafnode. */
+ if (grub_le_to_cpu32 (extents[i].offset2) <= blk
+ && ((grub_le_to_cpu16 (extents[i].extent.length))
+ + (extents[i].extent.length2 << 16)
+ + grub_le_to_cpu32 (extents[i].offset2)) > blk)
+ return (blk - grub_le_to_cpu32 (extents[i].offset2)
+ + grub_le_to_cpu32 (extents[i].extent.blk2));
}
+ else
+ if (blk >= grub_le_to_cpu32 (extents[i].offset2))
+ found = i;
+ }
- if (found != -1)
- {
- struct
- {
- struct grub_jfs_treehead treehead;
- struct grub_jfs_tree_extent extents[254];
- } tree;
-
- if (grub_disk_read (data->disk,
- ((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2))
- << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS), 0,
- sizeof (tree), (char *) &tree))
- return -1;
-
- return getblk (&tree.treehead, &tree.extents[0]);
- }
+ if (found != -1)
+ {
+ struct
+ {
+ struct grub_jfs_treehead treehead;
+ struct grub_jfs_tree_extent extents[254];
+ } tree;
+
+ if (grub_disk_read (data->disk,
+ ((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2))
+ << (grub_le_to_cpu16 (data->sblock.log2_blksz)
+ - GRUB_DISK_SECTOR_BITS), 0,
+ sizeof (tree), (char *) &tree))
+ return -1;
- return -1;
+ return getblk (&tree.treehead, &tree.extents[0], data, blk);
}
- return getblk (&inode->file.tree, &inode->file.extents[0]);
+ return -1;
+}
+
+/* Get the block number for the block BLK in the node INODE in the
+ mounted filesystem DATA. */
+static grub_int64_t
+grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
+ grub_uint64_t blk)
+{
+ return getblk (&inode->file.tree, &inode->file.extents[0], data, blk);
}
@@ -489,6 +489,13 @@ grub_jfs_closedir (struct grub_jfs_diropen *diro)
grub_free (diro);
}
+static void
+le_to_cpu16_copy (grub_uint16_t *out, grub_uint16_t *in, grub_size_t len)
+{
+ while (len--)
+ *out++ = grub_le_to_cpu16 (*in++);
+}
+
/* Read in the next dirent from the directory described by DIRO. */
static grub_err_t
@@ -501,15 +508,6 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
int nextent;
grub_uint16_t filename[256];
- auto void addstr (grub_uint16_t *uname, int ulen);
-
- /* Add the unicode string to the utf16 filename buffer. */
- void addstr (grub_uint16_t *name, int ulen)
- {
- while (ulen--)
- filename[strpos++] = grub_le_to_cpu16 (*(name++));
- }
-
/* The last node, read in more. */
if (diro->index == diro->count)
{
@@ -547,8 +545,10 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
return grub_jfs_getent (diro);
}
- addstr (leaf->namepart, len < diro->data->namecomponentlen ? len
- : diro->data->namecomponentlen);
+ le_to_cpu16_copy (filename + strpos, leaf->namepart, len < diro->data->namecomponentlen ? len
+ : diro->data->namecomponentlen);
+ strpos += len < diro->data->namecomponentlen ? len
+ : diro->data->namecomponentlen;
diro->ino = grub_le_to_cpu32 (leaf->inode);
len -= diro->data->namecomponentlen;
@@ -558,7 +558,8 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
do
{
next_leaf = &diro->next_leaf[nextent];
- addstr (next_leaf->namepart, len < 15 ? len : 15 );
+ le_to_cpu16_copy (filename + strpos, next_leaf->namepart, len < 15 ? len : 15);
+ strpos += len < 15 ? len : 15;
len -= 15;
nextent = next_leaf->next;
--
1.8.1.4