From 5a498ad24dcfeac9f3d747e894f22901f3ac10ef Mon Sep 17 00:00:00 2001 From: probonopd Date: Thu, 15 Sep 2016 21:09:52 +0200 Subject: [PATCH] Add -offset function to skip n bytes at the beginning of the squashfs file --- squashfs-tools/mksquashfs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c index d221c358..92b6a319 100644 --- a/squashfs-tools/mksquashfs.c +++ b/squashfs-tools/mksquashfs.c @@ -98,6 +98,7 @@ 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; @@ -516,9 +517,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, SEEK_SET) == -1) { + if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) { ERROR("read_fs_bytes: Lseek on destination failed because %s, " - "offset=0x%llx\n", strerror(errno), off); + "offset=0x%llx\n", strerror(errno), off+squashfs_start_offset); res = 0; } else if(read_bytes(fd, buff, bytes) < bytes) { ERROR("Read on destination failed\n"); @@ -557,10 +558,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, SEEK_SET) == -1) { + if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) { ERROR("write_destination: Lseek on destination " "failed because %s, offset=0x%llx\n", strerror(errno), - off); + off+squashfs_start_offset); BAD_ERROR("Probably out of space on output %s\n", block_device ? "block device" : "filesystem"); } @@ -2315,9 +2316,9 @@ void *writer(void *arg) pthread_cleanup_push((void *) pthread_mutex_unlock, &pos_mutex); pthread_mutex_lock(&pos_mutex); - if(lseek(fd, off, SEEK_SET) == -1) { + if(lseek(fd, off+squashfs_start_offset, SEEK_SET) == -1) { ERROR("writer: Lseek on destination failed because " - "%s, offset=0x%llx\n", strerror(errno), off); + "%s, offset=0x%llx\n", strerror(errno), off+squashfs_start_offset); BAD_ERROR("Probably out of space on output " "%s\n", block_device ? "block device" : "filesystem"); @@ -5341,6 +5342,15 @@ int main(int argc, char *argv[]) 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 " @@ -5641,6 +5651,9 @@ int main(int argc, char *argv[]) ERROR("\nMiscellaneous options:\n"); ERROR("-root-owned\t\talternative name for -all-root" "\n"); + ERROR("-o \t\tSkip 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"