smb_dev.c (87192) | smb_dev.c (89306) |
---|---|
1/* 2 * Copyright (c) 2000-2001 Boris Popov 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 2000-2001 Boris Popov 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/sys/netsmb/smb_dev.c 87192 2001-12-02 08:47:29Z bp $ | 32 * $FreeBSD: head/sys/netsmb/smb_dev.c 89306 2002-01-13 11:58:06Z alfred $ |
33 */ 34#include <sys/param.h> 35#include <sys/kernel.h> 36#include <sys/systm.h> 37#include <sys/conf.h> 38#include <sys/fcntl.h> 39#include <sys/ioccom.h> 40#include <sys/lock.h> --- 348 unchanged lines hidden (view full) --- 389/* 390 * Convert a file descriptor to appropriate smb_share pointer 391 */ 392static struct file* 393nsmb_getfp(struct filedesc* fdp, int fd, int flag) 394{ 395 struct file* fp; 396 | 33 */ 34#include <sys/param.h> 35#include <sys/kernel.h> 36#include <sys/systm.h> 37#include <sys/conf.h> 38#include <sys/fcntl.h> 39#include <sys/ioccom.h> 40#include <sys/lock.h> --- 348 unchanged lines hidden (view full) --- 389/* 390 * Convert a file descriptor to appropriate smb_share pointer 391 */ 392static struct file* 393nsmb_getfp(struct filedesc* fdp, int fd, int flag) 394{ 395 struct file* fp; 396 |
397 FILEDESC_LOCK(fdp); |
|
397 if (((u_int)fd) >= fdp->fd_nfiles || 398 (fp = fdp->fd_ofiles[fd]) == NULL || | 398 if (((u_int)fd) >= fdp->fd_nfiles || 399 (fp = fdp->fd_ofiles[fd]) == NULL || |
399 (fp->f_flag & flag) == 0) | 400 (fp->f_flag & flag) == 0) { 401 FILEDESC_UNLOCK(fdp); |
400 return (NULL); | 402 return (NULL); |
403 } 404 fhold(fp); 405 FILEDESC_UNLOCK(fdp); |
|
401 return (fp); 402} 403 404int 405smb_dev2share(int fd, int mode, struct smb_cred *scred, 406 struct smb_share **sspp) 407{ 408 struct file *fp; 409 struct vnode *vp; 410 struct smb_dev *sdp; 411 struct smb_share *ssp; 412 dev_t dev; 413 int error; 414 415 fp = nsmb_getfp(scred->scr_td->td_proc->p_fd, fd, FREAD | FWRITE); 416 if (fp == NULL) 417 return EBADF; 418 vp = (struct vnode*)fp->f_data; | 406 return (fp); 407} 408 409int 410smb_dev2share(int fd, int mode, struct smb_cred *scred, 411 struct smb_share **sspp) 412{ 413 struct file *fp; 414 struct vnode *vp; 415 struct smb_dev *sdp; 416 struct smb_share *ssp; 417 dev_t dev; 418 int error; 419 420 fp = nsmb_getfp(scred->scr_td->td_proc->p_fd, fd, FREAD | FWRITE); 421 if (fp == NULL) 422 return EBADF; 423 vp = (struct vnode*)fp->f_data; |
419 if (vp == NULL) | 424 if (vp == NULL) { 425 fdrop(fp, curthread); |
420 return EBADF; | 426 return EBADF; |
427 } |
|
421 dev = vn_todev(vp); | 428 dev = vn_todev(vp); |
422 if (dev == NODEV) | 429 if (dev == NODEV) { 430 fdrop(fp, curthread); |
423 return EBADF; | 431 return EBADF; |
432 } |
|
424 SMB_CHECKMINOR(dev); 425 ssp = sdp->sd_share; | 433 SMB_CHECKMINOR(dev); 434 ssp = sdp->sd_share; |
426 if (ssp == NULL) | 435 if (ssp == NULL) { 436 fdrop(fp, curthread); |
427 return ENOTCONN; | 437 return ENOTCONN; |
438 } |
|
428 error = smb_share_get(ssp, LK_EXCLUSIVE, scred); | 439 error = smb_share_get(ssp, LK_EXCLUSIVE, scred); |
429 if (error) 430 return error; 431 *sspp = ssp; 432 return 0; | 440 if (error == 0) 441 *sspp = ssp; 442 fdrop(fp, curthread); 443 return error; |
433} 434 | 444} 445 |