37 #include <sys/param.h>
  38 #include <sys/isa_defs.h>
  39 #include <sys/types.h>
  40 #include <sys/sysmacros.h>
  41 #include <sys/systm.h>
  42 #include <sys/errno.h>
  43 #include <sys/fcntl.h>
  44 #include <sys/flock.h>
  45 #include <sys/vnode.h>
  46 #include <sys/file.h>
  47 #include <sys/mode.h>
  48 #include <sys/proc.h>
  49 #include <sys/filio.h>
  50 #include <sys/share.h>
  51 #include <sys/debug.h>
  52 #include <sys/rctl.h>
  53 #include <sys/nbmlock.h>
  54 
  55 #include <sys/cmn_err.h>
  56 
  57 static int flock_check(vnode_t *, flock64_t *, offset_t, offset_t);
  58 static int flock_get_start(vnode_t *, flock64_t *, offset_t, u_offset_t *);
  59 static void fd_too_big(proc_t *);
  60 
  61 /*
  62  * File control.
  63  */
  64 int
  65 fcntl(int fdes, int cmd, intptr_t arg)
  66 {
  67         int iarg;
  68         int error = 0;
  69         int retval;
  70         proc_t *p;
  71         file_t *fp;
  72         vnode_t *vp;
  73         u_offset_t offset;
  74         u_offset_t start;
  75         struct vattr vattr;
  76         int in_crit;
  77         int flag;
 
 348 
 349                 /*
 350                  * 64-bit support: check for overflow for 32-bit lock ops
 351                  */
 352                 if ((error = flock_check(vp, &bf, offset, maxoffset)) != 0)
 353                         break;
 354 
 355                 if (cmd == F_FLOCK || cmd == F_FLOCKW) {
 356                         /* FLOCK* locking is always over the entire file. */
 357                         if (bf.l_whence != 0 || bf.l_start != 0 ||
 358                             bf.l_len != 0) {
 359                                 error = EINVAL;
 360                                 break;
 361                         }
 362                         if (bf.l_type < F_RDLCK || bf.l_type > F_UNLCK) {
 363                                 error = EINVAL;
 364                                 break;
 365                         }
 366                 }
 367 
 368                 if (cmd == F_OFD_SETLK || cmd == F_OFD_SETLKW) {
 369                         /*
 370                          * TBD OFD-style locking is currently limited to
 371                          * covering the entire file.
 372                          */
 373                         if (bf.l_whence != 0 || bf.l_start != 0 ||
 374                             bf.l_len != 0) {
 375                                 error = EINVAL;
 376                                 break;
 377                         }
 378                 }
 379 
 380                 /*
 381                  * Not all of the filesystems understand F_O_GETLK, and
 382                  * there's no need for them to know.  Map it to F_GETLK.
 383                  *
 384                  * The *_frlock functions in the various file systems basically
 385                  * do some validation and then funnel everything through the
 386                  * fs_frlock function. For OFD-style locks fs_frlock will do
 387                  * nothing so that once control returns here we can call the
 388                  * ofdlock function with the correct fp. For OFD-style locks
 
 | 
 
 
  37 #include <sys/param.h>
  38 #include <sys/isa_defs.h>
  39 #include <sys/types.h>
  40 #include <sys/sysmacros.h>
  41 #include <sys/systm.h>
  42 #include <sys/errno.h>
  43 #include <sys/fcntl.h>
  44 #include <sys/flock.h>
  45 #include <sys/vnode.h>
  46 #include <sys/file.h>
  47 #include <sys/mode.h>
  48 #include <sys/proc.h>
  49 #include <sys/filio.h>
  50 #include <sys/share.h>
  51 #include <sys/debug.h>
  52 #include <sys/rctl.h>
  53 #include <sys/nbmlock.h>
  54 
  55 #include <sys/cmn_err.h>
  56 
  57 /* This is global so that it can be used by brand emulation. */
  58 int flock_check(vnode_t *, flock64_t *, offset_t, offset_t);
  59 static int flock_get_start(vnode_t *, flock64_t *, offset_t, u_offset_t *);
  60 static void fd_too_big(proc_t *);
  61 
  62 /*
  63  * File control.
  64  */
  65 int
  66 fcntl(int fdes, int cmd, intptr_t arg)
  67 {
  68         int iarg;
  69         int error = 0;
  70         int retval;
  71         proc_t *p;
  72         file_t *fp;
  73         vnode_t *vp;
  74         u_offset_t offset;
  75         u_offset_t start;
  76         struct vattr vattr;
  77         int in_crit;
  78         int flag;
 
 349 
 350                 /*
 351                  * 64-bit support: check for overflow for 32-bit lock ops
 352                  */
 353                 if ((error = flock_check(vp, &bf, offset, maxoffset)) != 0)
 354                         break;
 355 
 356                 if (cmd == F_FLOCK || cmd == F_FLOCKW) {
 357                         /* FLOCK* locking is always over the entire file. */
 358                         if (bf.l_whence != 0 || bf.l_start != 0 ||
 359                             bf.l_len != 0) {
 360                                 error = EINVAL;
 361                                 break;
 362                         }
 363                         if (bf.l_type < F_RDLCK || bf.l_type > F_UNLCK) {
 364                                 error = EINVAL;
 365                                 break;
 366                         }
 367                 }
 368 
 369                 if (cmd == F_OFD_GETLK || cmd == F_OFD_SETLK ||
 370                     cmd == F_OFD_SETLKW) {
 371                         /*
 372                          * TBD OFD-style locking is currently limited to
 373                          * covering the entire file.
 374                          */
 375                         if (bf.l_whence != 0 || bf.l_start != 0 ||
 376                             bf.l_len != 0) {
 377                                 error = EINVAL;
 378                                 break;
 379                         }
 380                 }
 381 
 382                 /*
 383                  * Not all of the filesystems understand F_O_GETLK, and
 384                  * there's no need for them to know.  Map it to F_GETLK.
 385                  *
 386                  * The *_frlock functions in the various file systems basically
 387                  * do some validation and then funnel everything through the
 388                  * fs_frlock function. For OFD-style locks fs_frlock will do
 389                  * nothing so that once control returns here we can call the
 390                  * ofdlock function with the correct fp. For OFD-style locks
 
 |