Whamcloud - gitweb
LU-14286 osd-ldiskfs: fallocate() should zero new blocks
[fs/lustre-release.git] / lustre / tests / badarea_io.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2014, Intel Corporation.
24  * Use is subject to license terms.
25  */
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31
32 #undef perror
33 #define perror(str) ((void)0)
34
35 int main(int argc, char **argv)
36 {
37         int rc;
38         int fd = open(argv[1], O_WRONLY);
39
40         if (fd == -1) {
41                 perror(argv[1]);
42                 goto read;
43         }
44
45         /* We need rc because Sles11 compiler warns against unchecked
46          * return value of read and write */
47         rc = write(fd, (void *)0x4096000, 5);
48         if (rc != 5)
49                 perror("write badarea (Should have failed)");
50
51         rc = write(fd, &fd, 0);
52         if (rc != 0)
53                 perror("write zero bytes");
54
55         rc = write(fd, &fd, 1);
56         if (rc != 1)
57                 perror("write one byte");
58
59         rc = write(fd, &fd, 2UL*1024*1024);
60         if (rc != 2UL*1024*1024)
61                 perror("write 2M");
62
63         rc = write(fd, &fd, 2UL*1024*1024*1024);
64         if (rc != 2UL*1024*1024*1024)
65                 perror("write 2G");
66
67         rc = write(fd, &fd, -2);
68         if (rc != -2)
69                 perror("write -2");
70
71         close(fd);
72
73 read:
74         fd = open(argv[1], O_RDONLY);
75         if (fd == -1)
76                 return 0;
77         rc = read(fd, (void *)0x4096000, 5);
78         perror("read");
79
80         close(fd);
81
82         /* Tame the compiler spooked about rc assigned, but not used */
83         if (!rc)
84                 return -1; /* Not really important. */
85
86         return 0;
87 }