2 * Copyright (C) 2012 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 #define _FILE_OFFSET_BITS 64
18 #define _LARGEFILE64_SOURCE 1
26 #include <sys/types.h>
28 #include <sys/types.h>
31 #include <sparse/sparse.h>
39 fprintf(stderr
, "Usage: simg2simg <sparse image file> <sparse_image_file> <max_size>\n");
42 int main(int argc
, char *argv
[])
48 struct sparse_file
*s
;
50 struct sparse_file
**out_s
;
59 max_size
= atoll(argv
[3]);
61 in
= open(argv
[1], O_RDONLY
| O_BINARY
);
63 fprintf(stderr
, "Cannot open input file %s\n", argv
[1]);
67 s
= sparse_file_import(in
, true, false);
69 fprintf(stderr
, "Failed to import sparse file\n");
73 files
= sparse_file_resparse(s
, max_size
, NULL
, 0);
75 fprintf(stderr
, "Failed to resparse\n");
79 out_s
= calloc(sizeof(struct sparse_file
*), files
);
81 fprintf(stderr
, "Failed to allocate sparse file array\n");
85 files
= sparse_file_resparse(s
, max_size
, out_s
, files
);
87 fprintf(stderr
, "Failed to resparse\n");
91 for (i
= 0; i
< files
; i
++) {
92 ret
= snprintf(filename
, sizeof(filename
), "%s.%d", argv
[2], i
);
93 if (ret
>= (int)sizeof(filename
)) {
94 fprintf(stderr
, "Filename too long\n");
98 out
= open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0664);
100 fprintf(stderr
, "Cannot open output file %s\n", argv
[2]);
104 ret
= sparse_file_write(out_s
[i
], out
, false, true, false);
106 fprintf(stderr
, "Failed to write sparse file\n");