From 351b7b6d1a27e1c445123ae704cbc39c82e813ba Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 19 Oct 2003 23:23:29 +0000 Subject: [PATCH] Add a fp_vpopen() function to kern_fp.c, and add reserved fields to various checkpoint structures. --- sys/kern/kern_fp.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-- sys/sys/ckpt.h | 31 ++++++++++------- sys/sys/file.h | 4 ++- 3 files changed, 104 insertions(+), 16 deletions(-) diff --git a/sys/kern/kern_fp.c b/sys/kern/kern_fp.c index feeca141e9..fa702f3399 100644 --- a/sys/kern/kern_fp.c +++ b/sys/kern/kern_fp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_fp.c,v 1.3 2003/10/19 19:24:18 dillon Exp $ + * $DragonFly: src/sys/kern/kern_fp.c,v 1.4 2003/10/19 23:23:26 dillon Exp $ */ /* @@ -99,7 +99,6 @@ fp_open(const char *path, int flags, int mode, file_t *fpp) NDINIT(&nd, NAMEI_LOOKUP, 0, UIO_SYSSPACE, path, td); flags = FFLAGS(flags); - printf("%08x\n", flags); if ((error = vn_open(&nd, flags, mode)) == 0) { NDFREE(&nd, NDF_ONLY_PNBUF); fp->f_data = (caddr_t)nd.ni_vp; @@ -114,6 +113,88 @@ fp_open(const char *path, int flags, int mode, file_t *fpp) return(error); } + +/* + * fp_vpopen(): open a file pointer given a vnode. The vnode must be locked. + * The vnode will be returned unlocked whether an error occurs or not. + */ +int +fp_vpopen(struct vnode *vp, int flags, file_t *fpp) +{ + struct thread *td; + struct file *fp; + int vmode; + int error; + + *fpp = NULL; + td = curthread; + + /* + * Vnode checks (from vn_open()) + */ + if (vp->v_type == VLNK) { + error = EMLINK; + goto done; + } + if (vp->v_type == VSOCK) { + error = EOPNOTSUPP; + goto done; + } + flags = FFLAGS(flags); + vmode = 0; + if (flags & (FWRITE | O_TRUNC)) { + if (vp->v_type == VDIR) { + error = EISDIR; + goto done; + } + error = vn_writechk(vp); + if (error) + goto done; + vmode |= VWRITE; + } + if (flags & FREAD) + vmode |= VREAD; + if (vmode) { + error = VOP_ACCESS(vp, vmode, td->td_proc->p_ucred, td); + if (error) + goto done; + } + error = VOP_OPEN(vp, flags, td->td_proc->p_ucred, td); + if (error) + goto done; + /* + * Make sure that a VM object is created for VMIO support. + */ + if (vn_canvmio(vp) == TRUE) { + if ((error = vfs_object_create(vp, td)) != 0) + goto done; + } + + /* + * File pointer setup + */ + if ((error = falloc(NULL, fpp, NULL)) != 0) + goto done; + fp = *fpp; + if ((flags & O_ROOTCRED) == 0 && td->td_proc) + fsetcred(fp, td->td_proc->p_ucred); + fp->f_data = (caddr_t)vp; + fp->f_flag = flags; + fp->f_ops = &vnops; + fp->f_type = DTYPE_VNODE; + + /* + * All done, set return value and update v_writecount now that no more + * errors can occur. + */ + *fpp = fp; + if (flags & FWRITE) + vp->v_writecount++; +done: + VOP_UNLOCK(vp, 0, td); + return (error); +} + /* * fp_*read() is meant to operate like the normal descriptor based syscalls * would. Note that if 'buf' points to user memory a UIO_USERSPACE diff --git a/sys/sys/ckpt.h b/sys/sys/ckpt.h index 547035456b..b9ed7ea7d4 100644 --- a/sys/sys/ckpt.h +++ b/sys/sys/ckpt.h @@ -1,32 +1,37 @@ /* - * $DragonFly: src/sys/sys/ckpt.h,v 1.1 2003/10/19 19:24:20 dillon Exp $ + * $DragonFly: src/sys/sys/ckpt.h,v 1.2 2003/10/19 23:23:29 dillon Exp $ */ #ifndef _SYS_CKPT_H_ #define _SYS_CKPT_H_ struct ckpt_filehdr { - int cfh_nfiles; + int cfh_magic; /* XXX implement */ + int cfh_nfiles; + int cfh_reserved[8]; }; struct ckpt_fileinfo { - int cfi_index; - u_int cfi_flags; /* saved f_flag */ - off_t cfi_offset; /* saved f_offset */ - fhandle_t cfi_fh; + int cfi_index; + u_int cfi_flags; /* saved f_flag */ + off_t cfi_offset; /* saved f_offset */ + fhandle_t cfi_fh; + int cfi_reserved[8]; }; struct ckpt_siginfo { - int csi_ckptpisz; - struct procsig csi_procsig; - struct sigacts csi_sigacts; - struct itimerval csi_itimerval; - int csi_sigparent; + int csi_ckptpisz; + struct procsig csi_procsig; + struct sigacts csi_sigacts; + struct itimerval csi_itimerval; + int csi_sigparent; + int csi_reserved[8]; }; struct vn_hdr { - fhandle_t vnh_fh; - Elf_Phdr vnh_phdr; + fhandle_t vnh_fh; + Elf_Phdr vnh_phdr; + int vnh_reserved[8]; }; #ifdef _KERNEL diff --git a/sys/sys/file.h b/sys/sys/file.h index a666a2c91a..70edc4e449 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -32,7 +32,7 @@ * * @(#)file.h 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/sys/file.h,v 1.22.2.7 2002/11/21 23:39:24 sam Exp $ - * $DragonFly: src/sys/sys/file.h,v 1.7 2003/10/19 19:24:20 dillon Exp $ + * $DragonFly: src/sys/sys/file.h,v 1.8 2003/10/19 23:23:29 dillon Exp $ */ #ifndef _SYS_FILE_H_ @@ -54,6 +54,7 @@ struct uio; struct knote; struct file; struct ucred; +struct vnode; struct lwkt_port; struct fileops { @@ -122,6 +123,7 @@ MALLOC_DECLARE(M_FILE); extern int fdrop (struct file *fp, struct thread *td); extern int fp_open(const char *path, int flags, int mode, struct file **fpp); +extern int fp_vpopen(struct vnode *vp, int flags, struct file **fpp); extern int fp_pread(struct file *fp, void *buf, size_t nbytes, off_t offset, ssize_t *res); extern int fp_pwrite(struct file *fp, void *buf, size_t nbytes, off_t offset, ssize_t *res); extern int fp_read(struct file *fp, void *buf, size_t nbytes, ssize_t *res); -- 2.41.0