1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <inttypes.h>
5 #include <sys/types.h>
6 
7 #include "sd-id128.h"
8 
9 #include "fdisk-util.h"
10 #include "macro.h"
11 
12 typedef struct PartitionInfo PartitionInfo;
13 
14 typedef enum PartitionChange {
15         PARTITION_FLAGS           = 1 << 0,
16         PARTITION_NO_AUTO         = 1 << 1,
17         PARTITION_READ_ONLY       = 1 << 2,
18         PARTITION_GROWFS          = 1 << 3,
19         PARTITION_UUID            = 1 << 4,
20         PARTITION_LABEL           = 1 << 5,
21         _PARTITION_CHANGE_MAX     = (1 << 6) - 1, /* all of the above */
22         _PARTITION_CHANGE_INVALID = -EINVAL,
23 } PartitionChange;
24 
25 struct PartitionInfo {
26         size_t partno;
27         uint64_t start, size;
28         uint64_t flags;
29         sd_id128_t type, uuid;
30         char *label;
31         char *device; /* Note that this might point to some non-existing path in case we operate on a loopback file */
32         bool no_auto:1;
33         bool read_only:1;
34         bool growfs:1;
35 };
36 
37 #define PARTITION_INFO_NULL                     \
38         {                                       \
39                 .partno = SIZE_MAX,             \
40                 .start = UINT64_MAX,            \
41                 .size = UINT64_MAX,             \
42         }
43 
44 void partition_info_destroy(PartitionInfo *p);
45 
46 int read_partition_info(struct fdisk_context *c, struct fdisk_table *t, size_t i, PartitionInfo *ret);
47 
48 int find_suitable_partition(const char *device, uint64_t space, sd_id128_t *partition_type, PartitionInfo *ret);
49 int patch_partition(const char *device, const PartitionInfo *info, PartitionChange change);
50