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