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