本文整理汇总了C++中NDFREE函数的典型用法代码示例。如果您正苦于以下问题:C++ NDFREE函数的具体用法?C++ NDFREE怎么用?C++ NDFREE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NDFREE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: swap_file_open
static int
swap_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,代码来源:nandsim_swap.c
示例2: randomdev_write_file
int
randomdev_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,代码来源:rwfile.c
示例3: vfs_mountroot_readconf
static int
vfs_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,代码来源:vfs_mountroot.c
示例4: linux_newstat
int
linux_newstat(struct proc *p, struct linux_newstat_args *args)
{
struct stat buf;
struct nameidata nd;
int error;
caddr_t sg;
sg = stackgap_init();
CHECKALTEXIST(p, &sg, args->path);
#ifdef DEBUG
printf("Linux-emul(%ld): newstat(%s, *)\n", (long)p->p_pid,
args->path);
#endif
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
args->path, p);
error = namei(&nd);
if (error)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
error = vn_stat(nd.ni_vp, &buf, p);
vput(nd.ni_vp);
if (error)
return (error);
return (newstat_copyout(&buf, args->buf));
}
开发者ID:kame,项目名称:kame,代码行数:30,代码来源:linux_stats.c
示例5: kobj_open_file_vnode
static void *
kobj_open_file_vnode(const char *file)
{
struct thread *td = curthread;
struct filedesc *fd;
struct nameidata nd;
int error, flags, vfslocked;
fd = td->td_proc->p_fd;
FILEDESC_XLOCK(fd);
if (fd->fd_rdir == NULL) {
fd->fd_rdir = rootvnode;
vref(fd->fd_rdir);
}
if (fd->fd_cdir == NULL) {
fd->fd_cdir = rootvnode;
vref(fd->fd_cdir);
}
FILEDESC_XUNLOCK(fd);
flags = FREAD | O_NOFOLLOW;
NDINIT(&nd, LOOKUP, MPSAFE, UIO_SYSSPACE, file, td);
error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL);
if (error != 0)
return (NULL);
vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
/* We just unlock so we hold a reference. */
VOP_UNLOCK(nd.ni_vp, 0);
VFS_UNLOCK_GIANT(vfslocked);
return (nd.ni_vp);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:32,代码来源:opensolaris_kobj.c
示例6: alq_open_flags
int
alq_open_flags(struct alq **alqp, const char *file, struct ucred *cred, int cmode,
int size, int flags)
{
struct thread *td;
struct nameidata nd;
struct alq *alq;
int oflags;
int error;
int vfslocked;
KASSERT((size > 0), ("%s: size <= 0", __func__));
*alqp = NULL;
td = curthread;
NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, file, td);
oflags = FWRITE | O_NOFOLLOW | O_CREAT;
error = vn_open_cred(&nd, &oflags, cmode, 0, cred, NULL);
if (error)
return (error);
vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
/* We just unlock so we hold a reference */
VOP_UNLOCK(nd.ni_vp, 0);
VFS_UNLOCK_GIANT(vfslocked);
alq = bsd_malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO);
alq->aq_vp = nd.ni_vp;
alq->aq_cred = crhold(cred);
mtx_init(&alq->aq_mtx, "ALD Queue", NULL, MTX_SPIN|MTX_QUIET);
alq->aq_buflen = size;
alq->aq_entmax = 0;
alq->aq_entlen = 0;
alq->aq_freebytes = alq->aq_buflen;
alq->aq_entbuf = bsd_malloc(alq->aq_buflen, M_ALD, M_WAITOK|M_ZERO);
alq->aq_writehead = alq->aq_writetail = 0;
if (flags & ALQ_ORDERED)
alq->aq_flags |= AQ_ORDERED;
if ((error = ald_add(alq)) != 0) {
alq_destroy(alq);
return (error);
}
*alqp = alq;
return (0);
}
开发者ID:runsisi,项目名称:ufreebsdtcp,代码行数:54,代码来源:kern_alq.c
示例7: nfsrv_lookupfilename
/*
* Look up a file name. Basically just initialize stuff and call namei().
*/
int
nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p)
{
int error;
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname, p);
error = namei(ndp);
if (!error) {
NDFREE(ndp, NDF_ONLY_PNBUF);
}
return (error);
}
开发者ID:DangerDexter,项目名称:FreeBSD-8.0-dyntick,代码行数:15,代码来源:nfs_commonport.c
示例8: parse_mount_dev_present
static int
parse_mount_dev_present(const char *dev)
{
struct nameidata nd;
int error;
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, dev, curthread);
error = namei(&nd);
if (!error)
vput(nd.ni_vp);
NDFREE(&nd, NDF_ONLY_PNBUF);
return (error != 0) ? 0 : 1;
}
开发者ID:ChristosKa,项目名称:freebsd,代码行数:13,代码来源:vfs_mountroot.c
示例9: osi_lookupname
int
osi_lookupname(char *aname, enum uio_seg seg, int followlink,
struct vnode **vpp)
{
struct nameidata n;
int flags, error, glocked;
#ifdef AFS_FBSD50_ENV
glocked = ISAFS_GLOCK();
if (glocked)
AFS_GUNLOCK();
#endif
flags = 0;
flags = LOCKLEAF;
if (followlink)
flags |= FOLLOW;
else
flags |= NOFOLLOW;
#ifdef AFS_FBSD80_ENV
flags |= MPSAFE; /* namei must take GIANT if needed */
#endif
NDINIT(&n, LOOKUP, flags, seg, aname, curproc);
if ((error = namei(&n)) != 0) {
#ifdef AFS_FBSD50_ENV
if (glocked)
AFS_GLOCK();
#endif
return error;
}
*vpp = n.ni_vp;
/* XXX should we do this? Usually NOT (matt) */
#if defined(AFS_FBSD80_ENV)
/*VOP_UNLOCK(n.ni_vp, 0);*/
#elif defined(AFS_FBSD50_ENV)
VOP_UNLOCK(n.ni_vp, 0, curthread);
#else
VOP_UNLOCK(n.ni_vp, 0, curproc);
#endif
NDFREE(&n, NDF_ONLY_PNBUF);
#ifdef AFS_FBSD50_ENV
if (glocked)
AFS_GLOCK();
#endif
return 0;
}
开发者ID:maxendpoint,项目名称:openafs_cvs,代码行数:46,代码来源:osi_misc.c
示例10: kobj_open_file_vnode
static void *
kobj_open_file_vnode(const char *file)
{
struct thread *td = curthread;
struct nameidata nd;
int error, flags;
pwd_ensure_dirs();
flags = FREAD | O_NOFOLLOW;
NDINIT(&nd, LOOKUP, 0, UIO_SYSSPACE, file, td);
error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL);
if (error != 0)
return (NULL);
NDFREE(&nd, NDF_ONLY_PNBUF);
/* We just unlock so we hold a reference. */
VOP_UNLOCK(nd.ni_vp, 0);
return (nd.ni_vp);
}
开发者ID:2asoft,项目名称:freebsd,代码行数:19,代码来源:opensolaris_kobj.c
示例11: lookupnameat
int
lookupnameat(char *dirname, enum uio_seg seg, enum symfollow follow,
vnode_t **dirvpp, vnode_t **compvpp, vnode_t *startvp)
{
struct nameidata nd;
int error, ltype;
ASSERT(dirvpp == NULL);
vref(startvp);
ltype = VOP_ISLOCKED(startvp);
VOP_UNLOCK(startvp, 0);
NDINIT_ATVP(&nd, LOOKUP, LOCKLEAF | MPSAFE | follow, seg, dirname,
startvp, curthread);
error = namei(&nd);
*compvpp = nd.ni_vp;
NDFREE(&nd, NDF_ONLY_PNBUF);
vn_lock(startvp, ltype | LK_RETRY);
return (error);
}
开发者ID:151706061,项目名称:osv,代码行数:20,代码来源:opensolaris_lookup.c
示例12: osi_lookupname
int
osi_lookupname(char *aname, enum uio_seg seg, int followlink,
struct vnode **vpp)
{
struct nameidata n;
int flags, error, glocked;
glocked = ISAFS_GLOCK();
if (glocked)
AFS_GUNLOCK();
#if __FreeBSD_version >= 1000021 /* MPSAFE is gone for good! */
flags = 0;
#else
flags = MPSAFE; /* namei must take Giant if needed */
#endif
if (followlink)
flags |= FOLLOW;
else
flags |= NOFOLLOW;
NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
if ((error = namei(&n)) != 0) {
if (glocked)
AFS_GLOCK();
return error;
}
*vpp = n.ni_vp;
/* XXX should we do this? Usually NOT (matt) */
#if defined(AFS_FBSD80_ENV)
/*VOP_UNLOCK(n.ni_vp, 0);*/
#else
VOP_UNLOCK(n.ni_vp, 0, curthread);
#endif
NDFREE(&n, NDF_ONLY_PNBUF);
if (glocked)
AFS_GLOCK();
return 0;
}
开发者ID:openafs,项目名称:openafs,代码行数:38,代码来源:osi_misc.c
示例13: quotaon
/*
* Q_QUOTAON - set up a quota file for a particular filesystem.
*/
int
quotaon(struct thread *td, struct mount *mp, int type, void *fname)
{
struct ufsmount *ump;
struct vnode *vp, **vpp;
struct vnode *mvp;
struct dquot *dq;
int error, flags;
struct nameidata nd;
error = priv_check(td, PRIV_UFS_QUOTAON);
if (error != 0) {
vfs_unbusy(mp);
return (error);
}
if ((mp->mnt_flag & MNT_RDONLY) != 0) {
vfs_unbusy(mp);
return (EROFS);
}
ump = VFSTOUFS(mp);
dq = NODQUOT;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fname, td);
flags = FREAD | FWRITE;
vfs_ref(mp);
vfs_unbusy(mp);
error = vn_open(&nd, &flags, 0, NULL);
if (error != 0) {
vfs_rel(mp);
return (error);
}
NDFREE(&nd, NDF_ONLY_PNBUF);
vp = nd.ni_vp;
error = vfs_busy(mp, MBF_NOWAIT);
vfs_rel(mp);
if (error == 0) {
if (vp->v_type != VREG) {
error = EACCES;
vfs_unbusy(mp);
}
}
if (error != 0) {
VOP_UNLOCK(vp, 0);
(void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
return (error);
}
UFS_LOCK(ump);
if ((ump->um_qflags[type] & (QTF_OPENING|QTF_CLOSING)) != 0) {
UFS_UNLOCK(ump);
VOP_UNLOCK(vp, 0);
(void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
vfs_unbusy(mp);
return (EALREADY);
}
ump->um_qflags[type] |= QTF_OPENING|QTF_CLOSING;
UFS_UNLOCK(ump);
if ((error = dqopen(vp, ump, type)) != 0) {
VOP_UNLOCK(vp, 0);
UFS_LOCK(ump);
ump->um_qflags[type] &= ~(QTF_OPENING|QTF_CLOSING);
UFS_UNLOCK(ump);
(void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
vfs_unbusy(mp);
return (error);
}
VOP_UNLOCK(vp, 0);
MNT_ILOCK(mp);
mp->mnt_flag |= MNT_QUOTA;
MNT_IUNLOCK(mp);
vpp = &ump->um_quotas[type];
if (*vpp != vp)
quotaoff1(td, mp, type);
/*
* When the directory vnode containing the quota file is
* inactivated, due to the shared lookup of the quota file
* vput()ing the dvp, the qsyncvp() call for the containing
* directory would try to acquire the quota lock exclusive.
* At the same time, lookup already locked the quota vnode
* shared. Mark the quota vnode lock as allowing recursion
* and automatically converting shared locks to exclusive.
*
* Also mark quota vnode as system.
*/
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
vp->v_vflag |= VV_SYSTEM;
VN_LOCK_AREC(vp);
VN_LOCK_DSHARE(vp);
VOP_UNLOCK(vp, 0);
*vpp = vp;
/*
* Save the credential of the process that turned on quotas.
* Set up the time limits for this quota.
//.........这里部分代码省略.........
开发者ID:jaredmcneill,项目名称:freebsd,代码行数:101,代码来源:ufs_quota.c
示例14: udf_mount
static int
udf_mount(struct mount *mp)
{
struct vnode *devvp; /* vnode of the mount device */
struct thread *td;
struct udf_mnt *imp = NULL;
struct vfsoptlist *opts;
char *fspec, *cs_disk, *cs_local;
int error, len, *udf_flags;
struct nameidata nd, *ndp = &nd;
td = curthread;
opts = mp->mnt_optnew;
/*
* Unconditionally mount as read-only.
*/
MNT_ILOCK(mp);
mp->mnt_flag |= MNT_RDONLY;
MNT_IUNLOCK(mp);
/*
* No root filesystem support. Probably not a big deal, since the
* bootloader doesn't understand UDF.
*/
if (mp->mnt_flag & MNT_ROOTFS)
return (ENOTSUP);
fspec = NULL;
error = vfs_getopt(opts, "from", (void **)&fspec, &len);
if (!error && fspec[len - 1] != '\0')
return (EINVAL);
if (mp->mnt_flag & MNT_UPDATE) {
return (0);
}
/* Check that the mount device exists */
if (fspec == NULL)
return (EINVAL);
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
if ((error = namei(ndp)))
return (error);
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (vn_isdisk(devvp, &error) == 0) {
vput(devvp);
return (error);
}
/* Check the access rights on the mount device */
error = VOP_ACCESS(devvp, VREAD, td->td_ucred, td);
if (error)
error = priv_check(td, PRIV_VFS_MOUNT_PERM);
if (error) {
vput(devvp);
return (error);
}
if ((error = udf_mountfs(devvp, mp))) {
vrele(devvp);
return (error);
}
imp = VFSTOUDFFS(mp);
udf_flags = NULL;
error = vfs_getopt(opts, "flags", (void **)&udf_flags, &len);
if (error || len != sizeof(int))
return (EINVAL);
imp->im_flags = *udf_flags;
if (imp->im_flags & UDFMNT_KICONV && udf_iconv) {
cs_disk = NULL;
error = vfs_getopt(opts, "cs_disk", (void **)&cs_disk, &len);
if (!error && cs_disk[len - 1] != '\0')
return (EINVAL);
cs_local = NULL;
error = vfs_getopt(opts, "cs_local", (void **)&cs_local, &len);
if (!error && cs_local[len - 1] != '\0')
return (EINVAL);
udf_iconv->open(cs_local, cs_disk, &imp->im_d2l);
#if 0
udf_iconv->open(cs_disk, cs_local, &imp->im_l2d);
#endif
}
vfs_mountedfrom(mp, fspec);
return 0;
};
开发者ID:coyizumi,项目名称:cs111,代码行数:91,代码来源:udf_vfsops.c
示例15: coda_mount
/*ARGSUSED*/
int
coda_mount(struct mount *vfsp)
{
struct vnode *dvp;
struct cnode *cp;
struct cdev *dev;
struct coda_mntinfo *mi;
struct vnode *rootvp;
struct CodaFid rootfid = INVAL_FID;
struct CodaFid ctlfid = CTL_FID;
int error;
struct nameidata ndp;
ENTRY;
char *from;
if (vfs_filteropt(vfsp->mnt_optnew, coda_opts))
return (EINVAL);
from = vfs_getopts(vfsp->mnt_optnew, "from", &error);
if (error)
return (error);
coda_vfsopstats_init();
coda_vnodeopstats_init();
MARK_ENTRY(CODA_MOUNT_STATS);
if (CODA_MOUNTED(vfsp)) {
MARK_INT_FAIL(CODA_MOUNT_STATS);
return (EBUSY);
}
/*
* Validate mount device. Similar to getmdev().
*/
NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, curthread);
error = namei(&ndp);
dvp = ndp.ni_vp;
if (error) {
MARK_INT_FAIL(CODA_MOUNT_STATS);
return (error);
}
if (dvp->v_type != VCHR) {
MARK_INT_FAIL(CODA_MOUNT_STATS);
vrele(dvp);
NDFREE(&ndp, NDF_ONLY_PNBUF);
return (ENXIO);
}
dev = dvp->v_rdev;
vrele(dvp);
NDFREE(&ndp, NDF_ONLY_PNBUF);
/*
* Initialize the mount record and link it to the vfs struct.
*/
mi = dev2coda_mntinfo(dev);
if (!mi) {
MARK_INT_FAIL(CODA_MOUNT_STATS);
printf("Coda mount: %s is not a cfs device\n", from);
return (ENXIO);
}
if (!VC_OPEN(&mi->mi_vcomm)) {
MARK_INT_FAIL(CODA_MOUNT_STATS);
return (ENODEV);
}
/*
* No initialization (here) of mi_vcomm!
*/
vfsp->mnt_data = mi;
vfs_getnewfsid (vfsp);
mi->mi_vfsp = vfsp;
mi->mi_started = 0; /* XXX See coda_root() */
/*
* Make a root vnode to placate the Vnode interface, but don't
* actually make the CODA_ROOT call to venus until the first call to
* coda_root in case a server is down while venus is starting.
*/
cp = make_coda_node(&rootfid, vfsp, VDIR);
rootvp = CTOV(cp);
rootvp->v_vflag |= VV_ROOT;
cp = make_coda_node(&ctlfid, vfsp, VREG);
coda_ctlvp = CTOV(cp);
/*
* Add vfs and rootvp to chain of vfs hanging off mntinfo.
*/
mi->mi_vfsp = vfsp;
mi->mi_rootvp = rootvp;
vfs_mountedfrom(vfsp, from);
/*
* Error is currently guaranteed to be zero, but in case some code
* changes...
*/
CODADEBUG(1, myprintf(("coda_mount returned %d\n", error)););
开发者ID:dcui,项目名称:FreeBSD-9.3_kernel,代码行数:94,代码来源:coda_vfsops.c
示例16: link_elf_load_file
static int
link_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,代码来源:link_elf_obj.c
示例17: sysctl_integriforce_so
static int
sysctl_integriforce_so(SYSCTL_HANDLER_ARGS)
{
integriforce_so_check_t *integriforce_so;
secadm_prison_entry_t *entry;
secadm_rule_t r, *rule;
struct nameidata nd;
struct vattr vap;
secadm_key_t key;
int err;
if (!(req->newptr) || req->newlen != sizeof(integriforce_so_check_t))
return (EINVAL);
if (!(req->oldptr) || req->oldlen != sizeof(integriforce_so_check_t))
return (EINVAL);
integriforce_so = malloc(sizeof(integriforce_so_check_t), M_SECADM, M_WAITOK);
err = SYSCTL_IN(req, integriforce_so, sizeof(integriforce_so_check_t));
if (err) {
free(integriforce_so, M_SECADM);
return (err);
}
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, integriforce_so->isc_path, req->td);
err = namei(&nd);
if (err) {
free(integriforce_so, M_SECADM);
NDFREE(&nd, 0);
return (err);
}
if ((err = vn_lock(nd.ni_vp, LK_SHARED | LK_RETRY)) != 0) {
free(integriforce_so, M_SECADM);
NDFREE(&nd, 0);
return (err);
}
err = VOP_GETATTR(nd.ni_vp, &vap, req->td->td_ucred);
if (err) {
free(integriforce_so, M_SECADM);
NDFREE(&nd, 0);
return (err);
}
VOP_UNLOCK(nd.ni_vp, 0);
key.sk_jid = req->td->td_ucred->cr_prison->pr_id;
key.sk_type = secadm_integriforce_rule;
key.sk_fileid = vap.va_fileid;
strncpy(key.sk_mntonname,
nd.ni_vp->v_mount->mnt_stat.f_mntonname, MNAMELEN);
r.sr_key = fnv_32_buf(&key, sizeof(secadm_key_t), FNV1_32_INIT);
entry = get_prison_list_entry(
req->td->td_ucred->cr_prison->pr_id);
PE_RLOCK(entry);
rule = RB_FIND(secadm_rules_tree, &(entry->sp_rules), &r);
if (rule) {
integriforce_so->isc_result =
do_integriforce_check(rule, &vap, nd.ni_vp,
req->td->td_ucred);
}
PE_RUNLOCK(entry);
SYSCTL_OUT(req, integriforce_so, sizeof(integriforce_so_check_t));
free(integriforce_so, M_SECADM);
NDFREE(&nd, 0);
return (0);
}
开发者ID:HardenedBSD,项目名称:secadm,代码行数:76,代码来源:integriforce.c
示例18: link_elf_ctf_get
static int
link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc)
{
#ifdef DDB_CTF
Elf_Ehdr *hdr = NULL;
Elf_Shdr *shdr = NULL;
caddr_t ctftab = NULL;
caddr_t raw = NULL;
caddr_t shstrtab = NULL;
elf_file_t ef = (elf_file_t) lf;
int flags;
int i;
int nbytes;
ssize_t resid;
int vfslocked;
size_t sz;
struct nameidata nd;
struct thread *td = curthread;
uint8_t ctf_hdr[CTF_HDR_SIZE];
#endif
int error = 0;
if (lf == NULL || lc == NULL)
return (EINVAL);
/* Set the defaults for no CTF present. That's not a crime! */
bzero(lc, sizeof(*lc));
#ifdef DDB_CTF
/*
* First check if we've tried to load CTF data previously and the
* CTF ELF section wasn't found. We flag that condition by setting
* ctfcnt to -1. See below.
*/
if (ef->ctfcnt < 0)
return (EFTYPE);
/* Now check if we've already loaded the CTF data.. */
if (ef->ctfcnt > 0) {
/* We only need to load once. */
lc->ctftab = ef->ctftab;
lc->ctfcnt = ef->ctfcnt;
lc->symtab = ef->ddbsymtab;
lc->strtab = ef->ddbstrtab;
lc->strcnt = ef->ddbstrcnt;
lc->nsym = ef->ddbsymcnt;
lc->ctfoffp = (uint32_t **) &ef->ctfoff;
lc->typoffp = (uint32_t **) &ef->typoff;
lc->typlenp = &ef->typlen;
return (0);
}
/*
* We need to try reading the CTF data. Flag no CTF data present
* by default and if we actually succeed in reading it, we'll
* update ctfcnt to the number of bytes read.
*/
ef->ctfcnt = -1;
NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, lf->pathname, td);
flags = FREAD;
error = vn_open(&nd, &flags, 0, NULL);
if (error)
return (error);
vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
/* Allocate memory for the FLF header. */
if ((hdr = malloc(sizeof(*hdr), M_LINKER, M_WAITOK)) == NULL) {
error = ENOMEM;
goto out;
}
/* Read the ELF header. */
if ((error = vn_rdwr(UIO_READ, nd.ni_vp, hdr, sizeof(*hdr),
0, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, &resid,
td)) != 0)
goto out;
/* Sanity check. */
if (!IS_ELF(*hdr)) {
error = ENOEXEC;
goto out;
}
nbytes = hdr->e_shnum * hdr->e_shentsize;
if (nbytes == 0 || hdr->e_shoff == 0 ||
hdr->e_shentsize != sizeof(Elf_Shdr)) {
error = ENOEXEC;
goto out;
}
/* Allocate memory for all the section headers */
if ((shdr = malloc(nbytes, M_LINKER, M_WAITOK)) == NULL) {
error = ENOMEM;
goto out;
}
/* Read all the section headers */
if ((error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)shdr, nbytes,
//.........这里部分代码省略.........
开发者ID:AhmadTux,项目名称:freebsd,代码行数:101,代码来源:kern_ctf.c
示例19: vfs_mountroot_shuffle
static int
vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs)
{
struct nameidata nd;
struct mount *mporoot, *mpnroot;
struct vnode *vp, *vporoot, *vpdevfs;
char *fspath;
int error;
mpnroot = TAILQ_NEXT(mpdevfs, mnt_list);
/* Shuffle the mountlist. */
mtx_lock(&mountlist_mtx);
mporoot = TAILQ_FIRST(&mountlist);
TAILQ_REMOVE(&mountlist, mpdevfs, mnt_list);
if (mporoot != mpdevfs) {
TAILQ_REMOVE(&mountlist, mpnroot, mnt_list);
TAILQ_INSERT_HEAD(&mountlist, mpnroot, mnt_list);
}
TAILQ_INSERT_TAIL(&mountlist, mpdevfs, mnt_list);
mtx_unlock(&mountlist_mtx);
cache_purgevfs(mporoot);
if (mporoot != mpdevfs)
cache_purgevfs(mpdevfs);
VFS_ROOT(mporoot, LK_EXCLUSIVE, &vporoot);
VI_LOCK(vporoot);
vporoot->v_iflag &= ~VI_MOUNT;
VI_UNLOCK(vporoot);
vporoot->v_mountedhere = NULL;
mporoot->mnt_flag &= ~MNT_ROOTFS;
mporoot->mnt_vnodecovered = NULL;
vput(vporoot);
/* Set up the new rootvnode, and purge the cache */
mpnroot->mnt_vnodecovered = NULL;
set_rootvnode();
cache_purgevfs(rootvnode->v_mount);
if (mporoot != mpdevfs) {
/* Remount old root under /.mount or /mnt */
fspath = "/.mount";
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
fspath, td);
error = namei(&nd);
if (error) {
NDFREE(&nd, NDF_ONLY_PNBUF);
fspath = "/mnt";
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
fspath, td);
error = namei(&nd);
}
if (!error) {
vp = nd.ni_vp;
error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
if (!error)
error = vinvalbuf(vp, V_SAVE, 0, 0);
if (!error) {
cache_purge(vp);
mporoot->mnt_vnodecovered = vp;
vp->v_mountedhere = mporoot;
strlcpy(mporoot->mnt_stat.f_mntonname,
fspath, MNAMELEN);
VOP_UNLOCK(vp, 0);
} else
vput(vp);
}
NDFREE(&nd, NDF_ONLY_PNBUF);
if (error && bootverbose)
printf("mountroot: unable to remount previous root "
"under /.mount or /mnt (error %d).\n", error);
}
/* Remount devfs under /dev */
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev", td);
error = namei(&nd);
if (!error) {
vp = nd.ni_vp;
error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
if (!error)
error = vinvalbuf(vp, V_SAVE, 0, 0);
if (!error) {
vpdevfs = mpdevfs->mnt_vnodecovered;
if (vpdevfs != NULL) {
cache_purge(vpdevfs);
vpdevfs->v_mountedhere = NULL;
vrele(vpdevfs);
}
mpdevfs->mnt_vnodecovered = vp;
vp->v_mountedhere = mpdevfs;
VOP_UNLOCK(vp, 0);
} else
vput(vp);
}
if (error && bootverbose)
printf("mountroot: unable to remount devfs under /dev "
"(error %d).\n", error);
//.........这里部分代码省略.........
开发者ID:ChristosKa,项目名称:freebsd,代码行数:101,代码来源:vfs_mountroot.c
示例20: ntfs_mount
static int
ntfs_mount(struct mount *mp)
{
int err = 0, error;
struct vnode *devvp;
struct nameidata ndp;
struct thread *td;
char *from;
td = curthread;
if (vfs_filteropt(mp->mnt_optnew, ntfs_opts))
return (EINVAL);
/* Force mount as read-only. */
MNT_ILOCK(mp);
mp->mnt_flag |= MNT_RDONLY;
MNT_IUNLOCK(mp);
from = vfs_getopts(mp->mnt_optnew, "from", &error);
if (error)
return (error);
/*
* If updating, check whether changing from read-only to
* read/write.
*/
if (mp->mnt_flag & MNT_UPDATE) {
if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0)) {
/* Process export requests in vfs_mount.c */
return (0);
} else {
printf("ntfs_mount(): MNT_UPDATE not supported\n");
return (EINVAL);
}
}
/*
* Not an update, or updating the name: look up the name
* and verify that it refers to a sensible block device.
*/
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
err = namei(&ndp);
if (err)
return (err);
NDFREE(&ndp, NDF_ONLY_PNBUF);
devvp = ndp.ni_vp;
if (!vn_isdisk(devvp, &err)) {
vput(devvp);
return (err);
}
/*
* If mount by non-root, then verify that user has necessary
* permissions on the device.
*/
err = VOP_ACCESS(devvp, VREAD, td->td_ucred, td);
if (err)
err = priv_check(td, PRIV_VFS_MOUNT_PERM);
if (err) {
vput(devvp);
return (err);
}
/*
* Since this is a new mount, we want the names for the device and
* the mount point copied in. If an error occurs, the mountpoint is
* discarded by the upper level code. Note that vfs_mount() handles
* copying the mountpoint f_mntonname for us, so we don't have to do
* it here unless we want to set it to something other than "path"
* for some rason.
*/
err = ntfs_mountfs(devvp, mp, td);
if (err == 0) {
/* Save "mounted from" info for mount point. */
vfs_mountedfrom(mp, from);
} else
vrele(devvp);
return (err);
}
开发者ID:vkhromov,项目名称:freebsd,代码行数:83,代码来源:ntfs_vfsops.c
注:本文中的NDFREE函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论