8000 minix/minix/tests/test50.c at master · zidiann/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
630 lines (472 loc) · 13.4 KB

test50.c

File metadata and controls

630 lines (472 loc) · 13.4 KB
if ((fd = open(TESTFILE, O_RDONLY)) < 0) e(4);
check_file(fd, nsize, osize, osize);
}
close(fd);
if (unlink(TESTFILE) != 0) e(5);
}
void test50f()
{
subtest = 6;
/* truncate(2) on a file that is not open. */
all_sizes(sub50f);
}
void sub50g(osize, nsize)
off_t osize;
off_t nsize;
{
int fd;
fd = make_file(osize);
if (ftruncate(fd, nsize) != 0) e(1);
check_file(fd, osize, nsize, nsize);
if (nsize < osize) {
if (ftruncate(fd, osize) != 0) e(2);
check_file(fd, nsize, osize, osize);
}
close(fd);
if (unlink(TESTFILE) != 0) e(3);
}
void test50g()
{
subtest = 7;
/* ftruncate(2) on an open file. */
all_sizes(sub50g);
}
void sub50h(osize, nsize)
off_t osize;
off_t nsize;
{
struct flock flock;
int fd;
fd = make_file(osize);
flock.l_whence = SEEK_SET;
flock.l_start = nsize;
flock.l_len = 0;
if (fcntl(fd, F_FREESP, &flock) != 0) e(1);
check_file(fd, osize, nsize, nsize);
if (nsize < osize) {
flock.l_whence = SEEK_SET;
flock.l_start = osize;
flock.l_len = 0;
if (fcntl(fd, F_FREESP, &flock) != 0) e(2);
check_file(fd, nsize, osize, osize);
}
close(fd);
if (unlink(TESTFILE) != 0) e(3);
}
void test50h()
{
subtest = 8;
/* fcntl(2) with F_FREESP and l_len=0. */
all_sizes(sub50h);
}
void sub50i(size, off, len, type)
off_t size;
off_t off;
size_t len;
int type;
{
struct flock flock;
int fd;
fd = make_file(size);
switch (type) {
case 0:
flock.l_whence = SEEK_SET;
flock.l_start = off;
break;
case 1:
if (lseek(fd, off, SEEK_SET) != off) e(1);
flock.l_whence = SEEK_CUR;
flock.l_start = 0;
break;
case 2:
flock.l_whence = SEEK_END;
flock.l_start = off - size;
break;
default:
e(1);
}
flock.l_len = len;
if (fcntl(fd, F_FREESP, &flock) != 0) e(2);
check_file(fd, off, off + len, size);
/* Repeat the call in order to see whether the file system can handle holes
* while freeing up. If not, the server would typically crash; we need not
* check the results again.
*/
flock.l_whence = SEEK_SET;
flock.l_start = off;
if (fcntl(fd, F_FREESP, &flock) != 0) e(3);
close(fd);
if (unlink(TESTFILE) != 0) e(4);
}
void test50i()
{
off_t off;
int i, j, k, l;
subtest = 9;
/* fcntl(2) with F_FREESP and l_len>0. */
/* This loop determines the size of the test file. */
for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
/* Big files simply take too long. We have to compromise here. */
if (sizes[i] >= THRESHOLD) continue;
/* This loop determines one of the two values for the offset. */
for (j = 0; j < sizeof(sizes) / sizeof(sizes[0]); j++) {
if (sizes[j] >= sizes[i]) continue;
/* This loop determines the other. */
for (k = 0; k < sizeof(sizes) / sizeof(sizes[0]); k++) {
if (sizes[k] > sizes[j]) continue;
/* Construct an offset by adding the two sizes. */
off = sizes[j] + sizes[k];
if (j + 1 < sizeof(sizes) / sizeof(sizes[0]) &&
off >= sizes[j + 1]) continue;
/* This loop determines the length of the hole. */
for (l = 0; l < sizeof(sizes) / sizeof(sizes[0]); l++) {
if (sizes[l] == 0 || off + sizes[l] > sizes[i])
continue;
/* This could have been a loop, too! */
sub50i(sizes[i], off, sizes[l], 0);
sub50i(sizes[i], off, sizes[l], 1);
sub50i(sizes[i], off, sizes[l], 2);
}
}
}
}
}
0