소스 검색

HBSD: First stab at listing extended attributes

Some magic is going on behind-the-scenes and I'm unsure why. More
research is needed.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
remotes/github/hardened/current/tmpfs_extattr
Shawn Webb 3 달 전
부모
커밋
65e86961fd
1개의 변경된 파일67개의 추가작업 그리고 2개의 파일을 삭제
  1. +67
    -2
      sys/fs/tmpfs/tmpfs_vnops.c

+ 67
- 2
sys/fs/tmpfs/tmpfs_vnops.c 파일 보기

@@ -79,6 +79,11 @@ static int tmpfs_extattr_set(struct vnode *, int, const char *,
static int tmpfs_extattr_get(struct vnode *, int, const char *,
struct uio *, size_t *, struct ucred *, struct thread *);

static int tmpfs_listextattr(struct vop_listextattr_args *);

static int tmpfs_extattr_list(struct vnode *, int, struct uio *,
size_t *, struct ucred *, struct thread *);

static int
tmpfs_vn_get_ino_alloc(struct mount *mp, void *arg, int lkflags,
struct vnode **rvp)
@@ -1707,19 +1712,27 @@ tmpfs_extattr_set(struct vnode *vp, int attrnamespace, const char *name,
return (EINVAL);
}

if (strlen(name) == 0) {
return (EINVAL);
}

if (strlen(name) >= TMPFS_EXTATTR_MAXNAME) {
return (EINVAL);
}

node = VP_TO_TMPFS_NODE(vp);

attr = tmpfs_node_has_extattr(node, attrnamespace, name);
if (attr == NULL) {
sz = MIN(TMPFS_EXTATTR_MAXVALUESIZE, uio->uio_resid);
attr = malloc(sizeof(*attr), M_TEMP, M_WAITOK);
attr = malloc(sizeof(*attr), M_TEMP, M_WAITOK|M_ZERO);
memset(attr, 0, sizeof(*attr));

attr->tele_value = malloc(sz, M_TEMP, M_WAITOK);
attr->tele_value_size = sz;
attr->tele_attrnamespace = attrnamespace;
strncpy(attr->tele_attrname, name,
sizeof(attr->tele_attrname));
sizeof(attr->tele_attrname)-1);

uiomove(attr->tele_value, sz, uio);

@@ -1730,6 +1743,57 @@ tmpfs_extattr_set(struct vnode *vp, int attrnamespace, const char *name,
return (0);
}

static int
tmpfs_listextattr(struct vop_listextattr_args *ap)
{

return tmpfs_extattr_list(ap->a_vp, ap->a_attrnamespace,
ap->a_uio, ap->a_size, ap->a_cred, ap->a_td);
}

static int
tmpfs_extattr_list(struct vnode *vp, int attrnamespace, struct uio *uio,
size_t *size, struct ucred *cred, struct thread *td)
{
struct tmpfs_extattr_list_entry *attr, *tattr;
struct tmpfs_node *node;
size_t namelen;
int error;

error = 0;

if (vp->v_type != VREG) {
return (EOPNOTSUPP);
}

node = VP_TO_TMPFS_NODE(vp);

if (size) {
*size = 0;
}

LIST_FOREACH_SAFE(attr, &(node->tn_reg.tn_extattr_list),
tele_entries, tattr) {
if (attr->tele_attrnamespace != attrnamespace) {
continue;
}

namelen = strlen(attr->tele_attrname);
if (size) {
*size += namelen + 1;
} else if (uio != NULL) {
error = uiomove(&(attr->tele_attrname), namelen + 1,
uio);
}

if (error) {
break;
}
}

return (error);
}

/*
* Vnode operations vector used for files stored in a tmpfs file system.
*/
@@ -1746,6 +1810,7 @@ struct vop_vector tmpfs_vnodeop_entries = {
.vop_setattr = tmpfs_setattr,
.vop_getextattr = tmpfs_getextattr,
.vop_setextattr = tmpfs_setextattr,
.vop_listextattr = tmpfs_listextattr,
.vop_read = tmpfs_read,
.vop_write = tmpfs_write,
.vop_fsync = tmpfs_fsync,


불러오는 중...
취소
저장