mirror of
https://git.openwrt.org/project/make_ext4fs.git
synced 2024-11-21 06:40:40 -05:00
libsparse: remove unused files
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
c657f39e16
commit
2964e1c736
@ -1,110 +0,0 @@
|
||||
# Copyright 2010 The Android Open Source Project
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
libsparse_src_files := \
|
||||
backed_block.c \
|
||||
output_file.c \
|
||||
sparse.c \
|
||||
sparse_crc32.c \
|
||||
sparse_err.c \
|
||||
sparse_read.c
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||
LOCAL_SRC_FILES := $(libsparse_src_files)
|
||||
LOCAL_MODULE := libsparse_host
|
||||
LOCAL_STATIC_LIBRARIES := libz
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_HOST_STATIC_LIBRARY)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||
LOCAL_SRC_FILES := $(libsparse_src_files)
|
||||
LOCAL_MODULE := libsparse
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||
LOCAL_SRC_FILES := $(libsparse_src_files)
|
||||
LOCAL_MODULE := libsparse_static
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
|
||||
LOCAL_STATIC_LIBRARIES := libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := simg2img.c \
|
||||
sparse_crc32.c
|
||||
LOCAL_MODULE := simg2img_host
|
||||
# Need a unique module name, but exe should still be called simg2img
|
||||
LOCAL_MODULE_STEM := simg2img
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libsparse_host \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_HOST_EXECUTABLE)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := simg2img.c \
|
||||
sparse_crc32.c
|
||||
LOCAL_MODULE := simg2img
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libsparse_static \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := img2simg.c
|
||||
LOCAL_MODULE := img2simg_host
|
||||
# Need a unique module name, but exe should still be called simg2img
|
||||
LOCAL_MODULE_STEM := img2simg
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libsparse_host \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_HOST_EXECUTABLE)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := img2simg.c
|
||||
LOCAL_MODULE := img2simg
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libsparse_static \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
|
||||
ifneq ($(HOST_OS),windows)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := append2simg.c
|
||||
LOCAL_MODULE := append2simg
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libsparse_host \
|
||||
libz
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_HOST_EXECUTABLE)
|
||||
|
||||
endif
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := simg_dump.py
|
||||
LOCAL_SRC_FILES := simg_dump.py
|
||||
LOCAL_MODULE_CLASS := EXECUTABLES
|
||||
LOCAL_IS_HOST_MODULE := true
|
||||
LOCAL_CFLAGS := -Werror
|
||||
include $(BUILD_PREBUILT)
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sparse/sparse.h>
|
||||
#include "sparse_file.h"
|
||||
#include "backed_block.h"
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define lseek64 lseek
|
||||
#endif
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define lseek64 lseek
|
||||
#define off64_t off_t
|
||||
#endif
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: append2simg <output> <input>\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int output;
|
||||
int output_block;
|
||||
char *output_path;
|
||||
struct sparse_file *sparse_output;
|
||||
|
||||
int input;
|
||||
char *input_path;
|
||||
off64_t input_len;
|
||||
|
||||
int tmp_fd;
|
||||
char *tmp_path;
|
||||
|
||||
int ret;
|
||||
|
||||
if (argc == 3) {
|
||||
output_path = argv[1];
|
||||
input_path = argv[2];
|
||||
} else {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = asprintf(&tmp_path, "%s.append2simg", output_path);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Couldn't allocate filename\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
output = open(output_path, O_RDWR | O_BINARY);
|
||||
if (output < 0) {
|
||||
fprintf(stderr, "Couldn't open output file (%s)\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sparse_output = sparse_file_import_auto(output, true, true);
|
||||
if (!sparse_output) {
|
||||
fprintf(stderr, "Couldn't import output file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
input = open(input_path, O_RDONLY | O_BINARY);
|
||||
if (input < 0) {
|
||||
fprintf(stderr, "Couldn't open input file (%s)\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
input_len = lseek64(input, 0, SEEK_END);
|
||||
if (input_len < 0) {
|
||||
fprintf(stderr, "Couldn't get input file length (%s)\n", strerror(errno));
|
||||
exit(-1);
|
||||
} else if (input_len % sparse_output->block_size) {
|
||||
fprintf(stderr, "Input file is not a multiple of the output file's block size");
|
||||
exit(-1);
|
||||
}
|
||||
lseek64(input, 0, SEEK_SET);
|
||||
|
||||
output_block = sparse_output->len / sparse_output->block_size;
|
||||
if (sparse_file_add_fd(sparse_output, input, 0, input_len, output_block) < 0) {
|
||||
fprintf(stderr, "Couldn't add input file\n");
|
||||
exit(-1);
|
||||
}
|
||||
sparse_output->len += input_len;
|
||||
|
||||
tmp_fd = open(tmp_path, O_WRONLY | O_CREAT | O_BINARY, 0664);
|
||||
if (tmp_fd < 0) {
|
||||
fprintf(stderr, "Couldn't open temporary file (%s)\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
lseek64(output, 0, SEEK_SET);
|
||||
if (sparse_file_write(sparse_output, tmp_fd, false, true, false) < 0) {
|
||||
fprintf(stderr, "Failed to write sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sparse_file_destroy(sparse_output);
|
||||
close(tmp_fd);
|
||||
close(output);
|
||||
close(input);
|
||||
|
||||
ret = rename(tmp_path, output_path);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Failed to rename temporary file (%s)\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
free(tmp_path);
|
||||
|
||||
exit(0);
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sparse/sparse.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define lseek64 lseek
|
||||
#define off64_t off_t
|
||||
#endif
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: img2simg <raw_image_file> <sparse_image_file> [<block_size>]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int in;
|
||||
int out;
|
||||
int ret;
|
||||
struct sparse_file *s;
|
||||
unsigned int block_size = 4096;
|
||||
off64_t len;
|
||||
|
||||
if (argc < 3 || argc > 4) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
block_size = atoi(argv[3]);
|
||||
}
|
||||
|
||||
if (block_size < 1024 || block_size % 4 != 0) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "-") == 0) {
|
||||
in = STDIN_FILENO;
|
||||
} else {
|
||||
in = open(argv[1], O_RDONLY | O_BINARY);
|
||||
if (in < 0) {
|
||||
fprintf(stderr, "Cannot open input file %s\n", argv[1]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(argv[2], "-") == 0) {
|
||||
out = STDOUT_FILENO;
|
||||
} else {
|
||||
out = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
|
||||
if (out < 0) {
|
||||
fprintf(stderr, "Cannot open output file %s\n", argv[2]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
len = lseek64(in, 0, SEEK_END);
|
||||
lseek64(in, 0, SEEK_SET);
|
||||
|
||||
s = sparse_file_new(block_size, len);
|
||||
if (!s) {
|
||||
fprintf(stderr, "Failed to create sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sparse_file_verbose(s);
|
||||
ret = sparse_file_read(s, in, false, false);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Failed to read file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = sparse_file_write(s, out, false, true, false);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Failed to write sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
close(in);
|
||||
close(out);
|
||||
|
||||
exit(0);
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sparse/sparse.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: simg2img <sparse_image_files> <raw_image_file>\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int in;
|
||||
int out;
|
||||
int i;
|
||||
int ret;
|
||||
struct sparse_file *s;
|
||||
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
out = open(argv[argc - 1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
|
||||
if (out < 0) {
|
||||
fprintf(stderr, "Cannot open output file %s\n", argv[argc - 1]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (i = 1; i < argc - 1; i++) {
|
||||
if (strcmp(argv[i], "-") == 0) {
|
||||
in = STDIN_FILENO;
|
||||
} else {
|
||||
in = open(argv[i], O_RDONLY | O_BINARY);
|
||||
if (in < 0) {
|
||||
fprintf(stderr, "Cannot open input file %s\n", argv[i]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
s = sparse_file_import(in, true, false);
|
||||
if (!s) {
|
||||
fprintf(stderr, "Failed to read sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
lseek(out, SEEK_SET, 0);
|
||||
|
||||
ret = sparse_file_write(s, out, false, false, false);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Cannot write output file\n");
|
||||
exit(-1);
|
||||
}
|
||||
sparse_file_destroy(s);
|
||||
close(in);
|
||||
}
|
||||
|
||||
close(out);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sparse/sparse.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: simg2simg <sparse image file> <sparse_image_file> <max_size>\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int in;
|
||||
int out;
|
||||
int i;
|
||||
int ret;
|
||||
struct sparse_file *s;
|
||||
int64_t max_size;
|
||||
struct sparse_file **out_s;
|
||||
int files;
|
||||
char filename[4096];
|
||||
|
||||
if (argc != 4) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
max_size = atoll(argv[3]);
|
||||
|
||||
in = open(argv[1], O_RDONLY | O_BINARY);
|
||||
if (in < 0) {
|
||||
fprintf(stderr, "Cannot open input file %s\n", argv[1]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
s = sparse_file_import(in, true, false);
|
||||
if (!s) {
|
||||
fprintf(stderr, "Failed to import sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
files = sparse_file_resparse(s, max_size, NULL, 0);
|
||||
if (files < 0) {
|
||||
fprintf(stderr, "Failed to resparse\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
out_s = calloc(sizeof(struct sparse_file *), files);
|
||||
if (!out_s) {
|
||||
fprintf(stderr, "Failed to allocate sparse file array\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
files = sparse_file_resparse(s, max_size, out_s, files);
|
||||
if (files < 0) {
|
||||
fprintf(stderr, "Failed to resparse\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (i = 0; i < files; i++) {
|
||||
ret = snprintf(filename, sizeof(filename), "%s.%d", argv[2], i);
|
||||
if (ret >= (int)sizeof(filename)) {
|
||||
fprintf(stderr, "Filename too long\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
out = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
|
||||
if (out < 0) {
|
||||
fprintf(stderr, "Cannot open output file %s\n", argv[2]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = sparse_file_write(out_s[i], out, false, true, false);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Failed to write sparse file\n");
|
||||
exit(-1);
|
||||
}
|
||||
close(out);
|
||||
}
|
||||
|
||||
close(in);
|
||||
|
||||
exit(0);
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# Copyright (C) 2012 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import getopt, posixpath, signal, struct, sys
|
||||
|
||||
def usage(argv0):
|
||||
print("""
|
||||
Usage: %s [-v] sparse_image_file ...
|
||||
-v verbose output
|
||||
""" % ( argv0 ))
|
||||
sys.exit(2)
|
||||
|
||||
def main():
|
||||
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
|
||||
me = posixpath.basename(sys.argv[0])
|
||||
|
||||
# Parse the command line
|
||||
verbose = 0 # -v
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:],
|
||||
"v",
|
||||
["verbose"])
|
||||
except getopt.GetoptError, e:
|
||||
print(e)
|
||||
usage(me)
|
||||
for o, a in opts:
|
||||
if o in ("-v", "--verbose"):
|
||||
verbose += 1
|
||||
else:
|
||||
print("Unrecognized option \"%s\"" % (o))
|
||||
usage(me)
|
||||
|
||||
if len(args) == 0:
|
||||
print("No sparse_image_file specified")
|
||||
usage(me)
|
||||
|
||||
for path in args:
|
||||
FH = open(path, 'rb')
|
||||
header_bin = FH.read(28)
|
||||
header = struct.unpack("<I4H4I", header_bin)
|
||||
|
||||
magic = header[0]
|
||||
major_version = header[1]
|
||||
minor_version = header[2]
|
||||
file_hdr_sz = header[3]
|
||||
chunk_hdr_sz = header[4]
|
||||
blk_sz = header[5]
|
||||
total_blks = header[6]
|
||||
total_chunks = header[7]
|
||||
image_checksum = header[8]
|
||||
|
||||
if magic != 0xED26FF3A:
|
||||
print("%s: %s: Magic should be 0xED26FF3A but is 0x%08X"
|
||||
% (me, path, magic))
|
||||
continue
|
||||
if major_version != 1 or minor_version != 0:
|
||||
print("%s: %s: I only know about version 1.0, but this is version %u.%u"
|
||||
% (me, path, major_version, minor_version))
|
||||
continue
|
||||
if file_hdr_sz != 28:
|
||||
print("%s: %s: The file header size was expected to be 28, but is %u."
|
||||
% (me, path, file_hdr_sz))
|
||||
continue
|
||||
if chunk_hdr_sz != 12:
|
||||
print("%s: %s: The chunk header size was expected to be 12, but is %u."
|
||||
% (me, path, chunk_hdr_sz))
|
||||
continue
|
||||
|
||||
print("%s: Total of %u %u-byte output blocks in %u input chunks."
|
||||
% (path, total_blks, blk_sz, total_chunks))
|
||||
|
||||
if image_checksum != 0:
|
||||
print("checksum=0x%08X" % (image_checksum))
|
||||
|
||||
if not verbose:
|
||||
continue
|
||||
print(" input_bytes output_blocks")
|
||||
print("chunk offset number offset number")
|
||||
offset = 0
|
||||
for i in xrange(1,total_chunks+1):
|
||||
header_bin = FH.read(12)
|
||||
header = struct.unpack("<2H2I", header_bin)
|
||||
chunk_type = header[0]
|
||||
reserved1 = header[1]
|
||||
chunk_sz = header[2]
|
||||
total_sz = header[3]
|
||||
data_sz = total_sz - 12
|
||||
|
||||
print("%4u %10u %10u %7u %7u" % (i, FH.tell(), data_sz, offset, chunk_sz),
|
||||
end=" ")
|
||||
|
||||
if chunk_type == 0xCAC1:
|
||||
if data_sz != (chunk_sz * blk_sz):
|
||||
print("Raw chunk input size (%u) does not match output size (%u)"
|
||||
% (data_sz, chunk_sz * blk_sz))
|
||||
break;
|
||||
else:
|
||||
print("Raw data", end="")
|
||||
FH.read(data_sz)
|
||||
elif chunk_type == 0xCAC2:
|
||||
if data_sz != 4:
|
||||
print("Fill chunk should have 4 bytes of fill, but this has %u"
|
||||
% (data_sz), end="")
|
||||
break;
|
||||
else:
|
||||
fill_bin = FH.read(4)
|
||||
fill = struct.unpack("<I", fill_bin)
|
||||
print("Fill with 0x%08X" % (fill))
|
||||
elif chunk_type == 0xCAC3:
|
||||
if data_sz != 0:
|
||||
print("Don't care chunk input size is non-zero (%u)" % (data_sz))
|
||||
break;
|
||||
else:
|
||||
print("Don't care", end="")
|
||||
elif chunk_type == 0xCAC4:
|
||||
if data_sz != 4:
|
||||
print("CRC32 chunk should have 4 bytes of CRC, but this has %u"
|
||||
% (data_sz), end="")
|
||||
break;
|
||||
else:
|
||||
crc_bin = FH.read(4)
|
||||
crc = struct.unpack("<I", crc)
|
||||
print("Unverified CRC32 0x%08X" % (crc))
|
||||
else:
|
||||
print("Unknown chunk type 0x%04X" % (chunk_type), end="")
|
||||
break;
|
||||
|
||||
if verbose > 1:
|
||||
header = struct.unpack("<12B", header_bin)
|
||||
print(" (%02X%02X %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X)"
|
||||
% (header[0], header[1], header[2], header[3],
|
||||
header[4], header[5], header[6], header[7],
|
||||
header[8], header[9], header[10], header[11]))
|
||||
else:
|
||||
print()
|
||||
|
||||
offset += chunk_sz
|
||||
|
||||
print(" %10u %7u End" % (FH.tell(), offset))
|
||||
|
||||
if total_blks != offset:
|
||||
print("The header said we should have %u output blocks, but we saw %u"
|
||||
% (total_blks, offset))
|
||||
|
||||
junk_len = len(FH.read())
|
||||
if junk_len:
|
||||
print("There were %u bytes of extra data at the end of the file."
|
||||
% (junk_len))
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user