1 /* Test suite for GNU tar - SEEK_HOLE detector.
3 Copyright 2015-2016 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program. If not, see <http://www.gnu.org/licenses/>.
18 Description: detect whether it is possible to work with SEEK_HOLE on
19 particular operating system and file system. */
24 #include <sys/types.h>
30 EX_OK = 0, /* SEEK_HOLE support */
31 EX_FAIL, /* test failed - no SEEK_HOLE support */
32 EX_BAD, /* test is not relevant */
36 check_seek_hole (int fd)
43 if (lseek (fd, 100*1024*1024, SEEK_END) < 0)
47 if (write (fd, "data\n", 5) != 5)
51 if (lseek (fd, 100*1024*1024, SEEK_END) < 0)
55 if (write (fd, "data\n", 5) != 5)
58 if (fstat (fd, &stat))
61 offset = lseek (fd, 0, SEEK_DATA);
62 if (offset == (off_t)-1)
65 offset = lseek (fd, offset, SEEK_HOLE);
66 if (offset == (off_t)-1 || offset == stat.st_size)
80 char template[] = "testseekhole-XXXXXX";
81 int fd = mkstemp (template);
84 rc = check_seek_hole (fd);