static int nsmb_close2(smb_dev_t *sdp, cred_t *cr) { struct smb_vc *vcp; struct smb_share *ssp; if (sdp->sd_smbfid != -1) (void) smb_usr_closefh(sdp, cr); ssp = sdp->sd_share; if (ssp != NULL) smb_share_rele(ssp); vcp = sdp->sd_vc; if (vcp != NULL) { /* * If this dev minor was opened by smbiod, * mark this VC as "dead" because it now * will have no IOD to service it. */ if (sdp->sd_flags & NSMBFL_IOD) smb_iod_disconnect(vcp); smb_vc_rele(vcp); } return (0); }
static int nsmb_dev_close(struct cdev *dev, int flag, int fmt, struct thread *td) { struct smb_dev *sdp; struct smb_vc *vcp; struct smb_share *ssp; struct smb_cred *scred; int s; scred = malloc(sizeof(struct smb_cred), M_NSMBDEV, M_WAITOK); SMB_CHECKMINOR(dev); s = splimp(); if ((sdp->sd_flags & NSMBFL_OPEN) == 0) { splx(s); free(scred, M_NSMBDEV); return EBADF; } smb_makescred(scred, td, NULL); ssp = sdp->sd_share; if (ssp != NULL) smb_share_rele(ssp, scred); vcp = sdp->sd_vc; if (vcp != NULL) smb_vc_rele(vcp, scred); /* smb_flushq(&sdp->sd_rqlist); smb_flushq(&sdp->sd_rplist); */ dev->si_drv1 = NULL; free(sdp, M_NSMBDEV); destroy_dev_sched(dev); splx(s); free(scred, M_NSMBDEV); return 0; }
int nsmb_dev_close(dev_t dev, int flag, int fmt, struct proc *p) { struct smb_dev *sdp; struct smb_vc *vcp; struct smb_share *ssp; struct smb_cred scred; int s; SMB_CHECKMINOR(dev); s = splnet(); if ((sdp->sd_flags & NSMBFL_OPEN) == 0) { splx(s); return EBADF; } smb_makescred(&scred, p, NULL); ssp = sdp->sd_share; if (ssp != NULL) smb_share_rele(ssp, &scred); vcp = sdp->sd_vc; if (vcp != NULL) smb_vc_rele(vcp, &scred); /* smb_flushq(&sdp->sd_rqlist); smb_flushq(&sdp->sd_rplist); */ smb_devtbl[minor(dev)] = NULL; free(sdp, M_SMBDATA); #ifndef __NetBSD__ destroy_dev(dev); #endif splx(s); return 0; }
static int nsmb_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) { struct smb_dev *sdp; struct smb_vc *vcp; struct smb_share *ssp; struct smb_cred *scred; int error = 0; SMB_CHECKMINOR(dev); if ((sdp->sd_flags & NSMBFL_OPEN) == 0) return EBADF; scred = malloc(sizeof(struct smb_cred), M_NSMBDEV, M_WAITOK); smb_makescred(scred, td, NULL); switch (cmd) { case SMBIOC_OPENSESSION: if (sdp->sd_vc) { error = EISCONN; goto out; } error = smb_usr_opensession((struct smbioc_ossn*)data, scred, &vcp); if (error) break; sdp->sd_vc = vcp; smb_vc_unlock(vcp, 0); sdp->sd_level = SMBL_VC; break; case SMBIOC_OPENSHARE: if (sdp->sd_share) { error = EISCONN; goto out; } if (sdp->sd_vc == NULL) { error = ENOTCONN; goto out; } error = smb_usr_openshare(sdp->sd_vc, (struct smbioc_oshare*)data, scred, &ssp); if (error) break; sdp->sd_share = ssp; smb_share_unlock(ssp, 0); sdp->sd_level = SMBL_SHARE; break; case SMBIOC_REQUEST: if (sdp->sd_share == NULL) { error = ENOTCONN; goto out; } error = smb_usr_simplerequest(sdp->sd_share, (struct smbioc_rq*)data, scred); break; case SMBIOC_T2RQ: if (sdp->sd_share == NULL) { error = ENOTCONN; goto out; } error = smb_usr_t2request(sdp->sd_share, (struct smbioc_t2rq*)data, scred); break; case SMBIOC_SETFLAGS: { struct smbioc_flags *fl = (struct smbioc_flags*)data; int on; if (fl->ioc_level == SMBL_VC) { if (fl->ioc_mask & SMBV_PERMANENT) { on = fl->ioc_flags & SMBV_PERMANENT; if ((vcp = sdp->sd_vc) == NULL) { error = ENOTCONN; goto out; } error = smb_vc_get(vcp, LK_EXCLUSIVE, scred); if (error) break; if (on && (vcp->obj.co_flags & SMBV_PERMANENT) == 0) { vcp->obj.co_flags |= SMBV_PERMANENT; smb_vc_ref(vcp); } else if (!on && (vcp->obj.co_flags & SMBV_PERMANENT)) { vcp->obj.co_flags &= ~SMBV_PERMANENT; smb_vc_rele(vcp, scred); } smb_vc_put(vcp, scred); } else error = EINVAL; } else if (fl->ioc_level == SMBL_SHARE) { if (fl->ioc_mask & SMBS_PERMANENT) { on = fl->ioc_flags & SMBS_PERMANENT; if ((ssp = sdp->sd_share) == NULL) { error = ENOTCONN; goto out; } error = smb_share_get(ssp, LK_EXCLUSIVE, scred); if (error) break; if (on && (ssp->obj.co_flags & SMBS_PERMANENT) == 0) { ssp->obj.co_flags |= SMBS_PERMANENT; smb_share_ref(ssp); } else if (!on && (ssp->obj.co_flags & SMBS_PERMANENT)) { ssp->obj.co_flags &= ~SMBS_PERMANENT; smb_share_rele(ssp, scred); } smb_share_put(ssp, scred); } else error = EINVAL; break; } else error = EINVAL; break; } case SMBIOC_LOOKUP: if (sdp->sd_vc || sdp->sd_share) { error = EISCONN; goto out; } vcp = NULL; ssp = NULL; error = smb_usr_lookup((struct smbioc_lookup*)data, scred, &vcp, &ssp); if (error) break; if (vcp) { sdp->sd_vc = vcp; smb_vc_unlock(vcp, 0); sdp->sd_level = SMBL_VC; } if (ssp) { sdp->sd_share = ssp; smb_share_unlock(ssp, 0); sdp->sd_level = SMBL_SHARE; } break; case SMBIOC_READ: case SMBIOC_WRITE: { struct smbioc_rw *rwrq = (struct smbioc_rw*)data; struct uio auio; struct iovec iov; if ((ssp = sdp->sd_share) == NULL) { error = ENOTCONN; goto out; } iov.iov_base = rwrq->ioc_base; iov.iov_len = rwrq->ioc_cnt; auio.uio_iov = &iov; auio.uio_iovcnt = 1; auio.uio_offset = rwrq->ioc_offset; auio.uio_resid = rwrq->ioc_cnt; auio.uio_segflg = UIO_USERSPACE; auio.uio_rw = (cmd == SMBIOC_READ) ? UIO_READ : UIO_WRITE; auio.uio_td = td; if (cmd == SMBIOC_READ) error = smb_read(ssp, rwrq->ioc_fh, &auio, scred); else error = smb_write(ssp, rwrq->ioc_fh, &auio, scred); rwrq->ioc_cnt -= auio.uio_resid; break; } default: error = ENODEV; } out: free(scred, M_NSMBDEV); return error; }