Deleted Added
full compact
kern_descrip.c (177380) kern_descrip.c (177633)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 21 unchanged lines hidden (view full) ---

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
35 */
36
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 21 unchanged lines hidden (view full) ---

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 177380 2008-03-19 09:58:25Z sobomax $");
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 177633 2008-03-26 15:23:12Z dfr $");
39
40#include "opt_compat.h"
41#include "opt_ddb.h"
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46

--- 268 unchanged lines hidden (view full) ---

315 long arg;
316};
317#endif
318/* ARGSUSED */
319int
320fcntl(struct thread *td, struct fcntl_args *uap)
321{
322 struct flock fl;
39
40#include "opt_compat.h"
41#include "opt_ddb.h"
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46

--- 268 unchanged lines hidden (view full) ---

315 long arg;
316};
317#endif
318/* ARGSUSED */
319int
320fcntl(struct thread *td, struct fcntl_args *uap)
321{
322 struct flock fl;
323 struct oflock ofl;
323 intptr_t arg;
324 int error;
324 intptr_t arg;
325 int error;
326 int cmd;
325
326 error = 0;
327
328 error = 0;
329 cmd = uap->cmd;
327 switch (uap->cmd) {
330 switch (uap->cmd) {
328 case F_GETLK:
329 case F_SETLK:
330 case F_SETLKW:
331 error = copyin((void *)(intptr_t)uap->arg, &fl, sizeof(fl));
331 case F_OGETLK:
332 case F_OSETLK:
333 case F_OSETLKW:
334 /*
335 * Convert old flock structure to new.
336 */
337 error = copyin((void *)(intptr_t)uap->arg, &ofl, sizeof(ofl));
338 fl.l_start = ofl.l_start;
339 fl.l_len = ofl.l_len;
340 fl.l_pid = ofl.l_pid;
341 fl.l_type = ofl.l_type;
342 fl.l_whence = ofl.l_whence;
343 fl.l_sysid = 0;
344
345 switch (uap->cmd) {
346 case F_OGETLK:
347 cmd = F_GETLK;
348 break;
349 case F_OSETLK:
350 cmd = F_SETLK;
351 break;
352 case F_OSETLKW:
353 cmd = F_SETLKW;
354 break;
355 }
332 arg = (intptr_t)&fl;
333 break;
356 arg = (intptr_t)&fl;
357 break;
358 case F_GETLK:
359 case F_SETLK:
360 case F_SETLKW:
361 case F_SETLK_REMOTE:
362 error = copyin((void *)(intptr_t)uap->arg, &fl, sizeof(fl));
363 arg = (intptr_t)&fl;
364 break;
334 default:
335 arg = uap->arg;
336 break;
337 }
338 if (error)
339 return (error);
365 default:
366 arg = uap->arg;
367 break;
368 }
369 if (error)
370 return (error);
340 error = kern_fcntl(td, uap->fd, uap->cmd, arg);
371 error = kern_fcntl(td, uap->fd, cmd, arg);
341 if (error)
342 return (error);
372 if (error)
373 return (error);
343 if (uap->cmd == F_GETLK)
374 if (uap->cmd == F_OGETLK) {
375 ofl.l_start = fl.l_start;
376 ofl.l_len = fl.l_len;
377 ofl.l_pid = fl.l_pid;
378 ofl.l_type = fl.l_type;
379 ofl.l_whence = fl.l_whence;
380 error = copyout(&ofl, (void *)(intptr_t)uap->arg, sizeof(ofl));
381 } else if (uap->cmd == F_GETLK) {
344 error = copyout(&fl, (void *)(intptr_t)uap->arg, sizeof(fl));
382 error = copyout(&fl, (void *)(intptr_t)uap->arg, sizeof(fl));
383 }
345 return (error);
346}
347
348static inline struct file *
349fdtofp(int fd, struct filedesc *fdp)
350{
351 struct file *fp;
352

--- 141 unchanged lines hidden (view full) ---

494 }
495 fhold(fp);
496 FILEDESC_SUNLOCK(fdp);
497 tmp = arg;
498 error = fo_ioctl(fp, FIOSETOWN, &tmp, td->td_ucred, td);
499 fdrop(fp, td);
500 break;
501
384 return (error);
385}
386
387static inline struct file *
388fdtofp(int fd, struct filedesc *fdp)
389{
390 struct file *fp;
391

--- 141 unchanged lines hidden (view full) ---

533 }
534 fhold(fp);
535 FILEDESC_SUNLOCK(fdp);
536 tmp = arg;
537 error = fo_ioctl(fp, FIOSETOWN, &tmp, td->td_ucred, td);
538 fdrop(fp, td);
539 break;
540
541 case F_SETLK_REMOTE:
542 error = priv_check(td, PRIV_NFS_LOCKD);
543 if (error)
544 return (error);
545 flg = F_REMOTE;
546 goto do_setlk;
547
502 case F_SETLKW:
503 flg |= F_WAIT;
504 /* FALLTHROUGH F_SETLK */
505
506 case F_SETLK:
548 case F_SETLKW:
549 flg |= F_WAIT;
550 /* FALLTHROUGH F_SETLK */
551
552 case F_SETLK:
553 do_setlk:
507 FILEDESC_SLOCK(fdp);
508 if ((fp = fdtofp(fd, fdp)) == NULL) {
509 FILEDESC_SUNLOCK(fdp);
510 error = EBADF;
511 break;
512 }
513 if (fp->f_type != DTYPE_VNODE) {
514 FILEDESC_SUNLOCK(fdp);

--- 39 unchanged lines hidden (view full) ---

554 PROC_LOCK(p->p_leader);
555 p->p_leader->p_flag |= P_ADVLOCK;
556 PROC_UNLOCK(p->p_leader);
557 error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK,
558 flp, flg);
559 break;
560 case F_UNLCK:
561 error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_UNLCK,
554 FILEDESC_SLOCK(fdp);
555 if ((fp = fdtofp(fd, fdp)) == NULL) {
556 FILEDESC_SUNLOCK(fdp);
557 error = EBADF;
558 break;
559 }
560 if (fp->f_type != DTYPE_VNODE) {
561 FILEDESC_SUNLOCK(fdp);

--- 39 unchanged lines hidden (view full) ---

601 PROC_LOCK(p->p_leader);
602 p->p_leader->p_flag |= P_ADVLOCK;
603 PROC_UNLOCK(p->p_leader);
604 error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK,
605 flp, flg);
606 break;
607 case F_UNLCK:
608 error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_UNLCK,
562 flp, F_POSIX);
609 flp, flg);
563 break;
610 break;
611 case F_UNLCKSYS:
612 /*
613 * Temporary api for testing remote lock
614 * infrastructure.
615 */
616 if (flg != F_REMOTE) {
617 error = EINVAL;
618 break;
619 }
620 error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader,
621 F_UNLCKSYS, flp, flg);
622 break;
564 default:
565 error = EINVAL;
566 break;
567 }
568 VFS_UNLOCK_GIANT(vfslocked);
569 vfslocked = 0;
570 /* Check for race with close */
571 FILEDESC_SLOCK(fdp);

--- 2364 unchanged lines hidden ---
623 default:
624 error = EINVAL;
625 break;
626 }
627 VFS_UNLOCK_GIANT(vfslocked);
628 vfslocked = 0;
629 /* Check for race with close */
630 FILEDESC_SLOCK(fdp);

--- 2364 unchanged lines hidden ---