/* This MUST be called BEFORE the fat_construct_new_fat(), because cluster * allocation depend on the old FAT. The reason is, old clusters may * still be needed during the resize, (particularly clusters in the directory * tree) even if they will be discarded later. */ static int alloc_root_dir (FatOpContext* ctx) { FatSpecific* old_fs_info = FAT_SPECIFIC (ctx->old_fs); FatSpecific* new_fs_info = FAT_SPECIFIC (ctx->new_fs); FatCluster i; FatCluster cluster; FatCluster cluster_count; PED_ASSERT (new_fs_info->fat_type == FAT_TYPE_FAT32); cluster_count = ped_div_round_up ( PED_MAX (16, old_fs_info->root_dir_sector_count), new_fs_info->cluster_sectors); for (i = 0; i < cluster_count; i++) { cluster = fat_table_alloc_check_cluster (new_fs_info->fat, ctx->new_fs); if (!cluster) return 0; ctx->new_root_dir [i] = cluster; clear_cluster (ctx->new_fs, cluster); } ctx->new_root_dir [i] = 0; new_fs_info->root_cluster = ctx->new_root_dir [0]; return 1; }
/* returns the minimum size of clusters for a given file system type */ PedSector fat_recommend_min_cluster_size (FatType fat_type, PedSector size) { switch (fat_type) { case FAT_TYPE_FAT12: return 1; case FAT_TYPE_FAT16: return fat_min_cluster_size(fat_type); case FAT_TYPE_FAT32: return PED_MAX(_smallest_power2_over(size / MAX_FAT32_CLUSTERS), fat_min_cluster_size (fat_type)); } return 0; }
/** * Return a constraint that requires a region to satisfy both \p a and \p b. * * Moreover, any region satisfying \p a and \p b will also satisfy the returned * constraint. * * \return \c NULL if no solution could be found (note that \c NULL is a valid * PedConstraint). */ PedConstraint* ped_constraint_intersect (const PedConstraint* a, const PedConstraint* b) { PedAlignment* start_align; PedAlignment* end_align; PedGeometry* start_range; PedGeometry* end_range; PedSector min_size; PedSector max_size; PedConstraint* constraint; if (!a || !b) return NULL; start_align = ped_alignment_intersect (a->start_align, b->start_align); if (!start_align) goto empty; end_align = ped_alignment_intersect (a->end_align, b->end_align); if (!end_align) goto empty_destroy_start_align; start_range = ped_geometry_intersect (a->start_range, b->start_range); if (!start_range) goto empty_destroy_end_align; end_range = ped_geometry_intersect (a->end_range, b->end_range); if (!end_range) goto empty_destroy_start_range; min_size = PED_MAX (a->min_size, b->min_size); max_size = PED_MIN (a->max_size, b->max_size); constraint = ped_constraint_new ( start_align, end_align, start_range, end_range, min_size, max_size); if (!constraint) goto empty_destroy_end_range; ped_alignment_destroy (start_align); ped_alignment_destroy (end_align); ped_geometry_destroy (start_range); ped_geometry_destroy (end_range); return constraint; empty_destroy_end_range: ped_geometry_destroy (end_range); empty_destroy_start_range: ped_geometry_destroy (start_range); empty_destroy_end_align: ped_alignment_destroy (end_align); empty_destroy_start_align: ped_alignment_destroy (start_align); empty: return NULL; }