Whamcloud - gitweb
b=3359
[fs/lustre-release.git] / libsysio / src / stat64.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 #ifdef _LARGEFILE64_SOURCE
45
46 #include <string.h>
47 #include <errno.h>
48 #include <assert.h>
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <unistd.h>
52 #include <sys/queue.h>
53
54 #include "sysio.h"
55 #include "inode.h"
56 #include "file.h"
57
58 #ifndef REDSTORM
59 #undef fstat64
60 #undef stat64
61 #undef lstat64
62 #endif
63
64 #undef __fxstat64
65 #undef __xstat64
66 #undef __lxstat64
67
68 int
69 PREPEND(__, SYSIO_INTERFACE_NAME(fxstat64))(int __ver,
70                                             int __fildes,
71                                             struct stat64 *__stat_buf)
72 {
73         struct file *fil;
74         int     err;
75         SYSIO_INTERFACE_DISPLAY_BLOCK;
76
77         SYSIO_INTERFACE_ENTER;
78         if (__ver != _STAT_VER) {
79                 err = -ENOSYS;
80                 goto out;
81         }
82
83         err = 0;
84         fil = _sysio_fd_find(__fildes);
85         if (!fil) {
86                 err = -EBADF;
87                 goto out;
88         }
89         /*
90          * Never use the attributes cached in the inode record. Give
91          * the driver a chance to refresh them.
92          */
93         err = fil->f_ino->i_ops.inop_getattr(NULL, fil->f_ino, __stat_buf);
94 out:
95         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
96 }
97
98 #ifndef REDSTORM
99 int
100 SYSIO_INTERFACE_NAME(fstat64)(int fd, struct stat64 *buf)
101 {
102
103         return PREPEND(__, SYSIO_INTERFACE_NAME(fxstat64))(_STAT_VER, fd, buf);
104 }
105 #endif
106
107 int
108 PREPEND(__, SYSIO_INTERFACE_NAME(xstat64))(int __ver,
109                                            const char *__filename,
110                                            struct stat64 *__stat_buf)
111 {
112         struct intent intent;
113         int     err;
114         struct pnode *pno;
115         struct inode *ino;
116         SYSIO_INTERFACE_DISPLAY_BLOCK;
117
118         SYSIO_INTERFACE_ENTER;
119         if (__ver != _STAT_VER) {
120                 err = -ENOSYS;
121                 goto out;
122         }
123
124         INTENT_INIT(&intent, INT_GETATTR, NULL, NULL);
125         err = _sysio_namei(_sysio_cwd, __filename, 0, &intent, &pno);
126         if (err)
127                 goto out;
128         /*
129          * Leverage the INT_GETATTR intent above. We are counting
130          * on the FS driver to either make sure the attributes cached in
131          * the inode are always correct or refresh them in the lookup, above.
132          */
133         ino = pno->p_base->pb_ino;
134         (void )memcpy(__stat_buf, &ino->i_stbuf, sizeof(struct intnl_stat));
135         P_RELE(pno);
136 out:
137         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
138 }
139
140 #ifndef REDSTORM
141 int
142 SYSIO_INTERFACE_NAME(stat64)(const char *filename, struct stat64 *buf)
143 {
144
145         return PREPEND(__, SYSIO_INTERFACE_NAME(xstat64))(_STAT_VER,
146                                                           filename,
147                                                           buf);
148 }
149 #endif
150
151 int
152 PREPEND(__, SYSIO_INTERFACE_NAME(lxstat64))(int __ver,
153                                             const char *__filename,
154                                             struct stat64 *__stat_buf)
155 {
156         struct intent intent;
157         int     err;
158         struct pnode *pno;
159         struct inode *ino;
160         SYSIO_INTERFACE_DISPLAY_BLOCK;
161
162         SYSIO_INTERFACE_ENTER;
163         if (__ver != _STAT_VER) {
164                 err = -ENOSYS;
165                 goto out;
166         }
167
168         INTENT_INIT(&intent, INT_GETATTR, NULL, NULL);
169         err = _sysio_namei(_sysio_cwd, __filename, ND_NOFOLLOW, &intent, &pno);
170         if (err)
171                 goto out;
172         /*
173          * Leverage the INT_GETATTR intent above. We are counting
174          * on the FS driver to either make sure the attributes cached in
175          * the inode are always correct or refresh them in the lookup, above.
176          */
177         ino = pno->p_base->pb_ino;
178         (void )memcpy(__stat_buf, &ino->i_stbuf, sizeof(struct intnl_stat));
179         P_RELE(pno);
180 out:
181         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
182 }
183
184 #ifndef REDSTORM
185 int
186 SYSIO_INTERFACE_NAME(lstat64)(const char *filename, struct stat64 *buf)
187 {
188
189         return PREPEND(__, SYSIO_INTERFACE_NAME(lxstat64))(_STAT_VER,
190                                                            filename,
191                                                            buf);
192 }
193 #endif
194 #endif /* !_LARGEFILE64_SOURCE */