Deleted Added
full compact
svr4_fcntl.c (83366) svr4_fcntl.c (89306)
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 83366 2001-09-12 08:38:13Z julian $
31 * $FreeBSD: head/sys/compat/svr4/svr4_fcntl.c 89306 2002-01-13 11:58:06Z 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 filedesc *fdp = td->td_proc->p_fd;
250 struct file *fp;
251 struct vnode *vp;
252 struct mount *mp;
253 struct vattr vattr;
254 int error, *retval;
255
256 retval = td->td_retval;
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;
257 if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
256 fp = ffind_hold(td, fd);
257 if (fp == NULL)
258 return EBADF;
259
258 return EBADF;
259
260 if (fp->f_type != DTYPE_VNODE)
260 if (fp->f_type != DTYPE_VNODE) {
261 fdrop(fp, td);
261 return EINVAL;
262 return EINVAL;
263 }
262
263 vp = (struct vnode *) fp->f_data;
264
265 if (vp->v_type != VCHR && vp->v_type != VBLK) {
266 error = EINVAL;
267 goto out;
268 }
269

--- 6 unchanged lines hidden (view full) ---

276
277 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
278 goto out;
279 if (vcount(vp) > 1)
280 VOP_REVOKE(vp, REVOKEALL);
281 vn_finished_write(mp);
282out:
283 vrele(vp);
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

--- 6 unchanged lines hidden (view full) ---

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);
286 fdrop(fp, td);
284 return error;
285}
286
287
288static int
289fd_truncate(td, fd, flp)
290 struct thread *td;
291 int fd;
292 struct flock *flp;
293{
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{
294 struct filedesc *fdp = td->td_proc->p_fd;
295 struct file *fp;
296 off_t start, length;
297 struct vnode *vp;
298 struct vattr vattr;
299 int error, *retval;
300 struct ftruncate_args ft;
301
302 retval = td->td_retval;
303
304 /*
305 * We only support truncating the file.
306 */
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 */
307 if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
309 fp = ffind_hold(td, fd);
310 if (fp == NULL)
308 return EBADF;
309
310 vp = (struct vnode *)fp->f_data;
311 return EBADF;
312
313 vp = (struct vnode *)fp->f_data;
311 if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO)
314 if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
315 fdrop(fp, td);
312 return ESPIPE;
316 return ESPIPE;
317 }
313
314 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0)
318
319 if ((error = VOP_GETATTR(vp, &vattr, td->td_proc->p_ucred, td)) != 0)
320 fdrop(fp, td);
315 return error;
321 return error;
322 }
316
317 length = vattr.va_size;
318
319 switch (flp->l_whence) {
320 case SEEK_CUR:
321 start = fp->f_offset + flp->l_start;
322 break;
323
324 case SEEK_END:
325 start = flp->l_start + length;
326 break;
327
328 case SEEK_SET:
329 start = flp->l_start;
330 break;
331
332 default:
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:
340 fdrop(fp, td);
333 return EINVAL;
334 }
335
336 if (start + flp->l_len < length) {
337 /* We don't support free'ing in the middle of the file */
338 return EINVAL;
339 }
340
341 SCARG(&ft, fd) = fd;
342 SCARG(&ft, length) = start;
343
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
344 return ftruncate(td, &ft);
352 error = ftruncate(td, &ft);
353
354 fdrop(fp, td);
355 return (error);
345}
346
347int
348svr4_sys_open(td, uap)
349 register struct thread *td;
350 struct svr4_sys_open_args *uap;
351{
352 struct proc *p = td->td_proc;

--- 15 unchanged lines hidden (view full) ---

368 }
369
370 retval = td->td_retval[0];
371
372 PROC_LOCK(p);
373 if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
374 !(td->td_proc->p_flag & P_CONTROLT)) {
375#if defined(NOTYET)
356}
357
358int
359svr4_sys_open(td, uap)
360 register struct thread *td;
361 struct svr4_sys_open_args *uap;
362{
363 struct proc *p = td->td_proc;

--- 15 unchanged lines hidden (view full) ---

379 }
380
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)
376 struct filedesc *fdp = td->td_proc->p_fd;
377 struct file *fp = fdp->fd_ofiles[retval];
387 struct file *fp;
378
388
389 fp = ffind_hold(td, retval);
379 PROC_UNLOCK(p);
390 PROC_UNLOCK(p);
391 /*
392 * we may have lost a race the above open() and
393 * another thread issuing a close()
394 */
395 if (fp == NULL)
396 return (EBADF); /* XXX: correct errno? */
380 /* ignore any error, just give it a try */
381 if (fp->f_type == DTYPE_VNODE)
382 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td);
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);
383 } else
400 fdrop(fp, td);
401 } else {
384 PROC_UNLOCK(p);
402 PROC_UNLOCK(p);
403 }
385#else
386 }
387 PROC_UNLOCK(p);
388#endif
389 return error;
390}
391
392int

--- 334 unchanged lines hidden ---
404#else
405 }
406 PROC_UNLOCK(p);
407#endif
408 return error;
409}
410
411int

--- 334 unchanged lines hidden ---