31004e6
From 1e33a3f3c57c499e8ef08f438b1de69b6da09f9b Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Sat, 2 Mar 2013 11:31:00 +0100
f74b50e
Subject: [PATCH 180/482] 	* grub-core/fs/hfs.c: Remove nested functions.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog          |   4 +
a5bd9f6
 grub-core/fs/hfs.c | 329 ++++++++++++++++++++++++++++++-----------------------
a5bd9f6
 2 files changed, 192 insertions(+), 141 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 838d8af..0ca4aae 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,7 @@
a5bd9f6
+2013-03-02  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
+	* grub-core/fs/hfs.c: Remove nested functions.
a5bd9f6
+
a5bd9f6
 2013-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
 	* grub-core/fs/hfsplus.c (grub_hfsplus_btree_iterate_node): Pass
a5bd9f6
diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c
a5bd9f6
index 4b2b5aa..73ac7f9 100644
a5bd9f6
--- a/grub-core/fs/hfs.c
a5bd9f6
+++ b/grub-core/fs/hfs.c
a5bd9f6
@@ -161,15 +161,15 @@ struct grub_hfs_filerec
a5bd9f6
 struct grub_hfs_record
a5bd9f6
 {
a5bd9f6
   void *key;
a5bd9f6
-  int keylen;
a5bd9f6
+  grub_size_t keylen;
a5bd9f6
   void *data;
a5bd9f6
-  int datalen;
a5bd9f6
+  grub_size_t datalen;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 static grub_dl_t my_mod;
a5bd9f6
 
a5bd9f6
 static int grub_hfs_find_node (struct grub_hfs_data *, char *,
a5bd9f6
-			       grub_uint32_t, int, char *, int);
a5bd9f6
+			       grub_uint32_t, int, char *, grub_size_t);
a5bd9f6
 
a5bd9f6
 /* Find block BLOCK of the file FILE in the mounted UFS filesystem
a5bd9f6
    DATA.  The first 3 extents are described by DAT.  If cache is set,
a5bd9f6
@@ -396,8 +396,8 @@ grub_hfs_mount (grub_disk_t disk)
a5bd9f6
 
a5bd9f6
 /* Compare the K1 and K2 catalog file keys using HFS character ordering.  */
a5bd9f6
 static int
a5bd9f6
-grub_hfs_cmp_catkeys (struct grub_hfs_catalog_key *k1,
a5bd9f6
-		      struct grub_hfs_catalog_key *k2)
a5bd9f6
+grub_hfs_cmp_catkeys (const struct grub_hfs_catalog_key *k1,
a5bd9f6
+		      const struct grub_hfs_catalog_key *k2)
a5bd9f6
 {
a5bd9f6
   /* Taken from hfsutils 3.2.6 and converted to a readable form */
a5bd9f6
   static const unsigned char hfs_charorder[256] = {
a5bd9f6
@@ -640,8 +640,8 @@ grub_hfs_cmp_catkeys (struct grub_hfs_catalog_key *k1,
a5bd9f6
 
a5bd9f6
 /* Compare the K1 and K2 extent overflow file keys.  */
a5bd9f6
 static int
a5bd9f6
-grub_hfs_cmp_extkeys (struct grub_hfs_extent_key *k1,
a5bd9f6
-		      struct grub_hfs_extent_key *k2)
a5bd9f6
+grub_hfs_cmp_extkeys (const struct grub_hfs_extent_key *k1,
a5bd9f6
+		      const struct grub_hfs_extent_key *k2)
a5bd9f6
 {
a5bd9f6
   int cmp = k1->forktype - k2->forktype;
a5bd9f6
   if (cmp == 0)
a5bd9f6
@@ -660,7 +660,9 @@ grub_hfs_cmp_extkeys (struct grub_hfs_extent_key *k1,
a5bd9f6
 static grub_err_t
a5bd9f6
 grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
a5bd9f6
 			  int this, int (*node_hook) (struct grub_hfs_node *hnd,
a5bd9f6
-						      struct grub_hfs_record *))
a5bd9f6
+						      struct grub_hfs_record *,
a5bd9f6
+						      void *hook_arg),
a5bd9f6
+			  void *hook_arg)
a5bd9f6
 {
a5bd9f6
   int nodesize = type == 0 ? data->cat_size : data->ext_size;
a5bd9f6
 
a5bd9f6
@@ -714,7 +716,7 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
a5bd9f6
 	      - pnt->keylen - 1
a5bd9f6
 	    };
a5bd9f6
 
a5bd9f6
-	  if (node_hook (&node.node, &rec))
a5bd9f6
+	  if (node_hook (&node.node, &rec, hook_arg))
a5bd9f6
 	    return 0;
a5bd9f6
 	}
a5bd9f6
 
a5bd9f6
@@ -724,143 +726,178 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
a5bd9f6
   return 0;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+struct grub_hfs_find_node_node_found_ctx
a5bd9f6
+{
a5bd9f6
+  int found;
a5bd9f6
+  int isleaf;
a5bd9f6
+  int done;
a5bd9f6
+  int type;
a5bd9f6
+  const char *key;
a5bd9f6
+  char *datar;
a5bd9f6
+  grub_size_t datalen;
a5bd9f6
+};
a5bd9f6
 
a5bd9f6
-/* Lookup a record in the mounted filesystem DATA using the key KEY.
a5bd9f6
-   The index of the node on top of the tree is IDX.  The tree is of
a5bd9f6
-   the type TYPE (0 = catalog node, 1 = extent overflow node).  Return
a5bd9f6
-   the data in DATAR with a maximum length of DATALEN.  */
a5bd9f6
 static int
a5bd9f6
-grub_hfs_find_node (struct grub_hfs_data *data, char *key,
a5bd9f6
-		    grub_uint32_t idx, int type, char *datar, int datalen)
a5bd9f6
+grub_hfs_find_node_node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec,
a5bd9f6
+			       void *hook_arg)
a5bd9f6
 {
a5bd9f6
-  int found = -1;
a5bd9f6
-  int isleaf = 0;
a5bd9f6
-  int done = 0;
a5bd9f6
-
a5bd9f6
-  auto int node_found (struct grub_hfs_node *, struct grub_hfs_record *);
a5bd9f6
+  struct grub_hfs_find_node_node_found_ctx *ctx = hook_arg;
a5bd9f6
+  int cmp = 1;
a5bd9f6
 
a5bd9f6
-  int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec)
a5bd9f6
+  if (ctx->type == 0)
a5bd9f6
+    cmp = grub_hfs_cmp_catkeys (rec->key, (const void *) ctx->key);
a5bd9f6
+  else
a5bd9f6
+    cmp = grub_hfs_cmp_extkeys (rec->key, (const void *) ctx->key);
a5bd9f6
+
a5bd9f6
+  /* If the key is smaller or equal to the current node, mark the
a5bd9f6
+     entry.  In case of a non-leaf mode it will be used to lookup
a5bd9f6
+     the rest of the tree.  */
a5bd9f6
+  if (cmp <= 0)
a5bd9f6
+    ctx->found = grub_be_to_cpu32 (grub_get_unaligned32 (rec->data));
a5bd9f6
+  else /* The key can not be found in the tree. */
a5bd9f6
+    return 1;
a5bd9f6
+
a5bd9f6
+  /* Check if this node is a leaf node.  */
a5bd9f6
+  if (hnd->type == GRUB_HFS_NODE_LEAF)
a5bd9f6
     {
a5bd9f6
-      int cmp = 1;
a5bd9f6
-
a5bd9f6
-      if (type == 0)
a5bd9f6
-	cmp = grub_hfs_cmp_catkeys (rec->key, (void *) key);
a5bd9f6
-      else
a5bd9f6
-	cmp = grub_hfs_cmp_extkeys (rec->key, (void *) key);
a5bd9f6
-
a5bd9f6
-      /* If the key is smaller or equal to the current node, mark the
a5bd9f6
-	 entry.  In case of a non-leaf mode it will be used to lookup
a5bd9f6
-	 the rest of the tree.  */
a5bd9f6
-      if (cmp <= 0)
a5bd9f6
-	found = grub_be_to_cpu32 (grub_get_unaligned32 (rec->data));
a5bd9f6
-      else /* The key can not be found in the tree. */
a5bd9f6
-	return 1;
a5bd9f6
-
a5bd9f6
-      /* Check if this node is a leaf node.  */
a5bd9f6
-      if (hnd->type == GRUB_HFS_NODE_LEAF)
a5bd9f6
-	{
a5bd9f6
-	  isleaf = 1;
a5bd9f6
+      ctx->isleaf = 1;
a5bd9f6
 
a5bd9f6
-	  /* Found it!!!!  */
a5bd9f6
-	  if (cmp == 0)
a5bd9f6
-	    {
a5bd9f6
-              done = 1;
a5bd9f6
+      /* Found it!!!!  */
a5bd9f6
+      if (cmp == 0)
a5bd9f6
+	{
a5bd9f6
+	  ctx->done = 1;
a5bd9f6
 
a5bd9f6
-	      grub_memcpy (datar, rec->data,
a5bd9f6
-			   rec->datalen < datalen ? rec->datalen : datalen);
a5bd9f6
-	      return 1;
a5bd9f6
-	    }
a5bd9f6
+	  grub_memcpy (ctx->datar, rec->data,
a5bd9f6
+		       rec->datalen < ctx->datalen ? rec->datalen : ctx->datalen);
a5bd9f6
+	  return 1;
a5bd9f6
 	}
a5bd9f6
-
a5bd9f6
-      return 0;
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+
a5bd9f6
+/* Lookup a record in the mounted filesystem DATA using the key KEY.
a5bd9f6
+   The index of the node on top of the tree is IDX.  The tree is of
a5bd9f6
+   the type TYPE (0 = catalog node, 1 = extent overflow node).  Return
a5bd9f6
+   the data in DATAR with a maximum length of DATALEN.  */
a5bd9f6
+static int
a5bd9f6
+grub_hfs_find_node (struct grub_hfs_data *data, char *key,
a5bd9f6
+		    grub_uint32_t idx, int type, char *datar, grub_size_t datalen)
a5bd9f6
+{
a5bd9f6
+  struct grub_hfs_find_node_node_found_ctx ctx =
a5bd9f6
+    {
a5bd9f6
+      .found = -1,
a5bd9f6
+      .isleaf = 0,
a5bd9f6
+      .done = 0,
a5bd9f6
+      .type = type,
a5bd9f6
+      .key = key,
a5bd9f6
+      .datar = datar,
a5bd9f6
+      .datalen = datalen
a5bd9f6
+    };
a5bd9f6
+
a5bd9f6
   do
a5bd9f6
     {
a5bd9f6
-      found = -1;
a5bd9f6
+      ctx.found = -1;
a5bd9f6
 
a5bd9f6
-      if (grub_hfs_iterate_records (data, type, idx, 0, node_found))
a5bd9f6
+      if (grub_hfs_iterate_records (data, type, idx, 0, grub_hfs_find_node_node_found, &ctx))
a5bd9f6
         return 0;
a5bd9f6
 
a5bd9f6
-      if (found == -1)
a5bd9f6
+      if (ctx.found == -1)
a5bd9f6
         return 0;
a5bd9f6
 
a5bd9f6
-      idx = found;
a5bd9f6
-    } while (! isleaf);
a5bd9f6
+      idx = ctx.found;
a5bd9f6
+    } while (! ctx.isleaf);
a5bd9f6
 
a5bd9f6
-  return done;
a5bd9f6
+  return ctx.done;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+struct grub_hfs_iterate_dir_node_found_ctx
a5bd9f6
+{
a5bd9f6
+  grub_uint32_t dir_be;
a5bd9f6
+  int found;
a5bd9f6
+  int isleaf;
a5bd9f6
+  grub_uint32_t next;
a5bd9f6
+  int (*hook) (struct grub_hfs_record *, void *hook_arg);
a5bd9f6
+  void *hook_arg;
a5bd9f6
+};
a5bd9f6
 
a5bd9f6
-/* Iterate over the directory with the id DIR.  The tree is searched
a5bd9f6
-   starting with the node ROOT_IDX.  For every entry in this directory
a5bd9f6
-   call HOOK.  */
a5bd9f6
-static grub_err_t
a5bd9f6
-grub_hfs_iterate_dir (struct grub_hfs_data *data, grub_uint32_t root_idx,
a5bd9f6
-		      unsigned int dir, int (*hook) (struct grub_hfs_record *))
a5bd9f6
+static int
a5bd9f6
+grub_hfs_iterate_dir_node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec,
a5bd9f6
+				 void *hook_arg)
a5bd9f6
 {
a5bd9f6
-  int found = -1;
a5bd9f6
-  int isleaf = 0;
a5bd9f6
-  int next = 0;
a5bd9f6
+  struct grub_hfs_iterate_dir_node_found_ctx *ctx = hook_arg;
a5bd9f6
+  struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
 
a5bd9f6
   /* The lowest key possible with DIR as root directory.  */
a5bd9f6
-  struct grub_hfs_catalog_key key = {0, grub_cpu_to_be32 (dir), 0, ""};
a5bd9f6
+  const struct grub_hfs_catalog_key key = {0, ctx->dir_be, 0, ""};
a5bd9f6
 
a5bd9f6
-  auto int node_found (struct grub_hfs_node *, struct grub_hfs_record *);
a5bd9f6
-  auto int it_dir (struct grub_hfs_node * __attribute ((unused)),
a5bd9f6
-		   struct grub_hfs_record *);
a5bd9f6
+  if (grub_hfs_cmp_catkeys (rec->key, &key) <= 0)
a5bd9f6
+    ctx->found = grub_be_to_cpu32 (grub_get_unaligned32 (rec->data));
a5bd9f6
 
a5bd9f6
-
a5bd9f6
-  int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec)
a5bd9f6
+  if (hnd->type == 0xFF && ckey->strlen > 0)
a5bd9f6
     {
a5bd9f6
-      struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
-
a5bd9f6
-      if (grub_hfs_cmp_catkeys (rec->key, (void *) &key) <= 0)
a5bd9f6
-	found = grub_be_to_cpu32 (grub_get_unaligned32 (rec->data));
a5bd9f6
+      ctx->isleaf = 1;
a5bd9f6
+      ctx->next = grub_be_to_cpu32 (hnd->next);
a5bd9f6
 
a5bd9f6
-      if (hnd->type == 0xFF && ckey->strlen > 0)
a5bd9f6
-	{
a5bd9f6
-	  isleaf = 1;
a5bd9f6
-	  next = grub_be_to_cpu32 (hnd->next);
a5bd9f6
+      /* An entry was found.  */
a5bd9f6
+      if (ckey->parent_dir == ctx->dir_be)
a5bd9f6
+	return ctx->hook (rec, ctx->hook_arg);
a5bd9f6
+    }
a5bd9f6
 
a5bd9f6
-	  /* An entry was found.  */
a5bd9f6
-	  if (grub_be_to_cpu32 (ckey->parent_dir) == dir)
a5bd9f6
-	    return hook (rec);
a5bd9f6
-	}
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
 
a5bd9f6
-      return 0;
a5bd9f6
-    }
a5bd9f6
+static int
a5bd9f6
+grub_hfs_iterate_dir_it_dir (struct grub_hfs_node *hnd __attribute ((unused)),
a5bd9f6
+			     struct grub_hfs_record *rec,
a5bd9f6
+			     void *hook_arg)
a5bd9f6
+{
a5bd9f6
+  struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
+  struct grub_hfs_iterate_dir_node_found_ctx *ctx = hook_arg;
a5bd9f6
+  
a5bd9f6
+  /* Stop when the entries do not match anymore.  */
a5bd9f6
+  if (ckey->parent_dir != ctx->dir_be)
a5bd9f6
+    return 1;
a5bd9f6
 
a5bd9f6
-  int it_dir (struct grub_hfs_node *hnd __attribute ((unused)),
a5bd9f6
-	      struct grub_hfs_record *rec)
a5bd9f6
-    {
a5bd9f6
-      struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
-      struct grub_hfs_catalog_key *origkey = &ke;;
a5bd9f6
+  return ctx->hook (rec, ctx->hook_arg);
a5bd9f6
+}
a5bd9f6
 
a5bd9f6
-      /* Stop when the entries do not match anymore.  */
a5bd9f6
-      if (grub_be_to_cpu32 (ckey->parent_dir)
a5bd9f6
-	  != grub_be_to_cpu32 ((origkey)->parent_dir))
a5bd9f6
-	return 1;
a5bd9f6
 
a5bd9f6
-      return hook (rec);
a5bd9f6
-    }
a5bd9f6
+/* Iterate over the directory with the id DIR.  The tree is searched
a5bd9f6
+   starting with the node ROOT_IDX.  For every entry in this directory
a5bd9f6
+   call HOOK.  */
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_hfs_iterate_dir (struct grub_hfs_data *data, grub_uint32_t root_idx,
a5bd9f6
+		      grub_uint32_t dir, int (*hook) (struct grub_hfs_record *, void *hook_arg),
a5bd9f6
+		      void *hook_arg)
a5bd9f6
+{
a5bd9f6
+  struct grub_hfs_iterate_dir_node_found_ctx ctx =
a5bd9f6
+  {
a5bd9f6
+    .dir_be = grub_cpu_to_be32 (dir),
a5bd9f6
+    .found = -1,
a5bd9f6
+    .isleaf = 0,
a5bd9f6
+    .next = 0,
a5bd9f6
+    .hook = hook,
a5bd9f6
+    .hook_arg = hook_arg
a5bd9f6
+  };
a5bd9f6
 
a5bd9f6
   do
a5bd9f6
     {
a5bd9f6
-      found = -1;
a5bd9f6
+      ctx.found = -1;
a5bd9f6
 
a5bd9f6
-      if (grub_hfs_iterate_records (data, 0, root_idx, 0, node_found))
a5bd9f6
+      if (grub_hfs_iterate_records (data, 0, root_idx, 0, grub_hfs_iterate_dir_node_found, &ctx))
a5bd9f6
         return grub_errno;
a5bd9f6
 
a5bd9f6
-      if (found == -1)
a5bd9f6
+      if (ctx.found == -1)
a5bd9f6
         return 0;
a5bd9f6
 
a5bd9f6
-      root_idx = found;
a5bd9f6
-    } while (! isleaf);
a5bd9f6
+      root_idx = ctx.found;
a5bd9f6
+    } while (! ctx.isleaf);
a5bd9f6
 
a5bd9f6
   /* If there was a matching record in this leaf node, continue the
a5bd9f6
      iteration until the last record was found.  */
a5bd9f6
-  grub_hfs_iterate_records (data, 0, next, 1, it_dir);
a5bd9f6
+  grub_hfs_iterate_records (data, 0, ctx.next, 1, grub_hfs_iterate_dir_it_dir, &ctx;;
a5bd9f6
   return grub_errno;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
@@ -1148,56 +1185,66 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
a5bd9f6
   return grub_errno;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-
a5bd9f6
-
a5bd9f6
-static grub_err_t
a5bd9f6
-grub_hfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
a5bd9f6
-	      void *hook_data)
a5bd9f6
+struct grub_hfs_dir_hook_ctx
a5bd9f6
 {
a5bd9f6
-  int inode;
a5bd9f6
+  grub_fs_dir_hook_t hook;
a5bd9f6
+  void *hook_data;
a5bd9f6
+};
a5bd9f6
 
a5bd9f6
-  auto int dir_hook (struct grub_hfs_record *rec);
a5bd9f6
+static int
a5bd9f6
+grub_hfs_dir_hook (struct grub_hfs_record *rec, void *hook_arg)
a5bd9f6
+{
a5bd9f6
+  struct grub_hfs_dir_hook_ctx *ctx = hook_arg;
a5bd9f6
+  struct grub_hfs_dirrec *drec = rec->data;
a5bd9f6
+  struct grub_hfs_filerec *frec = rec->data;
a5bd9f6
+  struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
+  char fname[sizeof (ckey->str) * MAX_UTF8_PER_MAC_ROMAN + 1];
a5bd9f6
+  struct grub_dirhook_info info;
a5bd9f6
+  grub_size_t len;
a5bd9f6
 
a5bd9f6
-  int dir_hook (struct grub_hfs_record *rec)
a5bd9f6
-    {
a5bd9f6
-      struct grub_hfs_dirrec *drec = rec->data;
a5bd9f6
-      struct grub_hfs_filerec *frec = rec->data;
a5bd9f6
-      struct grub_hfs_catalog_key *ckey = rec->key;
a5bd9f6
-      char fname[sizeof (ckey->str) * MAX_UTF8_PER_MAC_ROMAN + 1];
a5bd9f6
-      struct grub_dirhook_info info;
a5bd9f6
-      grub_size_t len;
a5bd9f6
+  grub_memset (fname, 0, sizeof (fname));
a5bd9f6
 
a5bd9f6
-      grub_memset (fname, 0, sizeof (fname));
a5bd9f6
+  grub_memset (&info, 0, sizeof (info));
a5bd9f6
 
a5bd9f6
-      grub_memset (&info, 0, sizeof (info));
a5bd9f6
+  len = ckey->strlen;
a5bd9f6
+  if (len > sizeof (ckey->str))
a5bd9f6
+    len = sizeof (ckey->str);
a5bd9f6
+  macroman_to_utf8 (fname, ckey->str, len, 1);
a5bd9f6
 
a5bd9f6
-      len = ckey->strlen;
a5bd9f6
-      if (len > sizeof (ckey->str))
a5bd9f6
-	len = sizeof (ckey->str);
a5bd9f6
-      macroman_to_utf8 (fname, ckey->str, len, 1);
a5bd9f6
+  info.case_insensitive = 1;
a5bd9f6
 
a5bd9f6
-      info.case_insensitive = 1;
a5bd9f6
+  if (drec->type == GRUB_HFS_FILETYPE_DIR)
a5bd9f6
+    {
a5bd9f6
+      info.dir = 1;
a5bd9f6
+      info.mtimeset = 1;
a5bd9f6
+      info.mtime = grub_be_to_cpu32 (drec->mtime) - 2082844800;
a5bd9f6
+      return ctx->hook (fname, &info, ctx->hook_data);
a5bd9f6
+    }
a5bd9f6
+  if (frec->type == GRUB_HFS_FILETYPE_FILE)
a5bd9f6
+    {
a5bd9f6
+      info.dir = 0;
a5bd9f6
+      info.mtimeset = 1;
a5bd9f6
+      info.mtime = grub_be_to_cpu32 (frec->mtime) - 2082844800;
a5bd9f6
+      return ctx->hook (fname, &info, ctx->hook_data);
a5bd9f6
+    }
a5bd9f6
 
a5bd9f6
-      if (drec->type == GRUB_HFS_FILETYPE_DIR)
a5bd9f6
-	{
a5bd9f6
-	  info.dir = 1;
a5bd9f6
-	  info.mtimeset = 1;
a5bd9f6
-	  info.mtime = grub_be_to_cpu32 (drec->mtime) - 2082844800;
a5bd9f6
-	  return hook (fname, &info, hook_data);
a5bd9f6
-	}
a5bd9f6
-      if (frec->type == GRUB_HFS_FILETYPE_FILE)
a5bd9f6
-	{
a5bd9f6
-	  info.dir = 0;
a5bd9f6
-	  info.mtimeset = 1;
a5bd9f6
-	  info.mtime = grub_be_to_cpu32 (frec->mtime) - 2082844800;
a5bd9f6
-	  return hook (fname, &info, hook_data);
a5bd9f6
-	}
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
 
a5bd9f6
-      return 0;
a5bd9f6
-    }
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_hfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
a5bd9f6
+	      void *hook_data)
a5bd9f6
+{
a5bd9f6
+  int inode;
a5bd9f6
 
a5bd9f6
   struct grub_hfs_data *data;
a5bd9f6
   struct grub_hfs_filerec frec;
a5bd9f6
+  struct grub_hfs_dir_hook_ctx ctx =
a5bd9f6
+    {
a5bd9f6
+      .hook = hook,
a5bd9f6
+      .hook_data = hook_data
a5bd9f6
+    };
a5bd9f6
 
a5bd9f6
   grub_dl_ref (my_mod);
a5bd9f6
 
a5bd9f6
@@ -1215,7 +1262,7 @@ grub_hfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
a5bd9f6
       goto fail;
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
-  grub_hfs_iterate_dir (data, data->cat_root, inode, dir_hook);
a5bd9f6
+  grub_hfs_iterate_dir (data, data->cat_root, inode, grub_hfs_dir_hook, &ctx;;
a5bd9f6
 
a5bd9f6
  fail:
a5bd9f6
   grub_free (data);
a5bd9f6
-- 
31004e6
1.8.2.1
a5bd9f6