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