Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / tests / expand_truncate_test.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <errno.h>
4 #include <sys/file.h>
5
6 int main(int argc, char **argv)
7 {
8         char *fname = argv[1];
9         char buf[5];
10         int fd;
11         off_t off;
12         int rc;
13
14         if (argc != 2) {
15                 fprintf(stdout, "usage: %s file\n", argv[0]);
16                 return 1;
17         }
18
19         fd = open(fname, O_RDWR | O_CREAT, 0666);
20         if (fd < 0) {
21                 fprintf(stderr, "open %s failed:%d\n", fname, errno);
22                 return fd;
23         }
24
25         off = 1021 * 1024 * 1024;
26         if (ftruncate(fd, off) < 0) {
27                 fprintf(stderr, "ftruncate %ld failed:%d\n", off, errno);
28                 rc = -1;
29                 goto close;
30         }
31
32         off -= 4;
33         off = lseek(fd, off, SEEK_SET);
34         if (off == (off_t)-1) {
35                 fprintf(stderr, "lseek %ld failed:%d\n", off, errno);
36                 rc = -1;
37                 goto close;
38         }
39
40         rc = read(fd, buf, 4);
41         if (rc < 0) {
42                 fprintf(stderr, "read 4 bytes failed:%d\n", errno);
43                 goto close;
44         } else if (rc != 4) {
45                 fprintf(stderr, "read returns %d, not 4 bytes\n", rc);
46                 rc = -1;
47         } else {
48                 rc = 0;
49         }
50
51 close:
52         close(fd);
53
54         return rc;
55 }