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-2005 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
48 #include <sys/types.h>
52 #include <sys/queue.h>
58 #include "sysio-symbols.h"
60 #ifdef HAVE_LUSTRE_HACK
61 #include <sys/syscall.h>
65 #ifdef HAVE_LUSTRE_HACK
67 _sysio_lustre_fcntl(int fd, int cmd, va_list ap, int *rtn)
69 long arg = va_arg(ap, long);
71 *rtn = syscall(SYSIO_SYS_fcntl, fd, cmd, arg);
72 return *rtn == -1 ? -errno : 0;
77 _sysio_fcntl_raw_call(struct inode *ino, int *r, int cmd, ...)
83 err = ino->i_ops.inop_fcntl(ino, cmd, ap, r);
89 * Convert offsets to absolute, when appropriate, and call appropriate driver
90 * to complete the fcntl lock function. If successful, convert
91 * returned values back to appropriate form.
94 _sysio_fcntl_lock(struct file *fil, int cmd, struct _SYSIO_FLOCK *fl)
96 struct _SYSIO_FLOCK flock;
102 * The drivers will not have a clue as to the
103 * current position of the file pointer. We need to
104 * convert relative whence values to absolute
105 * file adresses for them, then.
108 switch (flock.l_whence) {
111 * At least parameter check this one, too.
116 _sysio_lseek_prepare(fil,
123 flock.l_whence = SEEK_SET;
129 _sysio_fcntl_raw_call(fil->f_ino, &rtn, cmd, &flock);
133 * Ugh, convert back to relative form.
135 switch (fl->l_whence) {
139 fl->l_start = flock.l_start;
140 fl->l_start -= fil->f_pos;
143 fl->l_start = flock.l_start;
145 fil->f_ino->i_stbuf.st_size;
157 _sysio_vfcntl(int fd, int cmd, va_list ap)
162 SYSIO_INTERFACE_DISPLAY_BLOCK;
164 SYSIO_INTERFACE_ENTER;
166 fil = _sysio_fd_find(fd);
168 #ifdef HAVE_LUSTRE_HACK
169 err = _sysio_lustre_fcntl(fd, cmd, ap, &rtn);
184 newfd = va_arg(ap, long);
185 if (newfd != (int )newfd || newfd < 0) {
190 rtn = _sysio_fd_dup(fd, (int )newfd, 0);
197 #if !(defined(_LARGEFILE64_SOURCE) || F_GETLK64 == F_GETLK)
202 struct intnl_stat buf;
204 #ifdef _LARGEFILE64_SOURCE
205 struct _SYSIO_FLOCK flock64;
209 * Refresh the cached attributes.
212 fil->f_ino->i_ops.inop_getattr(NULL,
220 * Copy args to a temp and normalize.
222 fl = va_arg(ap, struct flock *);
223 #ifdef _LARGEFILE64_SOURCE
224 flock64.l_type = fl->l_type;
225 flock64.l_whence = fl->l_whence;
226 flock64.l_start = fl->l_start;
227 flock64.l_len = fl->l_len;
228 flock64.l_pid = fl->l_pid;
229 err = _sysio_fcntl_lock(fil, cmd, &flock64);
231 err = _sysio_fcntl_lock(fil, cmd, fl);
237 #ifdef _LARGEFILE64_SOURCE
239 * Copy back. Note that the fcntl_lock call
240 * should have ensured that no overflow was possible.
242 fl->l_type = flock64.l_type;
243 fl->l_whence = flock64.l_whence;
244 fl->l_start = flock64.l_start;
245 assert(fl->l_start == flock64.l_start);
246 fl->l_len = flock64.l_len;
247 assert(fl->l_len == flock64.l_len);
248 fl->l_pid = flock64.l_pid;
253 #endif /* !(_LARGEFILE64_SOURCE || F_GETLK64 == F_GETLK) */
254 #ifdef _LARGEFILE64_SOURCE
259 struct flock64 *fl64;
261 fl64 = va_arg(ap, struct flock64 *);
262 err = _sysio_fcntl_lock(fil, cmd, fl64);
268 err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap, &rtn);
273 SYSIO_INTERFACE_RETURN(rtn, err);
277 SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
283 err = _sysio_vfcntl(fd, cmd, ap);
288 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(fcntl),
289 SYSIO_INTERFACE_NAME(fcntl64))
293 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(fcntl),
294 PREPEND(__, SYSIO_INTERFACE_NAME(fcntl)))
299 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(fcntl),
300 PREPEND(_, SYSIO_INTERFACE_NAME(fcntl)))