]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-dissect-image.c
loop-util: accept loopback flags when creating loopback device
[thirdparty/systemd.git] / src / test / test-dissect-image.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8c1be37e
LP
2
3#include <fcntl.h>
e08f94ac 4#include <linux/loop.h>
8c1be37e
LP
5#include <stdio.h>
6
7#include "dissect-image.h"
8#include "log.h"
9#include "loop-util.h"
10#include "string-util.h"
6d7c4033 11#include "tests.h"
8c1be37e
LP
12
13int 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
6d7c4033 18 test_setup_logging(LOG_DEBUG);
8c1be37e
LP
19
20 if (argc < 2) {
21 log_error("Requires one command line argument.");
22 return EXIT_FAILURE;
23 }
24
e08f94ac 25 r = loop_device_make_by_path(argv[1], O_RDONLY, LO_FLAGS_PARTSCAN, &d);
8c1be37e
LP
26 if (r < 0) {
27 log_error_errno(r, "Failed to set up loopback device: %m");
28 return EXIT_FAILURE;
29 }
30
e0f9e7bd 31 r = dissect_image(d->fd, NULL, 0, DISSECT_IMAGE_REQUIRE_ROOT, &m);
8c1be37e
LP
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}