10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1610Sthurlow * Common Development and Distribution License (the "License"). 6*1610Sthurlow * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1610Sthurlow * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*1610Sthurlow * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _FHTAB_H 270Sstevel@tonic-gate #define _FHTAB_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* 320Sstevel@tonic-gate * Support for the fh mapping file for nfslog. 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * RPC dispatch table for file handles 410Sstevel@tonic-gate * Indexed by program, version, proc 420Sstevel@tonic-gate * Based on NFS dispatch table. 430Sstevel@tonic-gate * Differences: no xdr of args/res. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate struct nfsl_fh_proc_disp { 460Sstevel@tonic-gate void (*nfsl_dis_args)(); /* dispatch routine for proc */ 470Sstevel@tonic-gate bool_t (*xdr_args)(); /* XDR function for arguments */ 480Sstevel@tonic-gate bool_t (*xdr_res)(); /* XDR function for results */ 490Sstevel@tonic-gate int args_size; /* size of arguments struct */ 500Sstevel@tonic-gate int res_size; /* size of results struct */ 510Sstevel@tonic-gate }; 520Sstevel@tonic-gate 530Sstevel@tonic-gate struct nfsl_fh_vers_disp { 540Sstevel@tonic-gate int nfsl_dis_nprocs; /* number of procs */ 550Sstevel@tonic-gate struct nfsl_fh_proc_disp *nfsl_dis_proc_table; /* proc array */ 560Sstevel@tonic-gate }; 570Sstevel@tonic-gate 580Sstevel@tonic-gate struct nfsl_fh_prog_disp { 590Sstevel@tonic-gate int nfsl_dis_prog; /* program number */ 600Sstevel@tonic-gate int nfsl_dis_versmin; /* minimum version number */ 610Sstevel@tonic-gate int nfsl_dis_nvers; /* number of version values */ 620Sstevel@tonic-gate struct nfsl_fh_vers_disp *nfsl_dis_vers_table; /* versions array */ 630Sstevel@tonic-gate }; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* key comprised of inode/gen, currenly 8 or 10 bytes */ 660Sstevel@tonic-gate #define PRIMARY_KEY_LEN_MAX 16 670Sstevel@tonic-gate typedef char fh_primary_key[PRIMARY_KEY_LEN_MAX]; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* link key - directory primary key plus name (upto 2 components) */ 700Sstevel@tonic-gate #define SECONDARY_KEY_LEN_MAX (PRIMARY_KEY_LEN_MAX + MAXPATHLEN) 710Sstevel@tonic-gate typedef char fh_secondary_key[SECONDARY_KEY_LEN_MAX]; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * This is the runtime filehandle table entry. Because an fhandle_t is 750Sstevel@tonic-gate * used for both Version 2 and Version 3, we don't need two different types 760Sstevel@tonic-gate * of entries in the table. 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate typedef struct fhlist_ent { 790Sstevel@tonic-gate fhandle_t fh; /* filehandle for this component */ 800Sstevel@tonic-gate time32_t mtime; /* modification time of entry */ 810Sstevel@tonic-gate time32_t atime; /* access time of entry */ 820Sstevel@tonic-gate fhandle_t dfh; /* parent filehandle for this component */ 830Sstevel@tonic-gate ushort_t flags; 840Sstevel@tonic-gate short reclen; /* length of record */ 850Sstevel@tonic-gate char name[MAXPATHLEN]; /* variable record */ 860Sstevel@tonic-gate } fhlist_ent; 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* flags values */ 890Sstevel@tonic-gate #define EXPORT_POINT 0x01 /* if this is export point */ 900Sstevel@tonic-gate #define NAME_DELETED 0x02 /* is the dir info still valid for this fh? */ 910Sstevel@tonic-gate #define PUBLIC_PATH 0x04 /* is the dir info still valid for this fh? */ 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* 940Sstevel@tonic-gate * Information maintained for the secondary key 950Sstevel@tonic-gate * Note that this is a variable length record with 4 variable size fields: 960Sstevel@tonic-gate * fhkey - primary key (must be there) 970Sstevel@tonic-gate * name - component name (must be there) 980Sstevel@tonic-gate * next - next link in list (could be null) 990Sstevel@tonic-gate * prev - previous link in list (could be null) 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate #define MAX_LINK_VARBUF (3 * SECONDARY_KEY_LEN_MAX) 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate typedef struct linkinfo_ent { 1040Sstevel@tonic-gate fhandle_t dfh; /* directory filehandle */ 1050Sstevel@tonic-gate time32_t mtime; /* modification time of entry */ 1060Sstevel@tonic-gate time32_t atime; /* access time of entry */ 1070Sstevel@tonic-gate ushort_t flags; 1080Sstevel@tonic-gate short reclen; /* Actual record length */ 1090Sstevel@tonic-gate short fhkey_offset; /* offset of fhkey, from head of record */ 1100Sstevel@tonic-gate short name_offset; /* offset of name */ 1110Sstevel@tonic-gate short next_offset; /* offset of next link key */ 1120Sstevel@tonic-gate short prev_offset; /* offset of prev link key */ 1130Sstevel@tonic-gate char varbuf[MAX_LINK_VARBUF]; /* max size for above */ 1140Sstevel@tonic-gate } linkinfo_ent; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* Macros for lengths of the various fields */ 1170Sstevel@tonic-gate #define LN_FHKEY_LEN(link) ((link)->name_offset - (link)->fhkey_offset) 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define LN_NAME_LEN(link) ((link)->next_offset - (link)->name_offset) 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate #define LN_NEXT_LEN(link) ((link)->prev_offset - (link)->next_offset) 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #define LN_PREV_LEN(link) ((link)->reclen - (link)->prev_offset) 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* Macros for address of the various fields */ 1260Sstevel@tonic-gate #define LN_FHKEY(link) (char *)((uintptr_t)(link) + (link)->fhkey_offset) 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate #define LN_NAME(link) (char *)((uintptr_t)(link) + (link)->name_offset) 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #define LN_NEXT(link) (char *)((uintptr_t)(link) + (link)->next_offset) 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate #define LN_PREV(link) (char *)((uintptr_t)(link) + (link)->prev_offset) 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* Which record can reside in database */ 1350Sstevel@tonic-gate typedef union { 1360Sstevel@tonic-gate fhlist_ent fhlist_rec; 1370Sstevel@tonic-gate linkinfo_ent link_rec; 1380Sstevel@tonic-gate } db_record; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate void debug_opaque_print(FILE *, void *buf, int size); 1410Sstevel@tonic-gate int db_add(char *fhpath, fhandle_t *dfh, char *name, fhandle_t *fh, 1420Sstevel@tonic-gate uint_t flags); 1430Sstevel@tonic-gate fhlist_ent *db_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp, 1440Sstevel@tonic-gate int *errorp); 1450Sstevel@tonic-gate fhlist_ent *db_lookup_link(char *fhpath, fhandle_t *dfh, char *name, 1460Sstevel@tonic-gate fhlist_ent *fhrecp, int *errorp); 1470Sstevel@tonic-gate int db_delete(char *fhpath, fhandle_t *fh); 1480Sstevel@tonic-gate int db_delete_link(char *fhpath, fhandle_t *dfh, char *name); 1490Sstevel@tonic-gate int db_rename_link(char *fhpath, fhandle_t *from_dfh, char *from_name, 1500Sstevel@tonic-gate fhandle_t *to_dfh, char *to_name); 1510Sstevel@tonic-gate void db_print_all_keys(char *fhpath, fsid_t *fsidp, FILE *fp); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate char *nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate extern fhandle_t public_fh; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * Macro to determine which fhandle to use - input or public fh 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate #define NFSLOG_GET_FHANDLE2(fh) \ 1610Sstevel@tonic-gate (((fh)->fh_len > 0) ? fh : &public_fh) 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Macro to determine which fhandle to use - input or public fh 1650Sstevel@tonic-gate */ 1660Sstevel@tonic-gate #define NFSLOG_GET_FHANDLE3(fh3) \ 1670Sstevel@tonic-gate (((fh3)->fh3_length == sizeof (fhandle_t)) ? \ 168*1610Sthurlow (fhandle_t *)&(fh3)->fh3_u.data : &public_fh) 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate #ifdef __cplusplus 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate #endif 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #endif /* _FHTAB_H */ 175