Whamcloud - gitweb
Ignore generated files.
[fs/lustre-release.git] / libsysio / tests / test_stats.c
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2003 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 #define _BSD_SOURCE
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <unistd.h>
49 #include <errno.h>
50 #include <sys/types.h>
51 #include <sys/stat.h>
52 #include <fcntl.h>
53 #ifdef notdef
54 #include <sys/statvfs.h>
55 #endif
56 #include <sys/uio.h>
57
58 #include "xtio.h"
59 #include "test.h"
60
61 /*
62  * Get stats of file and file system.
63  *
64  * Usage: test_stats [<path> ...]
65  */
66
67 void    usage(void);
68 void    do_stats(const char *path);
69
70 int
71 main(int argc, char * const argv[])
72 {
73         int     i;
74         int     err;
75         extern int _test_sysio_startup(void);
76
77         /*
78          * Parse command-line args.
79          */
80         while ((i = getopt(argc, argv, "")) != -1)
81                 switch (i) {
82
83                 default:
84                         usage();
85                 }
86
87         err = _test_sysio_startup();
88         if (err) {
89                 errno = -err;
90                 perror("sysio startup");
91                 exit(1);
92         }       
93
94         (void )umask(022);
95
96         while (optind < argc)
97                 do_stats(argv[optind++]);
98
99         /*
100          * Clean up.
101          */
102         _test_sysio_shutdown();
103
104         return 0;
105 }
106
107 void
108 usage()
109 {
110
111         (void )fprintf(stderr,
112                        "Usage: test_stats"
113                        " source destination\n");
114         exit(1);
115 }
116
117 void
118 do_stats(const char *path)
119 {
120         int     fd;
121         int     err;
122         struct stat stbuf1, stbuf2;
123 #ifdef  notdef
124         struct statvfs stvfsbuf1, stvfsbuf2;
125 #endif
126
127         fd = open(path, O_RDONLY);
128         if (fd < 0) {
129                 perror(path);
130                 return;
131         }
132         err = fstat(fd, &stbuf1);
133         if (!err)
134                 err = stat(path, &stbuf2);
135 #ifdef notdef
136         if (!err)
137                 err = fstatvfs(fd, &stvfsbuf1);
138         if (!err)
139                 err = statvfs(path, &stvfsbuf1);
140 #endif
141         if (err) {
142                 perror(path);
143                 goto out;
144         }
145         if (stbuf1.st_dev != stbuf2.st_dev ||
146             stbuf1.st_ino != stbuf2.st_ino) {
147                 (void )fprintf(stderr, "%s: [f]stat info mismatch\n", path);
148                 goto out;
149         }
150 #ifdef notdef
151         if (stvfsbuf1.f_fsid != stvfsbuf2.f_fsid) {
152                 (void )fprintf(stderr, "%s: [f]statvfs info mismatch\n", path);
153         }
154 #endif
155         printf("%s:"
156                " dev %lu,"
157                " ino %lu,"
158                " mode %lu,"
159                " nlink %lu,"
160                " uid %lu,"
161                " gid %lu,"
162                " rdev %lu,"
163                " size %llu,"
164                " blksize %lu,"
165                " blocks %lu,"
166                " atime %lu,"
167                " mtime %lu,"
168                " ctime %lu"
169                "\n",
170                path,
171                (unsigned long )stbuf1.st_dev,
172                (unsigned long )stbuf1.st_ino,
173                (unsigned long )stbuf1.st_mode,
174                (unsigned long )stbuf1.st_nlink,
175                (unsigned long )stbuf1.st_uid,
176                (unsigned long )stbuf1.st_gid,
177                (unsigned long )stbuf1.st_rdev,
178                (unsigned long long)stbuf1.st_size,
179                (unsigned long )stbuf1.st_blksize,
180                (unsigned long )stbuf1.st_blocks,
181                (unsigned long )stbuf1.st_atime,
182                (unsigned long )stbuf1.st_mtime,
183                (unsigned long )stbuf1.st_ctime);
184 out:
185         if (close(fd) != 0)
186                 perror("closing file");
187 }