1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1999-2001 Robert N. M. Watson 5 * All rights reserved. 6 * 7 * This software was developed by Robert Watson for the TrustedBSD Project. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 */ 32 /* 33 * Developed by the TrustedBSD Project. 34 * Support for extended filesystem attributes. 35 */ 36 37 #ifndef _UFS_UFS_EXTATTR_H_ 38 #define _UFS_UFS_EXTATTR_H_ 39 40 #define UFS_EXTATTR_MAGIC 0x00b5d5ec 41 #define UFS_EXTATTR_VERSION 0x00000003 42 #define UFS_EXTATTR_FSROOTSUBDIR ".attribute" 43 #define UFS_EXTATTR_SUBDIR_SYSTEM "system" 44 #define UFS_EXTATTR_SUBDIR_USER "user" 45 #define UFS_EXTATTR_MAXEXTATTRNAME 65 /* including null */ 46 47 #define UFS_EXTATTR_ATTR_FLAG_INUSE 0x00000001 /* attr has been set */ 48 #define UFS_EXTATTR_PERM_KERNEL 0x00000000 49 #define UFS_EXTATTR_PERM_ROOT 0x00000001 50 #define UFS_EXTATTR_PERM_OWNER 0x00000002 51 #define UFS_EXTATTR_PERM_ANYONE 0x00000003 52 53 #define UFS_EXTATTR_UEPM_INITIALIZED 0x00000001 54 #define UFS_EXTATTR_UEPM_STARTED 0x00000002 55 56 #define UFS_EXTATTR_CMD_START 0x00000001 57 #define UFS_EXTATTR_CMD_STOP 0x00000002 58 #define UFS_EXTATTR_CMD_ENABLE 0x00000003 59 #define UFS_EXTATTR_CMD_DISABLE 0x00000004 60 61 struct ufs_extattr_fileheader { 62 u_int uef_magic; /* magic number for sanity checking */ 63 u_int uef_version; /* version of attribute file */ 64 u_int uef_size; /* size of attributes, w/o header */ 65 }; 66 67 struct ufs_extattr_header { 68 u_int ueh_flags; /* flags for attribute */ 69 u_int ueh_len; /* local defined length; <= uef_size */ 70 u_int32_t ueh_i_gen; /* generation number for sanity */ 71 /* data follows the header */ 72 }; 73 74 /* 75 * This structure defines the required fields of an extended-attribute header. 76 */ 77 struct extattr { 78 uint32_t ea_length; /* length of this attribute */ 79 uint8_t ea_namespace; /* name space of this attribute */ 80 uint8_t ea_contentpadlen; /* bytes of padding at end of attribute */ 81 uint8_t ea_namelength; /* length of attribute name */ 82 char ea_name[1]; /* attribute name (NOT nul-terminated) */ 83 /* padding, if any, to align attribute content to 8 byte boundary */ 84 /* extended attribute content follows */ 85 }; 86 87 /* 88 * These macros are used to access and manipulate an extended attribute: 89 * 90 * EXTATTR_NEXT(eap) returns a pointer to the next extended attribute 91 * following eap. 92 * EXTATTR_CONTENT(eap) returns a pointer to the extended attribute 93 * content referenced by eap. 94 * EXTATTR_CONTENT_SIZE(eap) returns the size of the extended attribute 95 * content referenced by eap. 96 */ 97 #define EXTATTR_NEXT(eap) \ 98 ((struct extattr *)(((u_char *)(eap)) + (eap)->ea_length)) 99 #define EXTATTR_CONTENT(eap) \ 100 (void *)(((u_char *)(eap)) + EXTATTR_BASE_LENGTH(eap)) 101 #define EXTATTR_CONTENT_SIZE(eap) \ 102 ((eap)->ea_length - EXTATTR_BASE_LENGTH(eap) - (eap)->ea_contentpadlen) 103 /* -1 below compensates for ea_name[1] */ 104 #define EXTATTR_BASE_LENGTH(eap) \ 105 roundup2((sizeof(struct extattr) - 1 + (eap)->ea_namelength), 8) 106 107 #ifdef _KERNEL 108 109 #include <sys/_sx.h> 110 111 struct vnode; 112 LIST_HEAD(ufs_extattr_list_head, ufs_extattr_list_entry); 113 struct ufs_extattr_list_entry { 114 LIST_ENTRY(ufs_extattr_list_entry) uele_entries; 115 struct ufs_extattr_fileheader uele_fileheader; 116 int uele_attrnamespace; 117 char uele_attrname[UFS_EXTATTR_MAXEXTATTRNAME]; 118 struct vnode *uele_backing_vnode; 119 }; 120 121 struct ucred; 122 struct ufs_extattr_per_mount { 123 struct sx uepm_lock; 124 struct ufs_extattr_list_head uepm_list; 125 struct ucred *uepm_ucred; 126 int uepm_flags; 127 }; 128 129 struct vop_getextattr_args; 130 struct vop_deleteextattr_args; 131 struct vop_setextattr_args; 132 133 void ufs_extattr_uepm_init(struct ufs_extattr_per_mount *uepm); 134 void ufs_extattr_uepm_destroy(struct ufs_extattr_per_mount *uepm); 135 int ufs_extattr_start(struct mount *mp, struct thread *td); 136 int ufs_extattr_autostart(struct mount *mp, struct thread *td); 137 int ufs_extattr_stop(struct mount *mp, struct thread *td); 138 int ufs_extattrctl(struct mount *mp, int cmd, struct vnode *filename, 139 int attrnamespace, const char *attrname); 140 int ufs_getextattr(struct vop_getextattr_args *ap); 141 int ufs_deleteextattr(struct vop_deleteextattr_args *ap); 142 int ufs_setextattr(struct vop_setextattr_args *ap); 143 void ufs_extattr_vnode_inactive(struct vnode *vp, struct thread *td); 144 145 #endif /* !_KERNEL */ 146 147 #endif /* !_UFS_UFS_EXTATTR_H_ */ 148