1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <linux/loop.h>
7 #include "dissect-image.h"
10 #include "string-util.h"
13 int main(int argc
, char *argv
[]) {
14 _cleanup_(loop_device_unrefp
) LoopDevice
*d
= NULL
;
15 _cleanup_(dissected_image_unrefp
) DissectedImage
*m
= NULL
;
18 test_setup_logging(LOG_DEBUG
);
21 log_error("Requires one command line argument.");
25 r
= loop_device_make_by_path(argv
[1], O_RDONLY
, LO_FLAGS_PARTSCAN
, &d
);
27 log_error_errno(r
, "Failed to set up loopback device: %m");
31 r
= dissect_image(d
->fd
, NULL
, 0, NULL
, NULL
, DISSECT_IMAGE_REQUIRE_ROOT
|DISSECT_IMAGE_RELAX_VAR_CHECK
, &m
);
33 log_error_errno(r
, "Failed to dissect image: %m");
37 for (i
= 0; i
< _PARTITION_DESIGNATOR_MAX
; i
++) {
39 if (!m
->partitions
[i
].found
)
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
));