[BACK]Return to kernfs_vnops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / miscfs / kernfs

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/miscfs/kernfs/kernfs_vnops.c between version 1.82 and 1.146

version 1.82, 2002/07/19 18:35:44 version 1.146, 2012/03/22 20:34:38
Line 15 
Line 15 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 71  __KERNEL_RCSID(0, "$NetBSD$");
Line 67  __KERNEL_RCSID(0, "$NetBSD$");
   
 #define READ_MODE       (S_IRUSR|S_IRGRP|S_IROTH)  #define READ_MODE       (S_IRUSR|S_IRGRP|S_IROTH)
 #define WRITE_MODE      (S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)  #define WRITE_MODE      (S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)
 #define DIR_MODE        (S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)  #define UREAD_MODE      (S_IRUSR)
   #define DIR_MODE        (S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
   #define UDIR_MODE       (S_IRUSR|S_IXUSR)
   
   #define N(s) sizeof(s)-1, s
 const struct kern_target kern_targets[] = {  const struct kern_target kern_targets[] = {
 /* NOTE: The name must be less than UIO_MX-16 chars in length */  /* NOTE: The name must be less than UIO_MX-16 chars in length */
 #define N(s) sizeof(s)-1, s  
      /*        name            data          tag           type  ro/rw */       /*        name            data          tag           type  ro/rw */
      { DT_DIR, N("."),         0,            KTT_NULL,     VDIR, DIR_MODE   },       { DT_DIR, N("."),         0,            KFSkern,        VDIR, DIR_MODE   },
      { DT_DIR, N(".."),        0,            KTT_NULL,     VDIR, DIR_MODE   },       { DT_DIR, N(".."),        0,            KFSroot,        VDIR, DIR_MODE   },
      { DT_REG, N("boottime"),  &boottime.tv_sec, KTT_INT,  VREG, READ_MODE  },       { DT_REG, N("boottime"),  &boottime.tv_sec, KFSint,     VREG, READ_MODE  },
                         /* XXX cast away const */                          /* XXXUNCONST */
      { DT_REG, N("copyright"), (void *)copyright,       { DT_REG, N("copyright"), __UNCONST(copyright),
                                              KTT_STRING,   VREG, READ_MODE  },                                               KFSstring,      VREG, READ_MODE  },
      { DT_REG, N("hostname"),  0,            KTT_HOSTNAME, VREG, WRITE_MODE },       { DT_REG, N("hostname"),  0,            KFShostname,    VREG, WRITE_MODE },
      { DT_REG, N("hz"),        &hz,          KTT_INT,      VREG, READ_MODE  },       { DT_REG, N("hz"),        &hz,          KFSint,         VREG, READ_MODE  },
      { DT_REG, N("loadavg"),   0,            KTT_AVENRUN,  VREG, READ_MODE  },       { DT_REG, N("loadavg"),   0,            KFSavenrun,     VREG, READ_MODE  },
      { DT_REG, N("msgbuf"),    0,            KTT_MSGBUF,   VREG, READ_MODE  },       { DT_REG, N("msgbuf"),    0,            KFSmsgbuf,      VREG, READ_MODE  },
      { DT_REG, N("pagesize"),  &uvmexp.pagesize, KTT_INT,  VREG, READ_MODE  },       { DT_REG, N("pagesize"),  &uvmexp.pagesize, KFSint,     VREG, READ_MODE  },
      { DT_REG, N("physmem"),   &physmem,     KTT_INT,      VREG, READ_MODE  },       { DT_REG, N("physmem"),   &physmem,     KFSint,         VREG, READ_MODE  },
 #if 0  #if 0
      { DT_DIR, N("root"),      0,            KTT_NULL,     VDIR, DIR_MODE   },       { DT_DIR, N("root"),      0,            KFSnull,        VDIR, DIR_MODE   },
 #endif  #endif
      { DT_BLK, N("rootdev"),   &rootdev,     KTT_DEVICE,   VBLK, READ_MODE  },       { DT_BLK, N("rootdev"),   &rootdev,     KFSdevice,      VBLK, READ_MODE  },
      { DT_CHR, N("rrootdev"),  &rrootdev,    KTT_DEVICE,   VCHR, READ_MODE  },       { DT_CHR, N("rrootdev"),  &rrootdev,    KFSdevice,      VCHR, READ_MODE  },
      { DT_REG, N("time"),      0,            KTT_TIME,     VREG, READ_MODE  },       { DT_REG, N("time"),      0,            KFStime,        VREG, READ_MODE  },
                         /* XXX cast away const */                          /* XXXUNCONST */
      { DT_REG, N("version"),   (void *)version,       { DT_REG, N("version"),   __UNCONST(version),
                                              KTT_STRING,   VREG, READ_MODE  },                                               KFSstring,      VREG, READ_MODE  },
   };
   const struct kern_target subdir_targets[] = {
   /* NOTE: The name must be less than UIO_MX-16 chars in length */
        /*        name            data          tag           type  ro/rw */
        { DT_DIR, N("."),         0,            KFSsubdir,      VDIR, DIR_MODE   },
        { DT_DIR, N(".."),        0,            KFSkern,        VDIR, DIR_MODE   },
   };
 #undef N  #undef N
   SIMPLEQ_HEAD(,dyn_kern_target) dyn_kern_targets =
           SIMPLEQ_HEAD_INITIALIZER(dyn_kern_targets);
   int nkern_targets = sizeof(kern_targets) / sizeof(kern_targets[0]);
   const int static_nkern_targets = sizeof(kern_targets) / sizeof(kern_targets[0]);
   int nkern_dirs = 2;
   
   int kernfs_try_fileop(kfstype, kfsfileop, void *, int);
   int kernfs_try_xread(kfstype, const struct kernfs_node *, char **,
       size_t, int);
   int kernfs_try_xwrite(kfstype, const struct kernfs_node *, char *,
       size_t, int);
   
   static int kernfs_default_xread(void *v);
   static int kernfs_default_xwrite(void *v);
   static int kernfs_default_fileop_getattr(void *);
   
   /* must include all fileop's */
   const struct kernfs_fileop kernfs_default_fileops[] = {
     { .kf_fileop = KERNFS_XREAD },
     { .kf_fileop = KERNFS_XWRITE },
     { .kf_fileop = KERNFS_FILEOP_OPEN },
     { .kf_fileop = KERNFS_FILEOP_GETATTR,
       .kf_vop = kernfs_default_fileop_getattr },
     { .kf_fileop = KERNFS_FILEOP_IOCTL },
     { .kf_fileop = KERNFS_FILEOP_CLOSE },
     { .kf_fileop = KERNFS_FILEOP_READ,
       .kf_vop = kernfs_default_xread },
     { .kf_fileop = KERNFS_FILEOP_WRITE,
       .kf_vop = kernfs_default_xwrite },
 };  };
 static int nkern_targets = sizeof(kern_targets) / sizeof(kern_targets[0]);  
   
 int     kernfs_lookup   __P((void *));  int     kernfs_lookup(void *);
 #define kernfs_create   genfs_eopnotsupp_rele  #define kernfs_create   genfs_eopnotsupp
 #define kernfs_mknod    genfs_eopnotsupp_rele  #define kernfs_mknod    genfs_eopnotsupp
 #define kernfs_open     genfs_nullop  int     kernfs_open(void *);
 #define kernfs_close    genfs_nullop  int     kernfs_close(void *);
 int     kernfs_access   __P((void *));  int     kernfs_access(void *);
 int     kernfs_getattr  __P((void *));  int     kernfs_getattr(void *);
 int     kernfs_setattr  __P((void *));  int     kernfs_setattr(void *);
 int     kernfs_read     __P((void *));  int     kernfs_read(void *);
 int     kernfs_write    __P((void *));  int     kernfs_write(void *);
 #define kernfs_fcntl    genfs_fcntl  #define kernfs_fcntl    genfs_fcntl
 #define kernfs_ioctl    genfs_enoioctl  int     kernfs_ioctl(void *);
 #define kernfs_poll     genfs_poll  #define kernfs_poll     genfs_poll
 #define kernfs_revoke   genfs_revoke  #define kernfs_revoke   genfs_revoke
 #define kernfs_fsync    genfs_nullop  #define kernfs_fsync    genfs_nullop
 #define kernfs_seek     genfs_nullop  #define kernfs_seek     genfs_nullop
 #define kernfs_remove   genfs_eopnotsupp_rele  #define kernfs_remove   genfs_eopnotsupp
 int     kernfs_link     __P((void *));  int     kernfs_link(void *);
 #define kernfs_rename   genfs_eopnotsupp_rele  #define kernfs_rename   genfs_eopnotsupp
 #define kernfs_mkdir    genfs_eopnotsupp_rele  #define kernfs_mkdir    genfs_eopnotsupp
 #define kernfs_rmdir    genfs_eopnotsupp_rele  #define kernfs_rmdir    genfs_eopnotsupp
 int     kernfs_symlink  __P((void *));  int     kernfs_symlink(void *);
 int     kernfs_readdir  __P((void *));  int     kernfs_readdir(void *);
 #define kernfs_readlink genfs_eopnotsupp  #define kernfs_readlink genfs_eopnotsupp
 #define kernfs_abortop  genfs_abortop  #define kernfs_abortop  genfs_abortop
 int     kernfs_inactive __P((void *));  int     kernfs_inactive(void *);
 int     kernfs_reclaim  __P((void *));  int     kernfs_reclaim(void *);
 #define kernfs_lock     genfs_lock  #define kernfs_lock     genfs_lock
 #define kernfs_unlock   genfs_unlock  #define kernfs_unlock   genfs_unlock
 #define kernfs_bmap     genfs_badop  #define kernfs_bmap     genfs_badop
 #define kernfs_strategy genfs_badop  #define kernfs_strategy genfs_badop
 int     kernfs_print    __P((void *));  int     kernfs_print(void *);
 #define kernfs_islocked genfs_islocked  #define kernfs_islocked genfs_islocked
 int     kernfs_pathconf __P((void *));  int     kernfs_pathconf(void *);
 #define kernfs_advlock  genfs_einval  #define kernfs_advlock  genfs_einval
 #define kernfs_blkatoff genfs_eopnotsupp  
 #define kernfs_valloc   genfs_eopnotsupp  
 #define kernfs_vfree    genfs_nullop  
 #define kernfs_truncate genfs_eopnotsupp  
 #define kernfs_update   genfs_nullop  
 #define kernfs_bwrite   genfs_eopnotsupp  #define kernfs_bwrite   genfs_eopnotsupp
 #define kernfs_putpages genfs_putpages  #define kernfs_putpages genfs_putpages
   
 static int      kernfs_xread __P((const struct kern_target *, int, char **, size_t, size_t *));  static int      kernfs_xread(struct kernfs_node *, int, char **,
 static int      kernfs_xwrite __P((const struct kern_target *, char *, size_t));                                  size_t, size_t *);
   static int      kernfs_xwrite(const struct kernfs_node *, char *, size_t);
   
 int (**kernfs_vnodeop_p) __P((void *));  int (**kernfs_vnodeop_p)(void *);
 const struct vnodeopv_entry_desc kernfs_vnodeop_entries[] = {  const struct vnodeopv_entry_desc kernfs_vnodeop_entries[] = {
         { &vop_default_desc, vn_default_error },          { &vop_default_desc, vn_default_error },
         { &vop_lookup_desc, kernfs_lookup },            /* lookup */          { &vop_lookup_desc, kernfs_lookup },            /* lookup */
Line 186  const struct vnodeopv_entry_desc kernfs_
Line 215  const struct vnodeopv_entry_desc kernfs_
         { &vop_islocked_desc, kernfs_islocked },        /* islocked */          { &vop_islocked_desc, kernfs_islocked },        /* islocked */
         { &vop_pathconf_desc, kernfs_pathconf },        /* pathconf */          { &vop_pathconf_desc, kernfs_pathconf },        /* pathconf */
         { &vop_advlock_desc, kernfs_advlock },          /* advlock */          { &vop_advlock_desc, kernfs_advlock },          /* advlock */
         { &vop_blkatoff_desc, kernfs_blkatoff },        /* blkatoff */  
         { &vop_valloc_desc, kernfs_valloc },            /* valloc */  
         { &vop_vfree_desc, kernfs_vfree },              /* vfree */  
         { &vop_truncate_desc, kernfs_truncate },        /* truncate */  
         { &vop_update_desc, kernfs_update },            /* update */  
         { &vop_bwrite_desc, kernfs_bwrite },            /* bwrite */          { &vop_bwrite_desc, kernfs_bwrite },            /* bwrite */
         { &vop_putpages_desc, kernfs_putpages },        /* putpages */          { &vop_putpages_desc, kernfs_putpages },        /* putpages */
         { NULL, NULL }          { NULL, NULL }
Line 198  const struct vnodeopv_entry_desc kernfs_
Line 222  const struct vnodeopv_entry_desc kernfs_
 const struct vnodeopv_desc kernfs_vnodeop_opv_desc =  const struct vnodeopv_desc kernfs_vnodeop_opv_desc =
         { &kernfs_vnodeop_p, kernfs_vnodeop_entries };          { &kernfs_vnodeop_p, kernfs_vnodeop_entries };
   
   static inline int
   kernfs_fileop_compare(struct kernfs_fileop *a, struct kernfs_fileop *b)
   {
           if (a->kf_type < b->kf_type)
                   return -1;
           if (a->kf_type > b->kf_type)
                   return 1;
           if (a->kf_fileop < b->kf_fileop)
                   return -1;
           if (a->kf_fileop > b->kf_fileop)
                   return 1;
           return (0);
   }
   
   SPLAY_HEAD(kfsfileoptree, kernfs_fileop) kfsfileoptree =
           SPLAY_INITIALIZER(kfsfileoptree);
   SPLAY_PROTOTYPE(kfsfileoptree, kernfs_fileop, kf_node, kernfs_fileop_compare);
   SPLAY_GENERATE(kfsfileoptree, kernfs_fileop, kf_node, kernfs_fileop_compare);
   
   kfstype
   kernfs_alloctype(int nkf, const struct kernfs_fileop *kf)
   {
           static u_char nextfreetype = KFSlasttype;
           struct kernfs_fileop *dkf, *fkf, skf;
           int i;
   
           /* XXX need to keep track of dkf's memory if we support
              deallocating types */
           dkf = malloc(sizeof(kernfs_default_fileops), M_TEMP, M_WAITOK);
           memcpy(dkf, kernfs_default_fileops, sizeof(kernfs_default_fileops));
   
           for (i = 0; i < sizeof(kernfs_default_fileops) /
                        sizeof(kernfs_default_fileops[0]); i++) {
                   dkf[i].kf_type = nextfreetype;
                   SPLAY_INSERT(kfsfileoptree, &kfsfileoptree, &dkf[i]);
           }
   
           for (i = 0; i < nkf; i++) {
                   skf.kf_type = nextfreetype;
                   skf.kf_fileop = kf[i].kf_fileop;
                   if ((fkf = SPLAY_FIND(kfsfileoptree, &kfsfileoptree, &skf)))
                           fkf->kf_vop = kf[i].kf_vop;
           }
   
           return nextfreetype++;
   }
   
   int
   kernfs_try_fileop(kfstype type, kfsfileop fileop, void *v, int error)
   {
           struct kernfs_fileop *kf, skf;
   
           skf.kf_type = type;
           skf.kf_fileop = fileop;
           if ((kf = SPLAY_FIND(kfsfileoptree, &kfsfileoptree, &skf)))
                   if (kf->kf_vop)
                           return kf->kf_vop(v);
           return error;
   }
   
   int
   kernfs_try_xread(kfstype type, const struct kernfs_node *kfs, char **bfp,
       size_t len, int error)
   {
           struct kernfs_fileop *kf, skf;
   
           skf.kf_type = type;
           skf.kf_fileop = KERNFS_XREAD;
           if ((kf = SPLAY_FIND(kfsfileoptree, &kfsfileoptree, &skf)))
                   if (kf->kf_xread)
                           return kf->kf_xread(kfs, bfp, len);
           return error;
   }
   
   int
   kernfs_try_xwrite(kfstype type, const struct kernfs_node *kfs, char *bf,
       size_t len, int error)
   {
           struct kernfs_fileop *kf, skf;
   
           skf.kf_type = type;
           skf.kf_fileop = KERNFS_XWRITE;
           if ((kf = SPLAY_FIND(kfsfileoptree, &kfsfileoptree, &skf)))
                   if (kf->kf_xwrite)
                           return kf->kf_xwrite(kfs, bf, len);
           return error;
   }
   
   int
   kernfs_addentry(kernfs_parentdir_t *pkt, kernfs_entry_t *dkt)
   {
           struct kernfs_subdir *ks, *parent;
   
           if (pkt == NULL) {
                   SIMPLEQ_INSERT_TAIL(&dyn_kern_targets, dkt, dkt_queue);
                   nkern_targets++;
                   if (dkt->dkt_kt.kt_vtype == VDIR)
                           nkern_dirs++;
           } else {
                   parent = (struct kernfs_subdir *)pkt->kt_data;
                   SIMPLEQ_INSERT_TAIL(&parent->ks_entries, dkt, dkt_queue);
                   parent->ks_nentries++;
                   if (dkt->dkt_kt.kt_vtype == VDIR)
                           parent->ks_dirs++;
           }
           if (dkt->dkt_kt.kt_vtype == VDIR && dkt->dkt_kt.kt_data == NULL) {
                   ks = malloc(sizeof(struct kernfs_subdir),
                       M_TEMP, M_WAITOK);
                   SIMPLEQ_INIT(&ks->ks_entries);
                   ks->ks_nentries = 2; /* . and .. */
                   ks->ks_dirs = 2;
                   ks->ks_parent = pkt ? pkt : &kern_targets[0];
                   dkt->dkt_kt.kt_data = ks;
           }
           return 0;
   }
   
 static int  static int
 kernfs_xread(kt, off, bufp, len, wrlen)  kernfs_xread(struct kernfs_node *kfs, int off, char **bufp, size_t len, size_t *wrlen)
         const struct kern_target *kt;  
         int off;  
         char **bufp;  
         size_t len;  
         size_t *wrlen;  
 {  {
           const struct kern_target *kt;
           int err;
   
           kt = kfs->kfs_kt;
   
         switch (kt->kt_tag) {          switch (kfs->kfs_type) {
         case KTT_TIME: {          case KFStime: {
                 struct timeval tv;                  struct timeval tv;
   
                 microtime(&tv);                  microtime(&tv);
                 sprintf(*bufp, "%ld %ld\n", tv.tv_sec, tv.tv_usec);                  snprintf(*bufp, len, "%lld %ld\n", (long long)tv.tv_sec,
                       (long)tv.tv_usec);
                 break;                  break;
         }          }
   
         case KTT_INT: {          case KFSint: {
                 int *ip = kt->kt_data;                  int *ip = kt->kt_data;
   
                 sprintf(*bufp, "%d\n", *ip);                  snprintf(*bufp, len, "%d\n", *ip);
                 break;                  break;
         }          }
   
         case KTT_STRING: {          case KFSstring: {
                 char *cp = kt->kt_data;                  char *cp = kt->kt_data;
   
                 *bufp = cp;                  *bufp = cp;
                 break;                  break;
         }          }
   
         case KTT_MSGBUF: {          case KFSmsgbuf: {
                 long n;                  long n;
   
                 /*                  /*
Line 264  kernfs_xread(kt, off, bufp, len, wrlen)
Line 405  kernfs_xread(kt, off, bufp, len, wrlen)
                 return (0);                  return (0);
         }          }
   
         case KTT_HOSTNAME: {          case KFShostname: {
                 char *cp = hostname;                  char *cp = hostname;
                 int xlen = hostnamelen;                  size_t xlen = hostnamelen;
   
                 if (xlen >= (len-2))                  if (xlen >= (len - 2))
                         return (EINVAL);                          return (EINVAL);
   
                 memcpy(*bufp, cp, xlen);                  memcpy(*bufp, cp, xlen);
Line 277  kernfs_xread(kt, off, bufp, len, wrlen)
Line 418  kernfs_xread(kt, off, bufp, len, wrlen)
                 break;                  break;
         }          }
   
         case KTT_AVENRUN:          case KFSavenrun:
                 averunnable.fscale = FSCALE;                  averunnable.fscale = FSCALE;
                 sprintf(*bufp, "%d %d %d %ld\n",                  snprintf(*bufp, len, "%d %d %d %ld\n",
                     averunnable.ldavg[0], averunnable.ldavg[1],                      averunnable.ldavg[0], averunnable.ldavg[1],
                     averunnable.ldavg[2], averunnable.fscale);                      averunnable.ldavg[2], averunnable.fscale);
                 break;                  break;
   
         default:          default:
                 *wrlen = 0;                  err = kernfs_try_xread(kfs->kfs_type, kfs, bufp, len,
                 return (0);                      EOPNOTSUPP);
                   if (err)
                           return err;
         }          }
   
         len = strlen(*bufp);          len = strlen(*bufp);
Line 300  kernfs_xread(kt, off, bufp, len, wrlen)
Line 443  kernfs_xread(kt, off, bufp, len, wrlen)
 }  }
   
 static int  static int
 kernfs_xwrite(kt, buf, len)  kernfs_xwrite(const struct kernfs_node *kfs, char *bf, size_t len)
         const struct kern_target *kt;  
         char *buf;  
         size_t len;  
 {  {
   
         switch (kt->kt_tag) {          switch (kfs->kfs_type) {
         case KTT_HOSTNAME:          case KFShostname:
                 if (buf[len-1] == '\n')                  if (bf[len-1] == '\n')
                         --len;                          --len;
                 memcpy(hostname, buf, len);                  memcpy(hostname, bf, len);
                 hostname[len] = '\0';                  hostname[len] = '\0';
                 hostnamelen = (size_t) len;                  hostnamelen = (size_t) len;
                 return (0);                  return (0);
   
         default:          default:
                 return (EIO);                  return kernfs_try_xwrite(kfs->kfs_type, kfs, bf, len, EIO);
         }          }
 }  }
   
Line 326  kernfs_xwrite(kt, buf, len)
Line 466  kernfs_xwrite(kt, buf, len)
  * ndp is the name to locate in that directory...   * ndp is the name to locate in that directory...
  */   */
 int  int
 kernfs_lookup(v)  kernfs_lookup(void *v)
         void *v;  
 {  {
         struct vop_lookup_args /* {          struct vop_lookup_args /* {
                 struct vnode * a_dvp;                  struct vnode * a_dvp;
Line 338  kernfs_lookup(v)
Line 477  kernfs_lookup(v)
         struct vnode **vpp = ap->a_vpp;          struct vnode **vpp = ap->a_vpp;
         struct vnode *dvp = ap->a_dvp;          struct vnode *dvp = ap->a_dvp;
         const char *pname = cnp->cn_nameptr;          const char *pname = cnp->cn_nameptr;
           const struct kernfs_node *kfs;
         const struct kern_target *kt;          const struct kern_target *kt;
         struct vnode *fvp;          const struct dyn_kern_target *dkt;
         int error, i, wantpunlock;          const struct kernfs_subdir *ks;
           int error, i;
 #ifdef KERNFS_DIAGNOSTIC  
         printf("kernfs_lookup(%p)\n", ap);  
         printf("kernfs_lookup(dp = %p, vpp = %p, cnp = %p)\n", dvp, vpp, ap->a_cnp);  
         printf("kernfs_lookup(%s)\n", pname);  
 #endif  
   
         *vpp = NULLVP;          *vpp = NULLVP;
         cnp->cn_flags &= ~PDIRUNLOCK;  
   
         if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)          if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
                 return (EROFS);                  return (EROFS);
   
         if (cnp->cn_namelen == 1 && *pname == '.') {          if (cnp->cn_namelen == 1 && *pname == '.') {
                 *vpp = dvp;                  *vpp = dvp;
                 VREF(dvp);                  vref(dvp);
                 return (0);                  return (0);
         }          }
   
         /*          kfs = VTOKERN(dvp);
          * This code only supports a flat directory, so we don't          switch (kfs->kfs_type) {
          * need to worry about ..          case KFSkern:
          */                  /*
                    * Shouldn't get here with .. in the root node.
                    */
                   if (cnp->cn_flags & ISDOTDOT)
                           return (EIO);
   
 #if 0                  for (i = 0; i < static_nkern_targets; i++) {
         if (cnp->cn_namelen == 4 && memcmp(pname, "root", 4) == 0) {                          kt = &kern_targets[i];
                 *vpp = rootdir;                          if (cnp->cn_namelen == kt->kt_namlen &&
                 VREF(rootdir);                              memcmp(kt->kt_name, pname, cnp->cn_namelen) == 0)
                 vn_lock(rootdir, LK_SHARED | LK_RETRY);                                  goto found;
                 return (0);                  }
         }                  SIMPLEQ_FOREACH(dkt, &dyn_kern_targets, dkt_queue) {
 #endif                          if (cnp->cn_namelen == dkt->dkt_kt.kt_namlen &&
                               memcmp(dkt->dkt_kt.kt_name, pname, cnp->cn_namelen) == 0) {
                                   kt = &dkt->dkt_kt;
                                   goto found;
                           }
                   }
                   break;
   
         wantpunlock = (~cnp->cn_flags & (LOCKPARENT | ISLASTCN));          found:
                   error = kernfs_allocvp(dvp->v_mount, vpp, kt->kt_tag, kt, 0);
                   return (error);
   
         for (kt = kern_targets, i = 0; i < nkern_targets; kt++, i++) {          case KFSsubdir:
                 if (cnp->cn_namelen == kt->kt_namlen &&                  ks = (struct kernfs_subdir *)kfs->kfs_kt->kt_data;
                     memcmp(kt->kt_name, pname, cnp->cn_namelen) == 0)                  if (cnp->cn_flags & ISDOTDOT) {
                           kt = ks->ks_parent;
                         goto found;                          goto found;
         }                  }
   
 #ifdef KERNFS_DIAGNOSTIC                  SIMPLEQ_FOREACH(dkt, &ks->ks_entries, dkt_queue) {
         printf("kernfs_lookup: i = %d, failed", i);                          if (cnp->cn_namelen == dkt->dkt_kt.kt_namlen &&
 #endif                              memcmp(dkt->dkt_kt.kt_name, pname, cnp->cn_namelen) == 0) {
                                   kt = &dkt->dkt_kt;
                                   goto found;
                           }
                   }
                   break;
   
           default:
                   return (ENOTDIR);
           }
   
         return (cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS);          return (cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS);
   }
   
 found:  int
         if (kt->kt_tag == KTT_DEVICE) {  kernfs_open(void *v)
                 dev_t *dp = kt->kt_data;  {
         loop:          struct vop_open_args /* {
                 if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp)) {                  struct vnode *a_vp;
                         return (ENOENT);                  int a_mode;
                 }                  kauth_cred_t a_cred;
                 *vpp = fvp;          } */ *ap = v;
                 if (vget(fvp, LK_EXCLUSIVE))          struct kernfs_node *kfs = VTOKERN(ap->a_vp);
                         goto loop;  
                 if (wantpunlock) {  
                         VOP_UNLOCK(dvp, 0);  
                         cnp->cn_flags |= PDIRUNLOCK;  
                 }  
                 return (0);  
         }  
   
 #ifdef KERNFS_DIAGNOSTIC          return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_OPEN, v, 0);
         printf("kernfs_lookup: allocate new vnode\n");  }
 #endif  
         error = getnewvnode(VT_KERNFS, dvp->v_mount, kernfs_vnodeop_p, &fvp);  
         if (error) {  
                 return (error);  
         }  
   
         MALLOC(fvp->v_data, void *, sizeof(struct kernfs_node), M_TEMP,  int
             M_WAITOK);  kernfs_close(void *v)
         VTOKERN(fvp)->kf_kt = kt;  {
         fvp->v_type = kt->kt_vtype;          struct vop_close_args /* {
         vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY);                  struct vnode *a_vp;
         *vpp = fvp;                  int a_fflag;
                   kauth_cred_t a_cred;
           } */ *ap = v;
           struct kernfs_node *kfs = VTOKERN(ap->a_vp);
   
 #ifdef KERNFS_DIAGNOSTIC          return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_CLOSE, v, 0);
         printf("kernfs_lookup: newvp = %p\n", fvp);  
 #endif  
         if (wantpunlock) {  
                 VOP_UNLOCK(dvp, 0);  
                 cnp->cn_flags |= PDIRUNLOCK;  
         }  
         return (0);  
 }  }
   
 int  int
 kernfs_access(v)  kernfs_access(void *v)
         void *v;  
 {  {
         struct vop_access_args /* {          struct vop_access_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 int a_mode;                  int a_mode;
                 struct ucred *a_cred;                  kauth_cred_t a_cred;
                 struct proc *a_p;  
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;          struct vattr va;
         mode_t mode;          int error;
   
         if (vp->v_flag & VROOT) {          if ((error = VOP_GETATTR(ap->a_vp, &va, ap->a_cred)) != 0)
                 mode = DIR_MODE;                  return (error);
         } else {  
                 const struct kern_target *kt = VTOKERN(vp)->kf_kt;  
                 mode = kt->kt_mode;  
         }  
   
         return (vaccess(vp->v_type, mode, (uid_t)0, (gid_t)0, ap->a_mode,          return kauth_authorize_vnode(ap->a_cred,
             ap->a_cred));              kauth_access_action(ap->a_mode, ap->a_vp->v_type, va.va_mode),
               ap->a_vp, NULL, genfs_can_access(va.va_type, va.va_mode,
               va.va_uid, va.va_gid, ap->a_mode, ap->a_cred));
   }
   
   static int
   kernfs_default_fileop_getattr(void *v)
   {
           struct vop_getattr_args /* {
                   struct vnode *a_vp;
                   struct vattr *a_vap;
                   kauth_cred_t a_cred;
           } */ *ap = v;
           struct vattr *vap = ap->a_vap;
   
           vap->va_nlink = 1;
           vap->va_bytes = vap->va_size = 0;
   
           return 0;
 }  }
   
 int  int
 kernfs_getattr(v)  kernfs_getattr(void *v)
         void *v;  
 {  {
         struct vop_getattr_args /* {          struct vop_getattr_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct vattr *a_vap;                  struct vattr *a_vap;
                 struct ucred *a_cred;                  kauth_cred_t a_cred;
                 struct proc *a_p;  
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;          struct kernfs_node *kfs = VTOKERN(ap->a_vp);
           struct kernfs_subdir *ks;
         struct vattr *vap = ap->a_vap;          struct vattr *vap = ap->a_vap;
         struct timeval tv;  
         int error = 0;          int error = 0;
         char strbuf[KSTRING], *buf;          char strbuf[KSTRING], *bf;
           size_t nread, total;
   
         memset((caddr_t) vap, 0, sizeof(*vap));  
         vattr_null(vap);          vattr_null(vap);
           vap->va_type = ap->a_vp->v_type;
         vap->va_uid = 0;          vap->va_uid = 0;
         vap->va_gid = 0;          vap->va_gid = 0;
         vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];          vap->va_mode = kfs->kfs_mode;
           vap->va_fileid = kfs->kfs_fileno;
           vap->va_flags = 0;
         vap->va_size = 0;          vap->va_size = 0;
         vap->va_blocksize = DEV_BSIZE;          vap->va_blocksize = DEV_BSIZE;
         /*          /* Make all times be current TOD, except for the "boottime" node. */
          * Make all times be current TOD.          if (kfs->kfs_kt->kt_namlen == 8 &&
          */              !memcmp(kfs->kfs_kt->kt_name, "boottime", 8)) {
         microtime(&tv);                  vap->va_ctime = boottime;
         TIMEVAL_TO_TIMESPEC(&tv, &vap->va_ctime);          } else {
                   getnanotime(&vap->va_ctime);
           }
         vap->va_atime = vap->va_mtime = vap->va_ctime;          vap->va_atime = vap->va_mtime = vap->va_ctime;
         vap->va_gen = 0;          vap->va_gen = 0;
         vap->va_flags = 0;          vap->va_flags = 0;
         vap->va_rdev = 0;          vap->va_rdev = 0;
         vap->va_bytes = 0;          vap->va_bytes = 0;
   
         if (vp->v_flag & VROOT) {          switch (kfs->kfs_type) {
 #ifdef KERNFS_DIAGNOSTIC          case KFSkern:
                 printf("kernfs_getattr: stat rootdir\n");                  vap->va_nlink = nkern_dirs;
 #endif                  vap->va_bytes = vap->va_size = DEV_BSIZE;
                 vap->va_type = VDIR;                  break;
                 vap->va_mode = DIR_MODE;  
                 vap->va_nlink = 2;          case KFSroot:
                 vap->va_fileid = 2;  
                 vap->va_size = DEV_BSIZE;  
         } else {  
                 const struct kern_target *kt = VTOKERN(vp)->kf_kt;  
                 size_t total;  
 #ifdef KERNFS_DIAGNOSTIC  
                 printf("kernfs_getattr: stat target %s\n", kt->kt_name);  
 #endif  
                 vap->va_type = kt->kt_vtype;  
                 vap->va_mode = kt->kt_mode;  
                 vap->va_nlink = 1;                  vap->va_nlink = 1;
                 vap->va_fileid = 1 + (kt - kern_targets);                  vap->va_bytes = vap->va_size = DEV_BSIZE;
                 buf = strbuf;                  break;
                 if (0 == (error = kernfs_xread(kt, 0, &buf,  
                                 sizeof(strbuf), &total)))          case KFSsubdir:
                         vap->va_size = total;                  ks = (struct kernfs_subdir *)kfs->kfs_kt->kt_data;
                   vap->va_nlink = ks->ks_dirs;
                   vap->va_bytes = vap->va_size = DEV_BSIZE;
                   break;
   
           case KFSnull:
           case KFStime:
           case KFSint:
           case KFSstring:
           case KFShostname:
           case KFSavenrun:
           case KFSdevice:
           case KFSmsgbuf:
                   vap->va_nlink = 1;
                   total = 0;
                   do {
                           bf = strbuf;
                           error = kernfs_xread(kfs, total, &bf,
                               sizeof(strbuf), &nread);
                           total += nread;
                   } while (error == 0 && nread != 0);
                   vap->va_bytes = vap->va_size = total;
                   break;
   
           default:
                   error = kernfs_try_fileop(kfs->kfs_type,
                       KERNFS_FILEOP_GETATTR, v, EINVAL);
                   break;
         }          }
   
 #ifdef KERNFS_DIAGNOSTIC  
         printf("kernfs_getattr: return error %d\n", error);  
 #endif  
         return (error);          return (error);
 }  }
   
 /*ARGSUSED*/  /*ARGSUSED*/
 int  int
 kernfs_setattr(v)  kernfs_setattr(void *v)
         void *v;  
 {  {
   
         /*          /*
          * Silently ignore attribute changes.           * Silently ignore attribute changes.
          * This allows for open with truncate to have no           * This allows for open with truncate to have no
Line 534  kernfs_setattr(v)
Line 704  kernfs_setattr(v)
 }  }
   
 int  int
 kernfs_read(v)  kernfs_default_xread(void *v)
         void *v;  
 {  {
         struct vop_read_args /* {          struct vop_read_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct uio *a_uio;                  struct uio *a_uio;
                 int  a_ioflag;                  int  a_ioflag;
                 struct ucred *a_cred;                  kauth_cred_t a_cred;
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;  
         struct uio *uio = ap->a_uio;          struct uio *uio = ap->a_uio;
         const struct kern_target *kt;          struct kernfs_node *kfs = VTOKERN(ap->a_vp);
         char strbuf[KSTRING], *buf;          char strbuf[KSTRING], *bf;
         off_t off;          int off;
         size_t len;          size_t len;
         int error;          int error;
   
         if (vp->v_type == VDIR)          if (ap->a_vp->v_type == VDIR)
                 return (EOPNOTSUPP);                  return EISDIR;
   
         kt = VTOKERN(vp)->kf_kt;  
   
 #ifdef KERNFS_DIAGNOSTIC          off = (int)uio->uio_offset;
         printf("kern_read %s\n", kt->kt_name);          /* Don't allow negative offsets */
 #endif          if (off < 0)
                   return EINVAL;
         off = uio->uio_offset;  
         buf = strbuf;          bf = strbuf;
         if ((error = kernfs_xread(kt, off, &buf, sizeof(strbuf), &len)) == 0)          if ((error = kernfs_xread(kfs, off, &bf, sizeof(strbuf), &len)) == 0)
                 error = uiomove(buf, len, uio);                  error = uiomove(bf, len, uio);
         return (error);          return (error);
 }  }
   
 int  int
 kernfs_write(v)  kernfs_read(void *v)
         void *v;  
 {  {
         struct vop_write_args /* {          struct vop_read_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct uio *a_uio;                  struct uio *a_uio;
                 int  a_ioflag;                  int  a_ioflag;
                 struct ucred *a_cred;                  struct ucred *a_cred;
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;          struct kernfs_node *kfs = VTOKERN(ap->a_vp);
         struct uio *uio = ap->a_uio;  
         const struct kern_target *kt;  
         int error, xlen;  
         char strbuf[KSTRING];  
   
         if (vp->v_type == VDIR)          if (kfs->kfs_type < KFSlasttype) {
                 return (EOPNOTSUPP);                  /* use default function */
                   return kernfs_default_xread(v);
           }
           return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_READ, v,
              EOPNOTSUPP);
   }
   
         kt = VTOKERN(vp)->kf_kt;  static int
   kernfs_default_xwrite(void *v)
   {
           struct vop_write_args /* {
                   struct vnode *a_vp;
                   struct uio *a_uio;
                   int  a_ioflag;
                   kauth_cred_t a_cred;
           } */ *ap = v;
           struct kernfs_node *kfs = VTOKERN(ap->a_vp);
           struct uio *uio = ap->a_uio;
           int error;
           size_t xlen;
           char strbuf[KSTRING];
   
         if (uio->uio_offset != 0)          if (uio->uio_offset != 0)
                 return (EINVAL);                  return (EINVAL);
Line 600  kernfs_write(v)
Line 779  kernfs_write(v)
   
         strbuf[xlen] = '\0';          strbuf[xlen] = '\0';
         xlen = strlen(strbuf);          xlen = strlen(strbuf);
         return (kernfs_xwrite(kt, strbuf, xlen));          return (kernfs_xwrite(kfs, strbuf, xlen));
 }  }
   
 int  int
 kernfs_readdir(v)  kernfs_write(void *v)
         void *v;  {
           struct vop_write_args /* {
                   struct vnode *a_vp;
                   struct uio *a_uio;
                   int  a_ioflag;
                   kauth_cred_t a_cred;
           } */ *ap = v;
           struct kernfs_node *kfs = VTOKERN(ap->a_vp);
   
           if (kfs->kfs_type < KFSlasttype) {
                   /* use default function */
                   return kernfs_default_xwrite(v);
           }
           return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_WRITE, v,
               EOPNOTSUPP);
   }
   
   int
   kernfs_ioctl(void *v)
   {
           struct vop_ioctl_args /* {
                   const struct vnodeop_desc *a_desc;
                   struct vnode *a_vp;
                   u_long a_command;
                   void *a_data;
                   int a_fflag;
                   kauth_cred_t a_cred;
           } */ *ap = v;
           struct kernfs_node *kfs = VTOKERN(ap->a_vp);
   
           return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_IOCTL, v,
               EPASSTHROUGH);
   }
   
   static int
   kernfs_setdirentfileno_kt(struct dirent *d, const struct kern_target *kt,
       u_int32_t value, struct vop_readdir_args *ap)
   {
           struct kernfs_node *kfs;
           struct vnode *vp;
           int error;
   
           if ((error = kernfs_allocvp(ap->a_vp->v_mount, &vp, kt->kt_tag, kt,
               value)) != 0)
                   return error;
           if (kt->kt_tag == KFSdevice) {
                   struct vattr va;
   
                   error = VOP_GETATTR(vp, &va, ap->a_cred);
                   if (error != 0) {
                           return error;
                   }
                   d->d_fileno = va.va_fileid;
           } else {
                   kfs = VTOKERN(vp);
                   d->d_fileno = kfs->kfs_fileno;
           }
           vput(vp);
           return 0;
   }
   
   static int
   kernfs_setdirentfileno(struct dirent *d, off_t entry,
       struct kernfs_node *thisdir_kfs, const struct kern_target *parent_kt,
       const struct kern_target *kt, struct vop_readdir_args *ap)
   {
           const struct kern_target *ikt;
           int error;
   
           switch (entry) {
           case 0:
                   d->d_fileno = thisdir_kfs->kfs_fileno;
                   return 0;
           case 1:
                   ikt = parent_kt;
                   break;
           default:
                   ikt = kt;
                   break;
           }
           if (ikt != thisdir_kfs->kfs_kt) {
                   if ((error = kernfs_setdirentfileno_kt(d, ikt, 0, ap)) != 0)
                           return error;
           } else
                   d->d_fileno = thisdir_kfs->kfs_fileno;
           return 0;
   }
   
   int
   kernfs_readdir(void *v)
 {  {
         struct vop_readdir_args /* {          struct vop_readdir_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct uio *a_uio;                  struct uio *a_uio;
                 struct ucred *a_cred;                  kauth_cred_t a_cred;
                 int *a_eofflag;                  int *a_eofflag;
                 off_t **a_cookies;                  off_t **a_cookies;
                 int a_*ncookies;                  int a_*ncookies;
         } */ *ap = v;          } */ *ap = v;
         struct uio *uio = ap->a_uio;          struct uio *uio = ap->a_uio;
         struct dirent d;          struct dirent d;
           struct kernfs_node *kfs = VTOKERN(ap->a_vp);
         const struct kern_target *kt;          const struct kern_target *kt;
         off_t i;          const struct dyn_kern_target *dkt = NULL;
           const struct kernfs_subdir *ks;
           off_t i, j;
         int error;          int error;
         off_t *cookies = NULL;          off_t *cookies = NULL;
         int ncookies = 0, nc = 0;          int ncookies = 0, n;
   
         if (ap->a_vp->v_type != VDIR)  
                 return (ENOTDIR);  
   
         if (uio->uio_resid < UIO_MX)          if (uio->uio_resid < UIO_MX)
                 return (EINVAL);                  return (EINVAL);
Line 633  kernfs_readdir(v)
Line 901  kernfs_readdir(v)
   
         error = 0;          error = 0;
         i = uio->uio_offset;          i = uio->uio_offset;
           memset(&d, 0, sizeof(d));
         if (i >= nkern_targets)  
                 return 0;  
   
         memset((caddr_t)&d, 0, UIO_MX);  
         d.d_reclen = UIO_MX;          d.d_reclen = UIO_MX;
           ncookies = uio->uio_resid / UIO_MX;
   
         if (ap->a_ncookies) {          switch (kfs->kfs_type) {
                 nc = uio->uio_resid / UIO_MX;          case KFSkern:
                 nc = min(nc, (nkern_targets - i));                  if (i >= nkern_targets)
                 cookies = malloc(nc * sizeof(off_t), M_TEMP, M_WAITOK);                          return (0);
                 *ap->a_cookies = cookies;  
         }  
   
         for (kt = &kern_targets[i];                  if (ap->a_ncookies) {
              uio->uio_resid >= UIO_MX && i < nkern_targets; kt++, i++) {                          ncookies = min(ncookies, (nkern_targets - i));
 #ifdef KERNFS_DIAGNOSTIC                          cookies = malloc(ncookies * sizeof(off_t), M_TEMP,
                 printf("kernfs_readdir: i = %d\n", (int)i);                              M_WAITOK);
 #endif                          *ap->a_cookies = cookies;
                   }
   
                   n = 0;
                   for (; i < nkern_targets && uio->uio_resid >= UIO_MX; i++) {
                           if (i < static_nkern_targets)
                                   kt = &kern_targets[i];
                           else {
                                   if (dkt == NULL) {
                                           dkt = SIMPLEQ_FIRST(&dyn_kern_targets);
                                           for (j = static_nkern_targets; j < i &&
                                                        dkt != NULL; j++)
                                                   dkt = SIMPLEQ_NEXT(dkt, dkt_queue);
                                           if (j != i)
                                                   break;
                                   } else {
                                           dkt = SIMPLEQ_NEXT(dkt, dkt_queue);
                                   }
                                   if (dkt == NULL)
                                           break;
                                   kt = &dkt->dkt_kt;
                           }
                           if (kt->kt_tag == KFSdevice) {
                                   dev_t *dp = kt->kt_data;
                                   struct vnode *fvp;
   
                                   if (*dp == NODEV ||
                                       !vfinddev(*dp, kt->kt_vtype, &fvp))
                                           continue;
                                   vrele(fvp);
                           }
                           if (kt->kt_tag == KFSmsgbuf) {
                                   if (!msgbufenabled
                                       || msgbufp->msg_magic != MSG_MAGIC) {
                                           continue;
                                   }
                           }
                           d.d_namlen = kt->kt_namlen;
                           if ((error = kernfs_setdirentfileno(&d, i, kfs,
                               &kern_targets[0], kt, ap)) != 0)
                                   break;
                           memcpy(d.d_name, kt->kt_name, kt->kt_namlen + 1);
                           d.d_type = kt->kt_type;
                           if ((error = uiomove(&d, UIO_MX, uio)) != 0)
                                   break;
                           if (cookies)
                                   *cookies++ = i + 1;
                           n++;
                   }
                   ncookies = n;
                   break;
   
           case KFSroot:
                   if (i >= 2)
                           return 0;
   
                   if (ap->a_ncookies) {
                           ncookies = min(ncookies, (2 - i));
                           cookies = malloc(ncookies * sizeof(off_t), M_TEMP,
                               M_WAITOK);
                           *ap->a_cookies = cookies;
                   }
   
                   n = 0;
                   for (; i < 2 && uio->uio_resid >= UIO_MX; i++) {
                           kt = &kern_targets[i];
                           d.d_namlen = kt->kt_namlen;
                           d.d_fileno = KERNFS_FILENO(kt, kt->kt_tag, 0);
                           memcpy(d.d_name, kt->kt_name, kt->kt_namlen + 1);
                           d.d_type = kt->kt_type;
                           if ((error = uiomove(&d, UIO_MX, uio)) != 0)
                                   break;
                           if (cookies)
                                   *cookies++ = i + 1;
                           n++;
                   }
                   ncookies = n;
                   break;
   
           case KFSsubdir:
                   ks = (struct kernfs_subdir *)kfs->kfs_kt->kt_data;
                   if (i >= ks->ks_nentries)
                           return (0);
   
                   if (ap->a_ncookies) {
                           ncookies = min(ncookies, (ks->ks_nentries - i));
                           cookies = malloc(ncookies * sizeof(off_t), M_TEMP,
                               M_WAITOK);
                           *ap->a_cookies = cookies;
                   }
   
                 if (kt->kt_tag == KTT_DEVICE) {                  dkt = SIMPLEQ_FIRST(&ks->ks_entries);
                         dev_t *dp = kt->kt_data;                  for (j = 0; j < i && dkt != NULL; j++)
                         struct vnode *fvp;                          dkt = SIMPLEQ_NEXT(dkt, dkt_queue);
                   n = 0;
                         if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp))                  for (; i < ks->ks_nentries && uio->uio_resid >= UIO_MX; i++) {
                                 continue;                          if (i < 2)
                 }                                  kt = &subdir_targets[i];
                           else {
                 d.d_fileno = i + 3;                                  /* check if ks_nentries lied to us */
                 d.d_namlen = kt->kt_namlen;                                  if (dkt == NULL)
                 memcpy(d.d_name, kt->kt_name, kt->kt_namlen + 1);                                          break;
                 d.d_type = kt->kt_type;                                  kt = &dkt->dkt_kt;
                                   dkt = SIMPLEQ_NEXT(dkt, dkt_queue);
                 if ((error = uiomove((caddr_t)&d, UIO_MX, uio)) != 0)                          }
                         break;                          if (kt->kt_tag == KFSdevice) {
                 if (cookies) {                                  dev_t *dp = kt->kt_data;
                         *cookies++ = i + 1;                                  struct vnode *fvp;
                         ncookies++;  
                                   if (*dp == NODEV ||
                                       !vfinddev(*dp, kt->kt_vtype, &fvp))
                                           continue;
                                   vrele(fvp);
                           }
                           d.d_namlen = kt->kt_namlen;
                           if ((error = kernfs_setdirentfileno(&d, i, kfs,
                               ks->ks_parent, kt, ap)) != 0)
                                   break;
                           memcpy(d.d_name, kt->kt_name, kt->kt_namlen + 1);
                           d.d_type = kt->kt_type;
                           if ((error = uiomove(&d, UIO_MX, uio)) != 0)
                                   break;
                           if (cookies)
                                   *cookies++ = i + 1;
                           n++;
                 }                  }
                   ncookies = n;
                   break;
   
           default:
                   error = ENOTDIR;
                   break;
         }          }
   
         if (ap->a_ncookies) {          if (ap->a_ncookies) {
                 if (error) {                  if (error) {
                         free(*ap->a_cookies, M_TEMP);                          if (cookies)
                                   free(*ap->a_cookies, M_TEMP);
                         *ap->a_ncookies = 0;                          *ap->a_ncookies = 0;
                         *ap->a_cookies = NULL;                          *ap->a_cookies = NULL;
                 } else                  } else
Line 688  kernfs_readdir(v)
Line 1063  kernfs_readdir(v)
 }  }
   
 int  int
 kernfs_inactive(v)  kernfs_inactive(void *v)
         void *v;  
 {  {
         struct vop_inactive_args /* {          struct vop_inactive_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct proc *a_p;                  bool *a_recycle;
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;          struct vnode *vp = ap->a_vp;
   
 #ifdef KERNFS_DIAGNOSTIC          *ap->a_recycle = false;
         printf("kernfs_inactive(%p)\n", vp);          VOP_UNLOCK(vp);
 #endif  
         /*  
          * Clear out the v_type field to avoid  
          * nasty things happening in vgone().  
          */  
         VOP_UNLOCK(vp, 0);  
         vp->v_type = VNON;  
         return (0);          return (0);
 }  }
   
 int  int
 kernfs_reclaim(v)  kernfs_reclaim(void *v)
         void *v;  
 {  {
         struct vop_reclaim_args /* {          struct vop_reclaim_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
         } */ *ap = v;          } */ *ap = v;
         struct vnode *vp = ap->a_vp;  
   
 #ifdef KERNFS_DIAGNOSTIC          return (kernfs_freevp(ap->a_vp));
         printf("kernfs_reclaim(%p)\n", vp);  
 #endif  
         if (vp->v_data) {  
                 FREE(vp->v_data, M_TEMP);  
                 vp->v_data = 0;  
         }  
         return (0);  
 }  }
   
 /*  /*
  * Return POSIX pathconf information applicable to special devices.   * Return POSIX pathconf information applicable to special devices.
  */   */
 int  int
 kernfs_pathconf(v)  kernfs_pathconf(void *v)
         void *v;  
 {  {
         struct vop_pathconf_args /* {          struct vop_pathconf_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
Line 774  kernfs_pathconf(v)
Line 1131  kernfs_pathconf(v)
  */   */
 /* ARGSUSED */  /* ARGSUSED */
 int  int
 kernfs_print(v)  kernfs_print(void *v)
         void *v;  
 {  {
   
         printf("tag VT_KERNFS, kernfs vnode\n");          printf("tag VT_KERNFS, kernfs vnode\n");
Line 783  kernfs_print(v)
Line 1139  kernfs_print(v)
 }  }
   
 int  int
 kernfs_link(v)  kernfs_link(void *v)
         void *v;  
 {  {
         struct vop_link_args /* {          struct vop_link_args /* {
                 struct vnode *a_dvp;                  struct vnode *a_dvp;
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct componentname *a_cnp;                  struct componentname *a_cnp;
         } */ *ap = v;          } */ *ap = v;
   
         VOP_ABORTOP(ap->a_dvp, ap->a_cnp);          VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
         vput(ap->a_dvp);          vput(ap->a_dvp);
         return (EROFS);          return (EROFS);
 }  }
   
 int  int
 kernfs_symlink(v)  kernfs_symlink(void *v)
         void *v;  
 {  {
         struct vop_symlink_args /* {          struct vop_symlink_args /* {
                 struct vnode *a_dvp;                  struct vnode *a_dvp;
Line 808  kernfs_symlink(v)
Line 1162  kernfs_symlink(v)
                 struct vattr *a_vap;                  struct vattr *a_vap;
                 char *a_target;                  char *a_target;
         } */ *ap = v;          } */ *ap = v;
   
         VOP_ABORTOP(ap->a_dvp, ap->a_cnp);          VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
         vput(ap->a_dvp);          vput(ap->a_dvp);
         return (EROFS);          return (EROFS);

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.146

CVSweb <webmaster@jp.NetBSD.org>