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 "make_ext4fs.h"
18 #include "ext4_utils.h"
23 #include <sparse/sparse.h>
35 #include <sys/types.h>
41 /* These match the Linux definitions of these flags.
42 L_xx is defined to avoid conflicting with the win32 versions.
57 #define L_S_IRUSR 00400
58 #define L_S_IWUSR 00200
59 #define L_S_IXUSR 00100
60 #define S_IRWXU (L_S_IRUSR | L_S_IWUSR | L_S_IXUSR)
64 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
68 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
69 #define S_ISUID 0004000
70 #define S_ISGID 0002000
71 #define S_ISVTX 0001000
75 #include <selinux/selinux.h>
76 #include <selinux/label.h>
83 #define MAX_BLK_MAPPING_STR 1000
85 const int blk_file_major_ver = 1;
86 const int blk_file_minor_ver = 0;
87 const char *blk_file_header_fmt = "Base EXT4 version %d.%d";
89 /* TODO: Not implemented:
90 Allocating blocks in the same block group as the file inode
91 Hash or binary tree directories
92 Special files: sockets, devices, fifos
95 static int filter_dot(const struct dirent *d)
97 return (strcmp(d->d_name, "..") && strcmp(d->d_name, "."));
100 static u32 build_default_directory_structure(const char *dir_path,
101 struct selabel_handle *sehnd)
105 struct dentry dentries = {
106 .filename = "lost+found",
107 .file_type = EXT4_FT_DIR,
113 root_inode = make_directory(0, 1, &dentries, 1);
114 inode = make_directory(root_inode, 0, NULL, 0);
115 *dentries.inode = inode;
116 inode_set_permissions(inode, dentries.mode,
117 dentries.uid, dentries.gid, dentries.mtime);
122 char *secontext = NULL;
124 asprintf(&path, "%slost+found", dir_path);
125 if (selabel_lookup(sehnd, &secontext, path, S_IFDIR) < 0) {
126 error("cannot lookup security context for %s", path);
128 inode_set_selinux(inode, secontext);
139 /* Read a local directory and create the same tree in the generated filesystem.
140 Calls itself recursively with each directory in the given directory.
141 full_path is an absolute or relative path, with a trailing slash, to the
142 directory on disk that should be copied, or NULL if this is a directory
143 that does not exist on disk (e.g. lost+found).
144 dir_path is an absolute path, with trailing slash, to the same directory
145 if the image were mounted at the specified mount point */
146 static u32 build_directory_structure(const char *full_path, const char *dir_path, const char *target_out_path,
147 u32 dir_inode, fs_config_func_t fs_config_func,
148 struct selabel_handle *sehnd, int verbose, time_t fixed_time)
151 struct dentry *dentries;
152 struct dirent **namelist = NULL;
159 bool needs_lost_and_found = false;
162 entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort);
165 /* The scandir function implemented in glibc has a bug that makes it
166 erroneously fail with ENOMEM under certain circumstances.
167 As a workaround we can retry the scandir call with the same arguments.
168 GLIBC BZ: https://sourceware.org/bugzilla/show_bug.cgi?id=17804 */
170 entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort);
173 error_errno("scandir");
174 return EXT4_ALLOCATE_FAILED;
179 if (dir_inode == 0) {
180 /* root directory, check if lost+found already exists */
181 for (i = 0; i < entries; i++)
182 if (strcmp(namelist[i]->d_name, "lost+found") == 0)
185 needs_lost_and_found = true;
188 dentries = calloc(entries, sizeof(struct dentry));
189 if (dentries == NULL)
190 critical_error_errno("malloc");
192 for (i = 0; i < entries; i++) {
193 dentries[i].filename = strdup(namelist[i]->d_name);
194 if (dentries[i].filename == NULL)
195 critical_error_errno("strdup");
197 asprintf(&dentries[i].path, "%s%s", dir_path, namelist[i]->d_name);
198 asprintf(&dentries[i].full_path, "%s%s", full_path, namelist[i]->d_name);
202 ret = lstat(dentries[i].full_path, &stat);
204 error_errno("lstat");
210 dentries[i].size = stat.st_size;
211 dentries[i].mode = stat.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
212 if (fixed_time == -1) {
213 dentries[i].mtime = stat.st_mtime;
215 dentries[i].mtime = fixed_time;
217 uint64_t capabilities;
218 if (fs_config_func != NULL) {
220 unsigned int mode = 0;
221 unsigned int uid = 0;
222 unsigned int gid = 0;
223 int dir = S_ISDIR(stat.st_mode);
224 fs_config_func(dentries[i].path, dir, target_out_path, &uid, &gid, &mode, &capabilities);
225 dentries[i].mode = mode;
226 dentries[i].uid = uid;
227 dentries[i].gid = gid;
228 dentries[i].capabilities = capabilities;
230 error("can't set android permissions - built without android support");
235 if (selabel_lookup(sehnd, &dentries[i].secon, dentries[i].path, stat.st_mode) < 0) {
236 error("cannot lookup security context for %s", dentries[i].path);
239 if (dentries[i].secon && verbose)
240 printf("Labeling %s as %s\n", dentries[i].path, dentries[i].secon);
244 if (S_ISREG(stat.st_mode)) {
245 dentries[i].file_type = EXT4_FT_REG_FILE;
246 } else if (S_ISDIR(stat.st_mode)) {
247 dentries[i].file_type = EXT4_FT_DIR;
249 } else if (S_ISCHR(stat.st_mode)) {
250 dentries[i].file_type = EXT4_FT_CHRDEV;
251 } else if (S_ISBLK(stat.st_mode)) {
252 dentries[i].file_type = EXT4_FT_BLKDEV;
253 } else if (S_ISFIFO(stat.st_mode)) {
254 dentries[i].file_type = EXT4_FT_FIFO;
255 } else if (S_ISSOCK(stat.st_mode)) {
256 dentries[i].file_type = EXT4_FT_SOCK;
257 } else if (S_ISLNK(stat.st_mode)) {
258 dentries[i].file_type = EXT4_FT_SYMLINK;
259 dentries[i].link = calloc(info.block_size, 1);
260 readlink(dentries[i].full_path, dentries[i].link, info.block_size - 1);
262 error("unknown file type on %s", dentries[i].path);
269 if (needs_lost_and_found) {
270 /* insert a lost+found directory at the beginning of the dentries */
271 struct dentry *tmp = calloc(entries + 1, sizeof(struct dentry));
272 memset(tmp, 0, sizeof(struct dentry));
273 memcpy(tmp + 1, dentries, entries * sizeof(struct dentry));
276 dentries[0].filename = strdup("lost+found");
277 asprintf(&dentries[0].path, "%slost+found", dir_path);
278 dentries[0].full_path = NULL;
279 dentries[0].size = 0;
280 dentries[0].mode = S_IRWXU;
281 dentries[0].file_type = EXT4_FT_DIR;
285 if (selabel_lookup(sehnd, &dentries[0].secon, dentries[0].path, dentries[0].mode) < 0)
286 error("cannot lookup security context for %s", dentries[0].path);
292 inode = make_directory(dir_inode, entries, dentries, dirs);
294 for (i = 0; i < entries; i++) {
295 if (dentries[i].file_type == EXT4_FT_REG_FILE) {
296 entry_inode = make_file(dentries[i].full_path, dentries[i].size);
297 } else if (dentries[i].file_type == EXT4_FT_DIR) {
298 char *subdir_full_path = NULL;
299 char *subdir_dir_path;
300 if (dentries[i].full_path) {
301 ret = asprintf(&subdir_full_path, "%s/", dentries[i].full_path);
303 critical_error_errno("asprintf");
305 ret = asprintf(&subdir_dir_path, "%s/", dentries[i].path);
307 critical_error_errno("asprintf");
308 entry_inode = build_directory_structure(subdir_full_path, subdir_dir_path, target_out_path,
309 inode, fs_config_func, sehnd, verbose, fixed_time);
310 free(subdir_full_path);
311 free(subdir_dir_path);
312 } else if (dentries[i].file_type == EXT4_FT_SYMLINK) {
313 entry_inode = make_link(dentries[i].link);
315 error("unknown file type on %s", dentries[i].path);
318 *dentries[i].inode = entry_inode;
320 ret = inode_set_permissions(entry_inode, dentries[i].mode,
321 dentries[i].uid, dentries[i].gid,
324 error("failed to set permissions on %s\n", dentries[i].path);
327 * It's important to call inode_set_selinux() before
328 * inode_set_capabilities(). Extended attributes need to
329 * be stored sorted order, and we guarantee this by making
330 * the calls in the proper order.
331 * Please see xattr_assert_sane() in contents.c
333 ret = inode_set_selinux(entry_inode, dentries[i].secon);
335 error("failed to set SELinux context on %s\n", dentries[i].path);
336 ret = inode_set_capabilities(entry_inode, dentries[i].capabilities);
338 error("failed to set capability on %s\n", dentries[i].path);
340 free(dentries[i].path);
341 free(dentries[i].full_path);
342 free(dentries[i].link);
343 free((void *)dentries[i].filename);
344 free(dentries[i].secon);
352 static u32 compute_block_size()
357 static u32 compute_journal_blocks()
359 u32 journal_blocks = DIV_ROUND_UP(info.len, info.block_size) / 64;
360 if (journal_blocks < 1024)
361 journal_blocks = 1024;
362 if (journal_blocks > 32768)
363 journal_blocks = 32768;
364 return journal_blocks;
367 static u32 compute_blocks_per_group()
369 return info.block_size * 8;
372 static u32 compute_inodes()
374 return DIV_ROUND_UP(info.len, info.block_size) / 4;
377 static u32 compute_inodes_per_group()
379 u32 blocks = DIV_ROUND_UP(info.len, info.block_size);
380 u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group);
381 u32 inodes = DIV_ROUND_UP(info.inodes, block_groups);
382 inodes = EXT4_ALIGN(inodes, (info.block_size / info.inode_size));
384 /* After properly rounding up the number of inodes/group,
385 * make sure to update the total inodes field in the info struct.
387 info.inodes = inodes * block_groups;
392 static u32 compute_bg_desc_reserve_blocks()
394 u32 blocks = DIV_ROUND_UP(info.len, info.block_size);
395 u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group);
396 u32 bg_desc_blocks = DIV_ROUND_UP(block_groups * sizeof(struct ext2_group_desc),
399 u32 bg_desc_reserve_blocks =
400 DIV_ROUND_UP(block_groups * 1024 * sizeof(struct ext2_group_desc),
401 info.block_size) - bg_desc_blocks;
403 if (bg_desc_reserve_blocks > info.block_size / sizeof(u32))
404 bg_desc_reserve_blocks = info.block_size / sizeof(u32);
406 return bg_desc_reserve_blocks;
409 void reset_ext4fs_info() {
410 // Reset all the global data structures used by make_ext4fs so it
411 // can be called again.
412 memset(&info, 0, sizeof(info));
413 memset(&aux_info, 0, sizeof(aux_info));
415 if (ext4_sparse_file) {
416 sparse_file_destroy(ext4_sparse_file);
417 ext4_sparse_file = NULL;
421 int make_ext4fs_sparse_fd(int fd, long long len,
422 const char *mountpoint, struct selabel_handle *sehnd)
424 return make_ext4fs_sparse_fd_directory(fd, len, mountpoint, sehnd, NULL);
427 int make_ext4fs_sparse_fd_directory(int fd, long long len,
428 const char *mountpoint, struct selabel_handle *sehnd,
429 const char *directory)
434 return make_ext4fs_internal(fd, directory, NULL, mountpoint, NULL,
436 sehnd, 0, -1, NULL, NULL, NULL);
439 int make_ext4fs(const char *filename, long long len,
440 const char *mountpoint, struct selabel_handle *sehnd)
442 return make_ext4fs_directory(filename, len, mountpoint, sehnd, NULL);
445 int make_ext4fs_directory(const char *filename, long long len,
446 const char *mountpoint, struct selabel_handle *sehnd,
447 const char *directory)
455 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
461 status = make_ext4fs_internal(fd, directory, NULL, mountpoint, NULL,
463 sehnd, 0, -1, NULL, NULL, NULL);
469 /* return a newly-malloc'd string that is a copy of str. The new string
470 is guaranteed to have a trailing slash. If absolute is true, the new string
471 is also guaranteed to have a leading slash.
473 static char *canonicalize_slashes(const char *str, bool absolute)
476 int len = strlen(str);
487 if (str[0] != '/' && absolute) {
490 if (str[len - 1] != '/') {
493 ret = malloc(newlen + 1);
495 critical_error("malloc");
499 if (str[0] != '/' && absolute) {
506 if (str[len - 1] != '/') {
510 if (ptr != ret + newlen) {
511 critical_error("assertion failed\n");
519 static char *canonicalize_abs_slashes(const char *str)
521 return canonicalize_slashes(str, true);
524 static char *canonicalize_rel_slashes(const char *str)
526 return canonicalize_slashes(str, false);
529 static int compare_chunks(const void* chunk1, const void* chunk2) {
530 struct region* c1 = (struct region*) chunk1;
531 struct region* c2 = (struct region*) chunk2;
532 return c1->block - c2->block;
535 static int get_block_group(u32 block) {
537 for(i = 0; i < aux_info.groups; i++) {
538 if (block >= aux_info.bgs[i].first_block)
546 static void extract_base_fs_allocations(const char *directory, const char *mountpoint,
547 FILE* base_alloc_file_in) {
548 #define err_msg "base file badly formatted"
550 // FORMAT Version 1.0: filename blk_mapping
551 const char *base_alloc_file_in_format = "%s %s";
552 const int base_file_format_param_count = 2;
554 char stored_file_name[MAX_PATH], real_file_name[MAX_PATH], file_map[MAX_BLK_MAPPING_STR];
555 struct block_allocation *fs_alloc;
556 struct block_group_info *bgs = aux_info.bgs;
557 int i, major_version = 0, minor_version = 0;
558 char *base_file_line = NULL;
559 size_t base_file_line_len = 0;
561 printf("[v%d.%d] Generating an Incremental EXT4 image\n",
562 blk_file_major_ver, blk_file_minor_ver);
563 if (base_fs_allocations == NULL)
564 base_fs_allocations = create_allocation();
565 fs_alloc = base_fs_allocations;
567 fscanf(base_alloc_file_in, blk_file_header_fmt, &major_version, &minor_version);
568 if (major_version == 0) {
569 critical_error("Invalid base file");
572 if (major_version != blk_file_major_ver) {
573 critical_error("Incompatible base file: version required is %d.X",
577 if (minor_version < blk_file_minor_ver) {
578 critical_error("Incompatible base file: version required is %d.%d or above",
579 blk_file_major_ver, blk_file_minor_ver);
582 while (getline(&base_file_line, &base_file_line_len, base_alloc_file_in) != -1) {
583 if (sscanf(base_file_line, base_alloc_file_in_format, &stored_file_name, &file_map)
584 != base_file_format_param_count) {
587 if (strlen(stored_file_name) < strlen(mountpoint)) {
590 snprintf(real_file_name, MAX_PATH, "%s%s", directory, stored_file_name + strlen(mountpoint));
591 if (!access(real_file_name, R_OK)) {
592 char *block_range, *end_string;
594 u32 start_block, end_block, block_file_size;
595 u32 real_file_block_size;
597 real_file_fd = open(real_file_name, O_RDONLY);
598 if (real_file_fd == -1) {
599 critical_error(err_msg);
601 real_file_block_size = get_file_size(real_file_fd);
603 real_file_block_size = DIV_ROUND_UP(real_file_block_size, info.block_size);
604 fs_alloc->filename = strdup(real_file_name);
605 block_range = strtok_r(file_map, ",", &end_string);
606 while (block_range && real_file_block_size) {
608 char *range, *end_token = NULL;
609 range = strtok_r(block_range, "-", &end_token);
611 critical_error(err_msg);
613 start_block = parse_num(range);
614 range = strtok_r(NULL, "-", &end_token);
616 end_block = start_block;
618 end_block = parse_num(range);
620 // Assummption is that allocations are within the same block group
621 block_group = get_block_group(start_block);
622 if (block_group != get_block_group(end_block)) {
623 critical_error("base file allocation's end block is in a different "
624 "block group than start block. did you change fs params?");
626 block_range = strtok_r(NULL, ",", &end_string);
627 int bg_first_block = bgs[block_group].first_block;
628 int min_bg_bound = bgs[block_group].chunks[0].block + bgs[block_group].chunks[0].len;
629 int max_bg_bound = bgs[block_group].chunks[bgs[block_group].chunk_count - 1].block;
631 if (min_bg_bound >= start_block - bg_first_block ||
632 max_bg_bound <= end_block - bg_first_block) {
635 block_file_size = end_block - start_block + 1;
636 if (block_file_size > real_file_block_size) {
637 block_file_size = real_file_block_size;
639 append_region(fs_alloc, start_block, block_file_size, block_group);
640 reserve_bg_chunk(block_group, start_block - bgs[block_group].first_block, block_file_size);
641 real_file_block_size -= block_file_size;
643 if (reserve_blocks_for_allocation(fs_alloc) < 0)
644 critical_error("failed to reserve base fs allocation");
645 fs_alloc->next = create_allocation();
646 fs_alloc = fs_alloc->next;
650 for (i = 0; i < aux_info.groups; i++) {
651 qsort(bgs[i].chunks, bgs[i].chunk_count, sizeof(struct region), compare_chunks);
654 free(base_file_line);
662 void generate_base_alloc_file_out(FILE* base_alloc_file_out, char* dir, char* mountpoint,
663 struct block_allocation* p)
665 size_t dirlen = dir ? strlen(dir) : 0;
666 fprintf(base_alloc_file_out, blk_file_header_fmt, blk_file_major_ver, blk_file_minor_ver);
667 fputc('\n', base_alloc_file_out);
669 if (dir && strncmp(p->filename, dir, dirlen) == 0) {
670 // substitute mountpoint for the leading directory in the filename, in the output file
671 fprintf(base_alloc_file_out, "%s%s", mountpoint, p->filename + dirlen);
673 fprintf(base_alloc_file_out, "%s", p->filename);
675 print_blocks(base_alloc_file_out, p, ',');
676 struct block_allocation* pn = p->next;
681 int make_ext4fs_internal(int fd, const char *_directory, const char *_target_out_directory,
682 const char *_mountpoint, fs_config_func_t fs_config_func, int gzip,
683 int sparse, int crc, int wipe, int real_uuid,
684 struct selabel_handle *sehnd, int verbose, time_t fixed_time,
685 FILE* block_list_file, FILE* base_alloc_file_in, FILE* base_alloc_file_out)
690 char *directory = NULL;
691 char *target_out_directory = NULL;
692 struct block_allocation* p;
694 if (setjmp(setjmp_env))
695 return EXIT_FAILURE; /* Handle a call to longjmp() */
697 info.block_device = is_block_device_fd(fd);
699 if (info.block_device && (sparse || gzip || crc)) {
700 fprintf(stderr, "No sparse/gzip/crc allowed for block device\n");
704 if (_mountpoint == NULL) {
705 mountpoint = strdup("");
707 mountpoint = canonicalize_abs_slashes(_mountpoint);
711 directory = canonicalize_rel_slashes(_directory);
714 if (_target_out_directory) {
715 target_out_directory = canonicalize_rel_slashes(_target_out_directory);
719 info.len = get_file_size(fd);
722 fprintf(stderr, "Need size of filesystem\n");
726 if (info.block_size <= 0)
727 info.block_size = compute_block_size();
729 /* Round down the filesystem length to be a multiple of the block size */
730 info.len &= ~((u64)info.block_size - 1);
732 if (info.journal_blocks == 0)
733 info.journal_blocks = compute_journal_blocks();
735 if (info.no_journal == 0)
736 info.feat_compat = EXT4_FEATURE_COMPAT_HAS_JOURNAL;
738 info.journal_blocks = 0;
740 if (info.blocks_per_group <= 0)
741 info.blocks_per_group = compute_blocks_per_group();
743 if (info.inodes <= 0)
744 info.inodes = compute_inodes();
746 if (info.inode_size <= 0)
747 info.inode_size = 256;
749 if (info.label == NULL)
752 info.inodes_per_group = compute_inodes_per_group();
755 EXT4_FEATURE_COMPAT_RESIZE_INODE |
756 EXT4_FEATURE_COMPAT_EXT_ATTR;
758 info.feat_ro_compat |=
759 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER |
760 EXT4_FEATURE_RO_COMPAT_LARGE_FILE |
761 EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
763 info.feat_incompat |=
764 EXT4_FEATURE_INCOMPAT_EXTENTS |
765 EXT4_FEATURE_INCOMPAT_FILETYPE;
768 info.bg_desc_reserve_blocks = compute_bg_desc_reserve_blocks();
770 printf("Creating filesystem with parameters:\n");
771 printf(" Size: %"PRIu64"\n", info.len);
772 printf(" Block size: %d\n", info.block_size);
773 printf(" Blocks per group: %d\n", info.blocks_per_group);
774 printf(" Inodes per group: %d\n", info.inodes_per_group);
775 printf(" Inode size: %d\n", info.inode_size);
776 printf(" Journal blocks: %d\n", info.journal_blocks);
777 printf(" Label: %s\n", info.label);
779 ext4_create_fs_aux_info();
781 printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks);
782 printf(" Block groups: %d\n", aux_info.groups);
783 printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks);
785 ext4_sparse_file = sparse_file_new(info.block_size, info.len);
787 block_allocator_init();
789 ext4_fill_in_sb(real_uuid);
791 if (base_alloc_file_in) {
792 extract_base_fs_allocations(directory, mountpoint, base_alloc_file_in);
794 if (reserve_inodes(0, 10) == EXT4_ALLOCATE_FAILED)
795 error("failed to reserve first 10 inodes");
797 if (info.feat_compat & EXT4_FEATURE_COMPAT_HAS_JOURNAL)
798 ext4_create_journal_inode();
800 if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE)
801 ext4_create_resize_inode();
804 // Windows needs only 'create an empty fs image' functionality
806 root_inode_num = build_default_directory_structure(mountpoint, sehnd);
809 root_inode_num = build_directory_structure(directory, mountpoint, target_out_directory, 0,
810 fs_config_func, sehnd, verbose, fixed_time);
812 root_inode_num = build_default_directory_structure(mountpoint, sehnd);
815 root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
816 inode_set_permissions(root_inode_num, root_mode, 0, 0, 0);
820 char *secontext = NULL;
822 if (selabel_lookup(sehnd, &secontext, mountpoint, S_IFDIR) < 0) {
823 error("cannot lookup security context for %s", mountpoint);
827 printf("Labeling %s as %s\n", mountpoint, secontext);
829 inode_set_selinux(root_inode_num, secontext);
837 // TODO: Consider migrating the OTA tools to the new base alloc file format
838 // used for generating incremental images (see go/incremental-ext4)
839 if (block_list_file) {
840 size_t dirlen = directory ? strlen(directory) : 0;
841 struct block_allocation* p = get_saved_allocation_chain();
843 if (directory && strncmp(p->filename, directory, dirlen) == 0) {
844 // substitute mountpoint for the leading directory in the filename, in the output file
845 fprintf(block_list_file, "%s%s", mountpoint, p->filename + dirlen);
847 fprintf(block_list_file, "%s", p->filename);
849 print_blocks(block_list_file, p, ' ');
850 struct block_allocation* pn = p->next;
855 if (base_alloc_file_out) {
856 struct block_allocation* p = get_saved_allocation_chain();
857 generate_base_alloc_file_out(base_alloc_file_out, directory, mountpoint, p);
860 printf("Created filesystem with %d/%d inodes and %d/%d blocks\n",
861 aux_info.sb->s_inodes_count - aux_info.sb->s_free_inodes_count,
862 aux_info.sb->s_inodes_count,
863 aux_info.sb->s_blocks_count_lo - aux_info.sb->s_free_blocks_count_lo,
864 aux_info.sb->s_blocks_count_lo);
866 if (wipe && WIPE_IS_SUPPORTED) {
867 wipe_block_device(fd, info.len);
870 write_ext4_image(fd, gzip, sparse, crc);
872 sparse_file_destroy(ext4_sparse_file);
873 ext4_sparse_file = NULL;
875 p = get_saved_allocation_chain();
877 struct block_allocation* pn = p->next;