Whamcloud - gitweb
Some racy problems happened when sanity-quota.sh run on buffalo.
[fs/lustre-release.git] / lustre / tests / multifstat.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <errno.h>
7 #include <string.h>
8
9 int main(int argc, char **argv)
10 {
11         int fd1, fd2;
12         struct stat st1, st2;
13
14         if (argc != 3) {
15                 printf("Usage %s file1 file2\n", argv[0]);
16                 return 1;
17         }
18
19
20         fd1 = open(argv[1], O_CREAT| O_RDWR, 0666);
21         if (fd1 == -1) {
22                 printf("Error opening %s: %s\n", argv[1], strerror(errno));
23                 return errno;
24         }
25
26         fd2 = open(argv[2], O_RDONLY);
27         if (fd2 == -1) {
28                 printf("Error opening %s: %s\n", argv[2], strerror(errno));
29                 return errno;
30         }
31
32         sleep(1);
33
34         if ( write(fd1, "hello", strlen("hello")) != strlen("hello")) {
35                 printf("Error writing: %s\n", strerror(errno));
36                 return errno;
37         }
38
39         if ( fstat(fd1, &st1) ) {
40                 printf("Error statting %s: %s\n", argv[1], strerror(errno));
41                 return errno;
42         }
43
44         if ( fstat(fd2, &st2) ) {
45                 printf("Error statting %s: %s\n", argv[2], strerror(errno));
46                 return errno;
47         }
48
49         if ( st1.st_size != st2.st_size ) {
50                 printf("Sizes don't match %lu, %lu\n",
51                        (unsigned long)st1.st_size, 
52                        (unsigned long)st2.st_size);
53                 return 1;
54         }
55
56         if ( st1.st_mtime != st2.st_mtime ) {
57                 printf("Mtimes don't match %ld, %ld\n",
58                        st1.st_mtime, st2.st_mtime);
59                 return 1;
60         }
61
62         return 0;
63 }