diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-09-18 14:31:59 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-09-19 15:45:27 +0200 |
commit | 2b344ea808dadb860396e7b95c5f0846db5d04b6 (patch) | |
tree | 16bc6f01dcb3ca61640c3e1a88fc4d9526d65cac /src/test/test-btrfs-physical-offset.c | |
parent | btrfs-util: introduce btrfs_get_file_physical_offset_fd (diff) | |
download | systemd-2b344ea808dadb860396e7b95c5f0846db5d04b6.tar.xz systemd-2b344ea808dadb860396e7b95c5f0846db5d04b6.zip |
test: introduce TEST-83-BTRFS
The Ubuntu CIs are deny-listed because the shipped
btrfs-progs is too old, i.e. doesn't support the
recently-added 'filesystem mkswapfile' command.
Diffstat (limited to 'src/test/test-btrfs-physical-offset.c')
-rw-r--r-- | src/test/test-btrfs-physical-offset.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/test-btrfs-physical-offset.c b/src/test/test-btrfs-physical-offset.c new file mode 100644 index 0000000000..bcc6252381 --- /dev/null +++ b/src/test/test-btrfs-physical-offset.c @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <fcntl.h> + +#include "btrfs-util.h" +#include "fd-util.h" +#include "format-util.h" +#include "log.h" +#include "memory-util.h" + +int main(int argc, char *argv[]) { + _cleanup_close_ int fd = -EBADF; + uint64_t offset; + int r; + + assert(argc == 2); + assert(!isempty(argv[1])); + + fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); + if (fd < 0) { + log_error_errno(fd, "Failed to open '%s': %m", argv[1]); + return EXIT_FAILURE; + } + + r = btrfs_get_file_physical_offset_fd(fd, &offset); + if (r < 0) { + log_error_errno(r, "Failed to get physical offset of '%s': %m", argv[1]); + return EXIT_FAILURE; + } + + printf("%" PRIu64 "\n", offset / page_size()); + return EXIT_SUCCESS; +} |