本文整理汇总了C++中VOP_GETATTR函数的典型用法代码示例。如果您正苦于以下问题:C++ VOP_GETATTR函数的具体用法?C++ VOP_GETATTR怎么用?C++ VOP_GETATTR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VOP_GETATTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: auto_getattr
static int
auto_getattr(
vnode_t *vp,
vattr_t *vap,
int flags,
cred_t *cred,
caller_context_t *ct)
{
fnnode_t *fnp = vntofn(vp);
vnode_t *newvp;
vfs_t *vfsp;
int error;
AUTOFS_DPRINT((4, "auto_getattr vp %p\n", (void *)vp));
if (flags & ATTR_TRIGGER) {
/*
* Pre-trigger the mount
*/
error = auto_trigger_mount(vp, cred, &newvp);
if (error)
return (error);
if (newvp == NULL)
goto defattr;
if (error = vn_vfsrlock_wait(vp)) {
VN_RELE(newvp);
return (error);
}
vfsp = newvp->v_vfsp;
VN_RELE(newvp);
} else {
/*
* Recursive auto_getattr/mount; go to the vfsp == NULL
* case.
*/
if (vn_vfswlock_held(vp))
goto defattr;
if (error = vn_vfsrlock_wait(vp))
return (error);
vfsp = vn_mountedvfs(vp);
}
if (vfsp != NULL) {
/*
* Node is mounted on.
*/
error = VFS_ROOT(vfsp, &newvp);
vn_vfsunlock(vp);
if (error)
return (error);
mutex_enter(&fnp->fn_lock);
if (fnp->fn_seen == newvp && fnp->fn_thread == curthread) {
/*
* Recursive auto_getattr(); just release newvp and drop
* into the vfsp == NULL case.
*/
mutex_exit(&fnp->fn_lock);
VN_RELE(newvp);
} else {
while (fnp->fn_thread && fnp->fn_thread != curthread) {
fnp->fn_flags |= MF_ATTR_WAIT;
cv_wait(&fnp->fn_cv_mount, &fnp->fn_lock);
}
fnp->fn_thread = curthread;
fnp->fn_seen = newvp;
mutex_exit(&fnp->fn_lock);
error = VOP_GETATTR(newvp, vap, flags, cred, ct);
VN_RELE(newvp);
mutex_enter(&fnp->fn_lock);
fnp->fn_seen = 0;
fnp->fn_thread = 0;
if (fnp->fn_flags & MF_ATTR_WAIT) {
fnp->fn_flags &= ~MF_ATTR_WAIT;
cv_broadcast(&fnp->fn_cv_mount);
}
mutex_exit(&fnp->fn_lock);
return (error);
}
} else {
vn_vfsunlock(vp);
}
defattr:
ASSERT(vp->v_type == VDIR || vp->v_type == VLNK);
vap->va_uid = 0;
vap->va_gid = 0;
vap->va_nlink = fnp->fn_linkcnt;
vap->va_nodeid = (u_longlong_t)fnp->fn_nodeid;
vap->va_size = fnp->fn_size;
vap->va_atime = fnp->fn_atime;
vap->va_mtime = fnp->fn_mtime;
vap->va_ctime = fnp->fn_ctime;
vap->va_type = vp->v_type;
vap->va_mode = fnp->fn_mode;
vap->va_fsid = vp->v_vfsp->vfs_dev;
//.........这里部分代码省略.........
示例2: vdev_file_open
static int
vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
{
vdev_file_t *vf;
vnode_t *vp;
vattr_t vattr;
int error;
/*
* We must have a pathname, and it must be absolute.
*/
if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
return (EINVAL);
}
/*
* Reopen the device if it's not currently open. Otherwise,
* just update the physical size of the device.
*/
if (vd->vdev_tsd != NULL) {
ASSERT(vd->vdev_reopening);
vf = vd->vdev_tsd;
goto skip_open;
}
vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
/*
* We always open the files from the root of the global zone, even if
* we're in a local zone. If the user has gotten to this point, the
* administrator has already decided that the pool should be available
* to local zone users, so the underlying devices should be as well.
*/
ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
spa_mode(vd->vdev_spa) | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
if (error) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
return (error);
}
vf->vf_vnode = vp;
#ifdef _KERNEL
/*
* Make sure it's a regular file.
*/
if (vp->v_type != VREG) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
return (ENODEV);
}
#endif
skip_open:
/*
* Determine the physical size of the file.
*/
vattr.va_mask = AT_SIZE;
error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
if (error) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
return (error);
}
*psize = vattr.va_size;
*ashift = SPA_MINBLOCKSHIFT;
return (0);
}
示例3: acl2_access
/* ARGSUSED */
void
acl2_access(ACCESS2args *args, ACCESS2res *resp, struct exportinfo *exi,
struct svc_req *req, cred_t *cr, bool_t ro)
{
int error;
vnode_t *vp;
vattr_t va;
int checkwriteperm;
vp = nfs_fhtovp(&args->fh, exi);
if (vp == NULL) {
resp->status = NFSERR_STALE;
return;
}
/*
* If the file system is exported read only, it is not appropriate
* to check write permissions for regular files and directories.
* Special files are interpreted by the client, so the underlying
* permissions are sent back to the client for interpretation.
*/
if (rdonly(ro, vp) && (vp->v_type == VREG || vp->v_type == VDIR))
checkwriteperm = 0;
else
checkwriteperm = 1;
/*
* We need the mode so that we can correctly determine access
* permissions relative to a mandatory lock file. Access to
* mandatory lock files is denied on the server, so it might
* as well be reflected to the server during the open.
*/
va.va_mask = AT_MODE;
error = VOP_GETATTR(vp, &va, 0, cr, NULL);
if (error) {
VN_RELE(vp);
resp->status = puterrno(error);
return;
}
resp->resok.access = 0;
if (args->access & ACCESS2_READ) {
error = VOP_ACCESS(vp, VREAD, 0, cr, NULL);
if (!error && !MANDLOCK(vp, va.va_mode))
resp->resok.access |= ACCESS2_READ;
}
if ((args->access & ACCESS2_LOOKUP) && vp->v_type == VDIR) {
error = VOP_ACCESS(vp, VEXEC, 0, cr, NULL);
if (!error)
resp->resok.access |= ACCESS2_LOOKUP;
}
if (checkwriteperm &&
(args->access & (ACCESS2_MODIFY|ACCESS2_EXTEND))) {
error = VOP_ACCESS(vp, VWRITE, 0, cr, NULL);
if (!error && !MANDLOCK(vp, va.va_mode))
resp->resok.access |=
(args->access & (ACCESS2_MODIFY|ACCESS2_EXTEND));
}
if (checkwriteperm &&
(args->access & ACCESS2_DELETE) && (vp->v_type == VDIR)) {
error = VOP_ACCESS(vp, VWRITE, 0, cr, NULL);
if (!error)
resp->resok.access |= ACCESS2_DELETE;
}
if (args->access & ACCESS2_EXECUTE) {
error = VOP_ACCESS(vp, VEXEC, 0, cr, NULL);
if (!error && !MANDLOCK(vp, va.va_mode))
resp->resok.access |= ACCESS2_EXECUTE;
}
va.va_mask = AT_ALL;
error = rfs4_delegated_getattr(vp, &va, 0, cr);
VN_RELE(vp);
/* check for overflowed values */
if (!error) {
error = vattr_to_nattr(&va, &resp->resok.attr);
}
if (error) {
resp->status = puterrno(error);
return;
}
resp->status = NFS_OK;
}
示例4: vdev_file_open
static int
vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
uint64_t *ashift)
{
vdev_file_t *vf;
vnode_t *vp;
vattr_t vattr;
int error = 0;
vnode_t *rootdir;
/*
* We must have a pathname, and it must be absolute.
*/
if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
return (EINVAL);
}
/*
* Reopen the device if it's not currently open. Otherwise,
* just update the physical size of the device.
*/
if (vd->vdev_tsd != NULL) {
ASSERT(vd->vdev_reopening);
vf = vd->vdev_tsd;
vnode_getwithvid(vf->vf_vnode, vf->vf_vid);
goto skip_open;
}
vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_PUSHPAGE);
/*
* We always open the files from the root of the global zone, even if
* we're in a local zone. If the user has gotten to this point, the
* administrator has already decided that the pool should be available
* to local zone users, so the underlying devices should be as well.
*/
ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
/*
vn_openat(char *pnamep,
enum uio_seg seg,
int filemode,
int createmode,
struct vnode **vpp,
enum create crwhy,
mode_t umask,
struct vnode *startvp)
extern int vn_openat(char *pnamep, enum uio_seg seg, int filemode,
int createmode, struct vnode **vpp, enum create crwhy,
mode_t umask, struct vnode *startvp);
*/
rootdir = getrootdir();
error = vn_openat(vd->vdev_path + 1,
UIO_SYSSPACE,
spa_mode(vd->vdev_spa) | FOFFMAX,
0,
&vp,
0,
0,
rootdir
);
if (error) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
return (error);
}
vf->vf_vnode = vp;
vf->vf_vid = vnode_vid(vp);
#ifdef _KERNEL
/*
* Make sure it's a regular file.
*/
if (!vnode_isreg(vp)) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
vnode_put(vf->vf_vnode);
return (ENODEV);
}
#endif
skip_open:
/*
* Determine the physical size of the file.
*/
vattr.va_mask = AT_SIZE;
error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
if (error) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
vnode_put(vf->vf_vnode);
return (error);
}
*max_psize = *psize = vattr.va_size;
*ashift = SPA_MINBLOCKSHIFT;
vnode_put(vf->vf_vnode);
//.........这里部分代码省略.........
示例5: puffs_biowrite
int
puffs_biowrite(struct vnode *vp, struct uio *uio, int ioflag,
struct ucred *cred)
{
int biosize = vp->v_mount->mnt_stat.f_iosize;
struct buf *bp;
struct vattr vattr;
off_t loffset, fsize;
int boff, bytes;
int error = 0;
int bcount;
int trivial;
KKASSERT(uio->uio_rw == UIO_WRITE);
KKASSERT(vp->v_type == VREG);
if (uio->uio_offset < 0)
return EINVAL;
if (uio->uio_resid == 0)
return 0;
/*
* If IO_APPEND then load uio_offset. We restart here if we cannot
* get the append lock.
*
* We need to obtain exclusize lock if we intend to modify file size
* in order to guarentee the append point with multiple contending
* writers.
*/
if (ioflag & IO_APPEND) {
/* XXXDF relock if necessary */
KKASSERT(vn_islocked(vp) == LK_EXCLUSIVE);
error = VOP_GETATTR(vp, &vattr);
if (error)
return error;
uio->uio_offset = puffs_meta_getsize(vp);
}
do {
boff = uio->uio_offset & (biosize-1);
loffset = uio->uio_offset - boff;
bytes = (int)szmin((unsigned)(biosize - boff), uio->uio_resid);
again:
/*
* Handle direct append and file extension cases, calculate
* unaligned buffer size. When extending B_CACHE will be
* set if possible. See UIO_NOCOPY note below.
*/
fsize = puffs_meta_getsize(vp);
if (uio->uio_offset + bytes > fsize) {
trivial = (uio->uio_segflg != UIO_NOCOPY &&
uio->uio_offset <= fsize);
puffs_meta_setsize(vp, uio->uio_offset + bytes,
trivial);
}
bp = getblk(vp, loffset, biosize, 0, 0);
if (bp == NULL) {
error = EINTR;
break;
}
/*
* Actual bytes in buffer which we care about
*/
if (loffset + biosize < fsize)
bcount = biosize;
else
bcount = (int)(fsize - loffset);
/*
* Avoid a read by setting B_CACHE where the data we
* intend to write covers the entire buffer. Note
* that the buffer may have been set to B_CACHE by
* puffs_meta_setsize() above or otherwise inherited the
* flag, but if B_CACHE isn't set the buffer may be
* uninitialized and must be zero'd to accomodate
* future seek+write's.
*
* See the comments in kern/vfs_bio.c's getblk() for
* more information.
*
* When doing a UIO_NOCOPY write the buffer is not
* overwritten and we cannot just set B_CACHE unconditionally
* for full-block writes.
*/
if (boff == 0 && bytes == biosize &&
uio->uio_segflg != UIO_NOCOPY) {
bp->b_flags |= B_CACHE;
bp->b_flags &= ~(B_ERROR | B_INVAL);
}
/*
* b_resid may be set due to file EOF if we extended out.
* The NFS bio code will zero the difference anyway so
* just acknowledged the fact and set b_resid to 0.
*/
if ((bp->b_flags & B_CACHE) == 0) {
bp->b_cmd = BUF_CMD_READ;
bp->b_bio2.bio_done = puffs_iodone;
bp->b_bio2.bio_flags |= BIO_SYNC;
//.........这里部分代码省略.........
示例6: smbfs_setattr
int
smbfs_setattr(void *v)
{
struct vop_setattr_args /* {
struct vnode *a_vp;
struct vattr *a_vap;
kauth_cred_t a_cred;
} */ *ap = v;
struct lwp *l = curlwp;
struct vnode *vp = ap->a_vp;
struct smbnode *np = VTOSMB(vp);
struct vattr *vap = ap->a_vap;
struct timespec *mtime, *atime;
struct smb_cred scred;
struct smb_share *ssp = np->n_mount->sm_share;
struct smb_vc *vcp = SSTOVC(ssp);
u_quad_t tsize = 0;
int isreadonly, doclose, error = 0;
SMBVDEBUG0("\n");
if (vap->va_flags != VNOVAL)
return EOPNOTSUPP;
isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
/*
* Disallow write attempts if the filesystem is mounted read-only.
*/
if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
vap->va_mode != (mode_t)VNOVAL) && isreadonly)
return EROFS;
smb_makescred(&scred, l, ap->a_cred);
if (vap->va_size != VNOVAL) {
switch (vp->v_type) {
case VDIR:
return EISDIR;
case VREG:
break;
default:
return EINVAL;
};
if (isreadonly)
return EROFS;
doclose = 0;
tsize = np->n_size;
np->n_size = vap->va_size;
uvm_vnp_setsize(vp, vap->va_size);
if ((np->n_flag & NOPEN) == 0) {
error = smbfs_smb_open(np,
SMB_SM_DENYNONE|SMB_AM_OPENRW, &scred);
if (error == 0)
doclose = 1;
}
if (error == 0)
error = smbfs_smb_setfsize(np, vap->va_size, &scred);
if (doclose)
smbfs_smb_close(ssp, np->n_fid, NULL, &scred);
if (error) {
np->n_size = tsize;
uvm_vnp_setsize(vp, tsize);
return (error);
}
}
mtime = atime = NULL;
if (vap->va_mtime.tv_sec != VNOVAL)
mtime = &vap->va_mtime;
if (vap->va_atime.tv_sec != VNOVAL)
atime = &vap->va_atime;
if (mtime != atime) {
error = kauth_authorize_vnode(ap->a_cred,
KAUTH_VNODE_WRITE_TIMES, ap->a_vp, NULL,
genfs_can_chtimes(ap->a_vp, vap->va_vaflags,
VTOSMBFS(vp)->sm_args.uid, ap->a_cred));
if (error)
return (error);
#if 0
if (mtime == NULL)
mtime = &np->n_mtime;
if (atime == NULL)
atime = &np->n_atime;
#endif
/*
* If file is opened, then we can use handle based calls.
* If not, use path based ones.
*/
if ((np->n_flag & NOPEN) == 0) {
if (vcp->vc_flags & SMBV_WIN95) {
error = VOP_OPEN(vp, FWRITE, ap->a_cred);
if (!error) {
/* error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
VOP_GETATTR(vp, &vattr, ap->a_cred);*/
if (mtime)
np->n_mtime = *mtime;
VOP_CLOSE(vp, FWRITE, ap->a_cred);
}
} else if (SMB_CAPS(vcp) & SMB_CAP_NT_SMBS) {
error = smbfs_smb_setpattrNT(np, 0, mtime, atime, &scred);
} else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
} else {
//.........这里部分代码省略.........
示例7: xattr_dir_getattr
/* ARGSUSED */
static int
xattr_dir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
caller_context_t *ct)
{
timestruc_t now;
vnode_t *pvp;
int error;
error = xattr_dir_realdir(vp, &pvp, LOOKUP_XATTR, cr, ct);
if (error == 0) {
error = VOP_GETATTR(pvp, vap, 0, cr, ct);
if (error) {
return (error);
}
vap->va_nlink += XATTRDIR_NENTS;
vap->va_size += XATTRDIR_NENTS;
return (0);
}
/*
* There is no real xattr directory. Cobble together
* an entry using info from the parent object (if needed)
* plus information common to all xattrs.
*/
if (vap->va_mask & PARENT_ATTRMASK) {
vattr_t pvattr;
uint_t off_bits;
pvp = gfs_file_parent(vp);
(void) memset(&pvattr, 0, sizeof (pvattr));
pvattr.va_mask = PARENT_ATTRMASK;
error = VOP_GETATTR(pvp, &pvattr, 0, cr, ct);
if (error) {
return (error);
}
/*
* VOP_GETATTR() might have turned off some bits in
* pvattr.va_mask. This means that the underlying
* file system couldn't process those attributes.
* We need to make sure those bits get turned off
* in the vattr_t structure that gets passed back
* to the caller. Figure out which bits were turned
* off (if any) then set pvattr.va_mask before it
* gets copied to the vattr_t that the caller sees.
*/
off_bits = (pvattr.va_mask ^ PARENT_ATTRMASK) & PARENT_ATTRMASK;
pvattr.va_mask = vap->va_mask & ~off_bits;
*vap = pvattr;
}
vap->va_type = VDIR;
vap->va_mode = MAKEIMODE(vap->va_type, S_ISVTX | 0777);
vap->va_fsid = vp->v_vfsp->vfs_dev;
vap->va_nodeid = gfs_file_inode(vp);
vap->va_nlink = XATTRDIR_NENTS+2;
vap->va_size = vap->va_nlink;
gethrestime(&now);
vap->va_atime = now;
vap->va_blksize = 0;
vap->va_nblocks = 0;
vap->va_seq = 0;
return (0);
}
示例8: linux_sys_ioctl
/*
* Most ioctl command are just converted to their NetBSD values,
* and passed on. The ones that take structure pointers and (flag)
* values need some massaging.
*/
int
linux_sys_ioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(u_long) com;
syscallarg(void *) data;
} */
int error;
switch (LINUX_IOCGROUP(SCARG(uap, com))) {
case 'M':
switch(SCARG(uap, com)) {
case LINUX_MEGARAID_CMD:
case LINUX_MEGARAID_GET_AEN:
{
struct sys_ioctl_args ua;
u_long com = 0;
if (SCARG(uap, com) & IOC_IN)
com |= IOC_OUT;
if (SCARG(uap, com) & IOC_OUT)
com |= IOC_IN;
SCARG(&ua, fd) = SCARG(uap, fd);
SCARG(&ua, com) = SCARG(uap, com);
SCARG(&ua, com) &= ~IOC_DIRMASK;
SCARG(&ua, com) |= com;
SCARG(&ua, data) = SCARG(uap, data);
error = sys_ioctl(l, (const void *)&ua, retval);
break;
}
default:
error = oss_ioctl_mixer(l, LINUX_TO_OSS(uap), retval);
break;
}
break;
case 'Q':
error = oss_ioctl_sequencer(l, LINUX_TO_OSS(uap), retval);
break;
case 'P':
error = oss_ioctl_audio(l, LINUX_TO_OSS(uap), retval);
break;
case 'V': /* video4linux2 */
case 'd': /* drm */
{
struct sys_ioctl_args ua;
u_long com = 0;
if (SCARG(uap, com) & IOC_IN)
com |= IOC_OUT;
if (SCARG(uap, com) & IOC_OUT)
com |= IOC_IN;
SCARG(&ua, fd) = SCARG(uap, fd);
SCARG(&ua, com) = SCARG(uap, com);
SCARG(&ua, com) &= ~IOC_DIRMASK;
SCARG(&ua, com) |= com;
SCARG(&ua, data) = SCARG(uap, data);
error = sys_ioctl(l, (const void *)&ua, retval);
break;
}
case 'r': /* VFAT ioctls; not yet supported */
error = ENOSYS;
break;
case 'S':
error = linux_ioctl_cdrom(l, uap, retval);
break;
case 't':
case 'f':
error = linux_ioctl_termios(l, uap, retval);
break;
case 'm':
error = linux_ioctl_mtio(l, uap, retval);
break;
case 'T':
{
#if NSEQUENCER > 0
/* XXX XAX 2x check this. */
/*
* Both termios and the MIDI sequencer use 'T' to identify
* the ioctl, so we have to differentiate them in another
* way. We do it by indexing in the cdevsw with the major
* device number and check if that is the sequencer entry.
*/
bool is_sequencer = false;
struct file *fp;
struct vnode *vp;
struct vattr va;
extern const struct cdevsw sequencer_cdevsw;
if ((fp = fd_getfile(SCARG(uap, fd))) == NULL)
return EBADF;
if (fp->f_type == DTYPE_VNODE &&
(vp = (struct vnode *)fp->f_data) != NULL &&
vp->v_type == VCHR) {
vn_lock(vp, LK_SHARED | LK_RETRY);
error = VOP_GETATTR(vp, &va, l->l_cred);
VOP_UNLOCK(vp);
//.........这里部分代码省略.........
示例9: secadm_vnode_check_exec
int
secadm_vnode_check_exec(struct ucred *ucred, struct vnode *vp,
struct label *vplabel, struct image_params *imgp,
struct label *execlabel)
{
struct rm_priotracker tracker;
struct secadm_prison_entry *entry;
secadm_rule_t *rule;
struct vattr vap;
size_t i;
int err=0, flags=0;
entry = get_prison_list_entry(ucred->cr_prison->pr_name, 0);
if (entry == NULL)
return (0);
err = VOP_GETATTR(imgp->vp, &vap, ucred);
if (err)
return (err);
SPL_RLOCK(entry, tracker);
for (rule = entry->spl_rules; rule != NULL; rule = rule->sr_next) {
if (vap.va_fileid != rule->sr_inode)
continue;
if (strcmp(imgp->vp->v_mount->mnt_stat.f_mntonname,
rule->sr_mount))
continue;
for (i=0; i < rule->sr_nfeatures; i++) {
switch(rule->sr_features[i].sf_type) {
case pageexec_enabled:
flags |= PAX_NOTE_PAGEEXEC;
break;
case pageexec_disabled:
flags |= PAX_NOTE_NOPAGEEXEC;
break;
case mprotect_enabled:
flags |= PAX_NOTE_MPROTECT;
break;
case mprotect_disabled:
flags |= PAX_NOTE_NOMPROTECT;
break;
case segvguard_enabled:
flags |= PAX_NOTE_SEGVGUARD;
break;
case segvguard_disabled:
flags |= PAX_NOTE_NOSEGVGUARD;
break;
case aslr_enabled:
flags |= PAX_NOTE_ASLR;
break;
case aslr_disabled:
flags |= PAX_NOTE_NOASLR;
break;
case integriforce:
err = do_integriforce_check(rule, &vap, imgp->vp, ucred);
break;
#if __HardenedBSD_version > 21
case shlibrandom_enabled:
flags |= PAX_NOTE_SHLIBRANDOM;
break;
case shlibrandom_disabled:
flags |= PAX_NOTE_NOSHLIBRANDOM;
break;
#endif
default:
break;
}
}
break;
}
SPL_RUNLOCK(entry, tracker);
if (err == 0 && flags)
err = pax_elf(imgp, flags);
return (err);
}
示例10: check_exec
/*
* check exec:
* given an "executable" described in the exec package's namei info,
* see what we can do with it.
*
* ON ENTRY:
* exec package with appropriate namei info
* proc pointer of exec'ing proc
* NO SELF-LOCKED VNODES
*
* ON EXIT:
* error: nothing held, etc. exec header still allocated.
* ok: filled exec package, one locked vnode.
*
* EXEC SWITCH ENTRY:
* Locked vnode to check, exec package, proc.
*
* EXEC SWITCH EXIT:
* ok: return 0, filled exec package, one locked vnode.
* error: destructive:
* everything deallocated except exec header.
* non-destructive:
* error code, locked vnode, exec header unmodified
*/
int
check_exec(struct proc *p, struct exec_package *epp)
{
int error, i;
struct vnode *vp;
struct nameidata *ndp;
size_t resid;
ndp = epp->ep_ndp;
ndp->ni_cnd.cn_nameiop = LOOKUP;
ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF | SAVENAME;
/* first get the vnode */
if ((error = namei(ndp)) != 0)
return (error);
epp->ep_vp = vp = ndp->ni_vp;
/* check for regular file */
if (vp->v_type == VDIR) {
error = EISDIR;
goto bad1;
}
if (vp->v_type != VREG) {
error = EACCES;
goto bad1;
}
/* get attributes */
if ((error = VOP_GETATTR(vp, epp->ep_vap, p->p_ucred, p)) != 0)
goto bad1;
/* Check mount point */
if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
error = EACCES;
goto bad1;
}
if ((vp->v_mount->mnt_flag & MNT_NOSUID))
epp->ep_vap->va_mode &= ~(VSUID | VSGID);
/* check access. for root we have to see if any exec bit on */
if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0)
goto bad1;
if ((epp->ep_vap->va_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) {
error = EACCES;
goto bad1;
}
/* try to open it */
if ((error = VOP_OPEN(vp, FREAD, p->p_ucred, p)) != 0)
goto bad1;
/* unlock vp, we need it unlocked from here */
VOP_UNLOCK(vp, 0, p);
/* now we have the file, get the exec header */
error = vn_rdwr(UIO_READ, vp, epp->ep_hdr, epp->ep_hdrlen, 0,
UIO_SYSSPACE, 0, p->p_ucred, &resid, p);
if (error)
goto bad2;
epp->ep_hdrvalid = epp->ep_hdrlen - resid;
/*
* set up the vmcmds for creation of the process
* address space
*/
error = ENOEXEC;
for (i = 0; i < nexecs && error != 0; i++) {
int newerror;
if (execsw[i].es_check == NULL)
continue;
newerror = (*execsw[i].es_check)(p, epp);
if (!newerror && !(epp->ep_emul->e_flags & EMUL_ENABLED))
newerror = EPERM;
/* make sure the first "interesting" error code is saved. */
if (!newerror || error == ENOEXEC)
//.........这里部分代码省略.........
示例11: loadfirmware
int
loadfirmware(const char *name, u_char **bufp, size_t *buflen)
{
struct proc *p = curproc;
struct nameidata nid;
char *path, *ptr;
struct iovec iov;
struct uio uio;
struct vattr va;
int error;
if (!rootvp || !vcount(rootvp))
return (EIO);
path = malloc(MAXPATHLEN, M_TEMP, M_NOWAIT);
if (path == NULL)
return (ENOMEM);
if (snprintf(path, MAXPATHLEN, "/etc/firmware/%s", name) >=
MAXPATHLEN) {
error = ENAMETOOLONG;
goto err;
}
NDINIT(&nid, LOOKUP, NOFOLLOW|LOCKLEAF, UIO_SYSSPACE, path, p);
error = namei(&nid);
if (error)
goto err;
error = VOP_GETATTR(nid.ni_vp, &va, p->p_ucred);
if (error)
goto fail;
if (nid.ni_vp->v_type != VREG || va.va_size == 0) {
error = EINVAL;
goto fail;
}
if (va.va_size > FIRMWARE_MAX) {
error = E2BIG;
goto fail;
}
ptr = malloc(va.va_size, M_DEVBUF, M_NOWAIT);
if (ptr == NULL) {
error = ENOMEM;
goto fail;
}
iov.iov_base = ptr;
iov.iov_len = va.va_size;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
uio.uio_offset = 0;
uio.uio_resid = va.va_size;
uio.uio_segflg = UIO_SYSSPACE;
uio.uio_rw = UIO_READ;
uio.uio_procp = p;
error = VOP_READ(nid.ni_vp, &uio, 0, p->p_ucred);
if (error == 0) {
*bufp = ptr;
*buflen = va.va_size;
} else
free(ptr, M_DEVBUF, va.va_size);
fail:
vput(nid.ni_vp);
err:
free(path, M_TEMP, MAXPATHLEN);
return (error);
}
示例12: smbfs_open
/* ARGSUSED */
int
smbfs_open(void *v)
{
struct vop_open_args /* {
struct vnode *a_vp;
int a_mode;
kauth_cred_t a_cred;
} */ *ap = v;
struct lwp *l = curlwp;
struct vnode *vp = ap->a_vp;
struct smbnode *np = VTOSMB(vp);
struct smb_cred scred;
struct vattr vattr;
u_int32_t sv_caps = SMB_CAPS(SSTOVC(np->n_mount->sm_share));
int error, accmode;
SMBVDEBUG("%.*s,%d\n", (int) np->n_nmlen, np->n_name,
(np->n_flag & NOPEN) != 0);
if (vp->v_type != VREG && vp->v_type != VDIR) {
SMBFSERR("open eacces vtype=%d\n", vp->v_type);
return EACCES;
}
if (vp->v_type == VDIR) {
if ((sv_caps & SMB_CAP_NT_SMBS) == 0) {
np->n_flag |= NOPEN;
return 0;
}
goto do_open; /* skip 'modified' check */
}
if (np->n_flag & NMODIFIED) {
if ((error = smbfs_vinvalbuf(vp, V_SAVE, ap->a_cred, l, 1)) == EINTR)
return error;
smbfs_attr_cacheremove(vp);
error = VOP_GETATTR(vp, &vattr, ap->a_cred);
if (error)
return error;
np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
} else {
error = VOP_GETATTR(vp, &vattr, ap->a_cred);
if (error)
return error;
if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
error = smbfs_vinvalbuf(vp, V_SAVE, ap->a_cred, l, 1);
if (error == EINTR)
return error;
np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
}
}
do_open:
if ((np->n_flag & NOPEN) != 0)
return 0;
smb_makescred(&scred, l, ap->a_cred);
if (vp->v_type == VDIR)
error = smbfs_smb_ntcreatex(np,
SMB_SM_DENYNONE|SMB_AM_OPENREAD, &scred);
else {
/*
* Use DENYNONE to give unixy semantics of permitting
* everything not forbidden by permissions. Ie denial
* is up to server with clients/openers needing to use
* advisory locks for further control.
*/
accmode = SMB_SM_DENYNONE|SMB_AM_OPENREAD;
if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
accmode = SMB_SM_DENYNONE|SMB_AM_OPENRW;
error = smbfs_smb_open(np, accmode, &scred);
if (error) {
if (ap->a_mode & FWRITE)
return EACCES;
error = smbfs_smb_open(np,
SMB_SM_DENYNONE|SMB_AM_OPENREAD, &scred);
}
}
if (!error)
np->n_flag |= NOPEN;
smbfs_attr_cacheremove(vp);
return error;
}
示例13: xfs_fhlookup
int
xfs_fhlookup (d_thread_t *proc,
struct xfs_fhandle_t *fhp,
struct vnode **vpp)
{
int error;
struct mount *mp;
#if !(defined(HAVE_GETFH) && defined(HAVE_FHOPEN))
struct ucred *cred = proc->p_ucred;
struct vattr vattr;
fsid_t fsid;
struct xfs_fh_args *fh_args = (struct xfs_fh_args *)fhp->fhdata;
NNPFSDEB(XDEBVFOPS, ("xfs_fhlookup (xfs)\n"));
error = xfs_suser (proc);
if (error)
return EPERM;
if (fhp->len < sizeof(struct xfs_fh_args))
return EINVAL;
fsid = SCARG(fh_args, fsid);
mp = xfs_vfs_getvfs (&fsid);
if (mp == NULL)
return ENXIO;
#ifdef __APPLE__
{
uint32_t ino = SCARG(fh_args, fileid);
error = VFS_VGET(mp, &ino, vpp);
}
#else
error = VFS_VGET(mp, SCARG(fh_args, fileid), vpp);
#endif
if (error)
return error;
if (*vpp == NULL)
return ENOENT;
error = VOP_GETATTR(*vpp, &vattr, cred, proc);
if (error) {
vput(*vpp);
return error;
}
if (vattr.va_gen != SCARG(fh_args, gen)) {
vput(*vpp);
return ENOENT;
}
#else /* HAVE_GETFH && HAVE_FHOPEN */
{
fhandle_t *fh = (fhandle_t *) fhp;
NNPFSDEB(XDEBVFOPS, ("xfs_fhlookup (native)\n"));
mp = xfs_vfs_getvfs (&fh->fh_fsid);
if (mp == NULL)
return ESTALE;
if ((error = VFS_FHTOVP(mp, &fh->fh_fid, vpp)) != 0) {
*vpp = NULL;
return error;
}
}
#endif /* HAVE_GETFH && HAVE_FHOPEN */
#ifdef HAVE_KERNEL_VFS_OBJECT_CREATE
if ((*vpp)->v_type == VREG && (*vpp)->v_object == NULL)
#ifdef HAVE_FREEBSD_THREAD
xfs_vfs_object_create (*vpp, proc, proc->td_proc->p_ucred);
#else
xfs_vfs_object_create (*vpp, proc, proc->p_ucred);
#endif
#elif __APPLE__
if ((*vpp)->v_type == VREG && (!UBCINFOEXISTS(*vpp))) {
ubc_info_init(*vpp);
}
ubc_hold(*vpp);
#endif
return 0;
}
示例14: smbfs_node_alloc
static int
smbfs_node_alloc(struct mount *mp, struct vnode *dvp,
const char *name, int nmlen, struct smbfattr *fap, struct vnode **vpp)
{
struct vattr vattr;
struct thread *td = curthread; /* XXX */
struct smbmount *smp = VFSTOSMBFS(mp);
struct smbnode_hashhead *nhpp;
struct smbnode *np, *np2, *dnp;
struct vnode *vp;
u_long hashval;
int error;
*vpp = NULL;
if (smp->sm_root != NULL && dvp == NULL) {
SMBERROR("do not allocate root vnode twice!\n");
return EINVAL;
}
if (nmlen == 2 && bcmp(name, "..", 2) == 0) {
if (dvp == NULL)
return EINVAL;
vp = VTOSMB(VTOSMB(dvp)->n_parent)->n_vnode;
error = vget(vp, LK_EXCLUSIVE, td);
if (error == 0)
*vpp = vp;
return error;
} else if (nmlen == 1 && name[0] == '.') {
SMBERROR("do not call me with dot!\n");
return EINVAL;
}
dnp = dvp ? VTOSMB(dvp) : NULL;
if (dnp == NULL && dvp != NULL) {
vprint("smbfs_node_alloc: dead parent vnode", dvp);
return EINVAL;
}
hashval = smbfs_hash(name, nmlen);
retry:
smbfs_hash_lock(smp);
loop:
nhpp = SMBFS_NOHASH(smp, hashval);
LIST_FOREACH(np, nhpp, n_hash) {
vp = SMBTOV(np);
if (np->n_parent != dvp ||
np->n_nmlen != nmlen || bcmp(name, np->n_name, nmlen) != 0)
continue;
VI_LOCK(vp);
smbfs_hash_unlock(smp);
if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td) != 0)
goto retry;
/* Force cached attributes to be refreshed if stale. */
(void)VOP_GETATTR(vp, &vattr, td->td_ucred);
/*
* If the file type on the server is inconsistent with
* what it was when we created the vnode, kill the
* bogus vnode now and fall through to the code below
* to create a new one with the right type.
*/
if ((vp->v_type == VDIR && (np->n_dosattr & SMB_FA_DIR) == 0) ||
(vp->v_type == VREG && (np->n_dosattr & SMB_FA_DIR) != 0)) {
vgone(vp);
vput(vp);
break;
}
*vpp = vp;
return 0;
}
示例15: xattr_fill_nvlist
//.........这里部分代码省略.........
XVA_SET_REQ(&xvattr, XAT_AV_MODIFIED);
break;
case F_AV_SCANSTAMP:
if (ppvp->v_type == VREG)
XVA_SET_REQ(&xvattr, XAT_AV_SCANSTAMP);
break;
case F_CRTIME:
XVA_SET_REQ(&xvattr, XAT_CREATETIME);
break;
case F_FSID:
fsid = (((uint64_t)vp->v_vfsp->vfs_fsid.val[0] << 32) |
(uint64_t)(vp->v_vfsp->vfs_fsid.val[1] &
0xffffffff));
VERIFY(nvlist_add_uint64(nvlp, attr_to_name(attr),
fsid) == 0);
break;
case F_REPARSE:
XVA_SET_REQ(&xvattr, XAT_REPARSE);
break;
case F_GEN:
XVA_SET_REQ(&xvattr, XAT_GEN);
break;
case F_OFFLINE:
XVA_SET_REQ(&xvattr, XAT_OFFLINE);
break;
case F_SPARSE:
XVA_SET_REQ(&xvattr, XAT_SPARSE);
break;
default:
break;
}
}
error = VOP_GETATTR(ppvp, &xvattr.xva_vattr, 0, cr, ct);
if (error)
return (error);
/*
* Process all the optional attributes together here. Notice that
* xoap was set when the optional attribute bits were set above.
*/
if ((xvattr.xva_vattr.va_mask & AT_XVATTR) && xoap) {
if (XVA_ISSET_RTN(&xvattr, XAT_READONLY)) {
VERIFY(nvlist_add_boolean_value(nvlp,
attr_to_name(F_READONLY),
xoap->xoa_readonly) == 0);
}
if (XVA_ISSET_RTN(&xvattr, XAT_HIDDEN)) {
VERIFY(nvlist_add_boolean_value(nvlp,
attr_to_name(F_HIDDEN),
xoap->xoa_hidden) == 0);
}
if (XVA_ISSET_RTN(&xvattr, XAT_SYSTEM)) {
VERIFY(nvlist_add_boolean_value(nvlp,
attr_to_name(F_SYSTEM),
xoap->xoa_system) == 0);
}
if (XVA_ISSET_RTN(&xvattr, XAT_ARCHIVE)) {
VERIFY(nvlist_add_boolean_value(nvlp,
attr_to_name(F_ARCHIVE),
xoap->xoa_archive) == 0);
}
if (XVA_ISSET_RTN(&xvattr, XAT_IMMUTABLE)) {
VERIFY(nvlist_add_boolean_value(nvlp,
attr_to_name(F_IMMUTABLE),
xoap->xoa_immutable) == 0);