diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
commit | 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch) | |
tree | 33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/test/test-btrfs-physical-offset.c | |
parent | Initial commit. (diff) | |
download | systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip |
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-btrfs-physical-offset.c')
-rw-r--r-- | src/test/test-btrfs-physical-offset.c | 37 |
1 files changed, 37 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 0000000..221c08e --- /dev/null +++ b/src/test/test-btrfs-physical-offset.c @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <errno.h> +#include <fcntl.h> + +#include "btrfs-util.h" +#include "fd-util.h" +#include "format-util.h" +#include "log.h" +#include "memory-util.h" +#include "tests.h" + +int main(int argc, char *argv[]) { + _cleanup_close_ int fd = -EBADF; + uint64_t offset; + int r; + + assert(argc == 2); + assert(!isempty(argv[1])); + + test_setup_logging(LOG_DEBUG); + + fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); + if (fd < 0) { + log_error_errno(errno, "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; +} |