| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <fcntl.h> |
| 4 |
|
| 5 |
#include "fd-util.h" |
| 6 |
#include "log.h" |
| 7 |
#include "qcow2-util.h" |
| 8 |
#include "tests.h" |
| 9 |
|
| 10 |
int main(int argc, char *argv[]) { |
| 11 |
_cleanup_close_ int sfd = -EBADF, dfd = -EBADF; |
| 12 |
int r; |
| 13 |
|
| 14 |
test_setup_logging(LOG_DEBUG); |
| 15 |
|
| 16 |
if (argc != 3) { |
| 17 |
log_error("Needs two arguments."); |
| 18 |
return EXIT_FAILURE; |
| 19 |
} |
| 20 |
|
| 21 |
sfd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); |
| 22 |
if (sfd < 0) { |
| 23 |
log_error_errno(errno, "Can't open source file: %m"); |
| 24 |
return EXIT_FAILURE; |
| 25 |
} |
| 26 |
|
| 27 |
dfd = open(argv[2], O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666); |
| 28 |
if (dfd < 0) { |
| 29 |
log_error_errno(errno, "Can't open destination file: %m"); |
| 30 |
return EXIT_FAILURE; |
| 31 |
} |
| 32 |
|
| 33 |
r = qcow2_convert(sfd, dfd); |
| 34 |
if (r < 0) { |
| 35 |
log_error_errno(r, "Failed to unpack: %m"); |
| 36 |
return EXIT_FAILURE; |
| 37 |
} |
| 38 |
|
| 39 |
return EXIT_SUCCESS; |
| 40 |
} |