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