]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-dissect-image.c
service: add new RootImageOptions feature
[thirdparty/systemd.git] / src / test / test-dissect-image.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <fcntl.h>
4 #include <linux/loop.h>
5 #include <stdio.h>
6
7 #include "dissect-image.h"
8 #include "log.h"
9 #include "loop-util.h"
10 #include "string-util.h"
11 #include "tests.h"
12
13 int main(int argc, char *argv[]) {
14 _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
15 _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
16 int r, i;
17
18 test_setup_logging(LOG_DEBUG);
19
20 if (argc < 2) {
21 log_error("Requires one command line argument.");
22 return EXIT_FAILURE;
23 }
24
25 r = loop_device_make_by_path(argv[1], O_RDONLY, LO_FLAGS_PARTSCAN, &d);
26 if (r < 0) {
27 log_error_errno(r, "Failed to set up loopback device: %m");
28 return EXIT_FAILURE;
29 }
30
31 r = dissect_image(d->fd, NULL, 0, NULL, NULL, DISSECT_IMAGE_REQUIRE_ROOT|DISSECT_IMAGE_RELAX_VAR_CHECK, &m);
32 if (r < 0) {
33 log_error_errno(r, "Failed to dissect image: %m");
34 return EXIT_FAILURE;
35 }
36
37 for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
38
39 if (!m->partitions[i].found)
40 continue;
41
42 printf("Found %s partition, %s of type %s at #%i (%s)\n",
43 partition_designator_to_string(i),
44 m->partitions[i].rw ? "writable" : "read-only",
45 strna(m->partitions[i].fstype),
46 m->partitions[i].partno,
47 strna(m->partitions[i].node));
48 }
49
50 return EXIT_SUCCESS;
51 }