• Home
  • Raw
  • Download

Lines Matching +full:- +full:fs

2  * initialize.c --- initialize a filesystem handle given superblock
7 * %Begin-Header%
10 * %End-Header%
58 static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) in calc_reserved_gdt_blocks() argument
60 struct ext2_super_block *sb = fs->super; in calc_reserved_gdt_blocks()
61 unsigned long bpg = sb->s_blocks_per_group; in calc_reserved_gdt_blocks()
76 rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg); in calc_reserved_gdt_blocks()
77 rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks; in calc_reserved_gdt_blocks()
92 ext2_filsys fs; in ext2fs_initialize() local
115 retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); in ext2fs_initialize()
119 memset(fs, 0, sizeof(struct struct_ext2_filsys)); in ext2fs_initialize()
120 fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS; in ext2fs_initialize()
121 fs->flags = flags | EXT2_FLAG_RW; in ext2fs_initialize()
122 fs->umask = 022; in ext2fs_initialize()
123 fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; in ext2fs_initialize()
125 fs->flags |= EXT2_FLAG_SWAP_BYTES; in ext2fs_initialize()
130 fs->now = strtoul(time_env, NULL, 0); in ext2fs_initialize()
138 retval = manager->open(name, io_flags, &fs->io); in ext2fs_initialize()
141 fs->image_io = fs->io; in ext2fs_initialize()
142 fs->io->app_data = fs; in ext2fs_initialize()
143 retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name); in ext2fs_initialize()
147 strcpy(fs->device_name, name); in ext2fs_initialize()
151 fs->super = super; in ext2fs_initialize()
155 #define set_field(field, default) (super->field = param->field ? \ in ext2fs_initialize()
156 param->field : (default)) in ext2fs_initialize()
157 #define assign_field(field) (super->field = param->field) in ext2fs_initialize()
159 super->s_magic = EXT2_SUPER_MAGIC; in ext2fs_initialize()
160 super->s_state = EXT2_VALID_FS; in ext2fs_initialize()
167 set_field(s_log_cluster_size, super->s_log_block_size+4); in ext2fs_initialize()
168 if (super->s_log_block_size > super->s_log_cluster_size) { in ext2fs_initialize()
173 super->s_log_cluster_size = super->s_log_block_size; in ext2fs_initialize()
175 set_field(s_first_data_block, super->s_log_cluster_size ? 0 : 1); in ext2fs_initialize()
189 if (super->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { in ext2fs_initialize()
193 if (super->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { in ext2fs_initialize()
199 if (super->s_rev_level >= EXT2_DYNAMIC_REV) { in ext2fs_initialize()
202 if (super->s_inode_size >= sizeof(struct ext2_inode_large)) { in ext2fs_initialize()
203 int extra_isize = sizeof(struct ext2_inode_large) - in ext2fs_initialize()
209 super->s_first_ino = EXT2_GOOD_OLD_FIRST_INO; in ext2fs_initialize()
210 super->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; in ext2fs_initialize()
214 super->s_mkfs_time = super->s_lastcheck = fs->now ? fs->now : time(NULL); in ext2fs_initialize()
216 super->s_creator_os = CREATOR_OS; in ext2fs_initialize()
218 fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(super); in ext2fs_initialize()
219 fs->cluster_ratio_bits = super->s_log_cluster_size - in ext2fs_initialize()
220 super->s_log_block_size; in ext2fs_initialize()
225 if (param->s_blocks_per_group && in ext2fs_initialize()
226 param->s_clusters_per_group && in ext2fs_initialize()
227 ((param->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs)) != in ext2fs_initialize()
228 param->s_blocks_per_group)) { in ext2fs_initialize()
232 if (param->s_clusters_per_group) in ext2fs_initialize()
234 else if (param->s_blocks_per_group) in ext2fs_initialize()
235 super->s_clusters_per_group = in ext2fs_initialize()
236 param->s_blocks_per_group / in ext2fs_initialize()
237 EXT2FS_CLUSTER_RATIO(fs); in ext2fs_initialize()
238 else if (super->s_log_cluster_size + 15 < 32) in ext2fs_initialize()
239 super->s_clusters_per_group = fs->blocksize * 8; in ext2fs_initialize()
241 super->s_clusters_per_group = (fs->blocksize - 1) * 8; in ext2fs_initialize()
242 if (super->s_clusters_per_group > EXT2_MAX_CLUSTERS_PER_GROUP(super)) in ext2fs_initialize()
243 super->s_clusters_per_group = EXT2_MAX_CLUSTERS_PER_GROUP(super); in ext2fs_initialize()
244 bpg = EXT2FS_C2B(fs, in ext2fs_initialize()
245 (unsigned long long) super->s_clusters_per_group); in ext2fs_initialize()
250 super->s_blocks_per_group = bpg; in ext2fs_initialize()
252 set_field(s_blocks_per_group, fs->blocksize * 8); in ext2fs_initialize()
253 if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) in ext2fs_initialize()
254 super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); in ext2fs_initialize()
255 super->s_clusters_per_group = super->s_blocks_per_group; in ext2fs_initialize()
259 ~((blk64_t) EXT2FS_CLUSTER_MASK(fs))); in ext2fs_initialize()
273 fs->group_desc_count = 0; in ext2fs_initialize()
274 ext2fs_mark_super_dirty(fs); in ext2fs_initialize()
275 *ret_fs = fs; in ext2fs_initialize()
280 fs->group_desc_count = (dgrp_t) ext2fs_div64_ceil( in ext2fs_initialize()
281 ext2fs_blocks_count(super) - super->s_first_data_block, in ext2fs_initialize()
283 if (fs->group_desc_count == 0) { in ext2fs_initialize()
292 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, in ext2fs_initialize()
295 i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize; in ext2fs_initialize()
307 if (super->s_inodes_count < EXT2_FIRST_INODE(super)+1) in ext2fs_initialize()
308 super->s_inodes_count = EXT2_FIRST_INODE(super)+1; in ext2fs_initialize()
316 ipg = ext2fs_div_ceil(super->s_inodes_count, fs->group_desc_count); in ext2fs_initialize()
317 if (ipg > fs->blocksize * 8) { in ext2fs_initialize()
318 if (!bigalloc_flag && super->s_blocks_per_group >= 256) { in ext2fs_initialize()
320 super->s_blocks_per_group -= 8; in ext2fs_initialize()
323 super->s_clusters_per_group = super->s_blocks_per_group; in ext2fs_initialize()
335 super->s_inodes_per_group = ipg; in ext2fs_initialize()
342 fs->inode_blocks_per_group = (((super->s_inodes_per_group * in ext2fs_initialize()
344 EXT2_BLOCK_SIZE(super) - 1) / in ext2fs_initialize()
346 super->s_inodes_per_group = ((fs->inode_blocks_per_group * in ext2fs_initialize()
354 if (super->s_inodes_per_group < 8) in ext2fs_initialize()
355 super->s_inodes_per_group = 8; in ext2fs_initialize()
356 super->s_inodes_per_group &= ~7; in ext2fs_initialize()
357 fs->inode_blocks_per_group = (((super->s_inodes_per_group * in ext2fs_initialize()
359 EXT2_BLOCK_SIZE(super) - 1) / in ext2fs_initialize()
365 if ((__u64)super->s_inodes_per_group * fs->group_desc_count > ~0U) { in ext2fs_initialize()
366 ipg--; in ext2fs_initialize()
369 super->s_inodes_count = super->s_inodes_per_group * in ext2fs_initialize()
370 fs->group_desc_count; in ext2fs_initialize()
371 super->s_free_inodes_count = super->s_inodes_count; in ext2fs_initialize()
377 rsv_gdt = calc_reserved_gdt_blocks(fs); in ext2fs_initialize()
381 if (super->s_reserved_gdt_blocks > EXT2_ADDR_PER_BLOCK(super)) { in ext2fs_initialize()
386 if (super->s_reserved_gdt_blocks + fs->desc_blocks > in ext2fs_initialize()
387 super->s_blocks_per_group * 3 / 4) { in ext2fs_initialize()
388 ext2fs_set_feature_meta_bg(fs->super); in ext2fs_initialize()
389 ext2fs_clear_feature_resize_inode(fs->super); in ext2fs_initialize()
399 overhead = (int) (3 + fs->inode_blocks_per_group + in ext2fs_initialize()
400 super->s_reserved_gdt_blocks); in ext2fs_initialize()
402 if (ext2fs_has_feature_meta_bg(fs->super)) in ext2fs_initialize()
405 overhead += fs->desc_blocks; in ext2fs_initialize()
408 if (overhead > super->s_blocks_per_group) { in ext2fs_initialize()
420 overhead = (int) (2 + fs->inode_blocks_per_group); in ext2fs_initialize()
425 * super->s_backup_bgs hasn't been set up yet. in ext2fs_initialize()
427 if (fs->group_desc_count == 2) in ext2fs_initialize()
428 has_bg = param->s_backup_bgs[0] != 0; in ext2fs_initialize()
430 has_bg = param->s_backup_bgs[1] != 0; in ext2fs_initialize()
432 has_bg = ext2fs_bg_has_super(fs, fs->group_desc_count - 1); in ext2fs_initialize()
434 overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks; in ext2fs_initialize()
435 rem = ((ext2fs_blocks_count(super) - super->s_first_data_block) % in ext2fs_initialize()
436 super->s_blocks_per_group); in ext2fs_initialize()
437 if ((fs->group_desc_count == 1) && rem && (rem < overhead)) { in ext2fs_initialize()
442 ext2fs_blocks_count_set(super, ext2fs_blocks_count(super) - in ext2fs_initialize()
464 if (super->s_backup_bgs[0] >= fs->group_desc_count) in ext2fs_initialize()
465 super->s_backup_bgs[0] = fs->group_desc_count - 1; in ext2fs_initialize()
466 if (super->s_backup_bgs[1] >= fs->group_desc_count) in ext2fs_initialize()
467 super->s_backup_bgs[1] = fs->group_desc_count - 1; in ext2fs_initialize()
468 if (super->s_backup_bgs[0] == super->s_backup_bgs[1]) in ext2fs_initialize()
469 super->s_backup_bgs[1] = 0; in ext2fs_initialize()
470 if (super->s_backup_bgs[0] > super->s_backup_bgs[1]) { in ext2fs_initialize()
471 __u32 t = super->s_backup_bgs[0]; in ext2fs_initialize()
472 super->s_backup_bgs[0] = super->s_backup_bgs[1]; in ext2fs_initialize()
473 super->s_backup_bgs[1] = t; in ext2fs_initialize()
477 retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf); in ext2fs_initialize()
482 strcat(buf, fs->device_name); in ext2fs_initialize()
483 retval = ext2fs_allocate_subcluster_bitmap(fs, buf, &fs->block_map); in ext2fs_initialize()
488 strcat(buf, fs->device_name); in ext2fs_initialize()
489 retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map); in ext2fs_initialize()
495 retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, in ext2fs_initialize()
496 &fs->group_desc); in ext2fs_initialize()
500 memset(fs->group_desc, 0, (size_t) fs->desc_blocks * fs->blocksize); in ext2fs_initialize()
509 * If FLEX_BG meta-data grouping is used, only account for the in ext2fs_initialize()
514 csum_flag = ext2fs_has_group_desc_csum(fs); in ext2fs_initialize()
515 reserved_inos = super->s_first_ino; in ext2fs_initialize()
516 for (i = 0; i < fs->group_desc_count; i++) { in ext2fs_initialize()
522 if (i != fs->group_desc_count - 1) in ext2fs_initialize()
523 ext2fs_bg_flags_set(fs, i, in ext2fs_initialize()
525 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); in ext2fs_initialize()
526 numblocks = super->s_inodes_per_group; in ext2fs_initialize()
529 numblocks -= reserved_inos; in ext2fs_initialize()
532 reserved_inos -= numblocks; in ext2fs_initialize()
536 ext2fs_bg_itable_unused_set(fs, i, numblocks); in ext2fs_initialize()
538 numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map); in ext2fs_initialize()
539 if (fs->super->s_log_groups_per_flex) in ext2fs_initialize()
540 numblocks += 2 + fs->inode_blocks_per_group; in ext2fs_initialize()
543 ext2fs_bg_free_blocks_count_set(fs, i, numblocks); in ext2fs_initialize()
544 ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group); in ext2fs_initialize()
545 ext2fs_bg_used_dirs_count_set(fs, i, 0); in ext2fs_initialize()
546 ext2fs_group_desc_csum_set(fs, i); in ext2fs_initialize()
548 free_blocks &= ~EXT2FS_CLUSTER_MASK(fs); in ext2fs_initialize()
552 if (((int) c) == -1) { in ext2fs_initialize()
553 super->s_flags |= EXT2_FLAGS_SIGNED_HASH; in ext2fs_initialize()
555 super->s_flags |= EXT2_FLAGS_UNSIGNED_HASH; in ext2fs_initialize()
558 ext2fs_mark_super_dirty(fs); in ext2fs_initialize()
559 ext2fs_mark_bb_dirty(fs); in ext2fs_initialize()
560 ext2fs_mark_ib_dirty(fs); in ext2fs_initialize()
562 io_channel_set_blksize(fs->io, fs->blocksize); in ext2fs_initialize()
564 *ret_fs = fs; in ext2fs_initialize()
568 ext2fs_free(fs); in ext2fs_initialize()