svr4_fcntl.c (89306) | svr4_fcntl.c (89319) |
---|---|
1/* 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1994, 1997 Christos Zoulas. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * | 1/* 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1994, 1997 Christos Zoulas. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * |
31 * $FreeBSD: head/sys/compat/svr4/svr4_fcntl.c 89306 2002-01-13 11:58:06Z alfred $ | 31 * $FreeBSD: head/sys/compat/svr4/svr4_fcntl.c 89319 2002-01-14 00:13:45Z alfred $ |
32 */ 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/file.h> 36#include <sys/filedesc.h> 37/*#include <sys/ioctl.h>*/ 38#include <sys/lock.h> 39#include <sys/mount.h> --- 201 unchanged lines hidden (view full) --- 241} 242 243 244static int 245fd_revoke(td, fd) 246 struct thread *td; 247 int fd; 248{ | 32 */ 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/file.h> 36#include <sys/filedesc.h> 37/*#include <sys/ioctl.h>*/ 38#include <sys/lock.h> 39#include <sys/mount.h> --- 201 unchanged lines hidden (view full) --- 241} 242 243 244static int 245fd_revoke(td, fd) 246 struct thread *td; 247 int fd; 248{ |
249 struct file *fp; | |
250 struct vnode *vp; 251 struct mount *mp; 252 struct vattr vattr; 253 int error, *retval; 254 255 retval = td->td_retval; | 249 struct vnode *vp; 250 struct mount *mp; 251 struct vattr vattr; 252 int error, *retval; 253 254 retval = td->td_retval; |
256 fp = ffind_hold(td, fd); 257 if (fp == NULL) 258 return EBADF; | 255 if ((error = fgetvp(td, fd, &vp)) != 0) 256 return (error); |
259 | 257 |
260 if (fp->f_type != DTYPE_VNODE) { 261 fdrop(fp, td); 262 return EINVAL; 263 } 264 265 vp = (struct vnode *) fp->f_data; 266 | |
267 if (vp->v_type != VCHR && vp->v_type != VBLK) { 268 error = EINVAL; 269 goto out; 270 } 271 272 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0) 273 goto out; 274 275 if (td->td_proc->p_ucred->cr_uid != vattr.va_uid && 276 (error = suser_td(td)) != 0) 277 goto out; 278 279 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) 280 goto out; 281 if (vcount(vp) > 1) 282 VOP_REVOKE(vp, REVOKEALL); 283 vn_finished_write(mp); 284out: 285 vrele(vp); | 258 if (vp->v_type != VCHR && vp->v_type != VBLK) { 259 error = EINVAL; 260 goto out; 261 } 262 263 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0) 264 goto out; 265 266 if (td->td_proc->p_ucred->cr_uid != vattr.va_uid && 267 (error = suser_td(td)) != 0) 268 goto out; 269 270 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) 271 goto out; 272 if (vcount(vp) > 1) 273 VOP_REVOKE(vp, REVOKEALL); 274 vn_finished_write(mp); 275out: 276 vrele(vp); |
286 fdrop(fp, td); | |
287 return error; 288} 289 290 291static int 292fd_truncate(td, fd, flp) 293 struct thread *td; 294 int fd; 295 struct flock *flp; 296{ | 277 return error; 278} 279 280 281static int 282fd_truncate(td, fd, flp) 283 struct thread *td; 284 int fd; 285 struct flock *flp; 286{ |
297 struct file *fp; | |
298 off_t start, length; 299 struct vnode *vp; 300 struct vattr vattr; 301 int error, *retval; 302 struct ftruncate_args ft; 303 304 retval = td->td_retval; 305 306 /* 307 * We only support truncating the file. 308 */ | 287 off_t start, length; 288 struct vnode *vp; 289 struct vattr vattr; 290 int error, *retval; 291 struct ftruncate_args ft; 292 293 retval = td->td_retval; 294 295 /* 296 * We only support truncating the file. 297 */ |
309 fp = ffind_hold(td, fd); 310 if (fp == NULL) 311 return EBADF; | 298 if ((error = fgetvp(td, uap->fd, &vp)) != 0) 299 return (error); |
312 | 300 |
313 vp = (struct vnode *)fp->f_data; 314 if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { 315 fdrop(fp, td); | 301 if (vp->v_type == VFIFO) { 302 vrele(vp); |
316 return ESPIPE; 317 } 318 319 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0) | 303 return ESPIPE; 304 } 305 306 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0) |
320 fdrop(fp, td); | 307 vrele(vp); |
321 return error; 322 } 323 324 length = vattr.va_size; 325 326 switch (flp->l_whence) { 327 case SEEK_CUR: 328 start = fp->f_offset + flp->l_start; 329 break; 330 331 case SEEK_END: 332 start = flp->l_start + length; 333 break; 334 335 case SEEK_SET: 336 start = flp->l_start; 337 break; 338 339 default: | 308 return error; 309 } 310 311 length = vattr.va_size; 312 313 switch (flp->l_whence) { 314 case SEEK_CUR: 315 start = fp->f_offset + flp->l_start; 316 break; 317 318 case SEEK_END: 319 start = flp->l_start + length; 320 break; 321 322 case SEEK_SET: 323 start = flp->l_start; 324 break; 325 326 default: |
340 fdrop(fp, td); | 327 vrele(vp); |
341 return EINVAL; 342 } 343 344 if (start + flp->l_len < length) { 345 /* We don't support free'ing in the middle of the file */ 346 return EINVAL; 347 } 348 349 SCARG(&ft, fd) = fd; 350 SCARG(&ft, length) = start; 351 352 error = ftruncate(td, &ft); 353 | 328 return EINVAL; 329 } 330 331 if (start + flp->l_len < length) { 332 /* We don't support free'ing in the middle of the file */ 333 return EINVAL; 334 } 335 336 SCARG(&ft, fd) = fd; 337 SCARG(&ft, length) = start; 338 339 error = ftruncate(td, &ft); 340 |
354 fdrop(fp, td); | 341 vrele(vp); |
355 return (error); 356} 357 358int 359svr4_sys_open(td, uap) 360 register struct thread *td; 361 struct svr4_sys_open_args *uap; 362{ --- 18 unchanged lines hidden (view full) --- 381 retval = td->td_retval[0]; 382 383 PROC_LOCK(p); 384 if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) && 385 !(td->td_proc->p_flag & P_CONTROLT)) { 386#if defined(NOTYET) 387 struct file *fp; 388 | 342 return (error); 343} 344 345int 346svr4_sys_open(td, uap) 347 register struct thread *td; 348 struct svr4_sys_open_args *uap; 349{ --- 18 unchanged lines hidden (view full) --- 368 retval = td->td_retval[0]; 369 370 PROC_LOCK(p); 371 if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) && 372 !(td->td_proc->p_flag & P_CONTROLT)) { 373#if defined(NOTYET) 374 struct file *fp; 375 |
389 fp = ffind_hold(td, retval); | 376 error = fget(td, retval, &fp); |
390 PROC_UNLOCK(p); 391 /* 392 * we may have lost a race the above open() and 393 * another thread issuing a close() 394 */ | 377 PROC_UNLOCK(p); 378 /* 379 * we may have lost a race the above open() and 380 * another thread issuing a close() 381 */ |
395 if (fp == NULL) | 382 if (error) |
396 return (EBADF); /* XXX: correct errno? */ 397 /* ignore any error, just give it a try */ 398 if (fp->f_type == DTYPE_VNODE) 399 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td); 400 fdrop(fp, td); 401 } else { 402 PROC_UNLOCK(p); 403 } --- 342 unchanged lines hidden --- | 383 return (EBADF); /* XXX: correct errno? */ 384 /* ignore any error, just give it a try */ 385 if (fp->f_type == DTYPE_VNODE) 386 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td); 387 fdrop(fp, td); 388 } else { 389 PROC_UNLOCK(p); 390 } --- 342 unchanged lines hidden --- |