2000-06-30 17:55:04 +08:00
|
|
|
/* Some basic tests for LFS.
|
2001-01-09 06:28:15 +08:00
|
|
|
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
2000-06-30 17:55:04 +08:00
|
|
|
Contributed by Andreas Jaeger <aj@suse.de>, 2000.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <errno.h>
|
2000-10-25 05:12:01 +08:00
|
|
|
#include <sys/resource.h>
|
2000-06-30 17:55:04 +08:00
|
|
|
|
|
|
|
/* Prototype for our test function. */
|
|
|
|
extern void do_prepare (int argc, char *argv[]);
|
|
|
|
extern int do_test (int argc, char *argv[]);
|
|
|
|
|
|
|
|
/* We have a preparation function. */
|
|
|
|
#define PREPARE do_prepare
|
|
|
|
|
|
|
|
/* We might need a bit longer timeout. */
|
|
|
|
#define TIMEOUT 20 /* sec */
|
|
|
|
|
|
|
|
/* This defines the `main' function and some more. */
|
|
|
|
#include <test-skeleton.c>
|
|
|
|
|
|
|
|
/* These are for the temporary file we generate. */
|
|
|
|
char *name;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* 2^31 = 2GB. */
|
|
|
|
#define TWO_GB 2147483648LL
|
|
|
|
|
|
|
|
void
|
|
|
|
do_prepare (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char name_len;
|
2000-10-26 10:24:09 +08:00
|
|
|
struct rlimit64 rlim;
|
2000-06-30 17:55:04 +08:00
|
|
|
|
|
|
|
name_len = strlen (test_dir);
|
|
|
|
name = malloc (name_len + sizeof ("/lfsXXXXXX"));
|
|
|
|
mempcpy (mempcpy (name, test_dir, name_len),
|
|
|
|
"/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
|
|
|
|
add_temp_file (name);
|
|
|
|
|
|
|
|
/* Open our test file. */
|
2000-10-26 10:24:09 +08:00
|
|
|
fd = mkstemp64 (name);
|
|
|
|
if (fd == -1)
|
2000-06-30 17:55:04 +08:00
|
|
|
{
|
2000-10-26 10:24:09 +08:00
|
|
|
if (errno == ENOSYS)
|
|
|
|
{
|
|
|
|
/* Fail silently. */
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "open64 is not supported");
|
2000-10-26 10:24:09 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error (EXIT_FAILURE, errno, "cannot create temporary file");
|
2000-06-30 17:55:04 +08:00
|
|
|
}
|
|
|
|
|
2000-10-26 10:24:09 +08:00
|
|
|
if (getrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
|
|
|
{
|
|
|
|
error (0, errno, "cannot get resource limit");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
if (rlim.rlim_cur < TWO_GB + 200)
|
|
|
|
{
|
|
|
|
rlim.rlim_cur = TWO_GB + 200;
|
|
|
|
if (setrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
|
|
|
{
|
|
|
|
error (0, errno, "cannot reset file size limits");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
2000-06-30 17:55:04 +08:00
|
|
|
}
|
|
|
|
|
2001-02-06 05:38:54 +08:00
|
|
|
static void
|
|
|
|
test_ftello (void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int ret;
|
|
|
|
off64_t pos;
|
|
|
|
|
|
|
|
f = fopen64 (name, "w");
|
|
|
|
|
|
|
|
ret = fseeko64 (f, TWO_GB+100, SEEK_SET);
|
|
|
|
if (ret == -1 && errno == ENOSYS)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "fseeko64 is not supported.");
|
2001-02-06 05:38:54 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
if (ret == -1 && errno == EINVAL)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "LFS seems not to be supported");
|
2001-02-06 05:38:54 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, errno, "fseeko64 failed with error");
|
2001-02-06 05:38:54 +08:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fwrite ("Hello", 1, 5, f);
|
2001-06-11 16:43:24 +08:00
|
|
|
if (ret == -1 && errno == EFBIG)
|
|
|
|
{
|
|
|
|
error (0, errno, "LFS seems not to be supported");
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ENOSPC)
|
2001-02-06 05:38:54 +08:00
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "Not enough space to write file.");
|
2001-02-06 05:38:54 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 5)
|
2001-06-11 16:43:24 +08:00
|
|
|
error (EXIT_FAILURE, errno, "Cannot write test string to large file");
|
2001-02-06 05:38:54 +08:00
|
|
|
|
|
|
|
pos = ftello64 (f);
|
|
|
|
|
|
|
|
if (pos != TWO_GB+105)
|
|
|
|
{
|
|
|
|
error (0, 0, "ftello64 gives wrong result.");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (f);
|
|
|
|
}
|
|
|
|
|
2000-06-30 17:55:04 +08:00
|
|
|
int
|
|
|
|
do_test (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct stat64 statbuf;
|
|
|
|
|
|
|
|
ret = lseek64 (fd, TWO_GB+100, SEEK_SET);
|
|
|
|
if (ret == -1 && errno == ENOSYS)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "lseek64 is not supported.");
|
2000-06-30 17:55:04 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2001-01-09 06:28:15 +08:00
|
|
|
if (ret == -1 && errno == EINVAL)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "LFS seems not to be supported.");
|
2001-01-09 06:28:15 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2001-02-06 05:38:54 +08:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, errno, "lseek64 failed with error");
|
2001-02-06 05:38:54 +08:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
2000-06-30 17:55:04 +08:00
|
|
|
|
|
|
|
ret = write (fd, "Hello", 5);
|
2001-06-11 16:43:24 +08:00
|
|
|
if (ret == -1 && errno == EFBIG)
|
|
|
|
{
|
|
|
|
error (0, 0, "LFS seems not to be supported.");
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ENOSPC)
|
2000-06-30 17:55:04 +08:00
|
|
|
{
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "Not enough space to write file.");
|
2000-06-30 17:55:04 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2000-09-14 14:44:19 +08:00
|
|
|
|
2000-06-30 17:55:04 +08:00
|
|
|
if (ret != 5)
|
|
|
|
error (EXIT_FAILURE, errno, "cannot write test string to large file");
|
|
|
|
|
|
|
|
ret = close (fd);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
error (EXIT_FAILURE, errno, "error closing file");
|
|
|
|
|
|
|
|
ret = stat64 (name, &statbuf);
|
|
|
|
|
2000-09-14 14:44:19 +08:00
|
|
|
if (ret == -1 && (errno == ENOSYS || errno == EOVERFLOW))
|
2001-06-11 16:43:24 +08:00
|
|
|
error (0, 0, "stat64 is not supported.");
|
2000-06-30 17:55:04 +08:00
|
|
|
else if (ret == -1)
|
|
|
|
error (EXIT_FAILURE, errno, "cannot stat file `%s'", name);
|
2000-11-21 01:40:29 +08:00
|
|
|
else if (statbuf.st_size != (TWO_GB + 100 + 5))
|
2000-06-30 17:55:04 +08:00
|
|
|
error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
|
2000-11-21 01:40:29 +08:00
|
|
|
(long long int) statbuf.st_size, (TWO_GB + 100 + 5));
|
2000-06-30 17:55:04 +08:00
|
|
|
|
2001-02-06 05:38:54 +08:00
|
|
|
test_ftello ();
|
|
|
|
|
2000-06-30 17:55:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|