3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License version 2 for more details (a copy is included
13 * in the LICENSE file that accompanied this code).
15 * You should have received a copy of the GNU General Public License
16 * version 2 along with this program; If not, see
17 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2020, Whamcloud.
24 * Author: Mikhail Pershin <mpershin@whamcloud.com>
28 * Test does lseek with SEEK_DATA/SEEK_HOLE options on a file and prints result.
30 * Two input options are '-d|--data' for SEEK_DATA and '-l|--hole' for hole
38 #include <sys/types.h>
44 "Usage: %s [option] <start> <filename>\n"
45 " where options are:\n"
46 " --hole|-l seek first hole offset after given offset\n"
47 " --data|-d seek first data offset after given offset\n";
49 int main(int argc, char **argv)
52 struct option long_opts[] = {
53 { .name = "hole", .has_arg = no_argument, .val = 'l' },
54 { .name = "data", .has_arg = no_argument, .val = 'd' },
63 while ((c = getopt_long(argc, argv, "ld", long_opts, NULL)) != -1) {
72 fprintf(stderr, "error: %s: unknown option '%s'\n",
73 argv[0], argv[optind - 1]);
78 if (argc - optind < 2) {
79 fprintf(stderr, usage, argv[0]);
83 cur_off = atoll(argv[optind]);
85 fd = open(argv[optind + 1], O_RDONLY);
87 fprintf(stderr, "cannot open %s for reading, error %d",
88 argv[optind + 1], errno);
92 ret_off = lseek(fd, cur_off, opt);
96 fprintf(stderr, "lseek to %jd failed with %d\n",
100 printf("%jd\n", ret_off);