X Tutup
Skip to content

Commit eb5e261

Browse files
authored
Merge pull request systemd#17076 from poettering/dissect-cleanup
minor cleanups to the dissector code
2 parents f593965 + aa088f6 commit eb5e261

File tree

8 files changed

+49
-111
lines changed

8 files changed

+49
-111
lines changed

src/core/dbus-execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ static int read_mount_options(sd_bus_message *message, sd_bus_error *error, Moun
15131513
while ((r = sd_bus_message_read(message, "(ss)", &partition, &mount_options)) > 0) {
15141514
_cleanup_free_ char *previous = NULL, *escaped = NULL;
15151515
_cleanup_free_ MountOptions *o = NULL;
1516-
int partition_designator;
1516+
PartitionDesignator partition_designator;
15171517

15181518
if (chars_intersect(mount_options, WHITESPACE))
15191519
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,

src/core/load-fragment.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ int config_parse_root_image_options(
14831483
MountOptions *o = NULL;
14841484
_cleanup_free_ char *mount_options_resolved = NULL;
14851485
const char *mount_options = NULL, *partition = "root";
1486-
int partition_designator;
1486+
PartitionDesignator partition_designator;
14871487

14881488
/* Format is either 'root:foo' or 'foo' (root is implied) */
14891489
if (!isempty(*second)) {
@@ -4946,7 +4946,7 @@ int config_parse_mount_images(
49464946
for (;;) {
49474947
_cleanup_free_ char *partition = NULL, *mount_options = NULL, *mount_options_resolved = NULL;
49484948
MountOptions *o = NULL;
4949-
int partition_designator;
4949+
PartitionDesignator partition_designator;
49504950

49514951
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options, NULL);
49524952
if (r == -ENOMEM)

src/dissect/dissect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
456456
(void) table_set_empty_string(t, "-");
457457
(void) table_set_align_percent(t, table_get_cell(t, 0, 7), 100);
458458

459-
for (unsigned i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
459+
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
460460
DissectedPartition *p = m->partitions + i;
461461

462462
if (!p->found)

src/shared/dissect-image.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ int dissect_image(
325325
int r, generic_nr;
326326
struct stat st;
327327
sd_device *q;
328-
unsigned i;
329328

330329
assert(fd >= 0);
331330
assert(ret);
@@ -420,7 +419,7 @@ int dissect_image(
420419
m->verity = root_hash && verity_data;
421420
m->can_verity = !!verity_data;
422421

423-
options = mount_options_from_part(mount_options, PARTITION_ROOT);
422+
options = mount_options_from_designator(mount_options, PARTITION_ROOT);
424423
if (options) {
425424
o = strdup(options);
426425
if (!o)
@@ -504,7 +503,8 @@ int dissect_image(
504503
continue;
505504

506505
if (is_gpt) {
507-
int designator = _PARTITION_DESIGNATOR_INVALID, architecture = _ARCHITECTURE_INVALID;
506+
PartitionDesignator designator = _PARTITION_DESIGNATOR_INVALID;
507+
int architecture = _ARCHITECTURE_INVALID;
508508
const char *stype, *sid, *fstype = NULL;
509509
sd_id128_t type_id, id;
510510
bool rw = true;
@@ -716,7 +716,7 @@ int dissect_image(
716716
if (!n)
717717
return -ENOMEM;
718718

719-
options = mount_options_from_part(mount_options, designator);
719+
options = mount_options_from_designator(mount_options, designator);
720720
if (options) {
721721
o = strdup(options);
722722
if (!o)
@@ -773,7 +773,7 @@ int dissect_image(
773773
if (!n)
774774
return -ENOMEM;
775775

776-
options = mount_options_from_part(mount_options, PARTITION_XBOOTLDR);
776+
options = mount_options_from_designator(mount_options, PARTITION_XBOOTLDR);
777777
if (options) {
778778
o = strdup(options);
779779
if (!o)
@@ -827,7 +827,7 @@ int dissect_image(
827827
if (multiple_generic)
828828
return -ENOTUNIQ;
829829

830-
options = mount_options_from_part(mount_options, PARTITION_ROOT);
830+
options = mount_options_from_designator(mount_options, PARTITION_ROOT);
831831
if (options) {
832832
o = strdup(options);
833833
if (!o)
@@ -866,7 +866,7 @@ int dissect_image(
866866
b = NULL;
867867

868868
/* Fill in file system types if we don't know them yet. */
869-
for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
869+
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
870870
DissectedPartition *p = m->partitions + i;
871871

872872
if (!p->found)
@@ -894,12 +894,10 @@ int dissect_image(
894894
}
895895

896896
DissectedImage* dissected_image_unref(DissectedImage *m) {
897-
unsigned i;
898-
899897
if (!m)
900898
return NULL;
901899

902-
for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
900+
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
903901
free(m->partitions[i].fstype);
904902
free(m->partitions[i].node);
905903
free(m->partitions[i].decrypted_fstype);
@@ -1557,7 +1555,6 @@ int dissected_image_decrypt(
15571555

15581556
#if HAVE_LIBCRYPTSETUP
15591557
_cleanup_(decrypted_image_unrefp) DecryptedImage *d = NULL;
1560-
unsigned i;
15611558
int r;
15621559
#endif
15631560

@@ -1585,7 +1582,7 @@ int dissected_image_decrypt(
15851582
if (!d)
15861583
return -ENOMEM;
15871584

1588-
for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
1585+
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
15891586
DissectedPartition *p = m->partitions + i;
15901587
int k;
15911588

@@ -2039,14 +2036,14 @@ int dissect_image_and_warn(
20392036
}
20402037
}
20412038

2042-
bool dissected_image_can_do_verity(const DissectedImage *image, unsigned partition_designator) {
2039+
bool dissected_image_can_do_verity(const DissectedImage *image, PartitionDesignator partition_designator) {
20432040
if (image->single_file_system)
20442041
return partition_designator == PARTITION_ROOT && image->can_verity;
20452042

20462043
return PARTITION_VERITY_OF(partition_designator) >= 0;
20472044
}
20482045

2049-
bool dissected_image_has_verity(const DissectedImage *image, unsigned partition_designator) {
2046+
bool dissected_image_has_verity(const DissectedImage *image, PartitionDesignator partition_designator) {
20502047
int k;
20512048

20522049
if (image->single_file_system)
@@ -2068,10 +2065,10 @@ MountOptions* mount_options_free_all(MountOptions *options) {
20682065
return NULL;
20692066
}
20702067

2071-
const char* mount_options_from_part(const MountOptions *options, int designator) {
2072-
MountOptions *m;
2068+
const char* mount_options_from_designator(const MountOptions *options, PartitionDesignator designator) {
2069+
const MountOptions *m;
20732070

2074-
LIST_FOREACH(mount_options, m, (MountOptions *)options)
2071+
LIST_FOREACH(mount_options, m, options)
20752072
if (designator == m->partition_designator && !isempty(m->options))
20762073
return m->options;
20772074

@@ -2164,4 +2161,4 @@ static const char *const partition_designator_table[] = {
21642161
[PARTITION_VAR] = "var",
21652162
};
21662163

2167-
DEFINE_STRING_TABLE_LOOKUP(partition_designator, int);
2164+
DEFINE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator);

src/shared/dissect-image.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct DissectedPartition {
2727
char *mount_options;
2828
};
2929

30-
enum {
30+
typedef enum PartitionDesignator {
3131
PARTITION_ROOT,
3232
PARTITION_ROOT_SECONDARY, /* Secondary architecture */
3333
PARTITION_HOME,
@@ -41,9 +41,9 @@ enum {
4141
PARTITION_VAR,
4242
_PARTITION_DESIGNATOR_MAX,
4343
_PARTITION_DESIGNATOR_INVALID = -1
44-
};
44+
} PartitionDesignator;
4545

46-
static inline int PARTITION_VERITY_OF(int p) {
46+
static inline PartitionDesignator PARTITION_VERITY_OF(PartitionDesignator p) {
4747
if (p == PARTITION_ROOT)
4848
return PARTITION_ROOT_VERITY;
4949
if (p == PARTITION_ROOT_SECONDARY)
@@ -87,14 +87,14 @@ struct DissectedImage {
8787
};
8888

8989
struct MountOptions {
90-
int partition_designator;
90+
PartitionDesignator partition_designator;
9191
char *options;
9292
LIST_FIELDS(MountOptions, mount_options);
9393
};
9494

9595
MountOptions* mount_options_free_all(MountOptions *options);
9696
DEFINE_TRIVIAL_CLEANUP_FUNC(MountOptions*, mount_options_free_all);
97-
const char* mount_options_from_part(const MountOptions *options, int designator);
97+
const char* mount_options_from_designator(const MountOptions *options, PartitionDesignator designator);
9898

9999
int probe_filesystem(const char *node, char **ret_fstype);
100100
int dissect_image(int fd, const void *root_hash, size_t root_hash_size, const char *verity_data, const MountOptions *mount_options, DissectImageFlags flags, DissectedImage **ret);
@@ -114,11 +114,11 @@ DecryptedImage* decrypted_image_unref(DecryptedImage *p);
114114
DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);
115115
int decrypted_image_relinquish(DecryptedImage *d);
116116

117-
const char* partition_designator_to_string(int i) _const_;
118-
int partition_designator_from_string(const char *name) _pure_;
117+
const char* partition_designator_to_string(PartitionDesignator d) _const_;
118+
PartitionDesignator partition_designator_from_string(const char *name) _pure_;
119119

120120
int verity_metadata_load(const char *image, const char *root_hash_path, void **ret_roothash, size_t *ret_roothash_size, char **ret_verity_data, char **ret_roothashsig);
121-
bool dissected_image_can_do_verity(const DissectedImage *image, unsigned partition_designator);
122-
bool dissected_image_has_verity(const DissectedImage *image, unsigned partition_designator);
121+
bool dissected_image_can_do_verity(const DissectedImage *image, PartitionDesignator d);
122+
bool dissected_image_has_verity(const DissectedImage *image, PartitionDesignator d);
123123

124124
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device, DecryptedImage **ret_decrypted_image);

src/shared/gpt.h

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77

88
#include "id128-util.h"
99

10-
/* We only support root disk discovery for x86, x86-64, Itanium and ARM for
11-
* now, since EFI for anything else doesn't really exist, and we only
12-
* care for root partitions on the same disk as the EFI ESP. */
10+
/* We only support root disk discovery for x86, x86-64, Itanium and ARM for now, since EFI for anything else
11+
* doesn't really exist, and we only care for root partitions on the same disk as the EFI ESP. */
1312

14-
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
15-
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
16-
#define GPT_ROOT_ARM SD_ID128_MAKE(69,da,d7,10,2c,e4,4e,3c,b1,6c,21,a1,d4,9a,be,d3)
17-
#define GPT_ROOT_ARM_64 SD_ID128_MAKE(b9,21,b0,45,1d,f0,41,c3,af,44,4c,6f,28,0d,3f,ae)
18-
#define GPT_ROOT_IA64 SD_ID128_MAKE(99,3d,8d,3d,f8,0e,42,25,85,5a,9d,af,8e,d7,ea,97)
19-
#define GPT_ESP SD_ID128_MAKE(c1,2a,73,28,f8,1f,11,d2,ba,4b,00,a0,c9,3e,c9,3b)
20-
#define GPT_XBOOTLDR SD_ID128_MAKE(bc,13,c2,ff,59,e6,42,62,a3,52,b2,75,fd,6f,71,72)
21-
#define GPT_SWAP SD_ID128_MAKE(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
22-
#define GPT_HOME SD_ID128_MAKE(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
23-
#define GPT_SRV SD_ID128_MAKE(3b,8f,84,25,20,e0,4f,3b,90,7f,1a,25,a7,6f,98,e8)
24-
#define GPT_VAR SD_ID128_MAKE(4d,21,b0,16,b5,34,45,c2,a9,fb,5c,16,e0,91,fd,2d)
25-
#define GPT_TMP SD_ID128_MAKE(7e,c6,f5,57,3b,c5,4a,ca,b2,93,16,ef,5d,f6,39,d1)
26-
#define GPT_USER_HOME SD_ID128_MAKE(77,3f,91,ef,66,d4,49,b5,bd,83,d6,83,bf,40,ad,16)
13+
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
14+
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
15+
#define GPT_ROOT_ARM SD_ID128_MAKE(69,da,d7,10,2c,e4,4e,3c,b1,6c,21,a1,d4,9a,be,d3)
16+
#define GPT_ROOT_ARM_64 SD_ID128_MAKE(b9,21,b0,45,1d,f0,41,c3,af,44,4c,6f,28,0d,3f,ae)
17+
#define GPT_ROOT_IA64 SD_ID128_MAKE(99,3d,8d,3d,f8,0e,42,25,85,5a,9d,af,8e,d7,ea,97)
18+
#define GPT_ESP SD_ID128_MAKE(c1,2a,73,28,f8,1f,11,d2,ba,4b,00,a0,c9,3e,c9,3b)
19+
#define GPT_XBOOTLDR SD_ID128_MAKE(bc,13,c2,ff,59,e6,42,62,a3,52,b2,75,fd,6f,71,72)
20+
#define GPT_SWAP SD_ID128_MAKE(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
21+
#define GPT_HOME SD_ID128_MAKE(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
22+
#define GPT_SRV SD_ID128_MAKE(3b,8f,84,25,20,e0,4f,3b,90,7f,1a,25,a7,6f,98,e8)
23+
#define GPT_VAR SD_ID128_MAKE(4d,21,b0,16,b5,34,45,c2,a9,fb,5c,16,e0,91,fd,2d)
24+
#define GPT_TMP SD_ID128_MAKE(7e,c6,f5,57,3b,c5,4a,ca,b2,93,16,ef,5d,f6,39,d1)
25+
#define GPT_USER_HOME SD_ID128_MAKE(77,3f,91,ef,66,d4,49,b5,bd,83,d6,83,bf,40,ad,16)
26+
#define GPT_LINUX_GENERIC SD_ID128_MAKE(0f,c6,3d,af,84,83,47,72,8e,79,3d,69,d8,47,7d,e4)
2727

28-
/* Verity partitions for the root partitions above (we only define them for the root partitions, because only they are
29-
* are commonly read-only and hence suitable for verity). */
28+
/* Verity partitions for the root partitions above (we only define them for the root partitions, because only
29+
* they are are commonly read-only and hence suitable for verity). */
3030
#define GPT_ROOT_X86_VERITY SD_ID128_MAKE(d1,3c,5d,3b,b5,d1,42,2a,b2,9f,94,54,fd,c8,9d,76)
3131
#define GPT_ROOT_X86_64_VERITY SD_ID128_MAKE(2c,73,57,ed,eb,d2,46,d9,ae,c1,23,d4,37,ec,2b,f5)
3232
#define GPT_ROOT_ARM_VERITY SD_ID128_MAKE(73,86,cd,f2,20,3c,47,a9,a4,98,f2,ec,ce,45,a2,d6)
@@ -62,15 +62,12 @@
6262
#define GPT_FLAG_NO_BLOCK_IO_PROTOCOL (1ULL << 1)
6363
#define GPT_FLAG_LEGACY_BIOS_BOOTABLE (1ULL << 2)
6464

65-
/* Flags we recognize on the root, swap, home and srv partitions when
66-
* doing auto-discovery. These happen to be identical to what
67-
* Microsoft defines for its own Basic Data Partitions, but that's
68-
* just because we saw no point in defining any other values here. */
65+
/* Flags we recognize on the root, swap, home and srv partitions when doing auto-discovery. These happen to
66+
* be identical to what Microsoft defines for its own Basic Data Partitions, but that's just because we saw
67+
* no point in defining any other values here. */
6968
#define GPT_FLAG_READ_ONLY (1ULL << 60)
7069
#define GPT_FLAG_NO_AUTO (1ULL << 63)
7170

72-
#define GPT_LINUX_GENERIC SD_ID128_MAKE(0f,c6,3d,af,84,83,47,72,8e,79,3d,69,d8,47,7d,e4)
73-
7471
const char *gpt_partition_type_uuid_to_string(sd_id128_t id);
7572
const char *gpt_partition_type_uuid_to_string_harder(
7673
sd_id128_t id,

src/test/meson.build

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,6 @@ tests += [
421421
[],
422422
'', 'manual'],
423423

424-
[['src/test/test-dissect-image.c'],
425-
[],
426-
[libblkid],
427-
'', 'manual'],
428-
429424
[['src/test/test-signal-util.c'],
430425
[],
431426
[]],

src/test/test-dissect-image.c

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup