2 * Copyright (C) 2016 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.
24 #define MAX_FILE_VERSION 100
26 static void usage(char *filename)
28 fprintf(stderr, "Usage: %s input_blk_alloc_file output_base_fs_file \n", filename);
31 int main(int argc, char **argv)
33 FILE *blk_alloc_file = NULL, *base_fs_file = NULL;
34 char filename[MAX_PATH], file_version[MAX_FILE_VERSION], *spaced_allocs = NULL;
35 size_t spaced_allocs_len = 0;
41 blk_alloc_file = fopen(argv[1], "r");
42 if (blk_alloc_file == NULL) {
43 fprintf(stderr, "failed to open %s: %s\n", argv[1], strerror(errno));
46 base_fs_file = fopen(argv[2], "w");
47 if (base_fs_file == NULL) {
48 fprintf(stderr, "failed to open %s: %s\n", argv[2], strerror(errno));
51 if (fscanf(blk_alloc_file, "Base EXT4 version %s", file_version) > 0) {
53 printf("%s is already in *.base_fs format, just copying into %s...\n", argv[1], argv[2]);
54 rewind(blk_alloc_file);
55 while ((c = fgetc(blk_alloc_file)) != EOF) {
56 fputc(c, base_fs_file);
60 printf("Converting %s into *.base_fs format as %s...\n", argv[1], argv[2]);
61 rewind(blk_alloc_file);
63 fprintf(base_fs_file, "Base EXT4 version 1.0\n");
64 while(fscanf(blk_alloc_file, "%s ", filename) != EOF) {
66 fprintf(base_fs_file, "%s ", filename);
67 if (getline(&spaced_allocs, &spaced_allocs_len, blk_alloc_file) == -1) {
68 fprintf(stderr, "Bad blk_alloc format\n");
71 for (i = 0; spaced_allocs[i]; i++) {
72 if (spaced_allocs[i] == ' ') {
73 if (!isspace(spaced_allocs[i + 1])) fputc(',', base_fs_file);
74 } else fputc(spaced_allocs[i], base_fs_file);
78 fclose(blk_alloc_file);