xref: /minix/sys/ufs/ufs/extattr.h (revision 0a6a1f1d)
1 /*	$NetBSD: extattr.h,v 1.11 2014/12/19 10:59:21 manu Exp $	*/
2 
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: src/sys/ufs/ufs/extattr.h,v 1.20 2005/01/31 08:16:45 imp Exp $
31  */
32 
33 /*
34  * Support for file system extended attributes on the UFS1 file system.
35  * Developed by the TrustedBSD Project.
36  */
37 
38 #ifndef _UFS_UFS_EXTATTR_H_
39 #define	_UFS_UFS_EXTATTR_H_
40 
41 #define	UFS_EXTATTR_MAGIC		0x00b5d5ec
42 #define	UFS_EXTATTR_VERSION		0x00000003
43 #define	UFS_EXTATTR_FSROOTSUBDIR	".attribute"
44 #define	UFS_EXTATTR_SUBDIR_SYSTEM	"system"
45 #define	UFS_EXTATTR_SUBDIR_USER		"user"
46 #define	UFS_EXTATTR_MAXEXTATTRNAME	256	/* including null */
47 
48 #define	UFS_EXTATTR_ATTR_FLAG_INUSE	0x00000001	/* attr has been set */
49 #define	UFS_EXTATTR_PERM_KERNEL		0x00000000
50 #define	UFS_EXTATTR_PERM_ROOT		0x00000001
51 #define	UFS_EXTATTR_PERM_OWNER		0x00000002
52 #define	UFS_EXTATTR_PERM_ANYONE		0x00000003
53 
54 #define	UFS_EXTATTR_UEPM_INITIALIZED	0x00000001
55 #define	UFS_EXTATTR_UEPM_STARTED	0x00000002
56 
57 #define	UFS_EXTATTR_CMD_START		EXTATTR_CMD_START
58 #define	UFS_EXTATTR_CMD_STOP		EXTATTR_CMD_STOP
59 #define	UFS_EXTATTR_CMD_ENABLE		0x00000003
60 #define	UFS_EXTATTR_CMD_DISABLE		0x00000004
61 
62 struct ufs_extattr_fileheader {
63 	uint32_t	uef_magic;	/* magic number for sanity checking */
64 	uint32_t	uef_version;	/* version of attribute file */
65 	uint32_t	uef_size;	/* size of attributes, w/o header */
66 };
67 
68 struct ufs_extattr_header {
69 	uint32_t	ueh_flags;	/* flags for attribute */
70 	uint32_t	ueh_len;	/* local defined length; <= uef_size */
71 	uint32_t	ueh_i_gen;	/* generation number for sanity */
72 	/* data follows the header */
73 };
74 
75 #ifdef _KERNEL
76 
77 #ifdef MALLOC_DECLARE
78 MALLOC_DECLARE(M_EXTATTR);
79 #endif
80 
81 struct vnode;
82 LIST_HEAD(ufs_extattr_list_head, ufs_extattr_list_entry);
83 struct ufs_extattr_list_entry {
84 	LIST_ENTRY(ufs_extattr_list_entry)	uele_entries;
85 	struct ufs_extattr_fileheader		uele_fileheader;
86 	int		uele_attrnamespace;
87 	char		uele_attrname[UFS_EXTATTR_MAXEXTATTRNAME];
88 	struct vnode	*uele_backing_vnode;
89 	int		uele_flags;
90 };
91 
92 /* uele_flags */
93 #define	UELE_F_NEEDSWAP		0x01	/* needs byte swap */
94 
95 #define	UELE_NEEDSWAP(uele)	((uele)->uele_flags & UELE_F_NEEDSWAP)
96 
97 struct lock;
98 struct ufs_extattr_per_mount {
99 	kmutex_t			uepm_lock;
100 	struct ufs_extattr_list_head	uepm_list;
101 	kauth_cred_t			uepm_ucred;
102 	int				uepm_lockcnt;
103 	int				uepm_flags;
104 };
105 
106 void	ufs_extattr_uepm_init(struct ufs_extattr_per_mount *uepm);
107 void	ufs_extattr_uepm_destroy(struct ufs_extattr_per_mount *uepm);
108 int	ufs_extattr_start(struct mount *mp, struct lwp *l);
109 int	ufs_extattr_autostart(struct mount *mp, struct lwp *l);
110 void	ufs_extattr_stop(struct mount *mp, struct lwp *l);
111 int	ufs_extattrctl(struct mount *mp, int cmd, struct vnode *filename,
112 	    int attrnamespace, const char *attrname);
113 struct vop_getextattr_args;
114 int	ufs_getextattr(struct vop_getextattr_args *ap);
115 struct vop_deleteextattr_args;
116 int	ufs_deleteextattr(struct vop_deleteextattr_args *ap);
117 struct vop_setextattr_args;
118 int	ufs_setextattr(struct vop_setextattr_args *ap);
119 struct vop_listextattr_args;
120 int	ufs_listextattr(struct vop_listextattr_args *ap);
121 void	ufs_extattr_vnode_inactive(struct vnode *vp, struct lwp *l);
122 
123 void	ufs_extattr_init(void);
124 void	ufs_extattr_done(void);
125 
126 #endif /* !_KERNEL */
127 
128 #endif /* !_UFS_UFS_EXTATTR_H_ */
129