Print this page
OS-4098 move open, close and fcntl into the kernel


  57  */
  58 
  59 static int
  60 copen(int startfd, char *fname, int filemode, int createmode)
  61 {
  62         struct pathname pn;
  63         vnode_t *vp, *sdvp;
  64         file_t *fp, *startfp;
  65         enum vtype type;
  66         int error;
  67         int fd, dupfd;
  68         vnode_t *startvp;
  69         proc_t *p = curproc;
  70         uio_seg_t seg = UIO_USERSPACE;
  71         char *open_filename = fname;
  72         uint32_t auditing = AU_AUDITING();
  73         char startchar;
  74 
  75         if (filemode & (FSEARCH|FEXEC)) {
  76                 /*
  77                  * Must be one or the other and neither FREAD nor FWRITE
  78                  * Must not be any of FAPPEND FCREAT FTRUNC FXATTR FXATTRDIROPEN
  79                  * XXX: Should these just be silently ignored?

  80                  */
  81                 if ((filemode & (FREAD|FWRITE)) ||
  82                     (filemode & (FSEARCH|FEXEC)) == (FSEARCH|FEXEC) ||
  83                     (filemode & (FAPPEND|FCREAT|FTRUNC|FXATTR|FXATTRDIROPEN)))
  84                         return (set_errno(EINVAL));
  85         }
  86 
  87         if (startfd == AT_FDCWD) {
  88                 /*
  89                  * Regular open()
  90                  */
  91                 startvp = NULL;
  92         } else {
  93                 /*
  94                  * We're here via openat()
  95                  */
  96                 if (copyin(fname, &startchar, sizeof (char)))
  97                         return (set_errno(EFAULT));
  98 
  99                 /*
 100                  * if startchar is / then startfd is ignored
 101                  */
 102                 if (startchar == '/')




  57  */
  58 
  59 static int
  60 copen(int startfd, char *fname, int filemode, int createmode)
  61 {
  62         struct pathname pn;
  63         vnode_t *vp, *sdvp;
  64         file_t *fp, *startfp;
  65         enum vtype type;
  66         int error;
  67         int fd, dupfd;
  68         vnode_t *startvp;
  69         proc_t *p = curproc;
  70         uio_seg_t seg = UIO_USERSPACE;
  71         char *open_filename = fname;
  72         uint32_t auditing = AU_AUDITING();
  73         char startchar;
  74 
  75         if (filemode & (FSEARCH|FEXEC)) {
  76                 /*
  77                  * Must be one or the other.
  78                  * Must not be any of FAPPEND FCREAT FTRUNC FXATTR FXATTRDIROPEN
  79                  * XXX: Should these just be silently ignored like we
  80                  * silently ignore FREAD|FWRITE?
  81                  */
  82                 if ((filemode & (FSEARCH|FEXEC)) == (FSEARCH|FEXEC) ||

  83                     (filemode & (FAPPEND|FCREAT|FTRUNC|FXATTR|FXATTRDIROPEN)))
  84                         return (set_errno(EINVAL));
  85         }
  86 
  87         if (startfd == AT_FDCWD) {
  88                 /*
  89                  * Regular open()
  90                  */
  91                 startvp = NULL;
  92         } else {
  93                 /*
  94                  * We're here via openat()
  95                  */
  96                 if (copyin(fname, &startchar, sizeof (char)))
  97                         return (set_errno(EFAULT));
  98 
  99                 /*
 100                  * if startchar is / then startfd is ignored
 101                  */
 102                 if (startchar == '/')