[BACK]Return to advnops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / fs / adosfs

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

Diff for /src/sys/fs/adosfs/advnops.c between version 1.15 and 1.15.4.5

version 1.15, 2005/02/26 22:58:54 version 1.15.4.5, 2007/10/27 11:34:59
Line 47  __KERNEL_RCSID(0, "$NetBSD$");
Line 47  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/namei.h>  #include <sys/namei.h>
 #include <sys/buf.h>  #include <sys/buf.h>
 #include <sys/dirent.h>  #include <sys/dirent.h>
   #include <sys/inttypes.h>
 #include <sys/malloc.h>  #include <sys/malloc.h>
 #include <sys/pool.h>  #include <sys/pool.h>
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/unistd.h>  #include <sys/unistd.h>
 #include <sys/proc.h>  #include <sys/proc.h>
   #include <sys/kauth.h>
   
 #include <miscfs/genfs/genfs.h>  #include <miscfs/genfs/genfs.h>
 #include <miscfs/specfs/specdev.h>  #include <miscfs/specfs/specdev.h>
Line 83  int adosfs_pathconf __P((void *));
Line 85  int adosfs_pathconf __P((void *));
 #define adosfs_fsync    genfs_nullop  #define adosfs_fsync    genfs_nullop
 #define adosfs_lease_check      genfs_lease_check  #define adosfs_lease_check      genfs_lease_check
 #define adosfs_seek     genfs_seek  #define adosfs_seek     genfs_seek
 #define adosfs_vfree    genfs_nullop  
   
 #define adosfs_advlock  genfs_einval  #define adosfs_advlock  genfs_einval
 #define adosfs_blkatoff genfs_eopnotsupp  
 #define adosfs_bwrite   genfs_eopnotsupp  #define adosfs_bwrite   genfs_eopnotsupp
 #define adosfs_create   genfs_eopnotsupp  #define adosfs_create   genfs_eopnotsupp
 #define adosfs_mkdir    genfs_eopnotsupp  #define adosfs_mkdir    genfs_eopnotsupp
Line 97  int adosfs_pathconf __P((void *));
Line 97  int adosfs_pathconf __P((void *));
 #define adosfs_rename   genfs_eopnotsupp  #define adosfs_rename   genfs_eopnotsupp
 #define adosfs_rmdir    genfs_eopnotsupp  #define adosfs_rmdir    genfs_eopnotsupp
 #define adosfs_setattr  genfs_eopnotsupp  #define adosfs_setattr  genfs_eopnotsupp
 #define adosfs_truncate genfs_eopnotsupp  
 #define adosfs_update   genfs_nullop  
 #define adosfs_valloc   genfs_eopnotsupp  
   
 const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = {  const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = {
         { &vop_default_desc, vn_default_error },          { &vop_default_desc, vn_default_error },
Line 141  const struct vnodeopv_entry_desc adosfs_
Line 138  const struct vnodeopv_entry_desc adosfs_
         { &vop_islocked_desc, genfs_islocked },         /* islocked */          { &vop_islocked_desc, genfs_islocked },         /* islocked */
         { &vop_pathconf_desc, adosfs_pathconf },        /* pathconf */          { &vop_pathconf_desc, adosfs_pathconf },        /* pathconf */
         { &vop_advlock_desc, adosfs_advlock },          /* advlock */          { &vop_advlock_desc, adosfs_advlock },          /* advlock */
         { &vop_blkatoff_desc, adosfs_blkatoff },        /* blkatoff */  
         { &vop_valloc_desc, adosfs_valloc },            /* valloc */  
         { &vop_vfree_desc, adosfs_vfree },              /* vfree */  
         { &vop_truncate_desc, adosfs_truncate },        /* truncate */  
         { &vop_update_desc, adosfs_update },            /* update */  
         { &vop_bwrite_desc, adosfs_bwrite },            /* bwrite */          { &vop_bwrite_desc, adosfs_bwrite },            /* bwrite */
         { &vop_getpages_desc, genfs_getpages },         /* getpages */          { &vop_getpages_desc, genfs_getpages },         /* getpages */
         { &vop_putpages_desc, genfs_putpages },         /* putpages */          { &vop_putpages_desc, genfs_putpages },         /* putpages */
Line 162  adosfs_getattr(v)
Line 154  adosfs_getattr(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;                  struct lwp *a_l;
         } */ *sp = v;          } */ *sp = v;
         struct vattr *vap;          struct vattr *vap;
         struct adosfsmount *amp;          struct adosfsmount *amp;
Line 230  adosfs_read(v)
Line 222  adosfs_read(v)
                 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;
         } */ *sp = v;          } */ *sp = v;
         struct vnode *vp = sp->a_vp;          struct vnode *vp = sp->a_vp;
         struct adosfsmount *amp;          struct adosfsmount *amp;
Line 274  adosfs_read(v)
Line 266  adosfs_read(v)
          */           */
   
         if (vp->v_type == VREG && IS_FFS(amp)) {          if (vp->v_type == VREG && IS_FFS(amp)) {
                   const int advice = IO_ADV_DECODE(sp->a_ioflag);
                 error = 0;                  error = 0;
   
                 while (uio->uio_resid > 0) {                  while (uio->uio_resid > 0) {
                         void *win;                          void *win;
                         int flags;                          int flags;
Line 285  adosfs_read(v)
Line 279  adosfs_read(v)
                                 break;                                  break;
                         }                          }
                         win = ubc_alloc(&vp->v_uobj, uio->uio_offset,                          win = ubc_alloc(&vp->v_uobj, uio->uio_offset,
                                         &bytelen, UBC_READ);                                          &bytelen, advice, UBC_READ);
                         error = uiomove(win, bytelen, uio);                          error = uiomove(win, bytelen, uio);
                         flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;                          flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
                         ubc_release(win, flags);                          ubc_release(win, flags);
Line 316  adosfs_read(v)
Line 310  adosfs_read(v)
                  */                   */
                 error = bread(sp->a_vp, lbn, amp->bsize, NOCRED, &bp);                  error = bread(sp->a_vp, lbn, amp->bsize, NOCRED, &bp);
                 if (error) {                  if (error) {
                         brelse(bp);                          brelse(bp, 0);
                         goto reterr;                          goto reterr;
                 }                  }
                 if (!IS_FFS(amp)) {                  if (!IS_FFS(amp)) {
Line 338  adosfs_read(v)
Line 332  adosfs_read(v)
                 }                  }
   
                 if (error) {                  if (error) {
                         brelse(bp);                          brelse(bp, 0);
                         goto reterr;                          goto reterr;
                 }                  }
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
                 printf(" %d+%d-%d+%d", lbn, on, lbn, n);                  printf(" %" PRId64 "+%ld-%" PRId64 "+%ld", lbn, on, lbn, n);
 #endif  #endif
                 n = MIN(n, size - bp->b_resid);                  n = MIN(n, size - bp->b_resid);
                 error = uiomove(bp->b_data + on +                  error = uiomove((char *)bp->b_data + on +
                                 amp->bsize - amp->dbsize, (int)n, uio);                                  amp->bsize - amp->dbsize, (int)n, uio);
                 brelse(bp);                  brelse(bp, 0);
         } while (error == 0 && uio->uio_resid > 0 && n != 0);          } while (error == 0 && uio->uio_resid > 0 && n != 0);
   
 out:  out:
Line 367  adosfs_write(v)
Line 361  adosfs_write(v)
                 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;
         } */ *sp = v;          } */ *sp = v;
         advopprint(sp);          advopprint(sp);
         printf(" EOPNOTSUPP)");          printf(" EOPNOTSUPP)");
Line 396  adosfs_strategy(v)
Line 390  adosfs_strategy(v)
 #endif  #endif
         bp = sp->a_bp;          bp = sp->a_bp;
         if (bp->b_vp == NULL) {          if (bp->b_vp == NULL) {
                 bp->b_flags |= B_ERROR;                  bp->b_error = EIO;
                 biodone(bp);                  biodone(bp);
                 error = EIO;                  error = EIO;
                 goto reterr;                  goto reterr;
Line 406  adosfs_strategy(v)
Line 400  adosfs_strategy(v)
         if (bp->b_blkno == bp->b_lblkno) {          if (bp->b_blkno == bp->b_lblkno) {
                 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);                  error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
                 if (error) {                  if (error) {
                         bp->b_flags |= B_ERROR;                          bp->b_flags = error;
                         biodone(bp);                          biodone(bp);
                         goto reterr;                          goto reterr;
                 }                  }
Line 530  adosfs_bmap(v)
Line 524  adosfs_bmap(v)
         }          }
         while (flblk >= 0) {          while (flblk >= 0) {
                 if (flbp)                  if (flbp)
                         brelse(flbp);                          brelse(flbp, 0);
                 if (nb == 0) {                  if (nb == 0) {
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
                         printf("adosfs: bad file list chain.\n");                          printf("adosfs: bad file list chain.\n");
Line 541  adosfs_bmap(v)
Line 535  adosfs_bmap(v)
                 error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,                  error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,
                               ap->amp->bsize, NOCRED, &flbp);                                ap->amp->bsize, NOCRED, &flbp);
                 if (error) {                  if (error) {
                         brelse(flbp);                          brelse(flbp, 0);
                         goto reterr;                          goto reterr;
                 }                  }
                 if (adoscksum(flbp, ap->nwords)) {                  if (adoscksum(flbp, ap->nwords)) {
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
                         printf("adosfs: blk %ld failed cksum.\n", nb);                          printf("adosfs: blk %ld failed cksum.\n", nb);
 #endif  #endif
                         brelse(flbp);                          brelse(flbp, 0);
                         error = EINVAL;                          error = EINVAL;
                         goto reterr;                          goto reterr;
                 }                  }
Line 577  adosfs_bmap(v)
Line 571  adosfs_bmap(v)
 #endif  #endif
                 error = EINVAL;                  error = EINVAL;
         }          }
         brelse(flbp);          brelse(flbp, 0);
 reterr:  reterr:
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
         if (error == 0 && bnp)          if (error == 0 && bnp)
Line 603  adosfs_print(v)
Line 597  adosfs_print(v)
         return(0);          return(0);
 }  }
   
 struct adirent {  
         u_long  fileno;  
         u_short reclen;  
         char    type;  
         char    namlen;  
         char    name[ADMAXNAMELEN+2];   /* maxlen plus 2 NUL's */  
 };  
   
 int  int
 adosfs_readdir(v)  adosfs_readdir(v)
         void *v;          void *v;
Line 618  adosfs_readdir(v)
Line 604  adosfs_readdir(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;
         } */ *sp = v;          } */ *sp = v;
         int error, useri, chainc, hashi, scanned, uavail;          int error, first, useri, chainc, hashi, scanned;
         struct adirent ad, *adp;          u_long nextbn;
           struct dirent ad, *adp;
         struct anode *pap, *ap;          struct anode *pap, *ap;
         struct adosfsmount *amp;  
         struct vnode *vp;          struct vnode *vp;
         struct uio *uio;          struct uio *uio = sp->a_uio;
         u_long nextbn;          off_t uoff = uio->uio_offset;
         off_t uoff, *cookies = NULL;          off_t *cookies = NULL;
         int ncookies = 0;          int ncookies = 0;
   
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
         advopprint(sp);          advopprint(sp);
 #endif  #endif
   
         if (sp->a_vp->v_type != VDIR) {          if (sp->a_vp->v_type != VDIR) {
                 error = ENOTDIR;                  error = ENOTDIR;
                 goto reterr;                  goto reterr;
         }          }
   
         uio = sp->a_uio;  
         uoff = uio->uio_offset;  
         if (uoff < 0) {          if (uoff < 0) {
                 error = EINVAL;                  error = EINVAL;
                 goto reterr;                  goto reterr;
         }          }
   
         pap = VTOA(sp->a_vp);          pap = VTOA(sp->a_vp);
         amp = pap->amp;  
         adp = &ad;          adp = &ad;
         error = nextbn = hashi = chainc = scanned = 0;          error = nextbn = hashi = chainc = scanned = 0;
         uavail = uio->uio_resid / sizeof(ad);          first = useri = uoff / sizeof ad;
         useri = uoff / sizeof(ad);  
   
         /*          /*
          * if no slots available or offset requested is not on a slot boundry           * If offset requested is not on a slot boundary
          */           */
         if (uavail < 1 || uoff % sizeof(ad)) {          if (uoff % sizeof ad) {
                 error = EINVAL;                  error = EINVAL;
                 goto reterr;                  goto reterr;
         }          }
   
         if (sp->a_ncookies) {          for (;;) {
                 ncookies = 0;  
                 cookies = malloc(sizeof (off_t) * uavail, M_TEMP, M_WAITOK);  
                 *sp->a_cookies = cookies;  
         }  
   
         while (uavail) {  
                 if (hashi == pap->ntabent) {                  if (hashi == pap->ntabent) {
                         *sp->a_eofflag = 1;                          *sp->a_eofflag = 1;
                         break;                          break;
Line 682  adosfs_readdir(v)
Line 659  adosfs_readdir(v)
                         nextbn = pap->tab[hashi];                          nextbn = pap->tab[hashi];
   
                 /*                  /*
                  * first determine if we can skip this chain                   * First determine if we can skip this chain
                  */                   */
                 if (chainc == 0) {                  if (chainc == 0) {
                         int skip;                          int skip;
Line 697  adosfs_readdir(v)
Line 674  adosfs_readdir(v)
                 }                  }
   
                 /*                  /*
                  * now [continue to] walk the chain                   * Now [continue to] walk the chain
                  */                   */
                 ap = NULL;                  ap = NULL;
                 do {                  do {
                         error = VFS_VGET(amp->mp, (ino_t)nextbn, &vp);                          error = VFS_VGET(pap->amp->mp, (ino_t)nextbn, &vp);
                         if (error)                          if (error)
                                 goto reterr;                                  goto reterr;
                         ap = VTOA(vp);                          ap = VTOA(vp);
Line 727  adosfs_readdir(v)
Line 704  adosfs_readdir(v)
                 } while (ap == NULL && nextbn != 0);                  } while (ap == NULL && nextbn != 0);
   
                 /*                  /*
                  * we left the loop but without a result so do main over.                   * We left the loop but without a result so do main over.
                  */                   */
                 if (ap == NULL)                  if (ap == NULL)
                         continue;                          continue;
                 /*                  /*
                  * Fill in dirent record                   * Fill in dirent record
                  */                   */
                 memset(adp, 0, sizeof(struct adirent));                  memset(adp, 0, sizeof *adp);
                 adp->fileno = ap->block;                  adp->d_fileno = ap->block;
                 /*                  /*
                  * this deserves an function in kern/vfs_subr.c                   * This deserves a function in kern/vfs_subr.c
                  */                   */
                 switch (ATOV(ap)->v_type) {                  switch (ATOV(ap)->v_type) {
                 case VREG:                  case VREG:
                         adp->type = DT_REG;                          adp->d_type = DT_REG;
                         break;                          break;
                 case VDIR:                  case VDIR:
                         adp->type = DT_DIR;                          adp->d_type = DT_DIR;
                         break;                          break;
                 case VLNK:                  case VLNK:
                         adp->type = DT_LNK;                          adp->d_type = DT_LNK;
                         break;                          break;
                 default:                  default:
                         adp->type = DT_UNKNOWN;                          adp->d_type = DT_UNKNOWN;
                         break;                          break;
                 }                  }
                 adp->reclen = sizeof(struct adirent);                  adp->d_namlen = strlen(ap->name);
                 adp->namlen = strlen(ap->name);                  memcpy(adp->d_name, ap->name, adp->d_namlen);
                 memcpy(adp->name, ap->name, adp->namlen);                  adp->d_reclen = _DIRENT_SIZE(adp);
                 vput(vp);                  vput(vp);
   
                 error = uiomove(adp, sizeof(struct adirent), uio);                  if (adp->d_reclen > uio->uio_resid) {
                 if (error)                          if (useri == first)     /* no room for even one entry */
                                   error = EINVAL;
                         break;                          break;
                 if (sp->a_ncookies) {  
                         *cookies++ = uoff;  
                         ncookies++;  
                 }                  }
                 uoff += sizeof(struct adirent);                  error = uiomove(adp, adp->d_reclen, uio);
                   if (error)
                           break;
                 useri++;                  useri++;
                 uavail--;  
         }          }
 #if doesnt_uiomove_handle_this          ncookies = useri - first;
         uio->uio_offset = uoff;          uio->uio_offset = uoff + ncookies * sizeof ad;
 #endif  
 reterr:  reterr:
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
         printf(" %d)", error);          printf(" %d)", error);
 #endif  #endif
         if (sp->a_ncookies) {          if (sp->a_ncookies != NULL) {
                 if (error) {                  *sp->a_ncookies = ncookies;
                         free(*sp->a_cookies, M_TEMP);                  if (!error) {
                         *sp->a_ncookies = 0;                          *sp->a_cookies = cookies =
                         *sp->a_cookies = NULL;                             malloc(ncookies * sizeof *cookies, M_TEMP, M_WAITOK);
   
                           while (ncookies--) {
                                   uoff += sizeof ad;
                                   *cookies++ = uoff;
                           }
                 } else                  } else
                         *sp->a_ncookies = ncookies;                          *sp->a_cookies = NULL;
         }          }
   
         return(error);          return(error);
 }  }
   
Line 795  adosfs_access(v)
Line 776  adosfs_access(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;                  struct lwp *a_l;
         } */ *sp = v;          } */ *sp = v;
         struct anode *ap;          struct anode *ap;
         struct vnode *vp = sp->a_vp;          struct vnode *vp = sp->a_vp;
Line 845  adosfs_readlink(v)
Line 826  adosfs_readlink(v)
         struct vop_readlink_args /* {          struct vop_readlink_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;
         } */ *sp = v;          } */ *sp = v;
         struct anode *ap;          struct anode *ap;
         int error;          int error;
Line 868  adosfs_inactive(v)
Line 849  adosfs_inactive(v)
 {  {
         struct vop_inactive_args /* {          struct vop_inactive_args /* {
                 struct vnode *a_vp;                  struct vnode *a_vp;
                 struct proc *a_p;                  struct lwp *a_l;
         } */ *sp = v;          } */ *sp = v;
         struct vnode *vp = sp->a_vp;          struct vnode *vp = sp->a_vp;
         struct proc *p = sp->a_p;          struct lwp *l = sp->a_l;
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
         advopprint(sp);          advopprint(sp);
 #endif  #endif
         VOP_UNLOCK(vp, 0);          VOP_UNLOCK(vp, 0);
         /* XXX this needs to check if file was deleted */          /* XXX this needs to check if file was deleted */
         vrecycle(vp, NULL, p);          vrecycle(vp, NULL, l);
   
 #ifdef ADOSFS_DIAGNOSTIC  #ifdef ADOSFS_DIAGNOSTIC
         printf(" 0)");          printf(" 0)");
Line 910  adosfs_reclaim(v)
Line 891  adosfs_reclaim(v)
                 free(ap->tab, M_ANODE);                  free(ap->tab, M_ANODE);
         else if (vp->v_type == VLNK && ap->slinkto)          else if (vp->v_type == VLNK && ap->slinkto)
                 free(ap->slinkto, M_ANODE);                  free(ap->slinkto, M_ANODE);
           genfs_node_destroy(vp);
         pool_put(&adosfs_node_pool, ap);          pool_put(&adosfs_node_pool, ap);
         vp->v_data = NULL;          vp->v_data = NULL;
         return(0);          return(0);

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.15.4.5

CVSweb <webmaster@jp.NetBSD.org>