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