119370Spst/*
298948Sobrien * CDDL HEADER START
3130809Smarcel *
419370Spst * The contents of this file are subject to the terms of the
519370Spst * Common Development and Distribution License (the "License").
698948Sobrien * You may not use this file except in compliance with the License.
719370Spst *
898948Sobrien * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
998948Sobrien * or http://www.opensolaris.org/os/licensing.
1098948Sobrien * See the License for the specific language governing permissions
1198948Sobrien * and limitations under the License.
1219370Spst *
1398948Sobrien * When distributing Covered Code, include this CDDL HEADER in each
1498948Sobrien * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1598948Sobrien * If applicable, add the following below this CDDL HEADER, with the
1698948Sobrien * fields enclosed by brackets "[]" replaced with your own identifying
1719370Spst * information: Portions Copyright [yyyy] [name of copyright owner]
1898948Sobrien *
1998948Sobrien * CDDL HEADER END
2098948Sobrien */
2198948Sobrien/*
2219370Spst * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2319370Spst * Use is subject to license terms.
2419370Spst */
2519370Spst
2619370Spst#ifndef	_SYS_FS_ZFS_FUID_H
2719370Spst#define	_SYS_FS_ZFS_FUID_H
2819370Spst
2919370Spst#include <sys/types.h>
3019370Spst#ifdef _KERNEL
3119370Spst#include <sys/kidmap.h>
3219370Spst#include <sys/dmu.h>
3319370Spst#include <sys/zfs_vfsops.h>
3419370Spst#endif
3519370Spst#include <sys/avl.h>
3619370Spst#include <sys/list.h>
3719370Spst
3819370Spst#ifdef	__cplusplus
3919370Spstextern "C" {
4019370Spst#endif
4119370Spst
4219370Spsttypedef enum {
4319370Spst	ZFS_OWNER,
4419370Spst	ZFS_GROUP,
45130809Smarcel	ZFS_ACE_USER,
4619370Spst	ZFS_ACE_GROUP
4719370Spst} zfs_fuid_type_t;
4819370Spst
4919370Spst/*
5019370Spst * Estimate space needed for one more fuid table entry.
5198948Sobrien * for now assume its current size + 1K
5219370Spst */
5319370Spst#define	FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
5419370Spst
5519370Spst#define	FUID_INDEX(x)	((x) >> 32)
5619370Spst#define	FUID_RID(x)	((x) & 0xffffffff)
5798948Sobrien#define	FUID_ENCODE(idx, rid) (((uint64_t)(idx) << 32) | (rid))
5819370Spst/*
5998948Sobrien * FUIDs cause problems for the intent log
60130809Smarcel * we need to replay the creation of the FUID,
6119370Spst * but we can't count on the idmapper to be around
6219370Spst * and during replay the FUID index may be different than
6319370Spst * before.  Also, if an ACL has 100 ACEs and 12 different
6498948Sobrien * domains we don't want to log 100 domain strings, but rather
6519370Spst * just the unique 12.
6619370Spst */
6719370Spst
6819370Spst/*
6998948Sobrien * The FUIDs in the log will index into
7098948Sobrien * domain string table and the bottom half will be the rid.
7198948Sobrien * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
7298948Sobrien */
7319370Spsttypedef struct zfs_fuid {
7498948Sobrien	list_node_t 	z_next;
7519370Spst	uint64_t 	z_id;		/* uid/gid being converted to fuid */
7698948Sobrien	uint64_t	z_domidx;	/* index in AVL domain table */
7798948Sobrien	uint64_t	z_logfuid;	/* index for domain in log */
7898948Sobrien} zfs_fuid_t;
7998948Sobrien
8098948Sobrien/* list of unique domains */
8119370Spsttypedef struct zfs_fuid_domain {
8298948Sobrien	list_node_t	z_next;
8319370Spst	uint64_t	z_domidx;	/* AVL tree idx */
8498948Sobrien	const char	*z_domain;	/* domain string */
8519370Spst} zfs_fuid_domain_t;
8698948Sobrien
8719370Spst/*
8898948Sobrien * FUID information necessary for logging create, setattr, and setacl.
8998948Sobrien */
9019370Spsttypedef struct zfs_fuid_info {
9198948Sobrien	list_t	z_fuids;
9298948Sobrien	list_t	z_domains;
9398948Sobrien	uint64_t z_fuid_owner;
9498948Sobrien	uint64_t z_fuid_group;
9519370Spst	char **z_domain_table;  /* Used during replay */
9619370Spst	uint32_t z_fuid_cnt;	/* How many fuids in z_fuids */
9719370Spst	uint32_t z_domain_cnt;	/* How many domains */
9819370Spst	size_t	z_domain_str_sz; /* len of domain strings z_domain list */
9919370Spst} zfs_fuid_info_t;
10019370Spst
10119370Spst#ifdef _KERNEL
10219370Spststruct znode;
10398948Sobrienextern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t);
10419370Spstextern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t,
10519370Spst    uint64_t, uint64_t, zfs_fuid_type_t);
10619370Spstextern void zfs_fuid_destroy(zfsvfs_t *);
10719370Spstextern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t,
10819370Spst    cred_t *, zfs_fuid_info_t **);
10919370Spstextern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
11019370Spst    zfs_fuid_info_t **);
11119370Spstextern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr,
11219370Spst    uid_t *uid, uid_t *gid);
11319370Spstextern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
11419370Spstextern void zfs_fuid_info_free(zfs_fuid_info_t *);
11519370Spstextern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
11619370Spstvoid zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *);
11719370Spstextern int zfs_fuid_find_by_domain(zfsvfs_t *, const char *domain,
11819370Spst    char **retdomain, boolean_t addok);
11946283Sdfrextern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx);
12046283Sdfrextern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx);
12119370Spst#endif
12219370Spst
12346283Sdfrchar *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
12446283Sdfrvoid zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_t *);
12519370Spstuint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *);
12619370Spstvoid zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *);
12719370Spst
12846283Sdfr#ifdef	__cplusplus
12946283Sdfr}
13046283Sdfr#endif
13146283Sdfr
13246283Sdfr#endif	/* _SYS_FS_ZFS_FUID_H */
13319370Spst