⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vnode.c

📁 Solaris操作系统下的过滤驱动程序, C源码程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
  print_location();  return (error);}static intwrapfs_remove(	      vnode_t * vp,	      char *name,	      cred_t * cr){  int error = EPERM;  vnode_t *hidden_vp;  char *encoded_name = name;#ifdef FIST_FILTER_NAME  int encoded_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_remove vp %x\n", vp);  hidden_vp = vntofwn(vp)->fwn_vnodep;#ifdef FIST_FILTER_NAME  encoded_length = wrapfs_encode_filename(name, strlen(name), &encoded_name, SKIP_DOTS, vp, vp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_REMOVE(hidden_vp, encoded_name, cr);#ifdef FIST_FILTER_NAME  kmem_free(encoded_name, encoded_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}static intwrapfs_link(	    vnode_t * tdvp,	    vnode_t * svp,	    char *name,	    cred_t * cr){  int error = EPERM;  vnode_t *hidden_tdvp, *hidden_svp;  char *encoded_name = name;#ifdef FIST_FILTER_NAME  int encoded_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_link tdvp %x\n", tdvp);  /* MUST make sure we only hard link into our own file system! */  if (svp->v_op != &wrapfs_vnodeops) {    printk("HARDLINK NOT ALLOWED to %x\n", svp);    return EXDEV;  }  hidden_tdvp = vntofwn(tdvp)->fwn_vnodep;  hidden_svp = vntofwn(svp)->fwn_vnodep;#ifdef FIST_FILTER_NAME  encoded_length = wrapfs_encode_filename(name, strlen(name), &encoded_name, SKIP_DOTS, tdvp, tdvp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_LINK(hidden_tdvp, hidden_svp, encoded_name, cr);#ifdef FIST_FILTER_NAME  kmem_free(encoded_name, encoded_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}static intwrapfs_rename(	      vnode_t * sdvp,	      char *snm,	      vnode_t * tdvp,	      char *tnm,	      cred_t * cr){  int error = EPERM;  vnode_t *hidden_sdvp, *hidden_tdvp;  char *source_encoded_name = snm, *target_encoded_name = tnm;#ifdef FIST_FILTER_NAME  int source_encoded_length, target_encoded_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_rename sdvp %x, tdvp %x\n", sdvp, tdvp);  hidden_sdvp = vntofwn(sdvp)->fwn_vnodep;  hidden_tdvp = vntofwn(tdvp)->fwn_vnodep;#ifdef FIST_FILTER_NAME  source_encoded_length = wrapfs_encode_filename(snm, strlen(snm), &source_encoded_name, SKIP_DOTS, sdvp, sdvp->v_vfsp);  target_encoded_length = wrapfs_encode_filename(tnm, strlen(tnm), &target_encoded_name, SKIP_DOTS, tdvp, tdvp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_RENAME(hidden_sdvp, source_encoded_name, hidden_tdvp, target_encoded_name, cr);#ifdef FIST_FILTER_NAME  kmem_free(source_encoded_name, source_encoded_length);  kmem_free(target_encoded_name, target_encoded_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}static intwrapfs_mkdir(	     vnode_t * dvp,	     char *name,	     vattr_t * vap,	     vnode_t ** vpp,	     cred_t * cr){  int error = EPERM;  vnode_t *hidden_dvp;  char *encoded_name = name;#ifdef FIST_FILTER_NAME  int encoded_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_mkdir vp %x\n", dvp);  hidden_dvp = vntofwn(dvp)->fwn_vnodep;#ifdef FIST_FILTER_NAME  /* encode the name */  encoded_length = wrapfs_encode_filename(name, strlen(name), &encoded_name, SKIP_DOTS, dvp, dvp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_MKDIR(hidden_dvp, encoded_name, vap, vpp, cr);  fist_dprint(6, "mkdir: encoded name is %s\n", encoded_name);  /* if no error, interpose vnode */  if (!error) {    fist_dprint(6, "WRAPFS_MKDIR1: hidden_vp->v_count %d\n", (*vpp)->v_count);    *vpp = wrapfs_interpose(*vpp, dvp->v_vfsp);  }#ifdef FIST_FILTER_NAME  kmem_free(encoded_name, encoded_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}static intwrapfs_rmdir(	     vnode_t * vp,	     char *name,	     vnode_t * cdir,	     cred_t * cr){  int error = EPERM;  vnode_t *hidden_vp, *hidden_cdir;  char *encoded_name = name;#ifdef FIST_FILTER_NAME  int encoded_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_rmdir vp %x\n", vp);  hidden_vp = vntofwn(vp)->fwn_vnodep;  hidden_cdir = vntofwn(cdir)->fwn_vnodep;#ifdef FIST_FILTER_NAME  encoded_length = wrapfs_encode_filename(name, strlen(name), &encoded_name, SKIP_DOTS, vp, vp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_RMDIR(hidden_vp, encoded_name, hidden_cdir, cr);  fist_dprint(6, "rmdir: encoded name is %s\n", encoded_name);#ifdef FIST_FILTER_NAME  kmem_free(encoded_name, encoded_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}#ifdef FIST_FILTER_NAMEstatic intwrapfs_readdir(	       vnode_t * vp,	       uio_t * uiop,	       cred_t * cr,	       int *eofp){  int error = EPERM;  vnode_t *hidden_vp;  uio_t temp_uio;  iovec_t temp_iovec;  int aux, bytes_read, length, temp_length, tmp, old_reclen;  char *temp_name;  fist_dprint(4, "wrapfs_readdir vp %x\n", vp);  ASSERT(uiop->uio_iovcnt == 1);#ifdef FIST_DEBUG  fist_print_uios("wrapfs_readdir (START)", uiop);#endif /* FIST_DEBUG */  temp_iovec.iov_len = uiop->uio_resid;  temp_iovec.iov_base = kmem_zalloc(uiop->uio_resid, KM_SLEEP);  temp_uio.uio_iov = &temp_iovec;  temp_uio.uio_iovcnt = 1;  temp_uio.uio_loffset = uiop->uio_loffset;  temp_uio.uio_segflg = UIO_SYSSPACE;  temp_uio.uio_fmode = uiop->uio_fmode;  temp_uio.uio_llimit = uiop->uio_llimit;  temp_uio.uio_resid = uiop->uio_resid;  hidden_vp = vntofwn(vp)->fwn_vnodep;  /* pass operation to hidden filesystem, and return status */  error = VOP_READDIR(hidden_vp, &temp_uio, cr, eofp);  bytes_read = uiop->uio_resid - temp_uio.uio_resid;  temp_iovec.iov_base -= bytes_read;  temp_iovec.iov_len += bytes_read;  if (error)    goto clean_up;#define crt_dirent ((struct dirent64 *)(temp_iovec.iov_base + aux))  for (aux = 0; aux < bytes_read; aux += old_reclen) {    char *name = temp_name;    old_reclen = crt_dirent->d_reclen;    fist_dprint(5, "RD: old_reclen %d\n", old_reclen);    /* temp_length includes the terminating null */    temp_length = wrapfs_decode_filename(crt_dirent->d_name,					 crt_dirent->d_reclen - sizeof(struct dirent64) + 2,					 &temp_name,					 SKIP_DOTS, vp, vp->v_vfsp);    FIST_OP_READDIR_CALL;    /*     * We copy the dirent to userspace only if the csum matched     */    if (temp_length >= 0) {      /* will also copy terminating null */#if 0      strcpy(crt_dirent->d_name, temp_name);#else      bcopy(temp_name, crt_dirent->d_name, temp_length);#endif      length = temp_length - 2 + sizeof(struct dirent64);      fist_dprint(5, "RD: length calculated to %d, temp_length %d, struct dirent64: %d\n", length, temp_length, sizeof(struct dirent64));      if ((tmp = length & 3))	length += 4 - tmp;      crt_dirent->d_reclen = length;      kmem_free(temp_name, temp_length);#ifdef FIST_DEBUG      fist_dprint(5, "RD: adding entry \"%s\" of length %d\n",		  crt_dirent->d_name, crt_dirent->d_reclen);#endif /* FIST_DEBUG */      error = uiomove(temp_iovec.iov_base + aux, crt_dirent->d_reclen, UIO_READ, uiop);      if (error)	goto clean_up;    }  }  uiop->uio_offset = temp_uio.uio_offset;#ifdef FIST_DEBUG  fist_print_uios("wrapfs_readdir (END)", uiop);#endif /* FIST_DEBUG */clean_up:  kmem_free(temp_iovec.iov_base, temp_iovec.iov_len);  if (error) {    fist_dprint(4, "ERROR: wrapfs_readdir %d\n", error);  }  print_location();  return (error);}#else /* not FIST_FILTER_NAME */static intwrapfs_readdir(	       vnode_t * vp,	       uio_t * uiop,	       cred_t * cr,	       int *eofp){  int error = EPERM;  vnode_t *hidden_vp;  fist_dprint(4, "wrapfs_readdir vp %x\n", vp);  hidden_vp = vntofwn(vp)->fwn_vnodep;  /* pass operation to hidden filesystem, and return status */  error = VOP_READDIR(hidden_vp, uiop, cr, eofp);  print_location();  return (error);}#endif /* not FIST_FILTER_NAME */static intwrapfs_symlink(	       vnode_t * vp,	       char *linkname,	       vattr_t * vap,	       char *target,	       cred_t * cr){  int error = EPERM;  vnode_t *hidden_vp;  char *encoded_linkname = linkname, *encoded_target = target;#ifdef FIST_FILTER_NAME  int encoded_linkname_length, encoded_target_length;#endif /* FIST_FILTER_NAME */  fist_dprint(4, "wrapfs_symlink vp %x\n", vp);  hidden_vp = vntofwn(vp)->fwn_vnodep;#ifdef FIST_FILTER_NAME  encoded_linkname_length = wrapfs_encode_filename(linkname,						   strlen(linkname),						   &encoded_linkname,						   SKIP_DOTS, vp, vp->v_vfsp);  encoded_target_length = wrapfs_encode_filename(target,						 strlen(target),						 &encoded_target,						 DO_DOTS, vp, vp->v_vfsp);#endif /* FIST_FILTER_NAME */  /* pass operation to hidden filesystem, and return status */  error = VOP_SYMLINK(hidden_vp, encoded_linkname, vap, encoded_target, cr);#ifdef FIST_FILTER_NAME  kmem_free(encoded_linkname, encoded_linkname_length);  kmem_free(encoded_target, encoded_target_length);#endif /* FIST_FILTER_NAME */  print_location();  return (error);}#ifdef FIST_FILTER_NAMEstatic intwrapfs_readlink(		vnode_t * vp,		uio_t * uiop,		cred_t * cr){  int error = EPERM;  vnode_t *hidden_vp;  uio_t temp_uio;  iovec_t temp_iovec;  caddr_t temp_addr2free;  int bytes_read;  int temp_length, target_real_length;  char *temp_name;  fist_dprint(4, "wrapfs_readlink vp %x\n", vp);  fist_print_uios("wrapfs_readlink (START)", uiop);  temp_iovec.iov_len = PAGESIZE;  temp_iovec.iov_base = temp_addr2free = kmem_zalloc(PAGESIZE, KM_SLEEP);  if (!temp_iovec.iov_base) {    printk("no more memory in readlink\n");    error = ENOMEM;    goto out;  }  temp_uio.uio_iov = &temp_iovec;  temp_uio.uio_iovcnt = 1;  temp_uio.uio_loffset = 0;  temp_uio.uio_segflg = UIO_SYSSPACE;  temp_uio.uio_fmode = uiop->uio_fmode;  temp_uio.uio_llimit = uiop->uio_llimit;  temp_uio.uio_resid = uiop->uio_resid;  hidden_vp = vntofwn(vp)->fwn_vnodep;  /* pass operation to hidden filesystem, and return status */  error = VOP_READLINK(hidden_vp, &temp_uio, cr);  bytes_read = PAGESIZE - temp_iovec.iov_len;  temp_length = wrapfs_decode_filename(temp_iovec.iov_base - bytes_read,				       bytes_read,				       &temp_name,				       DO_DOTS, vp, vp->v_vfsp);  if (temp_length < 0) {    /* a checksum error had occured: skip entry */    cmn_err(CE_PANIC, "symlink value encoded with different key");  }  /* must find real string length, which is guaranteed null terminated here */  target_real_length = strlen(temp_name) + 1;  fist_dprint(4, "wrapfs_readlink DECODE len=%d, real_len=%d, bytes_read=%d, name=\"%s\"",	      temp_length, target_real_length, bytes_read, temp_name);  uiomove(temp_name, target_real_length, UIO_READ, uiop);  /* already OK: uiop->uio_resid and uiop->uio_loffset */  kmem_free(temp_name, temp_length);  kmem_free(temp_addr2free, PAGESIZE);  fist_print_uios("wrapfs_readlink (END)", uiop);out:  if (error) {    fist_dprint(4, "ERROR: wrapfs_readlink %d\n", error);  }  print_location();  return (error);}#else /* not FIST_FILTER_NAME */static intwrapfs_readlink(		vnode_t * vp,		uio_t * uiop,		cred_t * cr){  int error = EPERM;  vnode_t *hidden_vp;  fist_dprint(4, "wrapfs_readlink vp %x\n", vp);  hidden_vp = vntofwn(vp)->fwn_vnodep;  /* pass operation to hidden filesystem, and return status */  error = VOP_READLINK(hidden_vp, uiop, cr);  print_location();  return (error);}#endif /* not FIST_FILTER_NAME */static intwrapfs_fsync(	     vnode_t * vp,	     int syncflag,	     cred_t * cr){  int error = EPERM;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -