xref: /linux/tools/testing/selftests/damon/huge_count_read_write.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author: SeongJae Park <sj@kernel.org>
4  */
5 
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 
11 #pragma GCC diagnostic push
12 #if __GNUC__ >= 11 && __GNUC_MINOR__ >= 1
13 /* Ignore read(2) overflow and write(2) overread compile warnings */
14 #pragma GCC diagnostic ignored "-Wstringop-overread"
15 #pragma GCC diagnostic ignored "-Wstringop-overflow"
16 #endif
17 
18 void write_read_with_huge_count(char *file)
19 {
20 	int filedesc = open(file, O_RDWR);
21 	char buf[256];
22 	int ret;
23 
24 	printf("%s %s\n", __func__, file);
25 	if (filedesc < 0) {
26 		fprintf(stderr, "failed opening %s\n", file);
27 		exit(1);
28 	}
29 
30 	write(filedesc, "", 0xfffffffful);
31 	ret = read(filedesc, buf, 0xfffffffful);
32 	close(filedesc);
33 }
34 
35 #pragma GCC diagnostic pop
36 
37 int main(int argc, char *argv[])
38 {
39 	if (argc != 2) {
40 		fprintf(stderr, "Usage: %s <file>\n", argv[0]);
41 		exit(1);
42 	}
43 	write_read_with_huge_count(argv[1]);
44 
45 	return 0;
46 }
47