Lines Matching refs:p
179 #define PARTITION_IS_FOREIGN(p) (!(p)->definition_path) argument
180 #define PARTITION_EXISTS(p) (!!(p)->current_partition) argument
218 static uint64_t round_down_size(uint64_t v, uint64_t p) { in round_down_size() argument
219 return (v / p) * p; in round_down_size()
222 static uint64_t round_up_size(uint64_t v, uint64_t p) { in round_up_size() argument
224 v = DIV_ROUND_UP(v, p); in round_up_size()
226 if (v > UINT64_MAX / p) in round_up_size()
229 return v * p; in round_up_size()
233 Partition *p; in partition_new() local
235 p = new(Partition, 1); in partition_new()
236 if (!p) in partition_new()
239 *p = (Partition) { in partition_new()
259 return p; in partition_new()
262 static Partition* partition_free(Partition *p) { in partition_free() argument
263 if (!p) in partition_free()
266 free(p->current_label); in partition_free()
267 free(p->new_label); in partition_free()
268 free(p->definition_path); in partition_free()
270 if (p->current_partition) in partition_free()
271 fdisk_unref_partition(p->current_partition); in partition_free()
272 if (p->new_partition) in partition_free()
273 fdisk_unref_partition(p->new_partition); in partition_free()
275 free(p->copy_blocks_path); in partition_free()
276 safe_close(p->copy_blocks_fd); in partition_free()
278 free(p->format); in partition_free()
279 strv_free(p->copy_files); in partition_free()
280 strv_free(p->make_directories); in partition_free()
282 return mfree(p); in partition_free()
285 static Partition* partition_unlink_and_free(Context *context, Partition *p) { in partition_unlink_and_free() argument
286 if (!p) in partition_unlink_and_free()
289 LIST_REMOVE(partitions, context->partitions, p); in partition_unlink_and_free()
294 return partition_free(p); in partition_unlink_and_free()
378 LIST_FOREACH(partitions, p, context->partitions) { in context_drop_one_priority()
379 if (p->dropped) in context_drop_one_priority()
381 if (p->priority < priority) in context_drop_one_priority()
383 if (p->priority == priority) { in context_drop_one_priority()
384 exists = exists || PARTITION_EXISTS(p); in context_drop_one_priority()
388 priority = p->priority; in context_drop_one_priority()
389 exists = PARTITION_EXISTS(p); in context_drop_one_priority()
397 LIST_FOREACH(partitions, p, context->partitions) { in context_drop_one_priority()
398 if (p->priority < priority) in context_drop_one_priority()
401 if (p->dropped) in context_drop_one_priority()
404 p->dropped = true; in context_drop_one_priority()
405 …info("Can't fit partition %s of priority %" PRIi32 ", dropping.", p->definition_path, p->priority); in context_drop_one_priority()
411 static uint64_t partition_min_size(Context *context, const Partition *p) { in partition_min_size() argument
415 assert(p); in partition_min_size()
423 if (PARTITION_IS_FOREIGN(p)) { in partition_min_size()
425 assert(p->current_size != UINT64_MAX); in partition_min_size()
426 return p->current_size; in partition_min_size()
429 sz = p->current_size != UINT64_MAX ? p->current_size : HARD_MIN_SIZE; in partition_min_size()
431 if (!PARTITION_EXISTS(p)) { in partition_min_size()
434 if (p->encrypt != ENCRYPT_OFF) in partition_min_size()
437 if (p->copy_blocks_size != UINT64_MAX) in partition_min_size()
438 d += round_up_size(p->copy_blocks_size, context->grain_size); in partition_min_size()
439 else if (p->format || p->encrypt != ENCRYPT_OFF) { in partition_min_size()
443 …f = p->format ? round_up_size(minimal_size_by_fs_name(p->format), context->grain_size) : UINT64_MA… in partition_min_size()
451 …return MAX(round_up_size(p->size_min != UINT64_MAX ? p->size_min : DEFAULT_MIN_SIZE, context->grai… in partition_min_size()
454 static uint64_t partition_max_size(const Context *context, const Partition *p) { in partition_max_size() argument
462 assert(p); in partition_max_size()
464 if (PARTITION_IS_FOREIGN(p)) { in partition_max_size()
466 assert(p->current_size != UINT64_MAX); in partition_max_size()
467 return p->current_size; in partition_max_size()
470 sm = round_down_size(p->size_max, context->grain_size); in partition_max_size()
472 if (p->current_size != UINT64_MAX) in partition_max_size()
473 return MAX(p->current_size, sm); in partition_max_size()
478 static uint64_t partition_min_size_with_padding(Context *context, const Partition *p) { in partition_min_size_with_padding() argument
486 assert(p); in partition_min_size_with_padding()
488 sz = partition_min_size(context, p); in partition_min_size_with_padding()
490 if (p->padding_min != UINT64_MAX) in partition_min_size_with_padding()
491 sz += p->padding_min; in partition_min_size_with_padding()
493 if (PARTITION_EXISTS(p)) { in partition_min_size_with_padding()
495 assert(p->offset != UINT64_MAX); in partition_min_size_with_padding()
496 return round_up_size(p->offset + sz, context->grain_size) - p->offset; in partition_min_size_with_padding()
576 LIST_FOREACH(partitions, p, context->partitions) { in context_allocate_partitions()
582 if (p->dropped || PARTITION_EXISTS(p)) in context_allocate_partitions()
586 required = partition_min_size_with_padding(context, p); in context_allocate_partitions()
602 p->allocated_to_area = a; in context_allocate_partitions()
620 LIST_FOREACH(partitions, p, context->partitions) { in context_sum_weights()
621 if (p->padding_area != a && p->allocated_to_area != a) in context_sum_weights()
624 if (p->weight > UINT64_MAX - weight_sum) in context_sum_weights()
626 weight_sum += p->weight; in context_sum_weights()
628 if (p->padding_weight > UINT64_MAX - weight_sum) in context_sum_weights()
630 weight_sum += p->padding_weight; in context_sum_weights()
685 LIST_FOREACH(partitions, p, context->partitions) { in context_grow_partitions_phase()
689 if (p->allocated_to_area != a && p->padding_area != a) in context_grow_partitions_phase()
692 if (p->new_size == UINT64_MAX) { in context_grow_partitions_phase()
698 r = scale_by_weight(*span, p->weight, *weight_sum, &share); in context_grow_partitions_phase()
702 rsz = partition_min_size(context, p); in context_grow_partitions_phase()
703 xsz = partition_max_size(context, p); in context_grow_partitions_phase()
710 p->new_size = rsz; in context_grow_partitions_phase()
718 p->new_size = xsz; in context_grow_partitions_phase()
727 if (PARTITION_IS_FOREIGN(p)) in context_grow_partitions_phase()
729 p->new_size = p->current_size; in context_grow_partitions_phase()
731 … p->new_size = MAX(round_down_size(share, context->grain_size), rsz); in context_grow_partitions_phase()
737 *span = charge_size(context, *span, p->new_size); in context_grow_partitions_phase()
738 *weight_sum = charge_weight(*weight_sum, p->weight); in context_grow_partitions_phase()
745 if (p->new_padding == UINT64_MAX) { in context_grow_partitions_phase()
749 r = scale_by_weight(*span, p->padding_weight, *weight_sum, &share); in context_grow_partitions_phase()
753 … if (phase == PHASE_OVERCHARGE && p->padding_min != UINT64_MAX && p->padding_min > share) { in context_grow_partitions_phase()
754 p->new_padding = p->padding_min; in context_grow_partitions_phase()
756 … } else if (phase == PHASE_UNDERCHARGE && p->padding_max != UINT64_MAX && p->padding_max < share) { in context_grow_partitions_phase()
757 p->new_padding = p->padding_max; in context_grow_partitions_phase()
761 p->new_padding = round_down_size(share, context->grain_size); in context_grow_partitions_phase()
762 if (p->padding_min != UINT64_MAX && p->new_padding < p->padding_min) in context_grow_partitions_phase()
763 p->new_padding = p->padding_min; in context_grow_partitions_phase()
769 *span = charge_size(context, *span, p->new_padding); in context_grow_partitions_phase()
770 *weight_sum = charge_weight(*weight_sum, p->padding_weight); in context_grow_partitions_phase()
831 LIST_FOREACH(partitions, p, context->partitions) { in context_grow_partitions_on_free_area()
834 if (p->allocated_to_area != a) in context_grow_partitions_on_free_area()
837 if (PARTITION_IS_FOREIGN(p)) in context_grow_partitions_on_free_area()
840 assert(p->new_size != UINT64_MAX); in context_grow_partitions_on_free_area()
841 … m = MAX(p->new_size, round_down_size(p->new_size + span, context->grain_size)); in context_grow_partitions_on_free_area()
843 xsz = partition_max_size(context, p); in context_grow_partitions_on_free_area()
847 span = charge_size(context, span, m - p->new_size); in context_grow_partitions_on_free_area()
848 p->new_size = m; in context_grow_partitions_on_free_area()
875 LIST_FOREACH(partitions, p, context->partitions) { in context_grow_partitions()
876 if (p->dropped) in context_grow_partitions()
879 if (!PARTITION_EXISTS(p) || p->padding_area) { in context_grow_partitions()
881 assert(p->new_size != UINT64_MAX); in context_grow_partitions()
885 assert(p->new_size == UINT64_MAX); in context_grow_partitions()
886 p->new_size = p->current_size; in context_grow_partitions()
888 assert(p->new_padding == UINT64_MAX); in context_grow_partitions()
889 p->new_padding = p->current_padding; in context_grow_partitions()
901 LIST_FOREACH(partitions, p, context->partitions) { in context_place_partitions()
902 if (!PARTITION_EXISTS(p)) in context_place_partitions()
905 assert(p->partno != UINT64_MAX); in context_place_partitions()
906 if (p->partno >= partno) in context_place_partitions()
907 partno = p->partno + 1; in context_place_partitions()
927 LIST_FOREACH(partitions, p, context->partitions) { in context_place_partitions()
928 if (p->allocated_to_area != a) in context_place_partitions()
931 p->offset = start; in context_place_partitions()
932 p->partno = partno++; in context_place_partitions()
934 assert(left >= p->new_size); in context_place_partitions()
935 start += p->new_size; in context_place_partitions()
936 left -= p->new_size; in context_place_partitions()
938 assert(left >= p->new_padding); in context_place_partitions()
939 start += p->new_padding; in context_place_partitions()
940 left -= p->new_padding; in context_place_partitions()
1131 const char *p = rvalue, *target; in config_parse_copy_files() local
1138 … r = extract_first_word(&p, &source, ":", EXTRACT_CUNESCAPE|EXTRACT_DONT_COALESCE_SEPARATORS); in config_parse_copy_files()
1146 … r = extract_first_word(&p, &buffer, ":", EXTRACT_CUNESCAPE|EXTRACT_DONT_COALESCE_SEPARATORS); in config_parse_copy_files()
1154 if (!isempty(p)) in config_parse_copy_files()
1246 const char *p = rvalue; in config_parse_make_dirs() local
1255 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); in config_parse_make_dirs()
1312 static int partition_read_definition(Partition *p, const char *path) { in partition_read_definition() argument
1315 … { "Partition", "Type", config_parse_type, 0, &p->type_uuid }, in partition_read_definition()
1316 … { "Partition", "Label", config_parse_label, 0, &p->new_label }, in partition_read_definition()
1317 … { "Partition", "UUID", config_parse_id128, 0, &p->new_uuid }, in partition_read_definition()
1318 … { "Partition", "Priority", config_parse_int32, 0, &p->priority }, in partition_read_definition()
1319 … { "Partition", "Weight", config_parse_weight, 0, &p->weight }, in partition_read_definition()
1320 … { "Partition", "PaddingWeight", config_parse_weight, 0, &p->padding_weight }, in partition_read_definition()
1321 … { "Partition", "SizeMinBytes", config_parse_size4096, 1, &p->size_min }, in partition_read_definition()
1322 … { "Partition", "SizeMaxBytes", config_parse_size4096, -1, &p->size_max }, in partition_read_definition()
1323 … { "Partition", "PaddingMinBytes", config_parse_size4096, 1, &p->padding_min }, in partition_read_definition()
1324 … { "Partition", "PaddingMaxBytes", config_parse_size4096, -1, &p->padding_max }, in partition_read_definition()
1325 … { "Partition", "FactoryReset", config_parse_bool, 0, &p->factory_reset }, in partition_read_definition()
1326 … { "Partition", "CopyBlocks", config_parse_copy_blocks, 0, p }, in partition_read_definition()
1327 … { "Partition", "Format", config_parse_fstype, 0, &p->format }, in partition_read_definition()
1328 … { "Partition", "CopyFiles", config_parse_copy_files, 0, p }, in partition_read_definition()
1329 … { "Partition", "MakeDirectories", config_parse_make_dirs, 0, p }, in partition_read_definition()
1330 … { "Partition", "Encrypt", config_parse_encrypt, 0, &p->encrypt }, in partition_read_definition()
1331 … { "Partition", "Flags", config_parse_gpt_flags, 0, &p->gpt_flags }, in partition_read_definition()
1332 … { "Partition", "ReadOnly", config_parse_tristate, 0, &p->read_only }, in partition_read_definition()
1333 … { "Partition", "NoAuto", config_parse_tristate, 0, &p->no_auto }, in partition_read_definition()
1334 … { "Partition", "GrowFileSystem", config_parse_tristate, 0, &p->growfs }, in partition_read_definition()
1343 p, in partition_read_definition()
1348 if (p->size_min != UINT64_MAX && p->size_max != UINT64_MAX && p->size_min > p->size_max) in partition_read_definition()
1352 …if (p->padding_min != UINT64_MAX && p->padding_max != UINT64_MAX && p->padding_min > p->padding_ma… in partition_read_definition()
1356 if (sd_id128_is_null(p->type_uuid)) in partition_read_definition()
1360 if ((p->copy_blocks_path || p->copy_blocks_auto) && in partition_read_definition()
1361 (p->format || !strv_isempty(p->copy_files) || !strv_isempty(p->make_directories))) in partition_read_definition()
1365 …if ((!strv_isempty(p->copy_files) || !strv_isempty(p->make_directories)) && streq_ptr(p->format, "… in partition_read_definition()
1369 …if (!p->format && (!strv_isempty(p->copy_files) || !strv_isempty(p->make_directories) || (p->encry… in partition_read_definition()
1371 p->format = strdup("ext4"); in partition_read_definition()
1372 if (!p->format) in partition_read_definition()
1377 if ((gpt_partition_type_is_root_verity(p->type_uuid) || in partition_read_definition()
1378 gpt_partition_type_is_usr_verity(p->type_uuid)) && in partition_read_definition()
1379 p->read_only < 0) in partition_read_definition()
1380 p->read_only = true; in partition_read_definition()
1383 if (gpt_partition_type_knows_growfs(p->type_uuid) && in partition_read_definition()
1384 p->read_only <= 0) in partition_read_definition()
1385 p->growfs = true; in partition_read_definition()
1409 _cleanup_(partition_freep) Partition *p = NULL; in context_read_definitions()
1411 p = partition_new(); in context_read_definitions()
1412 if (!p) in context_read_definitions()
1415 p->definition_path = strdup(*f); in context_read_definitions()
1416 if (!p->definition_path) in context_read_definitions()
1419 r = partition_read_definition(p, *f); in context_read_definitions()
1423 LIST_INSERT_AFTER(partitions, context->partitions, last, p); in context_read_definitions()
1424 last = TAKE_PTR(p); in context_read_definitions()
1434 struct fdisk_partition *p, in determine_current_padding() argument
1444 assert(p); in determine_current_padding()
1446 if (!fdisk_partition_has_end(p)) in determine_current_padding()
1449 offset = fdisk_partition_get_end(p); in determine_current_padding()
1722 struct fdisk_partition *p; in context_load_partition_table() local
1730 p = fdisk_table_get_partition(t, i); in context_load_partition_table()
1731 if (!p) in context_load_partition_table()
1734 if (fdisk_partition_is_used(p) <= 0) in context_load_partition_table()
1737 if (fdisk_partition_has_start(p) <= 0 || in context_load_partition_table()
1738 fdisk_partition_has_size(p) <= 0 || in context_load_partition_table()
1739 fdisk_partition_has_partno(p) <= 0) in context_load_partition_table()
1742 pt = fdisk_partition_get_type(p); in context_load_partition_table()
1754 ids = fdisk_partition_get_uuid(p); in context_load_partition_table()
1762 label = fdisk_partition_get_name(p); in context_load_partition_table()
1769 sz = fdisk_partition_get_size(p); in context_load_partition_table()
1773 start = fdisk_partition_get_start(p); in context_load_partition_table()
1777 partno = fdisk_partition_get_partno(p); in context_load_partition_table()
1797 pp->current_partition = p; in context_load_partition_table()
1798 fdisk_ref_partition(p); in context_load_partition_table()
1800 … r = determine_current_padding(c, t, p, secsz, grainsz, &pp->current_padding); in context_load_partition_table()
1830 np->current_partition = p; in context_load_partition_table()
1831 fdisk_ref_partition(p); in context_load_partition_table()
1833 … r = determine_current_padding(c, t, p, secsz, grainsz, &np->current_padding); in context_load_partition_table()
1904 LIST_FOREACH(partitions, p, context->partitions) { in context_unload_partition_table()
1907 if (PARTITION_IS_FOREIGN(p)) { in context_unload_partition_table()
1908 partition_unlink_and_free(context, p); in context_unload_partition_table()
1915 p->dropped = false; in context_unload_partition_table()
1916 p->current_size = UINT64_MAX; in context_unload_partition_table()
1917 p->new_size = UINT64_MAX; in context_unload_partition_table()
1918 p->current_padding = UINT64_MAX; in context_unload_partition_table()
1919 p->new_padding = UINT64_MAX; in context_unload_partition_table()
1920 p->partno = UINT64_MAX; in context_unload_partition_table()
1921 p->offset = UINT64_MAX; in context_unload_partition_table()
1923 if (p->current_partition) { in context_unload_partition_table()
1924 fdisk_unref_partition(p->current_partition); in context_unload_partition_table()
1925 p->current_partition = NULL; in context_unload_partition_table()
1928 if (p->new_partition) { in context_unload_partition_table()
1929 fdisk_unref_partition(p->new_partition); in context_unload_partition_table()
1930 p->new_partition = NULL; in context_unload_partition_table()
1933 p->padding_area = NULL; in context_unload_partition_table()
1934 p->allocated_to_area = NULL; in context_unload_partition_table()
1936 p->current_uuid = SD_ID128_NULL; in context_unload_partition_table()
1937 p->current_label = mfree(p->current_label); in context_unload_partition_table()
1974 static const char *partition_label(const Partition *p) { in partition_label() argument
1975 assert(p); in partition_label()
1977 if (p->new_label) in partition_label()
1978 return p->new_label; in partition_label()
1980 if (p->current_label) in partition_label()
1981 return p->current_label; in partition_label()
1983 return gpt_partition_type_uuid_to_string(p->type_uuid); in partition_label()
2017 LIST_FOREACH(partitions, p, context->partitions) { in context_dump_partitions()
2022 if (p->dropped) in context_dump_partitions()
2025 if (p->current_size == UINT64_MAX) in context_dump_partitions()
2027 else if (p->current_size != p->new_size) in context_dump_partitions()
2030 label = partition_label(p); in context_dump_partitions()
2031 partname = p->partno != UINT64_MAX ? fdisk_partname(node, p->partno+1) : NULL; in context_dump_partitions()
2033 r = format_size_change(p->current_size, p->new_size, &size_change); in context_dump_partitions()
2037 r = format_size_change(p->current_padding, p->new_padding, &padding_change); in context_dump_partitions()
2041 if (p->new_size != UINT64_MAX) in context_dump_partitions()
2042 sum_size += p->new_size; in context_dump_partitions()
2043 if (p->new_padding != UINT64_MAX) in context_dump_partitions()
2044 sum_padding += p->new_padding; in context_dump_partitions()
2048 … TABLE_STRING, gpt_partition_type_uuid_to_string_harder(p->type_uuid, uuid_buffer), in context_dump_partitions()
2050 … TABLE_UUID, sd_id128_is_null(p->new_uuid) ? p->current_uuid : p->new_uuid, in context_dump_partitions()
2051 …TABLE_STRING, p->definition_path ? basename(p->definition_path) : "-", TABLE_SET_COLOR, p->definit… in context_dump_partitions()
2053 TABLE_UINT64, p->offset, in context_dump_partitions()
2054 TABLE_UINT64, p->current_size == UINT64_MAX ? 0 : p->current_size, in context_dump_partitions()
2055 TABLE_UINT64, p->new_size, in context_dump_partitions()
2056 …TABLE_STRING, size_change, TABLE_SET_COLOR, !p->partitions_next && sum_size > 0 ? ansi_underline()… in context_dump_partitions()
2057 … TABLE_UINT64, p->current_padding == UINT64_MAX ? 0 : p->current_padding, in context_dump_partitions()
2058 TABLE_UINT64, p->new_padding, in context_dump_partitions()
2059 …TABLE_STRING, padding_change, TABLE_SET_COLOR, !p->partitions_next && sum_padding > 0 ? ansi_under… in context_dump_partitions()
2097 Partition *p, in context_bar_char_process_partition() argument
2106 assert(p); in context_bar_char_process_partition()
2108 if (p->dropped) in context_bar_char_process_partition()
2111 assert(p->offset != UINT64_MAX); in context_bar_char_process_partition()
2112 assert(p->new_size != UINT64_MAX); in context_bar_char_process_partition()
2114 from = p->offset; in context_bar_char_process_partition()
2115 to = from + p->new_size; in context_bar_char_process_partition()
2130 bar[i] = p; in context_bar_char_process_partition()
2135 static int partition_hint(const Partition *p, const char *node, char **ret) { in partition_hint() argument
2142 if (p->definition_path) { in partition_hint()
2143 buf = strdup(basename(p->definition_path)); in partition_hint()
2147 label = partition_label(p); in partition_hint()
2153 if (p->partno != UINT64_MAX) { in partition_hint()
2154 buf = fdisk_partname(node, p->partno+1); in partition_hint()
2158 if (!sd_id128_is_null(p->new_uuid)) in partition_hint()
2159 id = p->new_uuid; in partition_hint()
2160 else if (!sd_id128_is_null(p->current_uuid)) in partition_hint()
2161 id = p->current_uuid; in partition_hint()
2163 id = p->type_uuid; in partition_hint()
2193 LIST_FOREACH(partitions, p, context->partitions) in context_dump_partition_bar()
2194 context_bar_char_process_partition(context, bar, c, p, start_array + j++); in context_dump_partition_bar()
2224 LIST_FOREACH(partitions, p, context->partitions) { in context_dump_partition_bar()
2251 (void) partition_hint(p, node, &hint); in context_dump_partition_bar()
2291 LIST_FOREACH(partitions, p, context->partitions) { in context_changed()
2292 if (p->dropped) in context_changed()
2295 if (p->allocated_to_area) in context_changed()
2298 if (p->new_size != p->current_size) in context_changed()
2345 static int context_wipe_partition(Context *context, Partition *p) { in context_wipe_partition() argument
2349 assert(p); in context_wipe_partition()
2350 assert(!PARTITION_EXISTS(p)); /* Safety check: never wipe existing partitions */ in context_wipe_partition()
2352 assert(p->offset != UINT64_MAX); in context_wipe_partition()
2353 assert(p->new_size != UINT64_MAX); in context_wipe_partition()
2355 r = context_wipe_range(context, p->offset, p->new_size); in context_wipe_partition()
2359 …log_info("Successfully wiped file system signatures from future partition %" PRIu64 ".", p->partno… in context_wipe_partition()
2423 static int context_discard_partition(Context *context, Partition *p) { in context_discard_partition() argument
2427 assert(p); in context_discard_partition()
2429 assert(p->offset != UINT64_MAX); in context_discard_partition()
2430 assert(p->new_size != UINT64_MAX); in context_discard_partition()
2431 assert(!PARTITION_EXISTS(p)); /* Safety check: never discard existing partitions */ in context_discard_partition()
2436 r = context_discard_range(context, p->offset, p->new_size); in context_discard_partition()
2438 …torage does not support discard, not discarding data in future partition %" PRIu64 ".", p->partno); in context_discard_partition()
2443 … device is busy, not discarding partition %" PRIu64 " because it probably is mounted.", p->partno); in context_discard_partition()
2447 log_info("Partition %" PRIu64 " too short for discard, skipping.", p->partno); in context_discard_partition()
2451 … return log_error_errno(r, "Failed to discard data for future partition %" PRIu64 ".", p->partno); in context_discard_partition()
2453 log_info("Successfully discarded data from future partition %" PRIu64 ".", p->partno); in context_discard_partition()
2457 static int context_discard_gap_after(Context *context, Partition *p) { in context_discard_gap_after() argument
2462 assert(!p || (p->offset != UINT64_MAX && p->new_size != UINT64_MAX)); in context_discard_gap_after()
2464 if (p) in context_discard_gap_after()
2465 gap = p->offset + p->new_size; in context_discard_gap_after()
2492 if (p) in context_discard_gap_after()
2493 …fo("Storage does not support discard, not discarding gap after partition %" PRIu64 ".", p->partno); in context_discard_gap_after()
2501 if (p) in context_discard_gap_after()
2502 … return log_error_errno(r, "Failed to discard gap after partition %" PRIu64 ".", p->partno); in context_discard_gap_after()
2507 if (p) in context_discard_gap_after()
2508 log_info("Successfully discarded gap after partition %" PRIu64 ".", p->partno); in context_discard_gap_after()
2524 LIST_FOREACH(partitions, p, context->partitions) { in context_wipe_and_discard()
2526 if (!p->allocated_to_area) in context_wipe_and_discard()
2529 r = context_wipe_partition(context, p); in context_wipe_and_discard()
2534 r = context_discard_partition(context, p); in context_wipe_and_discard()
2538 r = context_discard_gap_after(context, p); in context_wipe_and_discard()
2555 Partition *p, in partition_encrypt() argument
2569 assert(p); in partition_encrypt()
2570 assert(p->encrypt != ENCRYPT_OFF); in partition_encrypt()
2572 …log_debug("Encryption mode for partition %" PRIu64 ": %s", p->partno, encrypt_mode_to_string(p->en… in partition_encrypt()
2587 r = derive_uuid(p->new_uuid, "luks-uuid", &uuid); in partition_encrypt()
2591 log_info("Encrypting future partition %" PRIu64 "...", p->partno); in partition_encrypt()
2615 .label = strempty(p->new_label), in partition_encrypt()
2621 if (IN_SET(p->encrypt, ENCRYPT_KEY_FILE, ENCRYPT_KEY_FILE_TPM2)) { in partition_encrypt()
2633 if (IN_SET(p->encrypt, ENCRYPT_TPM2, ENCRYPT_KEY_FILE_TPM2)) { in partition_encrypt()
2687 log_info("Successfully encrypted future partition %" PRIu64 ".", p->partno); in partition_encrypt()
2739 LIST_FOREACH(partitions, p, context->partitions) { in context_copy_blocks()
2746 if (p->copy_blocks_fd < 0) in context_copy_blocks()
2749 if (p->dropped) in context_copy_blocks()
2752 if (PARTITION_EXISTS(p)) /* Never copy over existing partitions */ in context_copy_blocks()
2755 assert(p->new_size != UINT64_MAX); in context_copy_blocks()
2756 assert(p->copy_blocks_size != UINT64_MAX); in context_copy_blocks()
2757 assert(p->new_size >= p->copy_blocks_size); in context_copy_blocks()
2762 if (p->encrypt != ENCRYPT_OFF) { in context_copy_blocks()
2763 r = loop_device_make(whole_fd, O_RDWR, p->offset, p->new_size, 0, &d); in context_copy_blocks()
2765 …og_error_errno(r, "Failed to make loopback device of future partition %" PRIu64 ": %m", p->partno); in context_copy_blocks()
2771 … r = partition_encrypt(context, p, d->node, &cd, &encrypted, &encrypted_dev_fd); in context_copy_blocks()
2780 if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) in context_copy_blocks()
2787 p->copy_blocks_path, FORMAT_BYTES(p->copy_blocks_size), p->partno); in context_copy_blocks()
2789 … r = copy_bytes_full(p->copy_blocks_fd, target_fd, p->copy_blocks_size, 0, NULL, NULL, NULL, NULL); in context_copy_blocks()
2791 … return log_error_errno(r, "Failed to copy in data from '%s': %m", p->copy_blocks_path); in context_copy_blocks()
2796 if (p->encrypt != ENCRYPT_OFF) { in context_copy_blocks()
2811 log_info("Copying in of '%s' on block level completed.", p->copy_blocks_path); in context_copy_blocks()
2817 static int do_copy_files(Partition *p, const char *fs) { in do_copy_files() argument
2820 assert(p); in do_copy_files()
2823 STRV_FOREACH_PAIR(source, target, p->copy_files) { in do_copy_files()
2913 static int do_make_directories(Partition *p, const char *fs) { in do_make_directories() argument
2916 assert(p); in do_make_directories()
2919 STRV_FOREACH(d, p->make_directories) { in do_make_directories()
2929 static int partition_populate(Partition *p, const char *node) { in partition_populate() argument
2932 assert(p); in partition_populate()
2935 if (strv_isempty(p->copy_files) && strv_isempty(p->make_directories)) in partition_populate()
2938 log_info("Populating partition %" PRIu64 " with files.", p->partno); in partition_populate()
2957 …if (mount_nofollow_verbose(LOG_ERR, node, fs, p->format, MS_NOATIME|MS_NODEV|MS_NOEXEC|MS_NOSUID, … in partition_populate()
2960 if (do_copy_files(p, fs) < 0) in partition_populate()
2963 if (do_make_directories(p, fs) < 0) in partition_populate()
2975 log_info("Successfully populated partition %" PRIu64 " with files.", p->partno); in partition_populate()
2986 LIST_FOREACH(partitions, p, context->partitions) { in context_mkfs()
2994 if (p->dropped) in context_mkfs()
2997 if (PARTITION_EXISTS(p)) /* Never format existing partitions */ in context_mkfs()
3000 if (!p->format) in context_mkfs()
3003 assert(p->offset != UINT64_MAX); in context_mkfs()
3004 assert(p->new_size != UINT64_MAX); in context_mkfs()
3012 r = loop_device_make(fd, O_RDWR, p->offset, p->new_size, 0, &d); in context_mkfs()
3014 …og_error_errno(r, "Failed to make loopback device of future partition %" PRIu64 ": %m", p->partno); in context_mkfs()
3020 if (p->encrypt != ENCRYPT_OFF) { in context_mkfs()
3021 … r = partition_encrypt(context, p, d->node, &cd, &encrypted, &encrypted_dev_fd); in context_mkfs()
3032 log_info("Formatting future partition %" PRIu64 ".", p->partno); in context_mkfs()
3036 r = derive_uuid(p->new_uuid, "file-system-uuid", &fs_uuid); in context_mkfs()
3040 r = make_filesystem(fsdev, p->format, strempty(p->new_label), fs_uuid, arg_discard); in context_mkfs()
3047 log_info("Successfully formatted future partition %" PRIu64 ".", p->partno); in context_mkfs()
3050 if (p->encrypt != ENCRYPT_OFF) in context_mkfs()
3054 r = partition_populate(p, fsdev); in context_mkfs()
3065 if (p->encrypt != ENCRYPT_OFF) { in context_mkfs()
3086 static int partition_acquire_uuid(Context *context, Partition *p, sd_id128_t *ret) { in partition_acquire_uuid() argument
3100 assert(p); in partition_acquire_uuid()
3123 if (p == q) in partition_acquire_uuid()
3126 if (!sd_id128_equal(p->type_uuid, q->type_uuid)) in partition_acquire_uuid()
3132 plaintext.type_uuid = p->type_uuid; in partition_acquire_uuid()
3146 if (p == q) in partition_acquire_uuid()
3150 …lated from seed for partition %" PRIu64 " already used, reverting to randomized UUID.", p->partno); in partition_acquire_uuid()
3164 static int partition_acquire_label(Context *context, Partition *p, char **ret) { in partition_acquire_label() argument
3170 assert(p); in partition_acquire_label()
3173 prefix = gpt_partition_type_uuid_to_string(p->type_uuid); in partition_acquire_label()
3182 if (p == q) in partition_acquire_label()
3215 LIST_FOREACH(partitions, p, context->partitions) { in context_acquire_partition_uuids_and_labels()
3217 if (PARTITION_IS_FOREIGN(p)) { in context_acquire_partition_uuids_and_labels()
3218 p->new_uuid = p->current_uuid; in context_acquire_partition_uuids_and_labels()
3220 if (p->current_label) { in context_acquire_partition_uuids_and_labels()
3221 r = free_and_strdup_warn(&p->new_label, strempty(p->current_label)); in context_acquire_partition_uuids_and_labels()
3229 if (!sd_id128_is_null(p->current_uuid)) in context_acquire_partition_uuids_and_labels()
3230 p->new_uuid = p->current_uuid; /* Never change initialized UUIDs */ in context_acquire_partition_uuids_and_labels()
3231 else if (sd_id128_is_null(p->new_uuid)) { in context_acquire_partition_uuids_and_labels()
3233 r = partition_acquire_uuid(context, p, &p->new_uuid); in context_acquire_partition_uuids_and_labels()
3238 if (!isempty(p->current_label)) { in context_acquire_partition_uuids_and_labels()
3240 r = free_and_strdup_warn(&p->new_label, p->current_label); in context_acquire_partition_uuids_and_labels()
3243 } else if (!p->new_label) { in context_acquire_partition_uuids_and_labels()
3246 r = partition_acquire_label(context, p, &p->new_label); in context_acquire_partition_uuids_and_labels()
3273 static uint64_t partition_merge_flags(Partition *p) { in partition_merge_flags() argument
3276 assert(p); in partition_merge_flags()
3278 f = p->gpt_flags; in partition_merge_flags()
3280 if (p->no_auto >= 0) { in partition_merge_flags()
3281 if (gpt_partition_type_knows_no_auto(p->type_uuid)) in partition_merge_flags()
3282 SET_FLAG(f, GPT_FLAG_NO_AUTO, p->no_auto); in partition_merge_flags()
3286 yes_no(p->no_auto), in partition_merge_flags()
3287 gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer)); in partition_merge_flags()
3291 if (p->read_only >= 0) { in partition_merge_flags()
3292 if (gpt_partition_type_knows_read_only(p->type_uuid)) in partition_merge_flags()
3293 SET_FLAG(f, GPT_FLAG_READ_ONLY, p->read_only); in partition_merge_flags()
3297 yes_no(p->read_only), in partition_merge_flags()
3298 gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer)); in partition_merge_flags()
3302 if (p->growfs >= 0) { in partition_merge_flags()
3303 if (gpt_partition_type_knows_growfs(p->type_uuid)) in partition_merge_flags()
3304 SET_FLAG(f, GPT_FLAG_GROWFS, p->growfs); in partition_merge_flags()
3308 yes_no(p->growfs), in partition_merge_flags()
3309 gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer)); in partition_merge_flags()
3321 LIST_FOREACH(partitions, p, context->partitions) { in context_mangle_partitions()
3322 if (p->dropped) in context_mangle_partitions()
3325 assert(p->new_size != UINT64_MAX); in context_mangle_partitions()
3326 assert(p->offset != UINT64_MAX); in context_mangle_partitions()
3327 assert(p->partno != UINT64_MAX); in context_mangle_partitions()
3329 if (PARTITION_EXISTS(p)) { in context_mangle_partitions()
3332 assert(p->current_partition); in context_mangle_partitions()
3334 if (p->new_size != p->current_size) { in context_mangle_partitions()
3335 assert(p->new_size >= p->current_size); in context_mangle_partitions()
3336 assert(p->new_size % context->sector_size == 0); in context_mangle_partitions()
3338 r = fdisk_partition_size_explicit(p->current_partition, true); in context_mangle_partitions()
3342 … r = fdisk_partition_set_size(p->current_partition, p->new_size / context->sector_size); in context_mangle_partitions()
3346 log_info("Growing existing partition %" PRIu64 ".", p->partno); in context_mangle_partitions()
3350 if (!sd_id128_equal(p->new_uuid, p->current_uuid)) { in context_mangle_partitions()
3351 assert(!sd_id128_is_null(p->new_uuid)); in context_mangle_partitions()
3353 … r = fdisk_partition_set_uuid(p->current_partition, SD_ID128_TO_UUID_STRING(p->new_uuid)); in context_mangle_partitions()
3357 … log_info("Initializing UUID of existing partition %" PRIu64 ".", p->partno); in context_mangle_partitions()
3361 if (!streq_ptr(p->new_label, p->current_label)) { in context_mangle_partitions()
3362 … r = fdisk_partition_set_name(p->current_partition, strempty(p->new_label)); in context_mangle_partitions()
3366 … log_info("Setting partition label of existing partition %" PRIu64 ".", p->partno); in context_mangle_partitions()
3371 … assert(!PARTITION_IS_FOREIGN(p)); /* never touch foreign partitions */ in context_mangle_partitions()
3373 … r = fdisk_set_partition(context->fdisk_context, p->partno, p->current_partition); in context_mangle_partitions()
3381 assert(!p->new_partition); in context_mangle_partitions()
3382 assert(p->offset % context->sector_size == 0); in context_mangle_partitions()
3383 assert(p->new_size % context->sector_size == 0); in context_mangle_partitions()
3384 assert(!sd_id128_is_null(p->new_uuid)); in context_mangle_partitions()
3385 assert(p->new_label); in context_mangle_partitions()
3391 r = fdisk_parttype_set_typestr(t, SD_ID128_TO_UUID_STRING(p->type_uuid)); in context_mangle_partitions()
3407 r = fdisk_partition_set_start(q, p->offset / context->sector_size); in context_mangle_partitions()
3411 r = fdisk_partition_set_size(q, p->new_size / context->sector_size); in context_mangle_partitions()
3415 r = fdisk_partition_set_partno(q, p->partno); in context_mangle_partitions()
3419 r = fdisk_partition_set_uuid(q, SD_ID128_TO_UUID_STRING(p->new_uuid)); in context_mangle_partitions()
3423 r = fdisk_partition_set_name(q, strempty(p->new_label)); in context_mangle_partitions()
3428 r = set_gpt_flags(q, partition_merge_flags(p)); in context_mangle_partitions()
3432 log_info("Adding new partition %" PRIu64 " to partition table.", p->partno); in context_mangle_partitions()
3438 assert(!p->new_partition); in context_mangle_partitions()
3439 p->new_partition = TAKE_PTR(q); in context_mangle_partitions()
3601 LIST_FOREACH(partitions, p, context->partitions) { in context_factory_reset()
3603 if (!p->factory_reset || !PARTITION_EXISTS(p)) in context_factory_reset()
3606 assert(p->partno != UINT64_MAX); in context_factory_reset()
3608 log_info("Removing partition %" PRIu64 " for factory reset.", p->partno); in context_factory_reset()
3610 r = fdisk_delete_partition(context->fdisk_context, p->partno); in context_factory_reset()
3612 … return log_error_errno(r, "Failed to remove partition %" PRIu64 ": %m", p->partno); in context_factory_reset()
3633 LIST_FOREACH(partitions, p, context->partitions) in context_can_factory_reset()
3634 if (p->factory_reset && PARTITION_EXISTS(p)) in context_can_factory_reset()
3649 const char *pttype, *t, *p; in resolve_copy_blocks_auto_candidate() local
3681 r = sd_device_get_devname(dev, &p); in resolve_copy_blocks_auto_candidate()
3688 return log_error_errno(fd, "Failed to open block device %s: %m", p); in resolve_copy_blocks_auto_candidate()
3697 … return log_error_errno(errno_or_else(ENOMEM), "Failed to open block device '%s': %m", p); in resolve_copy_blocks_auto_candidate()
3705 log_debug("Didn't find partition table on block device '%s'.", p); in resolve_copy_blocks_auto_candidate()
3709 … return log_error_errno(errno_or_else(EIO), "Unable to probe for partition table of '%s': %m", p); in resolve_copy_blocks_auto_candidate()
3713 log_debug("Didn't find a GPT partition table on '%s'.", p); in resolve_copy_blocks_auto_candidate()
3720 … return log_error_errno(errno_or_else(EIO), "Unable read partition table of '%s': %m", p); in resolve_copy_blocks_auto_candidate()
3726 major(partition_devno), minor(partition_devno), p); in resolve_copy_blocks_auto_candidate()
3733 major(partition_devno), minor(partition_devno), p); in resolve_copy_blocks_auto_candidate()
3810 char p[SYS_BLOCK_PATH_MAX("/slaves")]; in resolve_copy_blocks_auto() local
3858 xsprintf_sys_block_path(p, "/slaves", devno); in resolve_copy_blocks_auto()
3859 d = opendir(p); in resolve_copy_blocks_auto()
3872 … return log_error_errno(errno, "Failed to read directory '%s': %m", p); in resolve_copy_blocks_auto()
3880 q = path_join(p, de->d_name, "/dev"); in resolve_copy_blocks_auto()
3912 return log_error_errno(errno, "Failed open %s: %m", p); in resolve_copy_blocks_auto()
3943 LIST_FOREACH(partitions, p, context->partitions) { in context_open_copy_block_paths()
3950 assert(p->copy_blocks_fd < 0); in context_open_copy_block_paths()
3951 assert(p->copy_blocks_size == UINT64_MAX); in context_open_copy_block_paths()
3953 if (PARTITION_EXISTS(p)) /* Never copy over partitions that already exist! */ in context_open_copy_block_paths()
3956 if (p->copy_blocks_path) { in context_open_copy_block_paths()
3958 …source_fd = chase_symlinks_and_open(p->copy_blocks_path, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEX… in context_open_copy_block_paths()
3960 … return log_error_errno(source_fd, "Failed to open '%s': %m", p->copy_blocks_path); in context_open_copy_block_paths()
3969 } else if (p->copy_blocks_auto) { in context_open_copy_block_paths()
3974 … r = resolve_copy_blocks_auto(p->type_uuid, root, restrict_devno, &devno, &uuid); in context_open_copy_block_paths()
4050 p->copy_blocks_fd = TAKE_FD(source_fd); in context_open_copy_block_paths()
4051 p->copy_blocks_size = size; in context_open_copy_block_paths()
4053 free_and_replace(p->copy_blocks_path, opened); in context_open_copy_block_paths()
4056 if (sd_id128_is_null(p->new_uuid) && !sd_id128_is_null(uuid)) in context_open_copy_block_paths()
4057 p->new_uuid = uuid; in context_open_copy_block_paths()
4470 const char *p, in acquire_root_devno() argument
4482 assert(p); in acquire_root_devno()
4486 fd = chase_symlinks_and_open(p, root, CHASE_PREFIX_ROOT, mode, &found_path); in acquire_root_devno()
4522 …, "Device '%s' has no dm-crypt/dm-verity device, no need to look for underlying block device.", p); in acquire_root_devno()
4524 … log_debug_errno(r, "Failed to find underlying block device for '%s', ignoring: %m", p); in acquire_root_devno()
4529 … log_debug_errno(r, "Failed to find whole disk block device for '%s', ignoring: %m", p); in acquire_root_devno()
4533 return log_debug_errno(r, "Failed to determine canonical path for '%s': %m", p); in acquire_root_devno()
4588 FOREACH_STRING(p, "/", "/usr") { in find_root()
4590 … r = acquire_root_devno(p, arg_root, O_RDONLY|O_DIRECTORY|O_CLOEXEC, ret, ret_fd); in find_root()
4593 return btrfs_log_dev_root(LOG_ERR, r, p); in find_root()
4595 … return log_error_errno(r, "Failed to determine backing device of %s: %m", p); in find_root()
4782 LIST_FOREACH(partitions, p, c->partitions) { in determine_auto_size()
4785 if (p->dropped) in determine_auto_size()
4788 m = partition_min_size_with_padding(c, p); in determine_auto_size()