1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2001, International Business Machines Corp.
4 * Copyright (c) 2020, Joerg Vehlow <joerg.vehlow@aox-tech.de>
5 *
6 * The purpose of this test is to verify the file size limitations
7 * of a filesystem. It writes one buffer at a time and lseeks from
8 * the beginning of the file to the end of the last write position.
9 * The intent is to test lseek64.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <time.h>
19
20 #include "tst_test.h"
21
22 static char *str_bufnum;
23 static int bufnum = 100;
24 static char buf[TST_MB];
25
setup(void)26 static void setup(void)
27 {
28 unsigned int i;
29
30 if (str_bufnum) {
31 if (tst_parse_int(str_bufnum, &bufnum, 0, INT_MAX)) {
32 tst_brk(TBROK, "Invalid buffer count '%s'", str_bufnum);
33 }
34 }
35
36 buf[0] = 'A';
37 for (i = 1; i < ARRAY_SIZE(buf) - 1; i++)
38 buf[i] = '0';
39 buf[ARRAY_SIZE(buf) - 1] = 'Z';
40 }
41
run(void)42 static void run(void)
43 {
44 time_t time1, time2;
45 int i, fd, diff;
46
47 time1 = time(NULL);
48 tst_res(TINFO, "started building a %d megabyte file", bufnum);
49
50 if ((fd = creat("large_file", 0755)) == -1)
51 tst_brk(TBROK | TERRNO, "creat() failed");
52
53 for (i = 0; i < bufnum; i++) {
54 if (write(fd, buf, sizeof(buf)) == -1) {
55 tst_brk(TFAIL | TERRNO, "write() failed");
56 }
57 fsync(fd);
58 if (lseek(fd, (i + 1) * sizeof(buf), 0) == -1)
59 tst_brk(TFAIL | TERRNO, "lseek failed");
60 }
61 close(fd);
62 time2 = time(NULL);
63 tst_res(TINFO, "finished building a %d megabyte file", bufnum);
64 diff = time2 - time1;
65 tst_res(TINFO, "total time for test to run: %d minute(s) and %d seconds",
66 diff / 60, diff % 60);
67
68 tst_res(TPASS, "test successfull");
69 }
70
71 static struct tst_test test = {
72 .options = (struct tst_option[]) {
73 {"n:", &str_bufnum, "COUNT Number of megabytes to write (default 100)"},
74 {}
75 },
76 .needs_tmpdir = 1,
77 .setup = setup,
78 .test_all = run
79 };
80