2 * This Cplant(TM) source code is the property of Sandia National
5 * This Cplant(TM) source code is copyrighted by Sandia National
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)
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
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.
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.
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
34 * Questions or comments about this library should be sent to:
37 * Sandia National Laboratories, New Mexico
39 * Albuquerque, NM 87185-1110
45 * Incorporate the GNU flags for open if we can.
53 #include <sys/types.h>
56 #include <sys/queue.h>
63 #include "sysio-symbols.h"
65 #include "sysio-symbols.h"
71 mode_t _sysio_umask = 0; /* process umask. */
74 * Internal form of open.
77 _sysio_open(struct pnode *pno, int flags, mode_t mode)
84 ro = IS_RDONLY(pno, pno->p_base->pb_ino);
85 w = flags & (O_WRONLY|O_RDWR);
86 if (w == (O_WRONLY|O_RDWR)) {
94 ino = pno->p_base->pb_ino;
95 if ((flags & O_CREAT) && !ino) {
103 parent = pno->p_parent;
104 err = _sysio_p_validate(parent, NULL, NULL);
106 ino = parent->p_base->pb_ino;
109 !IS_RDONLY(parent, ino)
110 ? (*ino->i_ops.inop_open)(pno, flags, mode)
113 } else if ((flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
116 err = _sysio_p_validate(pno, NULL, NULL);
119 * Simple open of pre-existing file.
121 err = (*ino->i_ops.inop_open)(pno, flags, mode);
130 SYSIO_INTERFACE_NAME(open)(const char *path, int flags, ...)
134 struct intent intent;
138 SYSIO_INTERFACE_DISPLAY_BLOCK;
140 SYSIO_INTERFACE_ENTER;
142 * Get mode argument and determine parameters for namei
146 intent.int_opmask = INT_OPEN;
147 if (flags & O_CREAT) {
151 * Set ndflags to indicate return of negative alias is OK.
156 * Will need mode too.
166 mode &= ~(_sysio_umask & 0777) | 07000; /* apply umask */
168 if (flags & O_EXCL) {
170 * Tell others we intend to create this file.
172 intent.int_opmask |= INT_CREAT;
176 if (flags & O_NOFOLLOW)
177 ndflags |= ND_NOFOLLOW;
184 INTENT_INIT(&intent, intent.int_opmask, &mode, &flags);
186 rtn = _sysio_namei(_sysio_cwd, path, ndflags, &intent, &pno);
190 * Ask for the open/creat.
192 rtn = _sysio_open(pno, flags, mode);
196 * Get a file descriptor.
198 fil = _sysio_fnew(pno->p_base->pb_ino, flags);
203 rtn = _sysio_fd_set(fil, -1);
209 SYSIO_INTERFACE_RETURN(rtn, 0);
216 SYSIO_INTERFACE_RETURN(-1, rtn);
221 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open)
223 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), SYSIO_INTERFACE_NAME(open64))
225 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open64)
230 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __libc_open64)
235 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), _open)
239 SYSIO_INTERFACE_NAME(close)(int fd)
242 SYSIO_INTERFACE_DISPLAY_BLOCK;
244 SYSIO_INTERFACE_ENTER;
245 err = _sysio_fd_close(fd);
246 SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
251 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), __close)
256 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), _close)
260 SYSIO_INTERFACE_NAME(creat)(const char *path, mode_t mode)
263 return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
268 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat)
270 #ifndef HAVE_LUSTRE_HACK
271 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
273 /* XXX workaround SuSE SLES 8, glibc-2.2.5 */
274 sysio_sym_strong_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
277 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat64)
282 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __libc_creat)
287 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), _creat)
291 SYSIO_INTERFACE_NAME(umask)(mode_t mask)
295 omask = _sysio_umask;
296 _sysio_umask = mask & 0777;
302 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(umask), __umask)