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"
69 mode_t _sysio_umask = 0; /* process umask. */
72 * Internal form of open.
75 _sysio_open(struct pnode *pno, int flags, mode_t mode)
82 ro = IS_RDONLY(pno, pno->p_base->pb_ino);
83 w = flags & (O_WRONLY|O_RDWR);
84 if (w == (O_WRONLY|O_RDWR)) {
92 ino = pno->p_base->pb_ino;
93 if ((flags & O_CREAT) && !ino) {
101 parent = pno->p_parent;
102 err = _sysio_p_validate(parent, NULL, NULL);
104 ino = parent->p_base->pb_ino;
107 !IS_RDONLY(parent, ino)
108 ? (*ino->i_ops.inop_open)(pno, flags, mode)
111 } else if ((flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
114 err = _sysio_p_validate(pno, NULL, NULL);
117 * Simple open of pre-existing file.
119 err = (*ino->i_ops.inop_open)(pno, flags, mode);
128 SYSIO_INTERFACE_NAME(open)(const char *path, int flags, ...)
132 struct intent intent;
136 SYSIO_INTERFACE_DISPLAY_BLOCK;
138 SYSIO_INTERFACE_ENTER;
140 * Get mode argument and determine parameters for namei
144 intent.int_opmask = INT_OPEN;
145 if (flags & O_CREAT) {
149 * Set ndflags to indicate return of negative alias is OK.
154 * Will need mode too.
164 mode &= ~(_sysio_umask & 0777) | 07000; /* apply umask */
166 if (flags & O_EXCL) {
168 * Tell others we intend to create this file.
170 intent.int_opmask |= INT_CREAT;
174 if (flags & O_NOFOLLOW)
175 ndflags |= ND_NOFOLLOW;
182 INTENT_INIT(&intent, intent.int_opmask, &mode, &flags);
184 rtn = _sysio_namei(_sysio_cwd, path, ndflags, &intent, &pno);
188 * Ask for the open/creat.
190 rtn = _sysio_open(pno, flags, mode);
194 * Get a file descriptor.
196 fil = _sysio_fnew(pno->p_base->pb_ino, flags);
201 rtn = _sysio_fd_set(fil, -1, 0);
207 SYSIO_INTERFACE_RETURN(rtn, 0);
214 SYSIO_INTERFACE_RETURN(-1, rtn);
219 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open)
221 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), SYSIO_INTERFACE_NAME(open64))
223 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open64)
228 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __libc_open64)
233 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), _open)
237 SYSIO_INTERFACE_NAME(close)(int fd)
240 SYSIO_INTERFACE_DISPLAY_BLOCK;
242 SYSIO_INTERFACE_ENTER;
243 err = _sysio_fd_close(fd);
244 SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
249 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), __close)
254 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), _close)
258 SYSIO_INTERFACE_NAME(creat)(const char *path, mode_t mode)
261 return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
266 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat)
268 #ifndef HAVE_LUSTRE_HACK
269 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
271 /* XXX workaround SuSE SLES 8, glibc-2.2.5 */
272 sysio_sym_strong_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
275 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat64)
280 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __libc_creat)
285 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), _creat)
289 SYSIO_INTERFACE_NAME(umask)(mode_t mask)
293 omask = _sysio_umask;
294 _sysio_umask = mask & 0777;
300 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(umask), __umask)