Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -offset option to skip n bytes #13

Merged
merged 2 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions squashfs-tools/mksquashfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 <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"
Expand Down
13 changes: 12 additions & 1 deletion squashfs-tools/unsquashfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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;
Expand Down Expand Up @@ -631,7 +632,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, SEEK_SET) == -1) {
if(lseek(fd, off + squashfs_start_offset, SEEK_SET) == -1) {
ERROR("Lseek failed because %s\n", strerror(errno));
return FALSE;
}
Expand Down Expand Up @@ -2544,6 +2545,14 @@ 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) ||
Expand Down Expand Up @@ -2636,6 +2645,8 @@ int main(int argc, char *argv[])
"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"
Expand Down