Skip to content

Commit d76aa04

Browse files
committed
优化 squashfs 解压流程, 提高程序启动速度.
1 parent 64a0dca commit d76aa04

File tree

2 files changed

+562
-504
lines changed

2 files changed

+562
-504
lines changed

module/squashfs/squashfs.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ typedef struct {
2525
} squashfs_compressor_stub_t;
2626

2727
static void squashfs_open(void *parent, const char *name, vfs_node_t node);
28+
static squashfs_handle_t *
29+
squashfs_handle_create(squashfs_mount_t *mount, sqfs_inode_generic_t *inode, const sqfs_u64 inode_ref);
2830

2931
static void squashfs_handle_release(squashfs_handle_t *handle) {
3032
if (handle == NULL) {
@@ -404,10 +406,23 @@ int squashfs_populate_dir(const vfs_node_t node, const squashfs_handle_t *handle
404406
if (!squashfs_child_exists(node, (const char *)ent->name)) {
405407
const vfs_node_t child = vfs_child_append(node, (const char *)ent->name, NULL);
406408
if (child != NULL) {
409+
sqfs_inode_generic_t *child_inode = NULL;
410+
squashfs_handle_t *child_handle = NULL;
411+
407412
child->fsid = squashfs_id;
408413
child->dev = node->dev;
409414
child->type = squashfs_map_inode_type(ent->type);
410415
child->visited = true;
416+
417+
if (squashfs_open_inode(handle->mount, state.ent_ref, &child_inode) == 0) {
418+
child_handle = squashfs_handle_create(handle->mount, child_inode, state.ent_ref);
419+
if (child_handle != NULL) {
420+
child->handle = child_handle;
421+
squashfs_fill_node(child, child_handle);
422+
} else {
423+
sqfs_free(child_inode);
424+
}
425+
}
411426
}
412427
}
413428

@@ -603,6 +618,9 @@ static void squashfs_open(void *parent, const char *name, vfs_node_t node) {
603618
return;
604619
}
605620

621+
if (node->handle != NULL) {
622+
return;
623+
}
606624
int ret =
607625
squashfs_lookup_child(parent_handle->mount, parent_handle->inode, name, &inode_ref, &inode);
608626
if (ret != 0) {
@@ -627,8 +645,8 @@ static void squashfs_open(void *parent, const char *name, vfs_node_t node) {
627645
}
628646

629647
static bool squashfs_close(void *current) {
630-
squashfs_handle_release(current);
631-
return true;
648+
(void)current;
649+
return false;
632650
}
633651

634652
static size_t squashfs_read(void *file, void *addr, size_t offset, size_t size) {

0 commit comments

Comments
 (0)