2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <sparse/sparse.h>
24 #include <sys/types.h>
26 #include <sys/types.h>
35 fprintf(stderr, "Usage: simg2img <sparse_image_files> <raw_image_file>\n");
38 int main(int argc, char *argv[])
44 struct sparse_file *s;
51 out = open(argv[argc - 1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
53 fprintf(stderr, "Cannot open output file %s\n", argv[argc - 1]);
57 for (i = 1; i < argc - 1; i++) {
58 if (strcmp(argv[i], "-") == 0) {
61 in = open(argv[i], O_RDONLY | O_BINARY);
63 fprintf(stderr, "Cannot open input file %s\n", argv[i]);
68 s = sparse_file_import(in, true, false);
70 fprintf(stderr, "Failed to read sparse file\n");
74 lseek(out, SEEK_SET, 0);
76 ret = sparse_file_write(s, out, false, false, false);
78 fprintf(stderr, "Cannot write output file\n");
81 sparse_file_destroy(s);