From a9093e846d7be8771b7ed509c37bb39cec26c565 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Tue, 6 Mar 2007 08:13:21 +0000 Subject: [PATCH] Move macros describing extended attributes in UFS from to . Move description of extended attributes in UFS from man9/extattr.9 to man5/fs.5. Note that restore will not compile until and have been updated. Suggested by: Robert Watson --- sbin/restore/tape.c | 1 + share/man/man5/fs.5 | 59 +++++++++++++++++++++++++++++++++++++++- share/man/man9/extattr.9 | 55 ------------------------------------- sys/sys/extattr.h | 47 -------------------------------- sys/ufs/ufs/extattr.h | 49 +++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 103 deletions(-) diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 15c204ac9cbd..6afa591081bf 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include diff --git a/share/man/man5/fs.5 b/share/man/man5/fs.5 index 559bf65e45eb..abb0f470bf8e 100644 --- a/share/man/man5/fs.5 +++ b/share/man/man5/fs.5 @@ -45,8 +45,11 @@ .Pp .In sys/types.h .In sys/lock.h +.In sys/extattr.h +.In sys/acl.h .In ufs/ufs/quota.h -.In ufs/ufs/inode.h +.In ufs/ufs/dinode.h +.In ufs/ufs/extattr.h .Sh DESCRIPTION The files .In fs.h @@ -385,6 +388,60 @@ text file, and the root. An inode is `named' by its device/i-number pair. For further information, see the include file .In ufs/ufs/inode.h . +.Pp +The format of an external attribute is defined by the extattr structure: +.Bd -literal +struct extattr { + int32_t ea_length; /* length of this attribute */ + int8_t ea_namespace; /* name space of this attribute */ + int8_t ea_contentpadlen; /* padding at end of attribute */ + int8_t ea_namelength; /* length of attribute name */ + char ea_name[1]; /* null-terminated attribute name */ + /* extended attribute content follows */ +}; +.Ed +.Pp +Several macros are defined to manipulate these structures. +Each macro takes a pointer to an extattr structure. +.Bl -tag -width ".Dv EXTATTR_SET_LENGTHS(eap, size)" +.It Dv EXTATTR_NEXT(eap) +Returns a pointer to the next extended attribute following +.Fa eap . +.It Dv EXTATTR_CONTENT(eap) +Returns a pointer to the extended attribute content referenced by +.Fa eap . +.It Dv EXTATTR_CONTENT_SIZE(eap) +Returns the size of the extended attribute content referenced by +.Fa eap . +.It Dv EXTATTR_SET_LENGTHS(eap, size) +Called with the size of the attribute content after initializing +the attribute name to calculate and set the +.Fa ea_length , +.Fa ea_namelength , +and +.Fa ea_contentpadlen +fields of the extended attribute structure. +.El +.Pp +The following code identifies an ACL: +.Bd -literal + if (eap->ea_namespace == EXTATTR_NAMESPACE_SYSTEM && + !strcmp(eap->ea_name, POSIX1E_ACL_ACCESS_EXTATTR_NAME) { + aclp = EXTATTR_CONTENT(eap); + acllen = EXTATTR_CONTENT_SIZE(eap); + ... + } +.Ed +.Pp +The following code creates an extended attribute +containing a copy of a structure +.Fa mygif : +.Bd -literal + eap->ea_namespace = EXTATTR_NAMESPACE_USER; + strcpy(eap->ea_name, "filepic.gif"); + EXTATTR_SET_LENGTHS(eap, sizeof(struct mygif)); + memcpy(EXTATTR_CONTENT(eap), &mygif, sizeof(struct mygif)); +.Ed .Sh HISTORY A super-block structure named filsys appeared in .At v6 . diff --git a/share/man/man9/extattr.9 b/share/man/man9/extattr.9 index 17dc127c21c8..9c74a60bf9bc 100644 --- a/share/man/man9/extattr.9 +++ b/share/man/man9/extattr.9 @@ -78,61 +78,6 @@ Appropriate vnode extended attribute calls are: .Xr VOP_LISTEXTATTR 9 , and .Xr VOP_SETEXTATTR 9 . -.Pp -The format of an external attribute is defined by the extattr structure: -.Bd -literal -struct extattr { - int32_t ea_length; /* length of this attribute */ - int8_t ea_namespace; /* name space of this attribute */ - int8_t ea_contentpadlen; /* padding at end of attribute */ - int8_t ea_namelength; /* length of attribute name */ - char ea_name[1]; /* null-terminated attribute name */ - /* extended attribute content follows */ -}; -.Ed -.Pp -Several macros are defined to manipulate these structures. -Each macro takes a pointer to an extattr structure. -.Bl -tag -width ".Dv EXTATTR_SET_LENGTHS(eap, size)" -.It Dv EXTATTR_NEXT(eap) -Returns a pointer to the next extended attribute following -.Fa eap . -.It Dv EXTATTR_CONTENT(eap) -Returns a pointer to the extended attribute content referenced by -.Fa eap . -.It Dv EXTATTR_CONTENT_SIZE(eap) -Returns the size of the extended attribute content referenced by -.Fa eap . -.It Dv EXTATTR_SET_LENGTHS(eap, size) -Called with the size of the attribute content after initializing -the attribute name to calculate and set the -.Fa ea_length , -.Fa ea_namelength , -and -.Fa ea_contentpadlen -fields of the extended attribute structure. -.El -.Pp -The following code identifies an ACL: -.Bd -literal - if (eap->ea_namespace == EXTATTR_NAMESPACE_SYSTEM && - !strcmp(eap->ea_name, POSIX1E_ACL_ACCESS_EXTATTR_NAME) { - aclp = EXTATTR_CONTENT(eap); - acllen = EXTATTR_CONTENT_SIZE(eap); - ... - } -.Ed -.Pp -The following code creates an extended attribute -containing a copy of a structure -.Fa mygif : -.Bd -literal - eap->ea_namespace = EXTATTR_NAMESPACE_USER; - strcpy(eap->ea_name, "filepic.gif"); - EXTATTR_SET_LENGTHS(eap, sizeof(struct mygif)); - memcpy(EXTATTR_CONTENT(eap), &mygif, sizeof(struct mygif)); -.Ed -.Pp .Sh SEE ALSO .Xr VFS 9 , .Xr VFS_EXTATTRCTL 9 , diff --git a/sys/sys/extattr.h b/sys/sys/extattr.h index ece538582b40..678c0cf99ad0 100644 --- a/sys/sys/extattr.h +++ b/sys/sys/extattr.h @@ -56,48 +56,6 @@ EXTATTR_NAMESPACE_USER_STRING, \ EXTATTR_NAMESPACE_SYSTEM_STRING } -/* - * This structure defines the required fields of an extended-attribute header. - */ -struct extattr { - int32_t ea_length; /* length of this attribute */ - int8_t ea_namespace; /* name space of this attribute */ - int8_t ea_contentpadlen; /* bytes of padding at end of attribute */ - int8_t ea_namelength; /* length of attribute name */ - char ea_name[1]; /* null-terminated attribute name */ - /* extended attribute content follows */ -}; - -/* - * These macros are used to access and manipulate an extended attribute: - * - * EXTATTR_NEXT(eap) returns a pointer to the next extended attribute - * following eap. - * EXTATTR_CONTENT(eap) returns a pointer to the extended attribute - * content referenced by eap. - * EXTATTR_CONTENT_SIZE(eap) returns the size of the extended attribute - * content referenced by eap. - * EXTATTR_SET_LENGTHS(eap, contentsize) called after initializing the - * attribute name to calculate and set the ea_length, ea_namelength, - * and ea_contentpadlen fields of the extended attribute structure. - */ -#define EXTATTR_NEXT(eap) \ - ((struct extattr *)(((void *)(eap)) + (eap)->ea_length)) -#define EXTATTR_CONTENT(eap) (((void *)(eap)) + EXTATTR_BASE_LENGTH(eap)) -#define EXTATTR_CONTENT_SIZE(eap) \ - ((eap)->ea_length - EXTATTR_BASE_LENGTH(eap) - (eap)->ea_contentpadlen) -#define EXTATTR_BASE_LENGTH(eap) \ - ((sizeof(struct extattr) + (eap)->ea_namelength + 7) & ~7) -#define EXTATTR_SET_LENGTHS(eap, contentsize) do { \ - KASSERT(((eap)->ea_name[0] != 0), \ - ("Must initialize name before setting lengths")); \ - (eap)->ea_namelength = strlen((eap)->ea_name); \ - (eap)->ea_contentpadlen = ((contentsize) % 8) ? \ - 8 - ((contentsize) % 8) : 0; \ - (eap)->ea_length = EXTATTR_BASE_LENGTH(eap) + \ - (contentsize) + (eap)->ea_contentpadlen; \ -} while (0) - #ifdef _KERNEL #define EXTATTR_MAXNAMELEN NAME_MAX @@ -110,11 +68,6 @@ int extattr_check_cred(struct vnode *vp, int attrnamespace, #else #include -/* User-level definition of KASSERT for macros above */ -#define KASSERT(cond, str) do { \ - if (!(cond)) { printf("panic: "); printf(str); printf("\n"); exit(1); }\ -} while (0) - struct iovec; __BEGIN_DECLS diff --git a/sys/ufs/ufs/extattr.h b/sys/ufs/ufs/extattr.h index cf3222767172..c1ceee58e738 100644 --- a/sys/ufs/ufs/extattr.h +++ b/sys/ufs/ufs/extattr.h @@ -69,6 +69,48 @@ struct ufs_extattr_header { /* data follows the header */ }; +/* + * This structure defines the required fields of an extended-attribute header. + */ +struct extattr { + int32_t ea_length; /* length of this attribute */ + int8_t ea_namespace; /* name space of this attribute */ + int8_t ea_contentpadlen; /* bytes of padding at end of attribute */ + int8_t ea_namelength; /* length of attribute name */ + char ea_name[1]; /* null-terminated attribute name */ + /* extended attribute content follows */ +}; + +/* + * These macros are used to access and manipulate an extended attribute: + * + * EXTATTR_NEXT(eap) returns a pointer to the next extended attribute + * following eap. + * EXTATTR_CONTENT(eap) returns a pointer to the extended attribute + * content referenced by eap. + * EXTATTR_CONTENT_SIZE(eap) returns the size of the extended attribute + * content referenced by eap. + * EXTATTR_SET_LENGTHS(eap, contentsize) called after initializing the + * attribute name to calculate and set the ea_length, ea_namelength, + * and ea_contentpadlen fields of the extended attribute structure. + */ +#define EXTATTR_NEXT(eap) \ + ((struct extattr *)(((void *)(eap)) + (eap)->ea_length)) +#define EXTATTR_CONTENT(eap) (((void *)(eap)) + EXTATTR_BASE_LENGTH(eap)) +#define EXTATTR_CONTENT_SIZE(eap) \ + ((eap)->ea_length - EXTATTR_BASE_LENGTH(eap) - (eap)->ea_contentpadlen) +#define EXTATTR_BASE_LENGTH(eap) \ + ((sizeof(struct extattr) + (eap)->ea_namelength + 7) & ~7) +#define EXTATTR_SET_LENGTHS(eap, contentsize) do { \ + KASSERT(((eap)->ea_name[0] != 0), \ + ("Must initialize name before setting lengths")); \ + (eap)->ea_namelength = strlen((eap)->ea_name); \ + (eap)->ea_contentpadlen = ((contentsize) % 8) ? \ + 8 - ((contentsize) % 8) : 0; \ + (eap)->ea_length = EXTATTR_BASE_LENGTH(eap) + \ + (contentsize) + (eap)->ea_contentpadlen; \ +} while (0) + #ifdef _KERNEL #ifdef MALLOC_DECLARE @@ -106,6 +148,13 @@ int ufs_deleteextattr(struct vop_deleteextattr_args *ap); int ufs_setextattr(struct vop_setextattr_args *ap); void ufs_extattr_vnode_inactive(struct vnode *vp, struct thread *td); +#else + +/* User-level definition of KASSERT for macros above */ +#define KASSERT(cond, str) do { \ + if (!(cond)) { printf("panic: "); printf(str); printf("\n"); exit(1); }\ +} while (0) + #endif /* !_KERNEL */ #endif /* !_UFS_UFS_EXTATTR_H_ */