15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 22*11574SJohn.Harres@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 265331Samw #ifndef _SYS_FS_ZFS_FUID_H 275331Samw #define _SYS_FS_ZFS_FUID_H 285331Samw 295331Samw #ifdef _KERNEL 305331Samw #include <sys/kidmap.h> 315331Samw #include <sys/sid.h> 325331Samw #include <sys/dmu.h> 335331Samw #include <sys/zfs_vfsops.h> 345331Samw #endif 355959Smarks #include <sys/avl.h> 365331Samw 375959Smarks #ifdef __cplusplus 385959Smarks extern "C" { 395959Smarks #endif 405331Samw 415331Samw typedef enum { 425331Samw ZFS_OWNER, 435331Samw ZFS_GROUP, 445331Samw ZFS_ACE_USER, 455331Samw ZFS_ACE_GROUP 465331Samw } zfs_fuid_type_t; 475331Samw 485824Smarks /* 495824Smarks * Estimate space needed for one more fuid table entry. 505824Smarks * for now assume its current size + 1K 515824Smarks */ 529396SMatthew.Ahrens@Sun.COM #define FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1)) 535331Samw 549396SMatthew.Ahrens@Sun.COM #define FUID_INDEX(x) ((x) >> 32) 559396SMatthew.Ahrens@Sun.COM #define FUID_RID(x) ((x) & 0xffffffff) 569396SMatthew.Ahrens@Sun.COM #define FUID_ENCODE(idx, rid) (((uint64_t)(idx) << 32) | (rid)) 575331Samw /* 585331Samw * FUIDs cause problems for the intent log 595331Samw * we need to replay the creation of the FUID, 605331Samw * but we can't count on the idmapper to be around 615331Samw * and during replay the FUID index may be different than 625331Samw * before. Also, if an ACL has 100 ACEs and 12 different 635331Samw * domains we don't want to log 100 domain strings, but rather 645331Samw * just the unique 12. 655331Samw */ 665331Samw 675331Samw /* 685331Samw * The FUIDs in the log will index into 695331Samw * domain string table and the bottom half will be the rid. 705331Samw * Used for mapping ephemeral uid/gid during ACL setting to FUIDs 715331Samw */ 725331Samw typedef struct zfs_fuid { 735331Samw list_node_t z_next; 745331Samw uint64_t z_id; /* uid/gid being converted to fuid */ 755331Samw uint64_t z_domidx; /* index in AVL domain table */ 765331Samw uint64_t z_logfuid; /* index for domain in log */ 775331Samw } zfs_fuid_t; 785331Samw 795331Samw /* list of unique domains */ 805331Samw typedef struct zfs_fuid_domain { 815331Samw list_node_t z_next; 825331Samw uint64_t z_domidx; /* AVL tree idx */ 835331Samw const char *z_domain; /* domain string */ 845331Samw } zfs_fuid_domain_t; 855331Samw 865331Samw /* 875331Samw * FUID information necessary for logging create, setattr, and setacl. 885331Samw */ 895331Samw typedef struct zfs_fuid_info { 905331Samw list_t z_fuids; 915331Samw list_t z_domains; 925331Samw uint64_t z_fuid_owner; 935331Samw uint64_t z_fuid_group; 945331Samw char **z_domain_table; /* Used during replay */ 955331Samw uint32_t z_fuid_cnt; /* How many fuids in z_fuids */ 965331Samw uint32_t z_domain_cnt; /* How many domains */ 975331Samw size_t z_domain_str_sz; /* len of domain strings z_domain list */ 985331Samw } zfs_fuid_info_t; 995331Samw 1005331Samw #ifdef _KERNEL 1015331Samw struct znode; 1025959Smarks extern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t); 103*11574SJohn.Harres@Sun.COM extern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t, 104*11574SJohn.Harres@Sun.COM uint64_t, uint64_t, zfs_fuid_type_t); 1055331Samw extern void zfs_fuid_destroy(zfsvfs_t *); 1065959Smarks extern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t, 1079179SMark.Shellenbaum@Sun.COM cred_t *, zfs_fuid_info_t **); 1085771Sjp151216 extern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t, 1099179SMark.Shellenbaum@Sun.COM zfs_fuid_info_t **); 1109179SMark.Shellenbaum@Sun.COM extern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr, 1119179SMark.Shellenbaum@Sun.COM uid_t *uid, uid_t *gid); 1125331Samw extern zfs_fuid_info_t *zfs_fuid_info_alloc(void); 1139179SMark.Shellenbaum@Sun.COM extern void zfs_fuid_info_free(zfs_fuid_info_t *); 1145331Samw extern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *); 1159179SMark.Shellenbaum@Sun.COM void zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *); 1169396SMatthew.Ahrens@Sun.COM extern int zfs_fuid_find_by_domain(zfsvfs_t *, const char *domain, 1179396SMatthew.Ahrens@Sun.COM char **retdomain, boolean_t addok); 1189396SMatthew.Ahrens@Sun.COM extern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx); 1199396SMatthew.Ahrens@Sun.COM extern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx); 1205331Samw #endif 1215331Samw 1225959Smarks char *zfs_fuid_idx_domain(avl_tree_t *, uint32_t); 1239179SMark.Shellenbaum@Sun.COM void zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_t *); 1245959Smarks uint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *); 1255959Smarks void zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *); 1265331Samw 1275331Samw #ifdef __cplusplus 1285331Samw } 1295331Samw #endif 1305331Samw 1315331Samw #endif /* _SYS_FS_ZFS_FUID_H */ 132