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