aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-12-09 22:27:51 +0000
committerColin Cross <ccross@android.com>2017-12-09 22:27:51 +0000
commitbe7549061d134b92ce90909c8168e4c076a0040b (patch)
treefe6dd0a3487802d48f202ea15197baa5a04eb808
parentfa8c3fb3d308912de3cffd80c3aea93ce7c91a92 (diff)
downloadsquashfs-tools-be7549061d134b92ce90909c8168e4c076a0040b.tar.gz
Revert "Merge remote-tracking branch 'aosp/upstream-master' into 'aosp/master'"
This reverts commit fa8c3fb3d308912de3cffd80c3aea93ce7c91a92. Reason for revert: Broke mac builds. Change-Id: I798551229a9824bc51448196121da2c255edc31b
-rw-r--r--squashfs-tools/Makefile20
-rw-r--r--squashfs-tools/action.c11
-rw-r--r--squashfs-tools/compressor.c8
-rw-r--r--squashfs-tools/fnmatch_compat.h32
-rw-r--r--squashfs-tools/gzip_wrapper.c4
-rw-r--r--squashfs-tools/info.c25
-rw-r--r--squashfs-tools/lz4_wrapper.c13
-rw-r--r--squashfs-tools/lzo_wrapper.c4
-rw-r--r--squashfs-tools/mksquashfs.c160
-rw-r--r--squashfs-tools/mksquashfs.h1
-rw-r--r--squashfs-tools/process_fragments.c1
-rw-r--r--squashfs-tools/pseudo.c52
-rw-r--r--squashfs-tools/pseudo.h5
-rw-r--r--squashfs-tools/read_xattrs.c4
-rw-r--r--squashfs-tools/squashfs_fs.h1
-rw-r--r--squashfs-tools/unsquashfs.c32
-rw-r--r--squashfs-tools/unsquashfs.h5
-rw-r--r--squashfs-tools/unsquashfs_info.c25
-rw-r--r--squashfs-tools/unsquashfs_xattr.c5
-rw-r--r--squashfs-tools/xattr.c15
-rw-r--r--squashfs-tools/xz_wrapper.c4
-rw-r--r--squashfs-tools/zstd_wrapper.c254
-rw-r--r--squashfs-tools/zstd_wrapper.h48
23 files changed, 164 insertions, 565 deletions
diff --git a/squashfs-tools/Makefile b/squashfs-tools/Makefile
index 22fc559..52d2582 100644
--- a/squashfs-tools/Makefile
+++ b/squashfs-tools/Makefile
@@ -75,18 +75,6 @@ GZIP_SUPPORT = 1
#LZMA_SUPPORT = 1
#LZMA_DIR = ../../../../LZMA/lzma465
-
-########### Building ZSTD support ############
-#
-# The ZSTD library is supported
-# ZSTD homepage: http://zstd.net
-# ZSTD source repository: https://github.com/facebook/zstd
-#
-# To build using the ZSTD library - install the library and uncomment the
-# ZSTD_SUPPORT line below.
-#
-#ZSTD_SUPPORT = 1
-
######## Specifying default compression ########
#
# The next line specifies which compression algorithm is used by default
@@ -189,14 +177,6 @@ LIBS += -llz4
COMPRESSORS += lz4
endif
-ifeq ($(ZSTD_SUPPORT),1)
-CFLAGS += -DZSTD_SUPPORT
-MKSQUASHFS_OBJS += zstd_wrapper.o
-UNSQUASHFS_OBJS += zstd_wrapper.o
-LIBS += -lzstd
-COMPRESSORS += zstd
-endif
-
ifeq ($(XATTR_SUPPORT),1)
ifeq ($(XATTR_DEFAULT),1)
CFLAGS += -DXATTR_SUPPORT -DXATTR_DEFAULT
diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
index 4b06ccb..7e43f17 100644
--- a/squashfs-tools/action.c
+++ b/squashfs-tools/action.c
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <fnmatch.h>
#include <pwd.h>
#include <grp.h>
#include <sys/wait.h>
@@ -38,11 +39,14 @@
#include <limits.h>
#include <errno.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#include "squashfs_fs.h"
#include "mksquashfs.h"
#include "action.h"
#include "error.h"
-#include "fnmatch_compat.h"
/*
* code to parse actions
@@ -2284,9 +2288,12 @@ static char *get_start(char *s, int n)
static int subpathname_fn(struct atom *atom, struct action_data *action_data)
{
- return fnmatch(atom->argv[0], get_start(strdupa(action_data->subpath),
+ char *path = strdup(action_data->subpath);
+ int is_match = fnmatch(atom->argv[0], get_start(path,
count_components(atom->argv[0])),
FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;
+ free(path);
+ return is_match;
}
/*
diff --git a/squashfs-tools/compressor.c b/squashfs-tools/compressor.c
index 02b5e90..525e316 100644
--- a/squashfs-tools/compressor.c
+++ b/squashfs-tools/compressor.c
@@ -65,13 +65,6 @@ static struct compressor xz_comp_ops = {
extern struct compressor xz_comp_ops;
#endif
-#ifndef ZSTD_SUPPORT
-static struct compressor zstd_comp_ops = {
- ZSTD_COMPRESSION, "zstd"
-};
-#else
-extern struct compressor zstd_comp_ops;
-#endif
static struct compressor unknown_comp_ops = {
0, "unknown"
@@ -84,7 +77,6 @@ struct compressor *compressor[] = {
&lzo_comp_ops,
&lz4_comp_ops,
&xz_comp_ops,
- &zstd_comp_ops,
&unknown_comp_ops
};
diff --git a/squashfs-tools/fnmatch_compat.h b/squashfs-tools/fnmatch_compat.h
deleted file mode 100644
index 7b4afd8..0000000
--- a/squashfs-tools/fnmatch_compat.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef FNMATCH_COMPAT
-#define FNMATCH_COMPAT
-/*
- * Squashfs
- *
- * Copyright (c) 2015
- * Phillip Lougher <phillip@squashfs.org.uk>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2,
- * or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * fnmatch_compat.h
- */
-
-#include <fnmatch.h>
-
-#ifndef FNM_EXTMATCH
-#define FNM_EXTMATCH 0
-#endif
-
-#endif
diff --git a/squashfs-tools/gzip_wrapper.c b/squashfs-tools/gzip_wrapper.c
index ac32bb9..076a587 100644
--- a/squashfs-tools/gzip_wrapper.c
+++ b/squashfs-tools/gzip_wrapper.c
@@ -276,7 +276,7 @@ failed:
}
-static void gzip_display_options(void *buffer, int size)
+void gzip_display_options(void *buffer, int size)
{
struct gzip_comp_opts *comp_opts = buffer;
int i, printed;
@@ -467,7 +467,7 @@ static int gzip_uncompress(void *d, void *s, int size, int outsize, int *error)
}
-static void gzip_usage()
+void gzip_usage()
{
fprintf(stderr, "\t -Xcompression-level <compression-level>\n");
fprintf(stderr, "\t\t<compression-level> should be 1 .. 9 (default "
diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
index 7968c77..60a3f5a 100644
--- a/squashfs-tools/info.c
+++ b/squashfs-tools/info.c
@@ -134,31 +134,22 @@ void dump_state()
void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
- int sig, waiting = 0;
+ int sig, err, waiting = 0;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, &timespec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
+ err = sigwait(&sigmask, &sig);
- if(sig == -1) {
+ if(err == -1) {
switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
continue;
default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
+ BAD_ERROR("sigwait failed "
"because %s\n", strerror(errno));
}
}
@@ -169,8 +160,12 @@ void *info_thrd(void *arg)
/* set one second interval period, if ^\ received
within then, dump queue and cache status */
waiting = 1;
- } else
+ alarm(1);
+ } else if (sig == SIGQUIT) {
dump_state();
+ } else if (sig == SIGALRM) {
+ waiting = 0;
+ }
}
}
diff --git a/squashfs-tools/lz4_wrapper.c b/squashfs-tools/lz4_wrapper.c
index 71b21a8..3c24971 100644
--- a/squashfs-tools/lz4_wrapper.c
+++ b/squashfs-tools/lz4_wrapper.c
@@ -184,7 +184,7 @@ failed:
}
-static void lz4_display_options(void *buffer, int size)
+void lz4_display_options(void *buffer, int size)
{
struct lz4_comp_opts *comp_opts = buffer;
@@ -225,20 +225,11 @@ static int lz4_compress(void *strm, void *dest, void *src, int size,
{
int res;
-/* ANDROID CHANGES START*/
-#ifdef ANDROID
if(hc)
res = LZ4_compress_HC(src, dest, size, block_size,
LZ4HC_CLEVEL_DEFAULT);
else
res = LZ4_compress_default(src, dest, size, block_size);
-#else
- if(hc)
- res = LZ4_compressHC_limitedOutput(src, dest, size, block_size);
- else
- res = LZ4_compress_limitedOutput(src, dest, size, block_size);
-#endif
-/* ANDROID CHANGES END */
if(res == 0) {
/*
@@ -271,7 +262,7 @@ static int lz4_uncompress(void *dest, void *src, int size, int outsize,
}
-static void lz4_usage()
+void lz4_usage()
{
fprintf(stderr, "\t -Xhc\n");
fprintf(stderr, "\t\tCompress using LZ4 High Compression\n");
diff --git a/squashfs-tools/lzo_wrapper.c b/squashfs-tools/lzo_wrapper.c
index f367fad..8c9bf95 100644
--- a/squashfs-tools/lzo_wrapper.c
+++ b/squashfs-tools/lzo_wrapper.c
@@ -263,7 +263,7 @@ failed:
}
-static void lzo_display_options(void *buffer, int size)
+void lzo_display_options(void *buffer, int size)
{
struct lzo_comp_opts *comp_opts = buffer;
@@ -391,7 +391,7 @@ static int lzo_uncompress(void *dest, void *src, int size, int outsize,
}
-static void lzo_usage()
+void lzo_usage()
{
int i;
diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index cbfc731..60be156 100644
--- a/squashfs-tools/mksquashfs.c
+++ b/squashfs-tools/mksquashfs.c
@@ -3,7 +3,7 @@
* filesystem.
*
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
- * 2012, 2013, 2014, 2017
+ * 2012, 2013, 2014
* Phillip Lougher <phillip@squashfs.org.uk>
*
* This program is free software; you can redistribute it and/or
@@ -46,10 +46,15 @@
#include <sys/mman.h>
#include <pthread.h>
#include <regex.h>
+#include <fnmatch.h>
#include <sys/wait.h>
#include <limits.h>
#include <ctype.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
@@ -92,10 +97,7 @@ FILE *block_map_file = NULL;
#endif
/* ANDROID CHANGES END */
-#include "fnmatch_compat.h"
-
int delete = FALSE;
-int quiet = FALSE;
int fd;
struct squashfs_super_block sBlk;
@@ -116,7 +118,6 @@ int old_exclude = TRUE;
int use_regex = FALSE;
int nopad = FALSE;
int exit_on_error = FALSE;
-static off_t squashfs_start_offset = 0;
long long global_uid = -1, global_gid = -1;
@@ -459,7 +460,8 @@ int mangle2(void *strm, char *d, char *s, int size,
"code %d\n", comp->name, error);
}
- if(c_byte == 0 || c_byte >= size) {
+ if(c_byte == 0 || c_byte >= size ||
+ (c_byte > (size * ((100.0 - compress_thresh_per) / 100.0)))) {
memcpy(d, s, size);
return size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :
SQUASHFS_COMPRESSED_BIT);
@@ -559,9 +561,9 @@ int read_fs_bytes(int fd, long long byte, int bytes, void *buff)
pthread_cleanup_push((void *) pthread_mutex_unlock, &pos_mutex);
pthread_mutex_lock(&pos_mutex);
- if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) {
+ if(lseek(fd, off, SEEK_SET) == -1) {
ERROR("read_fs_bytes: Lseek on destination failed because %s, "
- "offset=0x%llx\n", strerror(errno), off+squashfs_start_offset);
+ "offset=0x%llx\n", strerror(errno), off);
res = 0;
} else if(read_bytes(fd, buff, bytes) < bytes) {
ERROR("Read on destination failed\n");
@@ -600,10 +602,10 @@ void write_destination(int fd, long long byte, int bytes, void *buff)
pthread_cleanup_push((void *) pthread_mutex_unlock, &pos_mutex);
pthread_mutex_lock(&pos_mutex);
- if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) {
+ if(lseek(fd, off, SEEK_SET) == -1) {
ERROR("write_destination: Lseek on destination "
"failed because %s, offset=0x%llx\n", strerror(errno),
- off+squashfs_start_offset);
+ off);
BAD_ERROR("Probably out of space on output %s\n",
block_device ? "block device" : "filesystem");
}
@@ -871,13 +873,13 @@ char *subpathname(struct dir_ent *dir_ent)
}
-inline unsigned int get_inode_no(struct inode_info *inode)
+static inline unsigned int get_inode_no(struct inode_info *inode)
{
return inode->inode_number;
}
-inline unsigned int get_parent_no(struct dir_info *dir)
+static inline unsigned int get_parent_no(struct dir_info *dir)
{
return dir->depth ? get_inode_no(dir->dir_ent->inode) : inode_no;
}
@@ -999,8 +1001,10 @@ int create_inode(squashfs_inode *i_no, struct dir_info *dir_info,
"%d, fragment %d, offset %d, size %d\n", byte_size,
start_block, offset, fragment->index, fragment->offset,
fragment->size);
- for(i = 0; i < offset; i++)
+ for(i = 0; i < offset; i++) {
TRACE("Block %d, size %d\n", i, block_list[i]);
+ total_size += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);
+ }
/* ANDROID CHANGES START*/
#ifdef ANDROID
sub_path = subpathname(dir_ent);
@@ -1037,8 +1041,10 @@ int create_inode(squashfs_inode *i_no, struct dir_info *dir_info,
"blocks %d, fragment %d, offset %d, size %d, nlink %d"
"\n", byte_size, start_block, offset, fragment->index,
fragment->offset, fragment->size, nlink);
- for(i = 0; i < offset; i++)
+ for(i = 0; i < offset; i++) {
TRACE("Block %d, size %d\n", i, block_list[i]);
+ total_size += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);
+ }
/* ANDROID CHANGES START*/
#ifdef ANDROID
sub_path = subpathname(dir_ent);
@@ -1520,7 +1526,6 @@ again:
cache_block_put(compressed_buffer);
finished:
- do { } while (0);
pthread_cleanup_pop(0);
return buffer;
@@ -2137,7 +2142,7 @@ struct file_info *duplicate(long long file_size, long long bytes,
}
-inline int is_fragment(struct inode_info *inode)
+static inline int is_fragment(struct inode_info *inode)
{
off_t file_size = inode->buf.st_size;
@@ -2425,9 +2430,9 @@ void *writer(void *arg)
pthread_cleanup_push((void *) pthread_mutex_unlock, &pos_mutex);
pthread_mutex_lock(&pos_mutex);
- if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) {
+ if(lseek(fd, off, SEEK_SET) == -1) {
ERROR("writer: Lseek on destination failed because "
- "%s, offset=0x%llx\n", strerror(errno), off+squashfs_start_offset);
+ "%s, offset=0x%llx\n", strerror(errno), off);
BAD_ERROR("Probably out of space on output "
"%s\n", block_device ? "block device" :
"filesystem");
@@ -3116,19 +3121,19 @@ struct inode_info *lookup_inode3(struct stat *buf, int pseudo, int id,
}
-struct inode_info *lookup_inode2(struct stat *buf, int pseudo, int id)
+static inline struct inode_info *lookup_inode2(struct stat *buf, int pseudo, int id)
{
return lookup_inode3(buf, pseudo, id, NULL, 0);
}
-inline struct inode_info *lookup_inode(struct stat *buf)
+static inline struct inode_info *lookup_inode(struct stat *buf)
{
return lookup_inode2(buf, 0, 0);
}
-inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
+static inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
{
if (inode->inode_number == 0) {
inode->inode_number = use_this ? : inode_no ++;
@@ -3139,7 +3144,7 @@ inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
}
-inline struct dir_ent *create_dir_entry(char *name, char *source_name,
+static inline struct dir_ent *create_dir_entry(char *name, char *source_name,
char *nonstandard_pathname, struct dir_info *dir)
{
struct dir_ent *dir_ent = malloc(sizeof(struct dir_ent));
@@ -3162,15 +3167,8 @@ inline struct dir_ent *create_dir_entry(char *name, char *source_name,
}
-/* ANDROID CHANGES START*/
-#ifdef ANDROID
static inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
struct inode_info *inode_info)
-#else
-inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
- struct inode_info *inode_info)
-#endif
-/* ANDROID CHANGES END */
{
struct dir_info *dir = dir_ent->our_dir;
@@ -3205,8 +3203,7 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
dir->count++;
}
-
-inline void add_dir_entry2(char *name, char *source_name,
+static inline void add_dir_entry2(char *name, char *source_name,
char *nonstandard_pathname, struct dir_info *sub_dir,
struct inode_info *inode_info, struct dir_info *dir)
{
@@ -3218,7 +3215,7 @@ inline void add_dir_entry2(char *name, char *source_name,
}
-inline void free_dir_entry(struct dir_ent *dir_ent)
+static inline void free_dir_entry(struct dir_ent *dir_ent)
{
if(dir_ent->name)
free(dir_ent->name);
@@ -3239,7 +3236,7 @@ inline void free_dir_entry(struct dir_ent *dir_ent)
}
-inline void add_excluded(struct dir_info *dir)
+static inline void add_excluded(struct dir_info *dir)
{
dir->excluded ++;
}
@@ -3760,12 +3757,6 @@ void dir_scan2(struct dir_info *dir, struct pseudo *pseudo)
pseudo_ent->pathname, NULL,
lookup_inode2(&buf, PSEUDO_FILE_PROCESS,
pseudo_ent->dev->pseudo_id), dir);
- } else if(pseudo_ent->dev->type == 's') {
- add_dir_entry2(pseudo_ent->name, NULL,
- pseudo_ent->pathname, NULL,
- lookup_inode3(&buf, PSEUDO_FILE_OTHER, 0,
- pseudo_ent->dev->symlink,
- strlen(pseudo_ent->dev->symlink) + 1), dir);
} else {
add_dir_entry2(pseudo_ent->name, NULL,
pseudo_ent->pathname, NULL,
@@ -4377,6 +4368,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
BAD_ERROR("Failed to set signal mask in intialise_threads\n");
@@ -4456,8 +4448,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
main_thread = pthread_self();
- if(!quiet)
- printf("Parallel mksquashfs: Using %d processor%s\n", processors,
+ printf("Parallel mksquashfs: Using %d processor%s\n", processors,
processors == 1 ? "" : "s");
/* Restore the signal mask for the main thread */
@@ -5128,9 +5119,6 @@ void write_filesystem_tables(struct squashfs_super_block *sBlk, int nopad)
total_bytes += total_inode_bytes + total_directory_bytes +
sizeof(struct squashfs_super_block) + total_xattr_bytes;
- if(quiet)
- return;
-
printf("\n%sSquashfs %d.%d filesystem, %s compressed, data block size"
" %d\n", exportable ? "Exportable " : "", SQUASHFS_MAJOR,
SQUASHFS_MINOR, comp->name, block_size);
@@ -5196,6 +5184,9 @@ void write_filesystem_tables(struct squashfs_super_block *sBlk, int nopad)
group->gr_name, id_table[i]->id);
}
}
+
+ printf("Number of whitelisted (uncompressed) files %d\n",
+ whitelisted_count);
}
@@ -5308,20 +5299,47 @@ int parse_num(char *arg, int *res)
int get_physical_memory()
{
- /*
- * Long longs are used here because with PAE, a 32-bit
- * machine can have more than 4GB of physical memory
- *
- * sysconf(_SC_PHYS_PAGES) relies on /proc being mounted.
- * If it isn't fail.
- */
+ int phys_mem;
+#ifndef linux
+ #ifdef HW_MEMSIZE
+ #define SYSCTL_PHYSMEM HW_MEMSIZE
+ #elif defined(HW_PHYSMEM64)
+ #define SYSCTL_PHYSMEM HW_PHYSMEM64
+ #else
+ #define SYSCTL_PHYSMEM HW_PHYSMEM
+ #endif
+
+ int mib[2];
+ uint64_t sysctl_physmem = 0;
+ size_t sysctl_len = sizeof(sysctl_physmem);
+
+ mib[0] = CTL_HW;
+ mib[1] = SYSCTL_PHYSMEM;
+
+ if(sysctl(mib, 2, &sysctl_physmem, &sysctl_len, NULL, 0) == 0) {
+ /* some systems use 32-bit values, work with what we're given */
+ if (sysctl_len == 4)
+ sysctl_physmem = *(uint32_t*)&sysctl_physmem;
+ phys_mem = sysctl_physmem >> 20;
+ } else {
+ ERROR_START("Failed to get amount of available "
+ "memory.");
+ ERROR_EXIT(" Defaulting to least viable amount\n");
+ phys_mem = SQUASHFS_LOWMEM;
+ }
+ #undef SYSCTL_PHYSMEM
+#else
+ /* Long longs are used here because with PAE, a 32-bit
+ machine can have more than 4GB of physical memory */
+
long long num_pages = sysconf(_SC_PHYS_PAGES);
long long page_size = sysconf(_SC_PAGESIZE);
- int phys_mem = num_pages * page_size >> 20;
-
+ phys_mem = num_pages * page_size >> 20;
if(num_pages == -1 || page_size == -1)
return 0;
+#endif
+
if(phys_mem < SQUASHFS_LOWMEM)
BAD_ERROR("Mksquashfs requires more physical memory than is "
"available!\n");
@@ -5424,8 +5442,8 @@ void calculate_queue_sizes(int mem, int *readq, int *fragq, int *bwriteq,
#define VERSION() \
- printf("mksquashfs version 4.3-git (2017/07/18)\n");\
- printf("copyright (C) 2017 Phillip Lougher "\
+ printf("mksquashfs version 4.3-git (2014/09/12)\n");\
+ printf("copyright (C) 2014 Phillip Lougher "\
"<phillip@squashfs.org.uk>\n\n"); \
printf("This program is free software; you can redistribute it and/or"\
"\n");\
@@ -5680,15 +5698,6 @@ print_compressor_options:
force_progress = TRUE;
else if(strcmp(argv[i], "-no-exports") == 0)
exportable = FALSE;
- else if(strcmp(argv[i], "-offset") == 0 ||
- strcmp(argv[i], "-o") ==0) {
- if(++i == argc) {
- ERROR("%s: %s offset missing argument\n", argv[0],
- argv[i - 1]);
- exit(1);
- }
- squashfs_start_offset = (off_t)atol(argv[i]);
- }
else if(strcmp(argv[i], "-processors") == 0) {
if((++i == argc) || !parse_num(argv[i], &processors)) {
ERROR("%s: -processors missing or invalid "
@@ -5922,12 +5931,8 @@ print_compressor_options:
else if(strcmp(argv[i], "-noappend") == 0)
delete = TRUE;
- else if(strcmp(argv[i], "-quiet") == 0)
- quiet = TRUE;
-
else if(strcmp(argv[i], "-keep-as-directory") == 0)
keep_as_directory = TRUE;
-
/* ANDROID CHANGES START*/
#ifdef ANDROID
else if(strcmp(argv[i], "-android-fs-config") == 0)
@@ -5970,6 +5975,7 @@ print_compressor_options:
}
#endif
/* ANDROID CHANGES END */
+
else if(strcmp(argv[i], "-exit-on-error") == 0)
exit_on_error = TRUE;
@@ -6056,14 +6062,6 @@ printOptions:
"definition\n");
ERROR("-pf <pseudo-file>\tAdd list of pseudo file "
"definitions\n");
- ERROR("\t\t\tPseudo definitions should be of the "
- "format\n");
- ERROR("\t\t\t\tfilename d mode uid gid\n");
- ERROR("\t\t\t\tfilename m mode uid gid\n");
- ERROR("\t\t\t\tfilename b mode uid gid major minor\n");
- ERROR("\t\t\t\tfilename c mode uid gid major minor\n");
- ERROR("\t\t\t\tfilename f mode uid gid command\n");
- ERROR("\t\t\t\tfilename s mode uid gid symlink\n");
ERROR("-sort <sort_file>\tsort files according to "
"priorities in <sort_file>. One\n");
ERROR("\t\t\tfile or dir with priority per line. "
@@ -6095,7 +6093,6 @@ printOptions:
"using recovery file <name>\n");
ERROR("-no-recovery\t\tdon't generate a recovery "
"file\n");
- ERROR("-quiet\t\t\tno verbose output\n");
ERROR("-info\t\t\tprint files written to filesystem\n");
ERROR("-no-progress\t\tdon't display the progress "
"bar\n");
@@ -6112,9 +6109,6 @@ printOptions:
ERROR("\nMiscellaneous options:\n");
ERROR("-root-owned\t\talternative name for -all-root"
"\n");
- ERROR("-o <offset>\t\tSkip <offset> bytes at the "
- "beginning of the file.\n\t\t\t"
- "Default 0 bytes\n");
ERROR("-noInodeCompression\talternative name for -noI"
"\n");
ERROR("-noDataCompression\talternative name for -noD"
@@ -6307,10 +6301,8 @@ printOptions:
void *comp_data = compressor_dump_options(comp, block_size,
&size);
- if(!quiet)
- printf("Creating %d.%d filesystem on %s, block size %d.\n",
- SQUASHFS_MAJOR, SQUASHFS_MINOR,
- argv[source + 1], block_size);
+ printf("Creating %d.%d filesystem on %s, block size %d.\n",
+ SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);
/*
* store any compressor specific options after the superblock,
diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
index 0a091cb..bfbf0bf 100644
--- a/squashfs-tools/mksquashfs.h
+++ b/squashfs-tools/mksquashfs.h
@@ -29,6 +29,7 @@
#include <stdint.h>
#endif
/* ANDROID CHANGES END */
+#include <pthread.h>
struct dir_info {
char *pathname;
diff --git a/squashfs-tools/process_fragments.c b/squashfs-tools/process_fragments.c
index 971dc11..bba6f5a 100644
--- a/squashfs-tools/process_fragments.c
+++ b/squashfs-tools/process_fragments.c
@@ -210,7 +210,6 @@ again:
cache_block_put(compressed_buffer);
finished:
- do { } while (0);
pthread_cleanup_pop(0);
return buffer;
diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c
index cb74cf6..e12d399 100644
--- a/squashfs-tools/pseudo.c
+++ b/squashfs-tools/pseudo.c
@@ -2,7 +2,7 @@
* Create a squashfs filesystem. This is a highly compressed read only
* filesystem.
*
- * Copyright (c) 2009, 2010, 2012, 2014, 2017
+ * Copyright (c) 2009, 2010, 2012, 2014
* Phillip Lougher <phillip@squashfs.org.uk>
*
* This program is free software; you can redistribute it and/or
@@ -30,9 +30,9 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <sys/stat.h>
#include <ctype.h>
#include "pseudo.h"
@@ -274,7 +274,6 @@ struct pseudo_dev *get_pseudo_file(int pseudo_id)
int read_pseudo_def(char *def)
{
int n, bytes;
- int quoted = 0;
unsigned int major = 0, minor = 0, mode;
char type, *ptr;
char suid[100], sgid[100]; /* overflow safe */
@@ -285,22 +284,13 @@ int read_pseudo_def(char *def)
/*
* Scan for filename, don't use sscanf() and "%s" because
- * that can't handle filenames with spaces.
- *
- * Filenames with spaces should either escape (backslash) the
- * space or use double quotes.
+ * that can't handle filenames with spaces
*/
filename = malloc(strlen(def) + 1);
if(filename == NULL)
MEM_ERROR();
- for(name = filename; (quoted || !isspace(*def)) && *def != '\0';) {
- if(*def == '"') {
- quoted = !quoted;
- def ++;
- continue;
- }
-
+ for(name = filename; !isspace(*def) && *def != '\0';) {
if(*def == '\\') {
def ++;
if (*def == '\0')
@@ -327,11 +317,12 @@ int read_pseudo_def(char *def)
case -1:
/* FALLTHROUGH */
case 0:
- /* FALLTHROUGH */
+ ERROR("Read filename, but failed to read or match "
+ "type\n");
+ break;
case 1:
- ERROR("Couldn't parse filename, type or octal mode\n");
- ERROR("If the filename has spaces, either quote it, or "
- "backslash the spaces\n");
+ ERROR("Read filename and type, but failed to read or "
+ "match octal mode\n");
break;
case 2:
ERROR("Read filename, type and mode, but failed to "
@@ -397,20 +388,6 @@ int read_pseudo_def(char *def)
goto error;
}
break;
- case 's':
- if(def[0] == '\0') {
- ERROR("Not enough arguments in symlink pseudo "
- "definition \"%s\"\n", orig_def);
- ERROR("Expected symlink\n");
- goto error;
- }
-
- if(strlen(def) > 65535) {
- ERROR("Symlink pseudo definition %s is greater than 65535"
- " bytes!\n", def);
- goto error;
- }
- break;
default:
ERROR("Unsupported type %c\n", type);
goto error;
@@ -467,10 +444,6 @@ int read_pseudo_def(char *def)
case 'f':
mode |= S_IFREG;
break;
- case 's':
- /* permissions on symlinks are always rwxrwxrwx */
- mode = 0777 | S_IFLNK;
- break;
}
dev = malloc(sizeof(struct pseudo_dev));
@@ -487,8 +460,6 @@ int read_pseudo_def(char *def)
dev->command = strdup(def);
add_pseudo_file(dev);
}
- if(type == 's')
- dev->symlink = strdup(def);
pseudo = add_pseudo(pseudo, dev, filename, filename);
@@ -496,13 +467,12 @@ int read_pseudo_def(char *def)
return TRUE;
error:
- ERROR("Pseudo definitions should be of the format\n");
+ ERROR("Pseudo definitions should be of format\n");
ERROR("\tfilename d mode uid gid\n");
ERROR("\tfilename m mode uid gid\n");
ERROR("\tfilename b mode uid gid major minor\n");
ERROR("\tfilename c mode uid gid major minor\n");
- ERROR("\tfilename f mode uid gid command\n");
- ERROR("\tfilename s mode uid gid symlink\n");
+ ERROR("\tfilename f mode uid command\n");
free(filename);
return FALSE;
}
diff --git a/squashfs-tools/pseudo.h b/squashfs-tools/pseudo.h
index ef693c3..c0d9f6f 100644
--- a/squashfs-tools/pseudo.h
+++ b/squashfs-tools/pseudo.h
@@ -31,10 +31,7 @@ struct pseudo_dev {
unsigned int major;
unsigned int minor;
int pseudo_id;
- union {
- char *command;
- char *symlink;
- };
+ char *command;
};
struct pseudo_entry {
diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..837d3fb 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -39,13 +39,13 @@
#include <endian.h>
#endif
+#include <stdlib.h>
+
#include "squashfs_fs.h"
#include "squashfs_swap.h"
#include "xattr.h"
#include "error.h"
-#include <stdlib.h>
-
extern int read_fs_bytes(int, long long, int, void *);
extern int read_block(int, long long, long long *, int, void *);
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..791fe12 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -277,7 +277,6 @@ typedef long long squashfs_inode;
#define LZO_COMPRESSION 3
#define XZ_COMPRESSION 4
#define LZ4_COMPRESSION 5
-#define ZSTD_COMPRESSION 6
struct squashfs_super_block {
unsigned int s_magic;
diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
index c5e0876..0dbc4c2 100644
--- a/squashfs-tools/unsquashfs.c
+++ b/squashfs-tools/unsquashfs.c
@@ -30,9 +30,13 @@
#include "xattr.h"
#include "unsquashfs_info.h"
#include "stdarg.h"
-#include "fnmatch_compat.h"
+#ifndef linux
+#include <sys/sysctl.h>
+#else
#include <sys/sysinfo.h>
+#endif
+
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -43,7 +47,6 @@ struct cache *fragment_cache, *data_cache;
struct queue *to_reader, *to_inflate, *to_writer, *from_writer;
pthread_t *thread, *inflator_thread;
pthread_mutex_t fragment_mutex;
-static off_t squashfs_start_offset = 0;
/* user options that control parallelisation */
int processors = -1;
@@ -633,7 +636,7 @@ int read_fs_bytes(int fd, long long byte, int bytes, void *buff)
TRACE("read_bytes: reading from position 0x%llx, bytes %d\n", byte,
bytes);
- if(lseek(fd, off + squashfs_start_offset, SEEK_SET) == -1) {
+ if(lseek(fd, off, SEEK_SET) == -1) {
ERROR("Lseek failed because %s\n", strerror(errno));
return FALSE;
}
@@ -1119,11 +1122,7 @@ int create_inode(char *pathname, struct inode *i)
case SQUASHFS_CHRDEV_TYPE:
case SQUASHFS_LBLKDEV_TYPE:
case SQUASHFS_LCHRDEV_TYPE: {
- int chrdev = 0;
- if ( i->type == SQUASHFS_CHRDEV_TYPE ||
- i->type == SQUASHFS_LCHRDEV_TYPE)
- chrdev = 1;
-
+ int chrdev = i->type == SQUASHFS_CHRDEV_TYPE;
TRACE("create_inode: dev, rdev 0x%llx\n", i->data);
if(root_process) {
@@ -1646,9 +1645,9 @@ void squashfs_stat(char *source)
printf("Creation or last append time %s", mkfs_str ? mkfs_str :
"failed to get time\n");
- printf("Filesystem size %llu bytes (%.2f Kbytes / %.2f Mbytes)\n",
- sBlk.s.bytes_used, sBlk.s.bytes_used / 1024.0,
- sBlk.s.bytes_used / (1024.0 * 1024.0));
+ printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n",
+ sBlk.s.bytes_used / 1024.0, sBlk.s.bytes_used /
+ (1024.0 * 1024.0));
if(sBlk.s.s_major == 4) {
printf("Compression %s\n", comp->name);
@@ -2180,6 +2179,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
EXIT_UNSQUASH("Failed to set signal mask in initialise_threads"
"\n");
@@ -2550,14 +2550,6 @@ int main(int argc, char *argv[])
exit(1);
}
dest = argv[i];
- } else if (strcmp(argv[i], "-offset") == 0 ||
- strcmp(argv[i], "-o") == 0) {
- if(++i == argc) {
- fprintf(stderr, "%s: -offset missing argument\n",
- argv[0]);
- exit(1);
- }
- squashfs_start_offset = (off_t)atol(argv[i]);
} else if(strcmp(argv[i], "-processors") == 0 ||
strcmp(argv[i], "-p") == 0) {
if((++i == argc) ||
@@ -2650,8 +2642,6 @@ options:
"copyright information\n");
ERROR("\t-d[est] <pathname>\tunsquash to <pathname>, "
"default \"squashfs-root\"\n");
- ERROR("\t-o[ffset] <bytes>\tskip <bytes> at start of input file, "
- "default \"0\"\n");
ERROR("\t-n[o-progress]\t\tdon't display the progress "
"bar\n");
ERROR("\t-no[-xattrs]\t\tdon't extract xattrs in file system"
diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
index 0edbd25..4836b8d 100644
--- a/squashfs-tools/unsquashfs.h
+++ b/squashfs-tools/unsquashfs.h
@@ -40,12 +40,17 @@
#include <grp.h>
#include <time.h>
#include <regex.h>
+#include <fnmatch.h>
#include <signal.h>
#include <pthread.h>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/time.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
diff --git a/squashfs-tools/unsquashfs_info.c b/squashfs-tools/unsquashfs_info.c
index c8e2b9b..7d4f7af 100644
--- a/squashfs-tools/unsquashfs_info.c
+++ b/squashfs-tools/unsquashfs_info.c
@@ -97,31 +97,22 @@ void dump_state()
void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
- int sig, waiting = 0;
+ int sig, err, waiting = 0;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, &timespec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
+ err = sigwait(&sigmask, &sig);
- if(sig == -1) {
+ if(err == -1) {
switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
continue;
default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
+ BAD_ERROR("sigwait failed "
"because %s\n", strerror(errno));
}
}
@@ -133,8 +124,12 @@ void *info_thrd(void *arg)
/* set one second interval period, if ^\ received
within then, dump queue and cache status */
waiting = 1;
- } else
+ alarm(1);
+ } else if (sig == SIGQUIT) {
dump_state();
+ } else if (sig == SIGALRM) {
+ waiting = 0;
+ }
}
}
diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
index 59f4aae..13f0e35 100644
--- a/squashfs-tools/unsquashfs_xattr.c
+++ b/squashfs-tools/unsquashfs_xattr.c
@@ -27,6 +27,11 @@
#include <sys/xattr.h>
+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
+ #define lsetxattr(path_, name_, val_, sz_, flags_) \
+ setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
+#endif
+
#define NOSPACE_MAX 10
extern int root_process;
diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
index c34b2a7..6cecb74 100644
--- a/squashfs-tools/xattr.c
+++ b/squashfs-tools/xattr.c
@@ -22,6 +22,14 @@
* xattr.c
*/
+#ifndef linux
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#else
+#include <endian.h>
+#endif
+
#define TRUE 1
#define FALSE 0
@@ -36,6 +44,13 @@
#include <stdlib.h>
#include <sys/xattr.h>
+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
+ #define llistxattr(path_, buf_, sz_) \
+ listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
+ #define lgetxattr(path_, name_, val_, sz_) \
+ getxattr(path_, name_, val_, sz_, 0, XATTR_NOFOLLOW)
+#endif
+
#include "squashfs_fs.h"
#include "squashfs_swap.h"
#include "mksquashfs.h"
diff --git a/squashfs-tools/xz_wrapper.c b/squashfs-tools/xz_wrapper.c
index 0977f74..e77ec59 100644
--- a/squashfs-tools/xz_wrapper.c
+++ b/squashfs-tools/xz_wrapper.c
@@ -322,7 +322,7 @@ failed:
}
-static void xz_display_options(void *buffer, int size)
+void xz_display_options(void *buffer, int size)
{
struct comp_opts *comp_opts = buffer;
int dictionary_size, flags, printed;
@@ -503,7 +503,7 @@ static int xz_uncompress(void *dest, void *src, int size, int outsize,
}
-static void xz_usage()
+void xz_usage()
{
fprintf(stderr, "\t -Xbcj filter1,filter2,...,filterN\n");
fprintf(stderr, "\t\tCompress using filter1,filter2,...,filterN in");
diff --git a/squashfs-tools/zstd_wrapper.c b/squashfs-tools/zstd_wrapper.c
deleted file mode 100644
index dcab75a..0000000
--- a/squashfs-tools/zstd_wrapper.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (c) 2017
- * Phillip Lougher <phillip@squashfs.org.uk>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2,
- * or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * zstd_wrapper.c
- *
- * Support for ZSTD compression http://zstd.net
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <zstd.h>
-#include <zstd_errors.h>
-
-#include "squashfs_fs.h"
-#include "zstd_wrapper.h"
-#include "compressor.h"
-
-static int compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL;
-
-/*
- * This function is called by the options parsing code in mksquashfs.c
- * to parse any -X compressor option.
- *
- * This function returns:
- * >=0 (number of additional args parsed) on success
- * -1 if the option was unrecognised, or
- * -2 if the option was recognised, but otherwise bad in
- * some way (e.g. invalid parameter)
- *
- * Note: this function sets internal compressor state, but does not
- * pass back the results of the parsing other than success/failure.
- * The zstd_dump_options() function is called later to get the options in
- * a format suitable for writing to the filesystem.
- */
-static int zstd_options(char *argv[], int argc)
-{
- if (strcmp(argv[0], "-Xcompression-level") == 0) {
- if (argc < 2) {
- fprintf(stderr, "zstd: -Xcompression-level missing "
- "compression level\n");
- fprintf(stderr, "zstd: -Xcompression-level it should "
- "be 1 <= n <= %d\n", ZSTD_maxCLevel());
- goto failed;
- }
-
- compression_level = atoi(argv[1]);
- if (compression_level < 1 ||
- compression_level > ZSTD_maxCLevel()) {
- fprintf(stderr, "zstd: -Xcompression-level invalid, it "
- "should be 1 <= n <= %d\n", ZSTD_maxCLevel());
- goto failed;
- }
-
- return 1;
- }
-
- return -1;
-failed:
- return -2;
-}
-
-/*
- * This function is called by mksquashfs to dump the parsed
- * compressor options in a format suitable for writing to the
- * compressor options field in the filesystem (stored immediately
- * after the superblock).
- *
- * This function returns a pointer to the compression options structure
- * to be stored (and the size), or NULL if there are no compression
- * options.
- */
-static void *zstd_dump_options(int block_size, int *size)
-{
- static struct zstd_comp_opts comp_opts;
-
- /* don't return anything if the options are all default */
- if (compression_level == ZSTD_DEFAULT_COMPRESSION_LEVEL)
- return NULL;
-
- comp_opts.compression_level = compression_level;
-
- SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);
-
- *size = sizeof(comp_opts);
- return &comp_opts;
-}
-
-/*
- * This function is a helper specifically for the append mode of
- * mksquashfs. Its purpose is to set the internal compressor state
- * to the stored compressor options in the passed compressor options
- * structure.
- *
- * In effect this function sets up the compressor options
- * to the same state they were when the filesystem was originally
- * generated, this is to ensure on appending, the compressor uses
- * the same compression options that were used to generate the
- * original filesystem.
- *
- * Note, even if there are no compressor options, this function is still
- * called with an empty compressor structure (size == 0), to explicitly
- * set the default options, this is to ensure any user supplied
- * -X options on the appending mksquashfs command line are over-ridden.
- *
- * This function returns 0 on sucessful extraction of options, and -1 on error.
- */
-static int zstd_extract_options(int block_size, void *buffer, int size)
-{
- struct zstd_comp_opts *comp_opts = buffer;
-
- if (size == 0) {
- /* Set default values */
- compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL;
- return 0;
- }
-
- /* we expect a comp_opts structure of sufficient size to be present */
- if (size < sizeof(*comp_opts))
- goto failed;
-
- SQUASHFS_INSWAP_COMP_OPTS(comp_opts);
-
- if (comp_opts->compression_level < 1 ||
- comp_opts->compression_level > ZSTD_maxCLevel()) {
- fprintf(stderr, "zstd: bad compression level in compression "
- "options structure\n");
- goto failed;
- }
-
- compression_level = comp_opts->compression_level;
-
- return 0;
-
-failed:
- fprintf(stderr, "zstd: error reading stored compressor options from "
- "filesystem!\n");
-
- return -1;
-}
-
-static void zstd_display_options(void *buffer, int size)
-{
- struct zstd_comp_opts *comp_opts = buffer;
-
- /* we expect a comp_opts structure of sufficient size to be present */
- if (size < sizeof(*comp_opts))
- goto failed;
-
- SQUASHFS_INSWAP_COMP_OPTS(comp_opts);
-
- if (comp_opts->compression_level < 1 ||
- comp_opts->compression_level > ZSTD_maxCLevel()) {
- fprintf(stderr, "zstd: bad compression level in compression "
- "options structure\n");
- goto failed;
- }
-
- printf("\tcompression-level %d\n", comp_opts->compression_level);
-
- return;
-
-failed:
- fprintf(stderr, "zstd: error reading stored compressor options from "
- "filesystem!\n");
-}
-
-/*
- * This function is called by mksquashfs to initialise the
- * compressor, before compress() is called.
- *
- * This function returns 0 on success, and -1 on error.
- */
-static int zstd_init(void **strm, int block_size, int datablock)
-{
- ZSTD_CCtx *cctx = ZSTD_createCCtx();
-
- if (!cctx) {
- fprintf(stderr, "zstd: failed to allocate compression "
- "context!\n");
- return -1;
- }
-
- *strm = cctx;
- return 0;
-}
-
-static int zstd_compress(void *strm, void *dest, void *src, int size,
- int block_size, int *error)
-{
- const size_t res = ZSTD_compressCCtx((ZSTD_CCtx*)strm, dest, block_size,
- src, size, compression_level);
-
- if (ZSTD_isError(res)) {
- /* FIXME:
- * zstd does not expose stable error codes. The error enum may
- * change between versions. Until upstream zstd stablizes the
- * error codes, we have no way of knowing why the error occurs.
- * zstd shouldn't fail to compress any input unless there isn't
- * enough output space. We assume that is the cause and return
- * the special error code for not enough output space.
- */
- return 0;
- }
-
- return (int)res;
-}
-
-static int zstd_uncompress(void *dest, void *src, int size, int outsize,
- int *error)
-{
- const size_t res = ZSTD_decompress(dest, outsize, src, size);
-
- if (ZSTD_isError(res)) {
- fprintf(stderr, "\t%d %d\n", outsize, size);
-
- *error = (int)ZSTD_getErrorCode(res);
- return -1;
- }
-
- return (int)res;
-}
-
-static void zstd_usage(void)
-{
- fprintf(stderr, "\t -Xcompression-level <compression-level>\n");
- fprintf(stderr, "\t\t<compression-level> should be 1 .. %d (default "
- "%d)\n", ZSTD_maxCLevel(), ZSTD_DEFAULT_COMPRESSION_LEVEL);
-}
-
-struct compressor zstd_comp_ops = {
- .init = zstd_init,
- .compress = zstd_compress,
- .uncompress = zstd_uncompress,
- .options = zstd_options,
- .dump_options = zstd_dump_options,
- .extract_options = zstd_extract_options,
- .display_options = zstd_display_options,
- .usage = zstd_usage,
- .id = ZSTD_COMPRESSION,
- .name = "zstd",
- .supported = 1
-};
diff --git a/squashfs-tools/zstd_wrapper.h b/squashfs-tools/zstd_wrapper.h
deleted file mode 100644
index 4fbef0a..0000000
--- a/squashfs-tools/zstd_wrapper.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef ZSTD_WRAPPER_H
-#define ZSTD_WRAPPER_H
-/*
- * Squashfs
- *
- * Copyright (c) 2017
- * Phillip Lougher <phillip@squashfs.org.uk>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2,
- * or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * zstd_wrapper.h
- *
- */
-
-#ifndef linux
-#define __BYTE_ORDER BYTE_ORDER
-#define __BIG_ENDIAN BIG_ENDIAN
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#else
-#include <endian.h>
-#endif
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-extern unsigned int inswap_le16(unsigned short);
-extern unsigned int inswap_le32(unsigned int);
-
-#define SQUASHFS_INSWAP_COMP_OPTS(s) { \
- (s)->compression_level = inswap_le32((s)->compression_level); \
-}
-#else
-#define SQUASHFS_INSWAP_COMP_OPTS(s)
-#endif
-
-/* Default compression */
-#define ZSTD_DEFAULT_COMPRESSION_LEVEL 15
-
-struct zstd_comp_opts {
- int compression_level;
-};
-#endif