您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ vn_open函数代码示例

51自学网 2021-06-03 09:46:28
  C++
这篇教程C++ vn_open函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中vn_open函数的典型用法代码示例。如果您正苦于以下问题:C++ vn_open函数的具体用法?C++ vn_open怎么用?C++ vn_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了vn_open函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: kobj_load_file

/* * kobj_load_file: * *	Load an object located in the file system. */intkobj_load_file(kobj_t *kop, const char *filename, const char *base,	       bool autoload){	struct nameidata nd;	kauth_cred_t cred;	char *path;	int error;	kobj_t ko;	cred = kauth_cred_get();	ko = kmem_zalloc(sizeof(*ko), KM_SLEEP);	if (ko == NULL) {		return ENOMEM;	}	if (autoload) {		error = ENOENT;	} else {		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename);		error = vn_open(&nd, FREAD, 0);	}	if (error != 0) {		if (error != ENOENT) {			goto out;		}		path = PNBUF_GET();		snprintf(path, MAXPATHLEN - 1, "%s/%s/%s.kmod", base,		    filename, filename);		NDINIT(&nd, LOOKUP, FOLLOW | NOCHROOT, UIO_SYSSPACE, path);		error = vn_open(&nd, FREAD, 0);		if (error != 0) {			strlcat(path, ".o", MAXPATHLEN);			NDINIT(&nd, LOOKUP, FOLLOW | NOCHROOT, UIO_SYSSPACE,			    path);			error = vn_open(&nd, FREAD, 0);		}		PNBUF_PUT(path);		if (error != 0) {			goto out;		}	} out: 	if (error != 0) {	 	kmem_free(ko, sizeof(*ko));	 	return error;	}	ko->ko_type = KT_VNODE;	ko->ko_source = nd.ni_vp;	*kop = ko;	return kobj_load(ko);}
开发者ID:Tommmster,项目名称:netbsd-avr32,代码行数:60,


示例2: vfs_mountroot_readconf

static intvfs_mountroot_readconf(struct thread *td, struct sbuf *sb){	static char buf[128];	struct nameidata nd;	off_t ofs;	ssize_t resid;	int error, flags, len;	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/.mount.conf", td);	flags = FREAD;	error = vn_open(&nd, &flags, 0, NULL);	if (error)		return (error);	NDFREE(&nd, NDF_ONLY_PNBUF);	ofs = 0;	len = sizeof(buf) - 1;	while (1) {		error = vn_rdwr(UIO_READ, nd.ni_vp, buf, len, ofs,		    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred,		    NOCRED, &resid, td);		if (error)			break;		if (resid == len)			break;		buf[len - resid] = 0;		sbuf_printf(sb, "%s", buf);		ofs += len - resid;	}	VOP_UNLOCK(nd.ni_vp, 0);	vn_close(nd.ni_vp, FREAD, td->td_ucred, td);	return (error);}
开发者ID:ChristosKa,项目名称:freebsd,代码行数:35,


示例3: randomdev_write_file

intrandomdev_write_file(const char *filename, void *buf, size_t length){	struct nameidata nd;	struct thread* td = curthread;	int error;	ssize_t resid;	int flags;	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);	flags = FWRITE | O_CREAT | O_TRUNC;	error = vn_open(&nd, &flags, 0, NULL);	if (error == 0) {		NDFREE(&nd, NDF_ONLY_PNBUF);		if (nd.ni_vp->v_type != VREG)			error = ENOEXEC;		else			error = vn_rdwr(UIO_WRITE, nd.ni_vp, buf, length, 0, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, &resid, td);		VOP_UNLOCK(nd.ni_vp, 0);		vn_close(nd.ni_vp, FREAD, td->td_ucred, td);	}	return (error);}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:25,


示例4: fp_open

/* * fp_open: * *	Open a file as specified.  Use O_* flags for flags. * *	vn_open() asserts that the cred must match the process's cred. * *	NOTE! when fp_open() is called from a pure thread, root creds are *	used. */intfp_open(const char *path, int flags, int mode, file_t *fpp){    struct nlookupdata nd;    struct thread *td;    struct file *fp;    int error;    if ((error = falloc(NULL, fpp, NULL)) != 0)	return (error);    fp = *fpp;    td = curthread;    if (td->td_proc)	fsetcred(fp, td->td_proc->p_ucred);    error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_LOCKVP);    flags = FFLAGS(flags);    if (error == 0)	error = vn_open(&nd, fp, flags, mode);    nlookup_done(&nd);    if (error) {	fdrop(fp);	*fpp = NULL;    }    return(error);}
开发者ID:Gwenio,项目名称:DragonFlyBSD,代码行数:35,


示例5: swap_file_open

static intswap_file_open(struct chip_swap *swap, const char *swap_file){	struct nameidata nd;	int flags, error;	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, swap_file,	    curthread);	flags = FWRITE | FREAD | O_NOFOLLOW | O_CREAT | O_TRUNC;	error = vn_open(&nd, &flags, CHIP_SWAP_CMODE, NULL);	if (error) {		nand_debug(NDBG_SIM,"Cannot create swap file %s", swap_file);		NDFREE(&nd, NDF_ONLY_PNBUF);		return (error);	}	swap->swap_cred = crhold(curthread->td_ucred);	NDFREE(&nd, NDF_ONLY_PNBUF);	/* We just unlock so we hold a reference */	VOP_UNLOCK(nd.ni_vp, 0);	swap->swap_vp = nd.ni_vp;	return (0);}
开发者ID:JabirTech,项目名称:Source,代码行数:28,


示例6: kfcreate

static intkfcreate(char *filename, kfile_t **kfilep){	kfile_t	*fp;	int	rval;	ASSERT(modrootloaded);	fp = kmem_alloc(sizeof (kfile_t), KM_SLEEP);	fp->kf_vnflags = FCREAT | FWRITE | FTRUNC;	fp->kf_fname = filename;	fp->kf_fpos = 0;	fp->kf_state = 0;	KFDEBUG((CE_CONT, "create: %s flags 0x%x/n",		filename, fp->kf_vnflags));	rval = vn_open(filename, UIO_SYSSPACE, fp->kf_vnflags,	    0444, &fp->kf_vp, CRCREAT, 0);	if (rval != 0) {		kmem_free(fp, sizeof (kfile_t));		KFDEBUG((CE_CONT, "%s: create error %d/n",			filename, rval));		return (rval);	}	*kfilep = fp;	return (0);}
开发者ID:andreiw,项目名称:polaris,代码行数:29,


示例7: splat_vnode_test1

static intsplat_vnode_test1(struct file *file, void *arg){	vnode_t *vp;	int rc;	if ((rc = vn_open(SPLAT_VNODE_TEST_FILE, UIO_SYSSPACE,			  FREAD, 0644, &vp, 0, 0))) {		splat_vprint(file, SPLAT_VNODE_TEST1_NAME,			     "Failed to vn_open test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE, rc);		return -rc;	}        rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST1_NAME,			     "Failed to vn_close test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE, rc);		return -rc;	}	splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully vn_open'ed "		     "and vn_closed test file: %s/n", SPLAT_VNODE_TEST_FILE);        return -rc;} /* splat_vnode_test1() */
开发者ID:clopez,项目名称:spl-dkms,代码行数:28,


示例8: splat_vnode_test3

static intsplat_vnode_test3(struct file *file, void *arg){	vnode_t *vp;	char buf1[32] = "SPL VNode Interface Test File/n";	char buf2[32] = "";	int rc;	if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST3_NAME)))		return rc;	if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,			  FWRITE | FREAD | FCREAT | FEXCL,			  0644, &vp, 0, 0))) {		splat_vprint(file, SPLAT_VNODE_TEST3_NAME,			     "Failed to vn_open test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		return -rc;	}        rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST3_NAME,			     "Failed vn_rdwr write of test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		goto out;	}        rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST3_NAME,			     "Failed vn_rdwr read of test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		goto out;	}	if (strncmp(buf1, buf2, strlen(buf1))) {		rc = EINVAL;		splat_vprint(file, SPLAT_VNODE_TEST3_NAME,			     "Failed strncmp data written does not match "			     "data read/nWrote: %sRead:  %s/n", buf1, buf2);		goto out;	}	rc = 0;	splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Wrote: %s", buf1);	splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Read:  %s", buf2);	splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Successfully wrote and "		     "read expected data pattern to test file: %s/n",		     SPLAT_VNODE_TEST_FILE_RW);out:        VOP_CLOSE(vp, 0, 0, 0, 0, 0);	vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);        return -rc;} /* splat_vnode_test3() */
开发者ID:clopez,项目名称:spl-dkms,代码行数:59,


示例9: vdsp_open

voidvdsp_open(void *arg1, void *arg2){	struct vdsp_softc *sc = arg1;	struct proc *p = curproc;	struct vd_attr_info ai;	if (sc->sc_vp == NULL) {		struct nameidata nd;		struct vattr va;		const char *name;		int error;		name = mdesc_get_prop_str(sc->sc_idx, "vds-block-device");		if (name == NULL)			return;		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);		error = vn_open(&nd, FREAD | FWRITE, 0);		if (error) {			printf("VOP_OPEN: %s, %d/n", name, error);			return;		}		error = VOP_GETATTR(nd.ni_vp, &va, p->p_ucred, p);		if (error)			printf("VOP_GETATTR: %s, %d/n", name, error);		sc->sc_vdisk_block_size = DEV_BSIZE;		sc->sc_vdisk_size = va.va_size / DEV_BSIZE;		VOP_UNLOCK(nd.ni_vp, 0, p);		sc->sc_vp = nd.ni_vp;		vdsp_readlabel(sc);	}	bzero(&ai, sizeof(ai));	ai.tag.type = VIO_TYPE_CTRL;	ai.tag.stype = VIO_SUBTYPE_ACK;	ai.tag.stype_env = VIO_ATTR_INFO;	ai.tag.sid = sc->sc_local_sid;	ai.xfer_mode = sc->sc_xfer_mode;	ai.vd_type = VD_DISK_TYPE_DISK;	if (sc->sc_major > 1 || sc->sc_minor >= 1) {		if (vdsp_is_iso(sc))			ai.vd_mtype = VD_MEDIA_TYPE_CD;		else			ai.vd_mtype = VD_MEDIA_TYPE_FIXED;	}	ai.vdisk_block_size = sc->sc_vdisk_block_size;	ai.operations = VD_OP_MASK;	ai.vdisk_size = sc->sc_vdisk_size;	ai.max_xfer_sz = MAXPHYS / sc->sc_vdisk_block_size;	vdsp_sendmsg(sc, &ai, sizeof(ai), 1);}
开发者ID:toddfries,项目名称:OpenBSD-sys-patches,代码行数:55,


示例10: sys_acct

/* * Accounting system call.  Written based on the specification and * previous implementation done by Mark Tinguely. */intsys_acct(struct proc *p, void *v, register_t *retval){	struct sys_acct_args /* {		syscallarg(const char *) path;	} */ *uap = v;	struct nameidata nd;	int error;	/* Make sure that the caller is root. */	if ((error = suser(p, 0)) != 0)		return (error);	/*	 * If accounting is to be started to a file, open that file for	 * writing and make sure it's 'normal'.	 */	if (SCARG(uap, path) != NULL) {		NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path),		    p);		if ((error = vn_open(&nd, FWRITE|O_APPEND, 0)) != 0)			return (error);		VOP_UNLOCK(nd.ni_vp, 0);		if (nd.ni_vp->v_type != VREG) {			vn_close(nd.ni_vp, FWRITE, p->p_ucred, p);			return (EACCES);		}	}	/*	 * If accounting was previously enabled, kill the old space-watcher,	 * close the file, and (if no new file was specified, leave).	 */	if (acctp != NULL || savacctp != NULL) {		wakeup(&acct_proc);		error = vn_close((acctp != NULL ? acctp : savacctp), FWRITE,		    p->p_ucred, p);		acctp = savacctp = NULL;	}	if (SCARG(uap, path) == NULL)		return (0);	/*	 * Save the new accounting file vnode, and schedule the new	 * free space watcher.	 */	acctp = nd.ni_vp;	if ((error = acct_start()) != 0) {		acctp = NULL;		(void)vn_close(nd.ni_vp, FWRITE, p->p_ucred, p);		return (error);	}	return (0);}
开发者ID:sofuture,项目名称:bitrig,代码行数:58,


示例11: spa_config_write

static intspa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl){	size_t buflen;	char *buf;	vnode_t *vp;	int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX;	char *temp;	int err;	/*	 * If the nvlist is empty (NULL), then remove the old cachefile.	 */	if (nvl == NULL) {		err = vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);		return (err);	}	/*	 * Pack the configuration into a buffer.	 */	VERIFY(nvlist_size(nvl, &buflen, NV_ENCODE_XDR) == 0);	buf = kmem_alloc(buflen, KM_SLEEP);	temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP);	VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR,	    KM_SLEEP) == 0);	/*	 * Write the configuration to disk.  We need to do the traditional	 * 'write to temporary file, sync, move over original' to make sure we	 * always have a consistent view of the data.	 */	(void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path);	err = vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0);	if (err == 0) {		err = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,		    0, RLIM64_INFINITY, kcred, NULL);		if (err == 0)			err = VOP_FSYNC(vp, FSYNC, kcred, NULL);		if (err == 0)			err = vn_rename(temp, dp->scd_path, UIO_SYSSPACE);		(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);	}	(void) vn_remove(temp, UIO_SYSSPACE, RMFILE);	kmem_free(buf, buflen);	kmem_free(temp, MAXPATHLEN);	return (err);}
开发者ID:Digital-Chaos,项目名称:freebsd,代码行数:53,


示例12: vniocattach_shadow

static intvniocattach_shadow(struct vn_softc *vn, struct vn_ioctl_64 *vniop, 				   __unused dev_t dev, int in_kernel, proc_t p){	vfs_context_t ctx = vfs_context_current();	struct nameidata nd;	int error, flags;	shadow_map_t *	map;	off_t file_size;	flags = FREAD|FWRITE;	if (in_kernel) {		NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, UIO_SYSSPACE, vniop->vn_file, ctx);	}	else {		NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, 			   (IS_64BIT_PROCESS(p) ? UIO_USERSPACE64 : UIO_USERSPACE32), 			   vniop->vn_file, ctx);	}	/* vn_open gives both long- and short-term references */	error = vn_open(&nd, flags, 0);	if (error) {		/* shadow MUST be writable! */		return (error);	}	if (nd.ni_vp->v_type != VREG 	    || (error = vnode_size(nd.ni_vp, &file_size, ctx))) {		(void)vn_close(nd.ni_vp, flags, ctx);		vnode_put(nd.ni_vp);		return (error ? error : EINVAL);	}	map = shadow_map_create(vn->sc_fsize, file_size,				0, vn->sc_secsize);	if (map == NULL) {		(void)vn_close(nd.ni_vp, flags, ctx);		vnode_put(nd.ni_vp);		vn->sc_shadow_vp = NULL;		return (ENOMEM);	}	vn->sc_shadow_vp = nd.ni_vp;	vn->sc_shadow_vid = vnode_vid(nd.ni_vp);	vn->sc_shadow_vp->v_flag |= VNOCACHE_DATA;	vn->sc_shadow_map = map;	vn->sc_flags &= ~VNF_READONLY; /* we're now read/write */	/* lose the short-term reference */	vnode_put(nd.ni_vp);	return(0);}
开发者ID:Apple-FOSS-Mirror,项目名称:xnu,代码行数:49,


示例13: linker_search_path

char *linker_search_path(const char *name){    struct nameidata	nd;    struct proc		*p = curproc;	/* XXX */    char		*cp, *ep, *result;    int			error;    enum vtype		type;    /* qualified at all? */    if (index(name, '/'))	return(linker_strdup(name));    /* traverse the linker path */    cp = linker_path;    for (;;) {	/* find the end of this component */	for (ep = cp; (*ep != 0) && (*ep != ';'); ep++)	    ;	result = malloc((strlen(name) + (ep - cp) + 1), M_LINKER, M_WAITOK);	if (result == NULL)	/* actually ENOMEM */	    return(NULL);	strncpy(result, cp, ep - cp);	strcpy(result + (ep - cp), name);	/*	 * Attempt to open the file, and return the path if we succeed and it's	 * a regular file.	 */	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, p);	error = vn_open(&nd, FREAD, 0);	if (error == 0) {	    type = nd.ni_vp->v_type;	    VOP_UNLOCK(nd.ni_vp, 0, p);	    vn_close(nd.ni_vp, FREAD, p->p_ucred, p);	    if (type == VREG)		return(result);	}	free(result, M_LINKER);	if (*ep == 0)	    break;	cp = ep + 1;    }    return(NULL);}
开发者ID:UnitedMarsupials,项目名称:kame,代码行数:48,


示例14: dk_lookup

/* * Lookup the provided name in the filesystem.  If the file exists, * is a valid block device, and isn't being used by anyone else, * set *vpp to the file's vnode. */intdk_lookup(struct pathbuf *pb, struct lwp *l, struct vnode **vpp){	struct nameidata nd;	struct vnode *vp;	int     error;	if (l == NULL)		return ESRCH;	/* Is ESRCH the best choice? */	NDINIT(&nd, LOOKUP, FOLLOW, pb);	if ((error = vn_open(&nd, FREAD | FWRITE, 0)) != 0) {		DPRINTF((DKDB_FOLLOW|DKDB_INIT),		    ("%s: vn_open error = %d/n", __func__, error));		return error;	}	vp = nd.ni_vp;	if (vp->v_type != VBLK) {		error = ENOTBLK;		goto out;	}	/* Reopen as anonymous vnode to protect against forced unmount. */	if ((error = bdevvp(vp->v_rdev, vpp)) != 0)		goto out;	VOP_UNLOCK(vp);	if ((error = vn_close(vp, FREAD | FWRITE, l->l_cred)) != 0) {		vrele(*vpp);		return error;	}	if ((error = VOP_OPEN(*vpp, FREAD | FWRITE, l->l_cred)) != 0) {		vrele(*vpp);		return error;	}	mutex_enter((*vpp)->v_interlock);	(*vpp)->v_writecount++;	mutex_exit((*vpp)->v_interlock);	IFDEBUG(DKDB_VNODE, vprint("dk_lookup: vnode info", *vpp));	return 0;out:	VOP_UNLOCK(vp);	(void) vn_close(vp, FREAD | FWRITE, l->l_cred);	return error;}
开发者ID:ycui1984,项目名称:netbsd-src,代码行数:52,


示例15: vn_openat

intvn_openat(char *path, enum uio_seg x1, int flags, int mode, vnode_t **vpp, enum create x2,          mode_t x3, vnode_t *startvp, int fd){    char *realpath = kmem_alloc(strlen(path) + 2, KM_SLEEP);    int ret;    ASSERT(startvp == rootdir);    (void) sprintf(realpath, "/%s", path);    /* fd ignored for now, need if want to simulate nbmand support */    ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3);    kmem_free(realpath, strlen(path) + 2);    return (ret);}
开发者ID:zhihui-slash2,项目名称:slash2-stable,代码行数:17,


示例16: ccdlookup

/* * Lookup the provided name in the filesystem.  If the file exists, * is a valid block device, and isn't being used by anyone else, * set *vpp to the file's vnode. */intccdlookup(char *path, struct proc *p, struct vnode **vpp){	struct nameidata nd;	struct vnode *vp;	struct vattr va;	int error;	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p);	if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {		CCD_DPRINTF(CCDB_FOLLOW | CCDB_INIT,		    ("ccdlookup: vn_open error = %d/n", error));		return (error);	}	vp = nd.ni_vp;	if (vp->v_usecount > 1) {		VOP_UNLOCK(vp, 0, p);		(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);		return (EBUSY);	}	if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) != 0) {		CCD_DPRINTF(CCDB_FOLLOW | CCDB_INIT,		    ("ccdlookup: getattr error = %d/n", error));		VOP_UNLOCK(vp, 0, p);		(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);		return (error);	}	/* XXX: eventually we should handle VREG, too. */	if (va.va_type != VBLK) {		VOP_UNLOCK(vp, 0, p);		(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);		return (ENOTBLK);	}#ifdef DIAGNOSTIC	CCD_DCALL(CCDB_VNODE, vprint("ccdlookup: vnode info", vp));#endif	VOP_UNLOCK(vp, 0, p);	*vpp = vp;	return (0);}
开发者ID:avsm,项目名称:openbsd-xen-sys,代码行数:50,


示例17: kern_file_open

cfs_file_t *kern_file_open(const char * filename, int flags, int mode, int *err){	struct nameidata nd;	cfs_file_t	*fp;	register struct vnode	*vp;	int			rc;	extern struct fileops	vnops;	extern int nfiles;        CFS_DECL_CONE_DATA;        CFS_CONE_IN;	nfiles++;	MALLOC_ZONE(fp, cfs_file_t *, sizeof(cfs_file_t), M_FILE, M_WAITOK|M_ZERO);	bzero(fp, sizeof(cfs_file_t));	fp->f_count = 1;        LIST_CIRCLE(fp, f_list);	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, (char *)filename, current_proc());	if ((rc = vn_open(&nd, flags, mode)) != 0){                printf("filp_open failed at (%d)/n", rc);                if (err != NULL)                        *err = rc;                FREE_ZONE(fp, sizeof *fp, M_FILE);                CFS_CONE_EX;		return NULL;	}	vp = nd.ni_vp;	fp->f_flag = flags & FMASK;	fp->f_type = DTYPE_VNODE;	fp->f_ops = &vnops;	fp->f_data = (caddr_t)vp;	fp->f_cred = current_proc()->p_ucred;	/*	 * Hold cred to increase reference	 */	crhold(fp->f_cred);	/*	 * vnode is locked inside vn_open for lookup,	 * we should release the lock before return	 */	VOP_UNLOCK(vp, 0, current_proc());        CFS_CONE_EX;	return fp;}
开发者ID:dmlb2000,项目名称:lustre-release,代码行数:45,


示例18: kobj_load_vfs

/* * kobj_load_vfs: * *	Load an object located in the file system. */intkobj_load_vfs(kobj_t *kop, const char *path, const bool nochroot){	struct nameidata nd;	struct pathbuf *pb;	kauth_cred_t cred;	int error;	kobj_t ko;	KASSERT(path != NULL);	if (strchr(path, '/') == NULL)		return ENOENT;	cred = kauth_cred_get();	ko = kmem_zalloc(sizeof(*ko), KM_SLEEP);	if (ko == NULL) {		return ENOMEM;	}	pb = pathbuf_create(path);	if (pb == NULL) {	 	kmem_free(ko, sizeof(*ko));		return ENOMEM;	}	NDINIT(&nd, LOOKUP, FOLLOW | (nochroot ? NOCHROOT : 0), pb);	error = vn_open(&nd, FREAD, 0); 	if (error != 0) {		pathbuf_destroy(pb);	 	kmem_free(ko, sizeof(*ko));	 	return error;	}	ko->ko_type = KT_VNODE;	kobj_setname(ko, path);	ko->ko_source = nd.ni_vp;	ko->ko_read = kobj_read_vfs;	ko->ko_close = kobj_close_vfs;	pathbuf_destroy(pb);	*kop = ko;	return kobj_load(ko);}
开发者ID:RyanLucchese,项目名称:rumpkernel-netbsd-src,代码行数:50,


示例19: splat_vnode_test6

static intsplat_vnode_test6(struct file *file, void *arg){	vnode_t *vp;	char buf[32] = "SPL VNode Interface Test File/n";	int rc;	if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))		return rc;	if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,			  FWRITE | FCREAT | FEXCL, 0644, &vp, 0, 0))) {		splat_vprint(file, SPLAT_VNODE_TEST6_NAME,			     "Failed to vn_open test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		return -rc;	}        rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST6_NAME,			     "Failed vn_rdwr write of test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		goto out;	}	rc = vn_fsync(vp, 0, 0, 0);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST6_NAME,			     "Failed vn_fsync of test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE_RW, rc);		goto out;	}	rc = 0;	splat_vprint(file, SPLAT_VNODE_TEST6_NAME, "Successfully "		     "fsync'ed test file %s/n", SPLAT_VNODE_TEST_FILE_RW);out:        VOP_CLOSE(vp, 0, 0, 0, 0, 0);	vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);        return -rc;} /* splat_vnode_test6() */
开发者ID:clopez,项目名称:spl-dkms,代码行数:44,


示例20: dk_lookup

/* * Lookup the provided name in the filesystem.  If the file exists, * is a valid block device, and isn't being used by anyone else, * set *vpp to the file's vnode. */intdk_lookup(const char *path, struct lwp *l, struct vnode **vpp,    enum uio_seg segflg){	struct nameidata nd;	struct vnode *vp;	struct vattr va;	int     error;	if (l == NULL)		return ESRCH;	/* Is ESRCH the best choice? */	NDINIT(&nd, LOOKUP, FOLLOW, segflg, path);	if ((error = vn_open(&nd, FREAD | FWRITE, 0)) != 0) {		DPRINTF((DKDB_FOLLOW|DKDB_INIT),		    ("dk_lookup: vn_open error = %d/n", error));		return error;	}	vp = nd.ni_vp;	if ((error = VOP_GETATTR(vp, &va, l->l_cred)) != 0) {		DPRINTF((DKDB_FOLLOW|DKDB_INIT),		    ("dk_lookup: getattr error = %d/n", error));		goto out;	}	/* XXX: eventually we should handle VREG, too. */	if (va.va_type != VBLK) {		error = ENOTBLK;		goto out;	}	IFDEBUG(DKDB_VNODE, vprint("dk_lookup: vnode info", vp));	VOP_UNLOCK(vp, 0);	*vpp = vp;	return 0;out:	VOP_UNLOCK(vp, 0);	(void) vn_close(vp, FREAD | FWRITE, l->l_cred);	return error;}
开发者ID:lacombar,项目名称:netbsd-alc,代码行数:47,


示例21: kobj_open_file

struct _buf *kobj_open_file(const char *name){	struct _buf *file;	vnode_t *vp;	int rc;	file = kmalloc(sizeof(_buf_t), kmem_flags_convert(KM_SLEEP));	if (file == NULL)		return ((_buf_t *)-1UL);	if ((rc = vn_open(name, UIO_SYSSPACE, FREAD, 0644, &vp, 0, 0))) {		kfree(file);		return ((_buf_t *)-1UL);	}	file->vp = vp;	return (file);} /* kobj_open_file() */
开发者ID:bprotopopov,项目名称:spl,代码行数:20,


示例22: vn_openat

intvn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,          struct vnode **vpp, enum create crwhy,          mode_t umask, struct vnode *startvp){    char *path;    int pathlen = MAXPATHLEN;    int error;    path = (char *)kmem_zalloc(MAXPATHLEN, KM_SLEEP);    error = vn_getpath(startvp, path, &pathlen);    if (error == 0) {        strlcat(path, pnamep, MAXPATHLEN);        error = vn_open(path, seg, filemode, createmode, vpp, crwhy,                        umask);    }    kmem_free(path, MAXPATHLEN);    return (error);}
开发者ID:rottegift,项目名称:spl,代码行数:21,


示例23: splat_vnode_test5

static intsplat_vnode_test5(struct file *file, void *arg){	vnode_t *vp;	vattr_t vap;	int rc;	if ((rc = vn_open(SPLAT_VNODE_TEST_FILE, UIO_SYSSPACE,			  FREAD, 0644, &vp, 0, 0))) {		splat_vprint(file, SPLAT_VNODE_TEST5_NAME,			     "Failed to vn_open test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE, rc);		return -rc;	}	rc = VOP_GETATTR(vp, &vap, 0, 0, NULL);	if (rc) {		splat_vprint(file, SPLAT_VNODE_TEST5_NAME,			     "Failed to vn_getattr test file: %s (%d)/n",			     SPLAT_VNODE_TEST_FILE, rc);		goto out;	}	if (vap.va_type != VREG) {		rc = EINVAL;		splat_vprint(file, SPLAT_VNODE_TEST5_NAME,			     "Failed expected regular file type "			     "(%d != VREG): %s (%d)/n", vap.va_type,			     SPLAT_VNODE_TEST_FILE, rc);		goto out;	}	splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully "		     "vn_getattr'ed test file: %s/n", SPLAT_VNODE_TEST_FILE);out:        VOP_CLOSE(vp, 0, 0, 0, 0, 0);        return -rc;} /* splat_vnode_test5() */
开发者ID:clopez,项目名称:spl-dkms,代码行数:40,


示例24: cpr_get_config

/* * reads config data into cprconfig */static intcpr_get_config(void){	static char config_path[] = CPR_CONFIG;	struct cprconfig *cf = &cprconfig;	struct vnode *vp;	char *fmt;	int err;	if (cprconfig_loaded)		return (0);	fmt = "cannot %s config file /"%s/", error %d/n";	if (err = vn_open(config_path, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0)) {		cpr_err(CE_CONT, fmt, "open", config_path, err);		return (err);	}	err = cpr_rdwr(UIO_READ, vp, cf, sizeof (*cf));	(void) VOP_CLOSE(vp, FREAD, 1, (offset_t)0, CRED(), NULL);	VN_RELE(vp);	if (err) {		cpr_err(CE_CONT, fmt, "read", config_path, err);		return (err);	}	if (cf->cf_magic == CPR_CONFIG_MAGIC)		cprconfig_loaded = 1;	else {		cpr_err(CE_CONT, "invalid config file /"%s/", "		    "rerun pmconfig(1M)/n", config_path);		err = EINVAL;	}	return (err);}
开发者ID:apprisi,项目名称:illumos-gate,代码行数:39,


示例25: spa_config_sync

/* * Synchronize all pools to disk.  This must be called with the namespace lock * held. */voidspa_config_sync(void){	spa_t *spa = NULL;	nvlist_t *config;	size_t buflen;	char *buf;	vnode_t *vp;	int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX;	char pathname[128];	char pathname2[128];	ASSERT(MUTEX_HELD(&spa_namespace_lock));	VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, KM_SLEEP) == 0);	/*	 * Add all known pools to the configuration list, ignoring those with	 * alternate root paths.	 */	spa = NULL;	while ((spa = spa_next(spa)) != NULL) {		mutex_enter(&spa->spa_config_cache_lock);		if (spa->spa_config && spa->spa_name && spa->spa_root == NULL)			VERIFY(nvlist_add_nvlist(config, spa->spa_name,			    spa->spa_config) == 0);		mutex_exit(&spa->spa_config_cache_lock);	}	/*	 * Pack the configuration into a buffer.	 */	VERIFY(nvlist_size(config, &buflen, NV_ENCODE_XDR) == 0);	buf = kmem_alloc(buflen, KM_SLEEP);	VERIFY(nvlist_pack(config, &buf, &buflen, NV_ENCODE_XDR,	    KM_SLEEP) == 0);	/*	 * Write the configuration to disk.  We need to do the traditional	 * 'write to temporary file, sync, move over original' to make sure we	 * always have a consistent view of the data.	 */	(void) snprintf(pathname, sizeof (pathname), "%s/%s", spa_config_dir,	    ZPOOL_CACHE_TMP);	if (vn_open(pathname, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0) != 0)		goto out;	if (vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,	    0, RLIM64_INFINITY, kcred, NULL) == 0 &&	    VOP_FSYNC(vp, FSYNC, kcred) == 0) {		(void) snprintf(pathname2, sizeof (pathname2), "%s/%s",		    spa_config_dir, ZPOOL_CACHE_FILE);		(void) vn_rename(pathname, pathname2, UIO_SYSSPACE);	}	(void) VOP_CLOSE(vp, oflags, 1, 0, kcred);	VN_RELE(vp);out:	(void) vn_remove(pathname, UIO_SYSSPACE, RMFILE);	spa_config_generation++;	kmem_free(buf, buflen);	nvlist_free(config);}
开发者ID:andreiw,项目名称:polaris,代码行数:72,


示例26: link_elf_load_file

static intlink_elf_load_file(linker_class_t cls, const char *filename,    linker_file_t *result){	struct nameidata nd;	struct thread *td = curthread;	/* XXX */	Elf_Ehdr *hdr;	Elf_Shdr *shdr;	Elf_Sym *es;	int nbytes, i, j;	vm_offset_t mapbase;	size_t mapsize;	int error = 0;	ssize_t resid;	int flags;	elf_file_t ef;	linker_file_t lf;	int symtabindex;	int symstrindex;	int shstrindex;	int nsym;	int pb, rl, ra;	int alignmask;	shdr = NULL;	lf = NULL;	mapsize = 0;	hdr = NULL;	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);	flags = FREAD;	error = vn_open(&nd, &flags, 0, NULL);	if (error)		return error;	NDFREE(&nd, NDF_ONLY_PNBUF);	if (nd.ni_vp->v_type != VREG) {		error = ENOEXEC;		goto out;	}#ifdef MAC	error = mac_kld_check_load(td->td_ucred, nd.ni_vp);	if (error) {		goto out;	}#endif	/* Read the elf header from the file. */	hdr = malloc(sizeof(*hdr), M_LINKER, M_WAITOK);	error = vn_rdwr(UIO_READ, nd.ni_vp, (void *)hdr, sizeof(*hdr), 0,	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,	    &resid, td);	if (error)		goto out;	if (resid != 0){		error = ENOEXEC;		goto out;	}	if (!IS_ELF(*hdr)) {		error = ENOEXEC;		goto out;	}	if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS	    || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {		link_elf_error(filename, "Unsupported file layout");		error = ENOEXEC;		goto out;	}	if (hdr->e_ident[EI_VERSION] != EV_CURRENT	    || hdr->e_version != EV_CURRENT) {		link_elf_error(filename, "Unsupported file version");		error = ENOEXEC;		goto out;	}	if (hdr->e_type != ET_REL) {		error = ENOSYS;		goto out;	}	if (hdr->e_machine != ELF_TARG_MACH) {		link_elf_error(filename, "Unsupported machine");		error = ENOEXEC;		goto out;	}	lf = linker_make_file(filename, &link_elf_class);	if (!lf) {		error = ENOMEM;		goto out;	}	ef = (elf_file_t) lf;	ef->nprogtab = 0;	ef->e_shdr = 0;	ef->nreltab = 0;	ef->nrelatab = 0;	/* Allocate and read in the section header */	nbytes = hdr->e_shnum * hdr->e_shentsize;	if (nbytes == 0 || hdr->e_shoff == 0 ||	    hdr->e_shentsize != sizeof(Elf_Shdr)) {//.........这里部分代码省略.........
开发者ID:coyizumi,项目名称:cs111,代码行数:101,


示例27: vniocattach_file

static intvniocattach_file(struct vn_softc *vn,		 struct vn_ioctl_64 *vniop,		 dev_t dev,		 int in_kernel,		 proc_t p){	dev_t	cdev;	vfs_context_t ctx = vfs_context_current();	kauth_cred_t cred;	struct nameidata nd;	off_t file_size;	int error, flags;	flags = FREAD|FWRITE;	if (in_kernel) {		NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, UIO_SYSSPACE, vniop->vn_file, ctx);	}	else {		NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, 			   (IS_64BIT_PROCESS(p) ? UIO_USERSPACE64 : UIO_USERSPACE32), 			   vniop->vn_file, ctx);	}	/* vn_open gives both long- and short-term references */	error = vn_open(&nd, flags, 0);	if (error) {		if (error != EACCES && error != EPERM && error != EROFS) {			return (error);		}		flags &= ~FWRITE;		if (in_kernel) {			NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, UIO_SYSSPACE, 			       vniop->vn_file, ctx);		}		else {			NDINIT(&nd, LOOKUP, OP_OPEN, FOLLOW, 				   (IS_64BIT_PROCESS(p) ? UIO_USERSPACE64 : UIO_USERSPACE32), 			       vniop->vn_file, ctx);		}		error = vn_open(&nd, flags, 0);		if (error) {			return (error);		}	}	if (nd.ni_vp->v_type != VREG) {		error = EINVAL;	}	else {		error = vnode_size(nd.ni_vp, &file_size, ctx);	}	if (error != 0) {		(void) vn_close(nd.ni_vp, flags, ctx);		vnode_put(nd.ni_vp);		return (error);	}	cred = kauth_cred_proc_ref(p);	nd.ni_vp->v_flag |= VNOCACHE_DATA;	error = setcred(nd.ni_vp, cred);	if (error) {		(void)vn_close(nd.ni_vp, flags, ctx);		vnode_put(nd.ni_vp);		kauth_cred_unref(&cred);		return(error);	}	vn->sc_secsize = DEV_BSIZE;	vn->sc_fsize = file_size;	vn->sc_size = file_size / vn->sc_secsize;	vn->sc_vp = nd.ni_vp;	vn->sc_vid = vnode_vid(nd.ni_vp);	vn->sc_open_flags = flags;	vn->sc_cred = cred;	cdev = makedev(vndevice_cdev_major, minor(dev));	vn->sc_cdev = devfs_make_node(cdev, DEVFS_CHAR,				      UID_ROOT, GID_OPERATOR, 				      0600, "rvn%d", 				      minor(dev));	vn->sc_flags |= VNF_INITED;	if (flags == FREAD)		vn->sc_flags |= VNF_READONLY;	/* lose the short-term reference */	vnode_put(nd.ni_vp);	return(0);}
开发者ID:Apple-FOSS-Mirror,项目名称:xnu,代码行数:83,


示例28: spa_config_write

static voidspa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl){	size_t buflen;	char *buf;	vnode_t *vp;	int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX;	int error;	char *temp;	/*	 * If the nvlist is empty (NULL), then remove the old cachefile.	 */	if (nvl == NULL) {		(void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);		return;	}	/*	 * Pack the configuration into a buffer.	 */	VERIFY(nvlist_size(nvl, &buflen, NV_ENCODE_XDR) == 0);	buf = vmem_alloc(buflen, KM_SLEEP);	temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP);	VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR,	    KM_SLEEP) == 0);#if defined(__linux__) && defined(_KERNEL)	/*	 * Write the configuration to disk.  Due to the complexity involved	 * in performing a rename from within the kernel the file is truncated	 * and overwritten in place.  In the event of an error the file is	 * unlinked to make sure we always have a consistent view of the data.	 */	error = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);	if (error == 0) {		error = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0,		    UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, NULL);		if (error == 0)			error = VOP_FSYNC(vp, FSYNC, kcred, NULL);		(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);		if (error)			(void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);	}#else	/*	 * Write the configuration to disk.  We need to do the traditional	 * 'write to temporary file, sync, move over original' to make sure we	 * always have a consistent view of the data.	 */	(void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path);	error = vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0);	if (error == 0) {		if (vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,		    0, RLIM64_INFINITY, kcred, NULL) == 0 &&		    VOP_FSYNC(vp, FSYNC, kcred, NULL) == 0) {			(void) vn_rename(temp, dp->scd_path, UIO_SYSSPACE);		}		(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);	}	(void) vn_remove(temp, UIO_SYSSPACE, RMFILE);#endif	vmem_free(buf, buflen);	kmem_free(temp, MAXPATHLEN);}
开发者ID:koplover,项目名称:zfs,代码行数:72,



注:本文中的vn_open函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ vn_rdwr函数代码示例
C++ vn_lock函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。