]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
8c1be37e LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2016 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <fcntl.h> | |
22 | #include <stdio.h> | |
23 | ||
24 | #include "dissect-image.h" | |
25 | #include "log.h" | |
26 | #include "loop-util.h" | |
27 | #include "string-util.h" | |
28 | ||
29 | int main(int argc, char *argv[]) { | |
30 | _cleanup_(loop_device_unrefp) LoopDevice *d = NULL; | |
31 | _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; | |
32 | int r, i; | |
33 | ||
34 | log_set_max_level(LOG_DEBUG); | |
35 | ||
36 | if (argc < 2) { | |
37 | log_error("Requires one command line argument."); | |
38 | return EXIT_FAILURE; | |
39 | } | |
40 | ||
41 | r = loop_device_make_by_path(argv[1], O_RDONLY, &d); | |
42 | if (r < 0) { | |
43 | log_error_errno(r, "Failed to set up loopback device: %m"); | |
44 | return EXIT_FAILURE; | |
45 | } | |
46 | ||
e0f9e7bd | 47 | r = dissect_image(d->fd, NULL, 0, DISSECT_IMAGE_REQUIRE_ROOT, &m); |
8c1be37e LP |
48 | if (r < 0) { |
49 | log_error_errno(r, "Failed to dissect image: %m"); | |
50 | return EXIT_FAILURE; | |
51 | } | |
52 | ||
53 | for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) { | |
54 | ||
55 | if (!m->partitions[i].found) | |
56 | continue; | |
57 | ||
58 | printf("Found %s partition, %s of type %s at #%i (%s)\n", | |
59 | partition_designator_to_string(i), | |
60 | m->partitions[i].rw ? "writable" : "read-only", | |
61 | strna(m->partitions[i].fstype), | |
62 | m->partitions[i].partno, | |
63 | strna(m->partitions[i].node)); | |
64 | } | |
65 | ||
66 | return EXIT_SUCCESS; | |
67 | } |