1185029Spjd/*
2185029Spjd * CDDL HEADER START
3185029Spjd *
4185029Spjd * The contents of this file are subject to the terms of the
5185029Spjd * Common Development and Distribution License (the "License").
6185029Spjd * You may not use this file except in compliance with the License.
7185029Spjd *
8185029Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9185029Spjd * or http://www.opensolaris.org/os/licensing.
10185029Spjd * See the License for the specific language governing permissions
11185029Spjd * and limitations under the License.
12185029Spjd *
13185029Spjd * When distributing Covered Code, include this CDDL HEADER in each
14185029Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15185029Spjd * If applicable, add the following below this CDDL HEADER, with the
16185029Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17185029Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18185029Spjd *
19185029Spjd * CDDL HEADER END
20185029Spjd */
21185029Spjd/*
22219089Spjd * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23185029Spjd * Use is subject to license terms.
24185029Spjd */
25185029Spjd
26185029Spjd#ifndef	_SYS_FS_ZFS_FUID_H
27185029Spjd#define	_SYS_FS_ZFS_FUID_H
28185029Spjd
29185029Spjd#include <sys/types.h>
30185029Spjd#ifdef _KERNEL
31185029Spjd#include <sys/kidmap.h>
32185029Spjd#include <sys/dmu.h>
33185029Spjd#include <sys/zfs_vfsops.h>
34185029Spjd#endif
35185029Spjd#include <sys/avl.h>
36219089Spjd#include <sys/list.h>
37185029Spjd
38185029Spjd#ifdef	__cplusplus
39185029Spjdextern "C" {
40185029Spjd#endif
41185029Spjd
42185029Spjdtypedef enum {
43185029Spjd	ZFS_OWNER,
44185029Spjd	ZFS_GROUP,
45185029Spjd	ZFS_ACE_USER,
46185029Spjd	ZFS_ACE_GROUP
47185029Spjd} zfs_fuid_type_t;
48185029Spjd
49185029Spjd/*
50185029Spjd * Estimate space needed for one more fuid table entry.
51185029Spjd * for now assume its current size + 1K
52185029Spjd */
53209962Smm#define	FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
54185029Spjd
55209962Smm#define	FUID_INDEX(x)	((x) >> 32)
56209962Smm#define	FUID_RID(x)	((x) & 0xffffffff)
57209962Smm#define	FUID_ENCODE(idx, rid) (((uint64_t)(idx) << 32) | (rid))
58185029Spjd/*
59185029Spjd * FUIDs cause problems for the intent log
60185029Spjd * we need to replay the creation of the FUID,
61185029Spjd * but we can't count on the idmapper to be around
62185029Spjd * and during replay the FUID index may be different than
63185029Spjd * before.  Also, if an ACL has 100 ACEs and 12 different
64185029Spjd * domains we don't want to log 100 domain strings, but rather
65185029Spjd * just the unique 12.
66185029Spjd */
67185029Spjd
68185029Spjd/*
69185029Spjd * The FUIDs in the log will index into
70185029Spjd * domain string table and the bottom half will be the rid.
71185029Spjd * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
72185029Spjd */
73185029Spjdtypedef struct zfs_fuid {
74185029Spjd	list_node_t 	z_next;
75185029Spjd	uint64_t 	z_id;		/* uid/gid being converted to fuid */
76185029Spjd	uint64_t	z_domidx;	/* index in AVL domain table */
77185029Spjd	uint64_t	z_logfuid;	/* index for domain in log */
78185029Spjd} zfs_fuid_t;
79185029Spjd
80185029Spjd/* list of unique domains */
81185029Spjdtypedef struct zfs_fuid_domain {
82185029Spjd	list_node_t	z_next;
83185029Spjd	uint64_t	z_domidx;	/* AVL tree idx */
84185029Spjd	const char	*z_domain;	/* domain string */
85185029Spjd} zfs_fuid_domain_t;
86185029Spjd
87185029Spjd/*
88185029Spjd * FUID information necessary for logging create, setattr, and setacl.
89185029Spjd */
90185029Spjdtypedef struct zfs_fuid_info {
91185029Spjd	list_t	z_fuids;
92185029Spjd	list_t	z_domains;
93185029Spjd	uint64_t z_fuid_owner;
94185029Spjd	uint64_t z_fuid_group;
95185029Spjd	char **z_domain_table;  /* Used during replay */
96185029Spjd	uint32_t z_fuid_cnt;	/* How many fuids in z_fuids */
97185029Spjd	uint32_t z_domain_cnt;	/* How many domains */
98185029Spjd	size_t	z_domain_str_sz; /* len of domain strings z_domain list */
99185029Spjd} zfs_fuid_info_t;
100185029Spjd
101185029Spjd#ifdef _KERNEL
102185029Spjdstruct znode;
103185029Spjdextern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t);
104219089Spjdextern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t,
105219089Spjd    uint64_t, uint64_t, zfs_fuid_type_t);
106185029Spjdextern void zfs_fuid_destroy(zfsvfs_t *);
107185029Spjdextern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t,
108209962Smm    cred_t *, zfs_fuid_info_t **);
109185029Spjdextern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
110209962Smm    zfs_fuid_info_t **);
111209962Smmextern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr,
112209962Smm    uid_t *uid, uid_t *gid);
113185029Spjdextern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
114209962Smmextern void zfs_fuid_info_free(zfs_fuid_info_t *);
115185029Spjdextern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
116209962Smmvoid zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *);
117209962Smmextern int zfs_fuid_find_by_domain(zfsvfs_t *, const char *domain,
118209962Smm    char **retdomain, boolean_t addok);
119209962Smmextern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx);
120209962Smmextern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx);
121185029Spjd#endif
122185029Spjd
123185029Spjdchar *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
124209962Smmvoid zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_t *);
125185029Spjduint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *);
126185029Spjdvoid zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *);
127185029Spjd
128185029Spjd#ifdef	__cplusplus
129185029Spjd}
130185029Spjd#endif
131185029Spjd
132185029Spjd#endif	/* _SYS_FS_ZFS_FUID_H */
133