Whamcloud - gitweb
import older libsysio snapshot.
[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 <errno.h>
47 #include <assert.h>
48 #include <sys/types.h>
49 #include <sys/stat.h>
50 #include <unistd.h>
51 #include <sys/queue.h>
52
53 #include "sysio.h"
54 #include "inode.h"
55 #include "file.h"
56
57 #ifndef REDSTORM
58 #undef fstat64
59 #undef stat64
60 #undef lstat64
61 #endif
62
63 #undef __fxstat64
64 #undef __xstat64
65 #undef __lxstat64
66
67 int
68 PREPEND(__, SYSIO_INTERFACE_NAME(fxstat64))(int __ver,
69                                             int __fildes,
70                                             struct stat64 *__stat_buf)
71 {
72         struct file *fil;
73         int     err;
74         SYSIO_INTERFACE_DISPLAY_BLOCK;
75
76         SYSIO_INTERFACE_ENTER;
77         if (__ver != _STAT_VER) {
78                 err = -ENOSYS;
79                 goto out;
80         }
81
82         err = 0;
83         fil = _sysio_fd_find(__fildes);
84         if (!fil) {
85                 err = -EBADF;
86                 goto out;
87         }
88         err = fil->f_ino->i_ops.inop_getattr(NULL, fil->f_ino, __stat_buf);
89 out:
90         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
91 }
92
93 #ifndef REDSTORM
94 int
95 SYSIO_INTERFACE_NAME(fstat64)(int fd, struct stat64 *buf)
96 {
97
98         return PREPEND(__, SYSIO_INTERFACE_NAME(fxstat64))(_STAT_VER, fd, buf);
99 }
100 #endif
101
102 int
103 PREPEND(__, SYSIO_INTERFACE_NAME(xstat64))(int __ver,
104                                            const char *__filename,
105                                            struct stat64 *__stat_buf)
106 {
107         struct intent intent;
108         int     err;
109         struct pnode *pno;
110         SYSIO_INTERFACE_DISPLAY_BLOCK;
111
112         SYSIO_INTERFACE_ENTER;
113         if (__ver != _STAT_VER) {
114                 err = -ENOSYS;
115                 goto out;
116         }
117
118         INTENT_INIT(&intent, INT_GETATTR, NULL, NULL);
119         err = _sysio_namei(_sysio_cwd, __filename, 0, &intent, &pno);
120         if (err)
121                 goto out;
122         err =
123             pno->p_base->pb_ino->i_ops.inop_getattr(pno,
124                                                     pno->p_base->pb_ino,
125                                                     __stat_buf);
126         P_RELE(pno);
127 out:
128         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
129 }
130
131 #ifndef REDSTORM
132 int
133 SYSIO_INTERFACE_NAME(stat64)(const char *filename, struct stat64 *buf)
134 {
135
136         return PREPEND(__, SYSIO_INTERFACE_NAME(xstat64))(_STAT_VER,
137                                                           filename,
138                                                           buf);
139 }
140 #endif
141
142 int
143 PREPEND(__, SYSIO_INTERFACE_NAME(lxstat64))(int __ver,
144                                             const char *__filename,
145                                             struct stat64 *__stat_buf)
146 {
147         struct intent intent;
148         int     err;
149         struct pnode *pno;
150         SYSIO_INTERFACE_DISPLAY_BLOCK;
151
152         SYSIO_INTERFACE_ENTER;
153         if (__ver != _STAT_VER) {
154                 err = -ENOSYS;
155                 goto out;
156         }
157
158         INTENT_INIT(&intent, INT_GETATTR, NULL, NULL);
159         err = _sysio_namei(_sysio_cwd, __filename, ND_NOFOLLOW, &intent, &pno);
160         if (err)
161                 goto out;
162         err =
163             pno->p_base->pb_ino->i_ops.inop_getattr(pno,
164                                                     pno->p_base->pb_ino,
165                                                     __stat_buf);
166         P_RELE(pno);
167 out:
168         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
169 }
170
171 #ifndef REDSTORM
172 int
173 SYSIO_INTERFACE_NAME(lstat64)(const char *filename, struct stat64 *buf)
174 {
175
176         return PREPEND(__, SYSIO_INTERFACE_NAME(lxstat64))(_STAT_VER,
177                                                            filename,
178                                                            buf);
179 }
180 #endif
181 #endif /* !_LARGEFILE64_SOURCE */