* grub-core/fs/hfsplus.c (grub_hfsplus_btree_iterate_node): Pass
the context through. (grub_hfsplus_iterate_dir): Move nested function out of its parent.
This commit is contained in:
parent
f9b7d78007
commit
e114c3cc54
2 changed files with 139 additions and 117 deletions
|
@ -1,3 +1,9 @@
|
|||
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* grub-core/fs/hfsplus.c (grub_hfsplus_btree_iterate_node): Pass
|
||||
the context through.
|
||||
(grub_hfsplus_iterate_dir): Move nested function out of its parent.
|
||||
|
||||
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* util/grub-editenv.c (list_variables): Move print_var out of its
|
||||
|
|
|
@ -620,7 +620,8 @@ static int
|
|||
grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
|
||||
struct grub_hfsplus_btnode *first_node,
|
||||
grub_disk_addr_t first_rec,
|
||||
int (*hook) (void *record))
|
||||
int (*hook) (void *record, void *hook_arg),
|
||||
void *hook_arg)
|
||||
{
|
||||
grub_disk_addr_t rec;
|
||||
grub_uint64_t saved_node = -1;
|
||||
|
@ -633,7 +634,7 @@ grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
|
|||
/* Iterate over all records in this node. */
|
||||
for (rec = first_rec; rec < grub_be_to_cpu16 (first_node->count); rec++)
|
||||
{
|
||||
if (hook (grub_hfsplus_btree_recptr (btree, first_node, rec)))
|
||||
if (hook (grub_hfsplus_btree_recptr (btree, first_node, rec), hook_arg))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -764,21 +765,24 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
||||
grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
||||
struct list_nodes_ctx
|
||||
{
|
||||
int ret = 0;
|
||||
int ret;
|
||||
grub_fshelp_node_t dir;
|
||||
grub_fshelp_iterate_dir_hook_t hook;
|
||||
void *hook_data;
|
||||
};
|
||||
|
||||
auto int list_nodes (void *record);
|
||||
int list_nodes (void *record)
|
||||
{
|
||||
static int
|
||||
list_nodes (void *record, void *hook_arg)
|
||||
{
|
||||
struct grub_hfsplus_catkey *catkey;
|
||||
char *filename;
|
||||
int i;
|
||||
struct grub_fshelp_node *node;
|
||||
struct grub_hfsplus_catfile *fileinfo;
|
||||
enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
|
||||
struct list_nodes_ctx *ctx = hook_arg;
|
||||
|
||||
catkey = (struct grub_hfsplus_catkey *) record;
|
||||
|
||||
|
@ -789,7 +793,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
% 2));
|
||||
|
||||
/* Stop iterating when the last directory entry is found. */
|
||||
if (grub_be_to_cpu32 (catkey->parent) != dir->fileid)
|
||||
if (grub_be_to_cpu32 (catkey->parent) != ctx->dir->fileid)
|
||||
return 1;
|
||||
|
||||
/* Determine the type of the node that is found. */
|
||||
|
@ -812,18 +816,18 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
type = GRUB_FSHELP_DIR;
|
||||
break;
|
||||
case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR_THREAD):
|
||||
if (dir->fileid == 2)
|
||||
if (ctx->dir->fileid == 2)
|
||||
return 0;
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
return 1;
|
||||
node->data = dir->data;
|
||||
node->data = ctx->dir->data;
|
||||
node->mtime = 0;
|
||||
node->size = 0;
|
||||
node->fileid = grub_be_to_cpu32 (fileinfo->parentid);
|
||||
|
||||
ret = hook ("..", GRUB_FSHELP_DIR, node, hook_data);
|
||||
return ret;
|
||||
ctx->ret = ctx->hook ("..", GRUB_FSHELP_DIR, node, ctx->hook_data);
|
||||
return ctx->ret;
|
||||
}
|
||||
|
||||
if (type == GRUB_FSHELP_UNKNOWN)
|
||||
|
@ -859,7 +863,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
}
|
||||
|
||||
/* hfs+ is case insensitive. */
|
||||
if (! dir->data->case_sensitive)
|
||||
if (! ctx->dir->data->case_sensitive)
|
||||
type |= GRUB_FSHELP_CASE_INSENSITIVE;
|
||||
|
||||
/* A valid node is found; setup the node and call the
|
||||
|
@ -867,7 +871,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
return 1;
|
||||
node->data = dir->data;
|
||||
node->data = ctx->dir->data;
|
||||
|
||||
grub_memcpy (node->extents, fileinfo->data.extents,
|
||||
sizeof (node->extents));
|
||||
|
@ -875,12 +879,24 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
node->size = grub_be_to_cpu64 (fileinfo->data.size);
|
||||
node->fileid = grub_be_to_cpu32 (fileinfo->fileid);
|
||||
|
||||
ret = hook (filename, type, node, hook_data);
|
||||
ctx->ret = ctx->hook (filename, type, node, ctx->hook_data);
|
||||
|
||||
grub_free (filename);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ctx->ret;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
||||
grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
||||
{
|
||||
struct list_nodes_ctx ctx =
|
||||
{
|
||||
.ret = 0,
|
||||
.dir = dir,
|
||||
.hook = hook,
|
||||
.hook_data = hook_data
|
||||
};
|
||||
|
||||
struct grub_hfsplus_key_internal intern;
|
||||
struct grub_hfsplus_btnode *node;
|
||||
|
@ -908,11 +924,11 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|||
|
||||
/* Iterate over all entries in this directory. */
|
||||
grub_hfsplus_btree_iterate_node (&dir->data->catalog_tree, node, ptr,
|
||||
list_nodes);
|
||||
list_nodes, &ctx);
|
||||
|
||||
grub_free (node);
|
||||
|
||||
return ret;
|
||||
return ctx.ret;
|
||||
}
|
||||
|
||||
/* Open a file named NAME and initialize FILE. */
|
||||
|
|
Loading…
Reference in a new issue