xref: /freebsd/sys/contrib/openzfs/include/sys/zfs_fuid.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FS_ZFS_FUID_H
28 #define	_SYS_FS_ZFS_FUID_H
29 
30 #ifdef _KERNEL
31 #include <sys/sid.h>
32 #include <sys/dmu.h>
33 #include <sys/zfs_vfsops.h>
34 #endif
35 #include <sys/avl.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 typedef enum {
42 	ZFS_OWNER,
43 	ZFS_GROUP,
44 	ZFS_ACE_USER,
45 	ZFS_ACE_GROUP
46 } zfs_fuid_type_t;
47 
48 /*
49  * Estimate space needed for one more fuid table entry.
50  * for now assume its current size + 1K
51  */
52 #define	FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
53 
54 #define	FUID_INDEX(x)	((x) >> 32)
55 #define	FUID_RID(x)	((x) & 0xffffffff)
56 #define	FUID_ENCODE(idx, rid) (((uint64_t)(idx) << 32) | (rid))
57 /*
58  * FUIDs cause problems for the intent log
59  * we need to replay the creation of the FUID,
60  * but we can't count on the idmapper to be around
61  * and during replay the FUID index may be different than
62  * before.  Also, if an ACL has 100 ACEs and 12 different
63  * domains we don't want to log 100 domain strings, but rather
64  * just the unique 12.
65  */
66 
67 /*
68  * The FUIDs in the log will index into
69  * domain string table and the bottom half will be the rid.
70  * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
71  */
72 typedef struct zfs_fuid {
73 	list_node_t 	z_next;
74 	uint64_t 	z_id;		/* uid/gid being converted to fuid */
75 	uint64_t	z_domidx;	/* index in AVL domain table */
76 	uint64_t	z_logfuid;	/* index for domain in log */
77 } zfs_fuid_t;
78 
79 /* list of unique domains */
80 typedef struct zfs_fuid_domain {
81 	list_node_t	z_next;
82 	uint64_t	z_domidx;	/* AVL tree idx */
83 	const char	*z_domain;	/* domain string */
84 } zfs_fuid_domain_t;
85 
86 /*
87  * FUID information necessary for logging create, setattr, and setacl.
88  */
89 typedef struct zfs_fuid_info {
90 	list_t	z_fuids;
91 	list_t	z_domains;
92 	uint64_t z_fuid_owner;
93 	uint64_t z_fuid_group;
94 	char **z_domain_table;  /* Used during replay */
95 	uint32_t z_fuid_cnt;	/* How many fuids in z_fuids */
96 	uint32_t z_domain_cnt;	/* How many domains */
97 	size_t	z_domain_str_sz; /* len of domain strings z_domain list */
98 } zfs_fuid_info_t;
99 
100 #ifdef _KERNEL
101 struct znode;
102 extern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t);
103 extern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t,
104     uint64_t, uint64_t, zfs_fuid_type_t);
105 extern void zfs_fuid_destroy(zfsvfs_t *);
106 extern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t,
107     cred_t *, zfs_fuid_info_t **);
108 extern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
109     zfs_fuid_info_t **);
110 extern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr,
111     uid_t *uid, uid_t *gid);
112 extern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
113 extern void zfs_fuid_info_free(zfs_fuid_info_t *);
114 extern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
115 void zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *);
116 extern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx);
117 extern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx);
118 extern int zfs_id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
119     char *buf, size_t len, boolean_t addok);
120 #endif
121 
122 const char *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
123 void zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_t *);
124 uint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *);
125 void zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *);
126 
127 #ifdef	__cplusplus
128 }
129 #endif
130 
131 #endif	/* _SYS_FS_ZFS_FUID_H */
132