Whamcloud - gitweb
LU-15210 tests: fix sanity-lnet to handle duplicate IP
[fs/lustre-release.git] / lustre / tests / multifstat.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) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  */
29
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include <string.h>
37
38 int main(int argc, char **argv)
39 {
40         int fd1, fd2;
41         struct stat st1, st2;
42
43         if (argc != 3) {
44                 printf("Usage %s file1 file2\n", argv[0]);
45                 return 1;
46         }
47
48         fd1 = open(argv[1], O_CREAT | O_RDWR, 0666);
49         if (fd1 == -1) {
50                 printf("Error opening %s: %s\n", argv[1], strerror(errno));
51                 return errno;
52         }
53
54         fd2 = open(argv[2], O_RDONLY);
55         if (fd2 == -1) {
56                 printf("Error opening %s: %s\n", argv[2], strerror(errno));
57                 return errno;
58         }
59
60         sleep(1);
61
62         if (write(fd1, "hello", strlen("hello")) != strlen("hello")) {
63                 printf("Error writing: %s\n", strerror(errno));
64                 return errno;
65         }
66
67         if (fstat(fd1, &st1)) {
68                 printf("Error statting %s: %s\n", argv[1], strerror(errno));
69                 return errno;
70         }
71
72         if (fstat(fd2, &st2)) {
73                 printf("Error statting %s: %s\n", argv[2], strerror(errno));
74                 return errno;
75         }
76
77         if (st1.st_size != st2.st_size) {
78                 printf("Sizes don't match %lu, %lu\n",
79                        (unsigned long)st1.st_size,
80                        (unsigned long)st2.st_size);
81                 return 1;
82         }
83
84         if (st1.st_mtime != st2.st_mtime) {
85                 printf("Mtimes don't match %ld, %ld\n",
86                        st1.st_mtime, st2.st_mtime);
87                 return 1;
88         }
89
90         if (st1.st_blocks != st2.st_blocks) {
91                 printf("Blocks don't match %ld, %ld\n",
92                        (long)st1.st_blocks, (long)st2.st_blocks);
93                 return 1;
94         }
95
96         return 0;
97 }