|
|
f96e0b |
From b84a77fb369ad36eb12126ca42d6b0d31259f71e Mon Sep 17 00:00:00 2001
|
|
|
f96e0b |
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
Date: Fri, 1 Mar 2013 14:02:27 +0100
|
|
|
f96e0b |
Subject: [PATCH 179/482] * grub-core/fs/hfsplus.c
|
|
|
f96e0b |
(grub_hfsplus_btree_iterate_node): Pass the context through.
|
|
|
f96e0b |
(grub_hfsplus_iterate_dir): Move nested function out of its parent.
|
|
|
f96e0b |
|
|
|
f96e0b |
---
|
|
|
f96e0b |
ChangeLog | 6 ++
|
|
|
f96e0b |
grub-core/fs/hfsplus.c | 218 ++++++++++++++++++++++++++-----------------------
|
|
|
f96e0b |
2 files changed, 123 insertions(+), 101 deletions(-)
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f96e0b |
index 0bad8bf..838d8af 100644
|
|
|
f96e0b |
--- a/ChangeLog
|
|
|
f96e0b |
+++ b/ChangeLog
|
|
|
f96e0b |
@@ -1,5 +1,11 @@
|
|
|
f96e0b |
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
|
|
|
f96e0b |
+ * grub-core/fs/hfsplus.c (grub_hfsplus_btree_iterate_node): Pass
|
|
|
f96e0b |
+ the context through.
|
|
|
f96e0b |
+ (grub_hfsplus_iterate_dir): Move nested function out of its parent.
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
* util/grub-editenv.c (list_variables): Move print_var out of its
|
|
|
f96e0b |
parent.
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
|
|
|
f96e0b |
index 29a3a94..a507c0f 100644
|
|
|
f96e0b |
--- a/grub-core/fs/hfsplus.c
|
|
|
f96e0b |
+++ b/grub-core/fs/hfsplus.c
|
|
|
f96e0b |
@@ -620,7 +620,8 @@ static int
|
|
|
f96e0b |
grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
|
|
|
f96e0b |
struct grub_hfsplus_btnode *first_node,
|
|
|
f96e0b |
grub_disk_addr_t first_rec,
|
|
|
f96e0b |
- int (*hook) (void *record))
|
|
|
f96e0b |
+ int (*hook) (void *record, void *hook_arg),
|
|
|
f96e0b |
+ void *hook_arg)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
grub_disk_addr_t rec;
|
|
|
f96e0b |
grub_uint64_t saved_node = -1;
|
|
|
f96e0b |
@@ -633,7 +634,7 @@ grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
|
|
|
f96e0b |
/* Iterate over all records in this node. */
|
|
|
f96e0b |
for (rec = first_rec; rec < grub_be_to_cpu16 (first_node->count); rec++)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- if (hook (grub_hfsplus_btree_recptr (btree, first_node, rec)))
|
|
|
f96e0b |
+ if (hook (grub_hfsplus_btree_recptr (btree, first_node, rec), hook_arg))
|
|
|
f96e0b |
return 1;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
@@ -764,123 +765,138 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
|
|
|
f96e0b |
}
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
+struct list_nodes_ctx
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ int ret;
|
|
|
f96e0b |
+ grub_fshelp_node_t dir;
|
|
|
f96e0b |
+ grub_fshelp_iterate_dir_hook_t hook;
|
|
|
f96e0b |
+ void *hook_data;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
static int
|
|
|
f96e0b |
-grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|
|
f96e0b |
- grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
|
|
f96e0b |
+list_nodes (void *record, void *hook_arg)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- int ret = 0;
|
|
|
f96e0b |
+ struct grub_hfsplus_catkey *catkey;
|
|
|
f96e0b |
+ char *filename;
|
|
|
f96e0b |
+ int i;
|
|
|
f96e0b |
+ struct grub_fshelp_node *node;
|
|
|
f96e0b |
+ struct grub_hfsplus_catfile *fileinfo;
|
|
|
f96e0b |
+ enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
|
|
|
f96e0b |
+ struct list_nodes_ctx *ctx = hook_arg;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ catkey = (struct grub_hfsplus_catkey *) record;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ fileinfo =
|
|
|
f96e0b |
+ (struct grub_hfsplus_catfile *) ((char *) record
|
|
|
f96e0b |
+ + grub_be_to_cpu16 (catkey->keylen)
|
|
|
f96e0b |
+ + 2 + (grub_be_to_cpu16(catkey->keylen)
|
|
|
f96e0b |
+ % 2));
|
|
|
f96e0b |
|
|
|
f96e0b |
- auto int list_nodes (void *record);
|
|
|
f96e0b |
- int list_nodes (void *record)
|
|
|
f96e0b |
+ /* Stop iterating when the last directory entry is found. */
|
|
|
f96e0b |
+ if (grub_be_to_cpu32 (catkey->parent) != ctx->dir->fileid)
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ /* Determine the type of the node that is found. */
|
|
|
f96e0b |
+ switch (fileinfo->type)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- struct grub_hfsplus_catkey *catkey;
|
|
|
f96e0b |
- char *filename;
|
|
|
f96e0b |
- int i;
|
|
|
f96e0b |
- struct grub_fshelp_node *node;
|
|
|
f96e0b |
- struct grub_hfsplus_catfile *fileinfo;
|
|
|
f96e0b |
- enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- catkey = (struct grub_hfsplus_catkey *) record;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- fileinfo =
|
|
|
f96e0b |
- (struct grub_hfsplus_catfile *) ((char *) record
|
|
|
f96e0b |
- + grub_be_to_cpu16 (catkey->keylen)
|
|
|
f96e0b |
- + 2 + (grub_be_to_cpu16(catkey->keylen)
|
|
|
f96e0b |
- % 2));
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- /* Stop iterating when the last directory entry is found. */
|
|
|
f96e0b |
- if (grub_be_to_cpu32 (catkey->parent) != dir->fileid)
|
|
|
f96e0b |
+ case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_REG):
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ int mode = (grub_be_to_cpu16 (fileinfo->mode)
|
|
|
f96e0b |
+ & GRUB_HFSPLUS_FILEMODE_MASK);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (mode == GRUB_HFSPLUS_FILEMODE_REG)
|
|
|
f96e0b |
+ type = GRUB_FSHELP_REG;
|
|
|
f96e0b |
+ else if (mode == GRUB_HFSPLUS_FILEMODE_SYMLINK)
|
|
|
f96e0b |
+ type = GRUB_FSHELP_SYMLINK;
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ type = GRUB_FSHELP_UNKNOWN;
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR):
|
|
|
f96e0b |
+ type = GRUB_FSHELP_DIR;
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR_THREAD):
|
|
|
f96e0b |
+ if (ctx->dir->fileid == 2)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+ node = grub_malloc (sizeof (*node));
|
|
|
f96e0b |
+ if (!node)
|
|
|
f96e0b |
return 1;
|
|
|
f96e0b |
+ node->data = ctx->dir->data;
|
|
|
f96e0b |
+ node->mtime = 0;
|
|
|
f96e0b |
+ node->size = 0;
|
|
|
f96e0b |
+ node->fileid = grub_be_to_cpu32 (fileinfo->parentid);
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* Determine the type of the node that is found. */
|
|
|
f96e0b |
- switch (fileinfo->type)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_REG):
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- int mode = (grub_be_to_cpu16 (fileinfo->mode)
|
|
|
f96e0b |
- & GRUB_HFSPLUS_FILEMODE_MASK);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- if (mode == GRUB_HFSPLUS_FILEMODE_REG)
|
|
|
f96e0b |
- type = GRUB_FSHELP_REG;
|
|
|
f96e0b |
- else if (mode == GRUB_HFSPLUS_FILEMODE_SYMLINK)
|
|
|
f96e0b |
- type = GRUB_FSHELP_SYMLINK;
|
|
|
f96e0b |
- else
|
|
|
f96e0b |
- type = GRUB_FSHELP_UNKNOWN;
|
|
|
f96e0b |
- break;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
- case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR):
|
|
|
f96e0b |
- type = GRUB_FSHELP_DIR;
|
|
|
f96e0b |
- break;
|
|
|
f96e0b |
- case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR_THREAD):
|
|
|
f96e0b |
- if (dir->fileid == 2)
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- node = grub_malloc (sizeof (*node));
|
|
|
f96e0b |
- if (!node)
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- node->data = dir->data;
|
|
|
f96e0b |
- node->mtime = 0;
|
|
|
f96e0b |
- node->size = 0;
|
|
|
f96e0b |
- node->fileid = grub_be_to_cpu32 (fileinfo->parentid);
|
|
|
f96e0b |
+ ctx->ret = ctx->hook ("..", GRUB_FSHELP_DIR, node, ctx->hook_data);
|
|
|
f96e0b |
+ return ctx->ret;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
|
|
|
f96e0b |
- ret = hook ("..", GRUB_FSHELP_DIR, node, hook_data);
|
|
|
f96e0b |
- return ret;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ if (type == GRUB_FSHELP_UNKNOWN)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
|
|
|
f96e0b |
- if (type == GRUB_FSHELP_UNKNOWN)
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
+ filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen)
|
|
|
f96e0b |
+ * GRUB_MAX_UTF8_PER_UTF16 + 1);
|
|
|
f96e0b |
+ if (! filename)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
|
|
|
f96e0b |
- filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen)
|
|
|
f96e0b |
- * GRUB_MAX_UTF8_PER_UTF16 + 1);
|
|
|
f96e0b |
- if (! filename)
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
+ /* Make sure the byte order of the UTF16 string is correct. */
|
|
|
f96e0b |
+ for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* Make sure the byte order of the UTF16 string is correct. */
|
|
|
f96e0b |
- for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
|
|
|
f96e0b |
+ if (catkey->name[i] == '/')
|
|
|
f96e0b |
+ catkey->name[i] = ':';
|
|
|
f96e0b |
|
|
|
f96e0b |
- if (catkey->name[i] == '/')
|
|
|
f96e0b |
- catkey->name[i] = ':';
|
|
|
f96e0b |
+ /* If the name is obviously invalid, skip this node. */
|
|
|
f96e0b |
+ if (catkey->name[i] == 0)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* If the name is obviously invalid, skip this node. */
|
|
|
f96e0b |
- if (catkey->name[i] == 0)
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ *grub_utf16_to_utf8 ((grub_uint8_t *) filename, catkey->name,
|
|
|
f96e0b |
+ grub_be_to_cpu16 (catkey->namelen)) = '\0';
|
|
|
f96e0b |
|
|
|
f96e0b |
- *grub_utf16_to_utf8 ((grub_uint8_t *) filename, catkey->name,
|
|
|
f96e0b |
- grub_be_to_cpu16 (catkey->namelen)) = '\0';
|
|
|
f96e0b |
+ /* Restore the byte order to what it was previously. */
|
|
|
f96e0b |
+ for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ if (catkey->name[i] == ':')
|
|
|
f96e0b |
+ catkey->name[i] = '/';
|
|
|
f96e0b |
+ catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* Restore the byte order to what it was previously. */
|
|
|
f96e0b |
- for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- if (catkey->name[i] == ':')
|
|
|
f96e0b |
- catkey->name[i] = '/';
|
|
|
f96e0b |
- catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ /* hfs+ is case insensitive. */
|
|
|
f96e0b |
+ if (! ctx->dir->data->case_sensitive)
|
|
|
f96e0b |
+ type |= GRUB_FSHELP_CASE_INSENSITIVE;
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* hfs+ is case insensitive. */
|
|
|
f96e0b |
- if (! dir->data->case_sensitive)
|
|
|
f96e0b |
- type |= GRUB_FSHELP_CASE_INSENSITIVE;
|
|
|
f96e0b |
+ /* A valid node is found; setup the node and call the
|
|
|
f96e0b |
+ callback function. */
|
|
|
f96e0b |
+ node = grub_malloc (sizeof (*node));
|
|
|
f96e0b |
+ if (!node)
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+ node->data = ctx->dir->data;
|
|
|
f96e0b |
|
|
|
f96e0b |
- /* A valid node is found; setup the node and call the
|
|
|
f96e0b |
- callback function. */
|
|
|
f96e0b |
- node = grub_malloc (sizeof (*node));
|
|
|
f96e0b |
- if (!node)
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- node->data = dir->data;
|
|
|
f96e0b |
+ grub_memcpy (node->extents, fileinfo->data.extents,
|
|
|
f96e0b |
+ sizeof (node->extents));
|
|
|
f96e0b |
+ node->mtime = grub_be_to_cpu32 (fileinfo->mtime) - 2082844800;
|
|
|
f96e0b |
+ node->size = grub_be_to_cpu64 (fileinfo->data.size);
|
|
|
f96e0b |
+ node->fileid = grub_be_to_cpu32 (fileinfo->fileid);
|
|
|
f96e0b |
|
|
|
f96e0b |
- grub_memcpy (node->extents, fileinfo->data.extents,
|
|
|
f96e0b |
- sizeof (node->extents));
|
|
|
f96e0b |
- node->mtime = grub_be_to_cpu32 (fileinfo->mtime) - 2082844800;
|
|
|
f96e0b |
- node->size = grub_be_to_cpu64 (fileinfo->data.size);
|
|
|
f96e0b |
- node->fileid = grub_be_to_cpu32 (fileinfo->fileid);
|
|
|
f96e0b |
+ ctx->ret = ctx->hook (filename, type, node, ctx->hook_data);
|
|
|
f96e0b |
|
|
|
f96e0b |
- ret = hook (filename, type, node, hook_data);
|
|
|
f96e0b |
+ grub_free (filename);
|
|
|
f96e0b |
|
|
|
f96e0b |
- grub_free (filename);
|
|
|
f96e0b |
+ return ctx->ret;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
|
|
|
f96e0b |
- return ret;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|
|
f96e0b |
+ grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ struct list_nodes_ctx ctx =
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .ret = 0,
|
|
|
f96e0b |
+ .dir = dir,
|
|
|
f96e0b |
+ .hook = hook,
|
|
|
f96e0b |
+ .hook_data = hook_data
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
|
|
|
f96e0b |
struct grub_hfsplus_key_internal intern;
|
|
|
f96e0b |
struct grub_hfsplus_btnode *node;
|
|
|
f96e0b |
@@ -908,11 +924,11 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|
|
f96e0b |
|
|
|
f96e0b |
/* Iterate over all entries in this directory. */
|
|
|
f96e0b |
grub_hfsplus_btree_iterate_node (&dir->data->catalog_tree, node, ptr,
|
|
|
f96e0b |
- list_nodes);
|
|
|
f96e0b |
+ list_nodes, &ctx;;
|
|
|
f96e0b |
|
|
|
f96e0b |
grub_free (node);
|
|
|
f96e0b |
|
|
|
f96e0b |
- return ret;
|
|
|
f96e0b |
+ return ctx.ret;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
/* Open a file named NAME and initialize FILE. */
|
|
|
f96e0b |
--
|
|
|
f96e0b |
1.8.2.1
|
|
|
f96e0b |
|