Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_descrip.c
Show First 20 Lines • Show All 3,554 Lines • ▼ Show 20 Lines | sys_flock(struct thread *td, struct flock_args *uap) | ||||
struct file *fp; | struct file *fp; | ||||
struct vnode *vp; | struct vnode *vp; | ||||
struct flock lf; | struct flock lf; | ||||
int error; | int error; | ||||
error = fget(td, uap->fd, &cap_flock_rights, &fp); | error = fget(td, uap->fd, &cap_flock_rights, &fp); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
if (fp->f_type != DTYPE_VNODE || fp->f_ops == &path_fileops) { | error = EOPNOTSUPP; | ||||
fdrop(fp, td); | if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) { | ||||
return (EOPNOTSUPP); | goto done; | ||||
} | } | ||||
if (fp->f_ops == &path_fileops) { | |||||
goto done; | |||||
} | |||||
error = 0; | |||||
vp = fp->f_vnode; | vp = fp->f_vnode; | ||||
lf.l_whence = SEEK_SET; | lf.l_whence = SEEK_SET; | ||||
lf.l_start = 0; | lf.l_start = 0; | ||||
lf.l_len = 0; | lf.l_len = 0; | ||||
if (uap->how & LOCK_UN) { | if (uap->how & LOCK_UN) { | ||||
lf.l_type = F_UNLCK; | lf.l_type = F_UNLCK; | ||||
atomic_clear_int(&fp->f_flag, FHASLOCK); | atomic_clear_int(&fp->f_flag, FHASLOCK); | ||||
error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK); | error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK); | ||||
goto done2; | goto done; | ||||
} | } | ||||
if (uap->how & LOCK_EX) | if (uap->how & LOCK_EX) | ||||
lf.l_type = F_WRLCK; | lf.l_type = F_WRLCK; | ||||
else if (uap->how & LOCK_SH) | else if (uap->how & LOCK_SH) | ||||
lf.l_type = F_RDLCK; | lf.l_type = F_RDLCK; | ||||
else { | else { | ||||
error = EBADF; | error = EBADF; | ||||
goto done2; | goto done; | ||||
} | } | ||||
atomic_set_int(&fp->f_flag, FHASLOCK); | atomic_set_int(&fp->f_flag, FHASLOCK); | ||||
error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, | error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, | ||||
(uap->how & LOCK_NB) ? F_FLOCK : F_FLOCK | F_WAIT); | (uap->how & LOCK_NB) ? F_FLOCK : F_FLOCK | F_WAIT); | ||||
done2: | done: | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* Duplicate the specified descriptor to a free descriptor. | * Duplicate the specified descriptor to a free descriptor. | ||||
*/ | */ | ||||
int | int | ||||
dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, | dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, | ||||
▲ Show 20 Lines • Show All 1,551 Lines • Show Last 20 Lines |