Whamcloud - gitweb
LU-8347 ldlm: granting conflicting locks
[fs/lustre-release.git] / lustre / tests / badarea_io.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6
7 int main(int argc, char **argv)
8 {
9         int rc;
10         int fd = open(argv[1], O_WRONLY);
11
12         if (fd == -1) {
13                 perror(argv[1]);
14                 goto read;
15         }
16
17         /* We need rc because Sles11 compiler warns against unchecked
18          * return value of read and write */
19         rc = write(fd, (void *)0x4096000, 5);
20         if (rc != 5)
21                 perror("write badarea (Should have failed)");
22
23         rc = write(fd, &fd, 0);
24         if (rc != 0)
25                 perror("write zero bytes");
26
27         rc = write(fd, &fd, 1);
28         if (rc != 1)
29                 perror("write one byte");
30
31         rc = write(fd, &fd, 2UL*1024*1024);
32         if (rc != 2UL*1024*1024)
33                 perror("write 2M");
34
35         rc = write(fd, &fd, 2UL*1024*1024*1024);
36         if (rc != 2UL*1024*1024*1024)
37                 perror("write 2G");
38
39         rc = write(fd, &fd, -2);
40         if (rc != -2)
41                 perror("write -2");
42
43         close(fd);
44
45 read:
46         fd = open(argv[1], O_RDONLY);
47         if (fd == -1)
48                 return 0;
49         rc = read(fd, (void *)0x4096000, 5);
50         perror("read");
51
52         close(fd);
53
54         /* Tame the compiler spooked about rc assigned, but not used */
55         if (!rc)
56                 return -1; /* Not really important. */
57
58         return 0;
59 }