From 901a2e2652c2a45837bd155aa2c028c68bc8ad48 Mon Sep 17 00:00:00 2001 From: renxudong Date: Sun, 11 Aug 2019 01:11:24 -0400 Subject: [PATCH 4/8] unsquashfs-move-fs-table-reading-into-the-version-sp --- squashfs-tools/unsquash-1.c | 25 +++++++++++++++++-------- squashfs-tools/unsquash-2.c | 24 +++++++++++++++++++++++- squashfs-tools/unsquash-3.c | 22 ++++++++++++++++++++++ squashfs-tools/unsquash-4.c | 29 +++++++++++++++++++++++++++++ squashfs-tools/unsquashfs.c | 34 ++++++---------------------------- squashfs-tools/unsquashfs.h | 15 +++++++++------ 6 files changed, 106 insertions(+), 43 deletions(-) diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c index 41888fb..bf3589d 100644 --- a/squashfs-tools/unsquash-1.c +++ b/squashfs-tools/unsquash-1.c @@ -46,14 +46,6 @@ void read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks) } -int read_fragment_table_1(long long *directory_table_end) -{ - TRACE("read_fragment_table\n"); - *directory_table_end = sBlk.s.fragment_table_start; - return TRUE; -} - - struct inode *read_inode_1(unsigned int start_block, unsigned int offset) { static union squashfs_inode_header_1 header; @@ -359,3 +351,20 @@ int read_uids_guids_1() return TRUE; } + + +int read_filesystem_tables_1() +{ + if(read_uids_guids_1() == FALSE) + return FALSE; + + if(read_inode_table(sBlk.s.inode_table_start, + sBlk.s.directory_table_start) == FALSE) + return FALSE; + + if(read_directory_table(sBlk.s.directory_table_start, + sBlk.uid_start) == FALSE) + return FALSE; + + return TRUE; +} diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c index 0f2bfe8..9b4ade4 100644 --- a/squashfs-tools/unsquash-2.c +++ b/squashfs-tools/unsquash-2.c @@ -2,7 +2,7 @@ * Unsquash a squashfs filesystem. This is a highly compressed read only * filesystem. * - * Copyright (c) 2009, 2010, 2013 + * Copyright (c) 2009, 2010, 2013, 2019 * Phillip Lougher * * This program is free software; you can redistribute it and/or @@ -268,3 +268,25 @@ struct inode *read_inode_2(unsigned int start_block, unsigned int offset) } return &i; } + + +int read_filesystem_tables_2() +{ + long long directory_table_end; + + if(read_uids_guids_1() == FALSE) + return FALSE; + + if(read_fragment_table_2(&directory_table_end) == FALSE) + return FALSE; + + if(read_inode_table(sBlk.s.inode_table_start, + sBlk.s.directory_table_start) == FALSE) + return FALSE; + + if(read_directory_table(sBlk.s.directory_table_start, + directory_table_end) == FALSE) + return FALSE; + + return TRUE; +} diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c index ac04a6a..622ce1e 100644 --- a/squashfs-tools/unsquash-3.c +++ b/squashfs-tools/unsquash-3.c @@ -395,3 +395,25 @@ corrupted: free(dir); return NULL; } + + +int read_filesystem_tables_3() +{ + long long directory_table_end; + + if(read_uids_guids_1() == FALSE) + return FALSE; + + if(read_fragment_table_3(&directory_table_end) == FALSE) + return FALSE; + + if(read_inode_table(sBlk.s.inode_table_start, + sBlk.s.directory_table_start) == FALSE) + return FALSE; + + if(read_directory_table(sBlk.s.directory_table_start, + directory_table_end) == FALSE) + return FALSE; + + return TRUE; +} diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c index 05b0c5d..0f51888 100644 --- a/squashfs-tools/unsquash-4.c +++ b/squashfs-tools/unsquash-4.c @@ -24,6 +24,7 @@ #include "unsquashfs.h" #include "squashfs_swap.h" +#include "xattr.h" static struct squashfs_fragment_entry *fragment_table; static unsigned int *id_table; @@ -399,3 +400,31 @@ int read_uids_guids_4() return TRUE; } + + +int read_filesystem_tables_4() +{ + long long directory_table_end; + + if(read_uids_guids_4() == FALSE) + return FALSE; + + if(read_fragment_table_4(&directory_table_end) == FALSE) + return FALSE; + + if(read_inode_table(sBlk.s.inode_table_start, + sBlk.s.directory_table_start) == FALSE) + return FALSE; + + if(read_directory_table(sBlk.s.directory_table_start, + directory_table_end) == FALSE) + return FALSE; + + if(no_xattrs) + sBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK; + + if(read_xattrs_from_disk(fd, &sBlk.s) == 0) + return FALSE; + + return TRUE; +} diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c index 57cf2bc..875a6cd 100644 --- a/squashfs-tools/unsquashfs.c +++ b/squashfs-tools/unsquashfs.c @@ -1788,12 +1788,11 @@ int read_super(char *source) if(sBlk_4.s_magic == SQUASHFS_MAGIC && sBlk_4.s_major == 4 && sBlk_4.s_minor == 0) { + s_ops.read_filesystem_tables = read_filesystem_tables_4; s_ops.squashfs_opendir = squashfs_opendir_4; s_ops.read_fragment = read_fragment_4; - s_ops.read_fragment_table = read_fragment_table_4; s_ops.read_block_list = read_block_list_2; s_ops.read_inode = read_inode_4; - s_ops.read_uids_guids = read_uids_guids_4; memcpy(&sBlk, &sBlk_4, sizeof(sBlk_4)); /* @@ -1861,28 +1860,25 @@ int read_super(char *source) if(sBlk.s.s_major == 1) { sBlk.s.block_size = sBlk_3.block_size_1; sBlk.s.fragment_table_start = sBlk.uid_start; + s_ops.read_filesystem_tables = read_filesystem_tables_1; s_ops.squashfs_opendir = squashfs_opendir_1; - s_ops.read_fragment_table = read_fragment_table_1; s_ops.read_block_list = read_block_list_1; s_ops.read_inode = read_inode_1; - s_ops.read_uids_guids = read_uids_guids_1; } else { sBlk.s.fragment_table_start = sBlk_3.fragment_table_start_2; + s_ops.read_filesystem_tables = read_filesystem_tables_2; s_ops.squashfs_opendir = squashfs_opendir_1; s_ops.read_fragment = read_fragment_2; - s_ops.read_fragment_table = read_fragment_table_2; s_ops.read_block_list = read_block_list_2; s_ops.read_inode = read_inode_2; - s_ops.read_uids_guids = read_uids_guids_1; } } else if(sBlk.s.s_major == 3) { + s_ops.read_filesystem_tables = read_filesystem_tables_3; s_ops.squashfs_opendir = squashfs_opendir_3; s_ops.read_fragment = read_fragment_3; - s_ops.read_fragment_table = read_fragment_table_3; s_ops.read_block_list = read_block_list_2; s_ops.read_inode = read_inode_3; - s_ops.read_uids_guids = read_uids_guids_1; } else { ERROR("Filesystem on %s is (%d:%d), ", source, sBlk.s.s_major, sBlk.s.s_minor); @@ -2501,7 +2497,6 @@ int main(int argc, char *argv[]) int n; struct pathnames *paths = NULL; struct pathname *path = NULL; - long long directory_table_end; int fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT; int data_buffer_size = DATA_BUFFER_DEFAULT; @@ -2757,25 +2752,8 @@ options: memset(created_inode, 0, sBlk.s.inodes * sizeof(char *)); - if(s_ops.read_uids_guids() == FALSE) - EXIT_UNSQUASH("failed to uid/gid table\n"); - - if(s_ops.read_fragment_table(&directory_table_end) == FALSE) - EXIT_UNSQUASH("failed to read fragment table\n"); - - if(read_inode_table(sBlk.s.inode_table_start, - sBlk.s.directory_table_start) == FALSE) - EXIT_UNSQUASH("failed to read inode table\n"); - - if(read_directory_table(sBlk.s.directory_table_start, - directory_table_end) == FALSE) - EXIT_UNSQUASH("failed to read directory table\n"); - - if(no_xattrs) - sBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK; - - if(read_xattrs_from_disk(fd, &sBlk.s) == 0) - EXIT_UNSQUASH("failed to read the xattr table\n"); + if(s_ops.read_filesystem_tables() == FALSE) + EXIT_UNSQUASH("failed to read file system tables\n"); if(path) { paths = init_subdir(); diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h index ecd0bb4..f9c49ac 100644 --- a/squashfs-tools/unsquashfs.h +++ b/squashfs-tools/unsquashfs.h @@ -4,7 +4,7 @@ * Unsquash a squashfs filesystem. This is a highly compressed read only * filesystem. * - * Copyright (c) 2009, 2010, 2013, 2014 + * Copyright (c) 2009, 2010, 2013, 2014, 2019 * Phillip Lougher * * This program is free software; you can redistribute it and/or @@ -102,12 +102,11 @@ typedef struct squashfs_operations { unsigned int offset, struct inode **i); void (*read_fragment)(unsigned int fragment, long long *start_block, int *size); - int (*read_fragment_table)(long long *); void (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks); struct inode *(*read_inode)(unsigned int start_block, unsigned int offset); - int (*read_uids_guids)(); + int (*read_filesystem_tables)(); } squashfs_operations; struct test { @@ -235,10 +234,13 @@ extern int progress_enabled; extern int inode_number; extern int lookup_type[]; extern int fd; +extern int no_xattrs; extern struct queue *to_reader, *to_inflate, *to_writer; extern struct cache *fragment_cache, *data_cache; /* unsquashfs.c */ +extern int read_inode_table(long long, long long); +extern int read_directory_table(long long, long long); extern int lookup_entry(struct hash_table_entry **, long long); extern int read_fs_bytes(int fd, long long, int, void *); extern int read_block(int, long long, long long *, int, void *); @@ -249,7 +251,7 @@ extern void dump_cache(struct cache *); /* unsquash-1.c */ extern void read_block_list_1(unsigned int *, char *, int); -extern int read_fragment_table_1(long long *); +extern int read_filesystem_tables_1(); extern struct inode *read_inode_1(unsigned int, unsigned int); extern struct dir *squashfs_opendir_1(unsigned int, unsigned int, struct inode **); @@ -257,12 +259,13 @@ extern int read_uids_guids_1(); /* unsquash-2.c */ extern void read_block_list_2(unsigned int *, char *, int); -extern int read_fragment_table_2(long long *); +extern int read_filesystem_tables_2(); extern void read_fragment_2(unsigned int, long long *, int *); extern struct inode *read_inode_2(unsigned int, unsigned int); /* unsquash-3.c */ extern int read_fragment_table_3(long long *); +extern int read_filesystem_tables_3(); extern void read_fragment_3(unsigned int, long long *, int *); extern struct inode *read_inode_3(unsigned int, unsigned int); extern struct dir *squashfs_opendir_3(unsigned int, unsigned int, @@ -270,9 +273,9 @@ extern struct dir *squashfs_opendir_3(unsigned int, unsigned int, /* unsquash-4.c */ extern int read_fragment_table_4(long long *); +extern int read_filesystem_tables_4(); extern void read_fragment_4(unsigned int, long long *, int *); extern struct inode *read_inode_4(unsigned int, unsigned int); extern struct dir *squashfs_opendir_4(unsigned int, unsigned int, struct inode **); -extern int read_uids_guids_4(); #endif -- 1.8.3.1