diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-12-10 01:08:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-10 01:08:13 -0500 |
commit | 4a5567d5d6ab01974dd089eb8907fecd6aff4fcf (patch) | |
tree | 4f40cdd195f08022e2846d5c9757147ca436fede /src/test | |
parent | 2e1f244efd2dfc1a60d032bef3d88b9ba6e0444b (diff) | |
parent | 58abb66f4b9b0b3a16fe29211454d9936d35c35d (diff) |
Merge pull request #4795 from poettering/dissect
Generalize image dissection logic of nspawn, and make it useful for other tools.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-dissect-image.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/test-dissect-image.c b/src/test/test-dissect-image.c new file mode 100644 index 0000000000..0512a15e88 --- /dev/null +++ b/src/test/test-dissect-image.c @@ -0,0 +1,66 @@ +/*** + This file is part of systemd. + + Copyright 2016 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <fcntl.h> +#include <stdio.h> + +#include "dissect-image.h" +#include "log.h" +#include "loop-util.h" +#include "string-util.h" + +int main(int argc, char *argv[]) { + _cleanup_(loop_device_unrefp) LoopDevice *d = NULL; + _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; + int r, i; + + log_set_max_level(LOG_DEBUG); + + if (argc < 2) { + log_error("Requires one command line argument."); + return EXIT_FAILURE; + } + + r = loop_device_make_by_path(argv[1], O_RDONLY, &d); + if (r < 0) { + log_error_errno(r, "Failed to set up loopback device: %m"); + return EXIT_FAILURE; + } + + r = dissect_image(d->fd, NULL, 0, &m); + if (r < 0) { + log_error_errno(r, "Failed to dissect image: %m"); + return EXIT_FAILURE; + } + + for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) { + + if (!m->partitions[i].found) + continue; + + printf("Found %s partition, %s of type %s at #%i (%s)\n", + partition_designator_to_string(i), + m->partitions[i].rw ? "writable" : "read-only", + strna(m->partitions[i].fstype), + m->partitions[i].partno, + strna(m->partitions[i].node)); + } + + return EXIT_SUCCESS; +} |