1 /* Some basic tests for LFS.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <sys/types.h>
26 #include <sys/resource.h>
27 #include <support/check.h>
29 /* Prototype for our test function. */
30 extern void do_prepare (int argc
, char *argv
[]);
31 extern int do_test (int argc
, char *argv
[]);
33 /* We have a preparation function. */
34 #define PREPARE do_prepare
36 /* This defines the `main' function and some more. */
37 #include <test-skeleton.c>
39 /* These are for the temporary file we generate. */
44 #define TWO_GB 2147483648LL
47 do_prepare (int argc
, char *argv
[])
52 name_len
= strlen (test_dir
);
53 name
= xmalloc (name_len
+ sizeof ("/lfsXXXXXX"));
54 mempcpy (mempcpy (name
, test_dir
, name_len
),
55 "/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
57 /* Open our test file. */
58 fd
= mkstemp64 (name
);
64 error (0, 0, "open64 is not supported");
68 error (EXIT_FAILURE
, errno
, "cannot create temporary file");
70 if (!support_descriptor_supports_holes (fd
))
71 FAIL_UNSUPPORTED ("File %s does not support holes", name
);
74 if (getrlimit64 (RLIMIT_FSIZE
, &rlim
) != 0)
76 error (0, errno
, "cannot get resource limit");
79 if (rlim
.rlim_cur
< TWO_GB
+ 200)
81 rlim
.rlim_cur
= TWO_GB
+ 200;
82 if (setrlimit64 (RLIMIT_FSIZE
, &rlim
) != 0)
84 error (0, errno
, "cannot reset file size limits");
97 f
= fopen64 (name
, "w");
99 ret
= fseeko64 (f
, TWO_GB
+100, SEEK_SET
);
100 if (ret
== -1 && errno
== ENOSYS
)
102 error (0, 0, "fseeko64 is not supported.");
105 if (ret
== -1 && errno
== EINVAL
)
107 error (0, 0, "LFS seems not to be supported");
112 error (0, errno
, "fseeko64 failed with error");
116 ret
= fwrite ("Hello", 1, 5, f
);
117 if (ret
== -1 && errno
== EFBIG
)
119 error (0, errno
, "LFS seems not to be supported");
123 if (ret
== -1 && errno
== ENOSPC
)
125 error (0, 0, "Not enough space to write file.");
130 error (EXIT_FAILURE
, errno
, "Cannot write test string to large file");
134 if (pos
!= TWO_GB
+105)
136 error (0, 0, "ftello64 gives wrong result.");
144 do_test (int argc
, char *argv
[])
147 struct stat64 statbuf
;
149 ret
= lseek64 (fd
, TWO_GB
+100, SEEK_SET
);
150 if (ret
== -1 && errno
== ENOSYS
)
152 error (0, 0, "lseek64 is not supported.");
155 if (ret
== -1 && errno
== EINVAL
)
157 error (0, 0, "LFS seems not to be supported.");
162 error (0, errno
, "lseek64 failed with error");
165 off64_t offset64
= lseek64 (fd
, 0, SEEK_CUR
);
166 if (offset64
!= TWO_GB
+ 100)
168 error (0, 0, "lseek64 did not return expected offset");
171 off_t offset
= lseek (fd
, 0, SEEK_CUR
);
172 if (sizeof (off_t
) < sizeof (off64_t
))
174 if (offset
!= -1 || errno
!= EOVERFLOW
)
176 error (0, 0, "lseek did not fail with EOVERFLOW");
181 if (offset
!= TWO_GB
+ 100)
183 error (0, 0, "lseek did not return expected offset");
187 ret
= write (fd
, "Hello", 5);
188 if (ret
== -1 && errno
== EFBIG
)
190 error (0, 0, "LFS seems not to be supported.");
194 if (ret
== -1 && errno
== ENOSPC
)
196 error (0, 0, "Not enough space to write file.");
201 error (EXIT_FAILURE
, errno
, "cannot write test string to large file");
206 error (EXIT_FAILURE
, errno
, "error closing file");
208 ret
= stat64 (name
, &statbuf
);
210 if (ret
== -1 && (errno
== ENOSYS
|| errno
== EOVERFLOW
))
211 error (0, 0, "stat64 is not supported.");
213 error (EXIT_FAILURE
, errno
, "cannot stat file `%s'", name
);
214 else if (statbuf
.st_size
!= (TWO_GB
+ 100 + 5))
215 error (EXIT_FAILURE
, 0, "stat reported size %lld instead of %lld.",
216 (long long int) statbuf
.st_size
, (TWO_GB
+ 100 + 5));
218 fd2
= openat64 (AT_FDCWD
, name
, O_RDWR
);
223 /* Silently ignore this test. */
224 error (0, 0, "openat64 is not supported");
227 error (EXIT_FAILURE
, errno
, "openat64 failed to open big file");
234 error (EXIT_FAILURE
, errno
, "error closing file");