xref: /titanic_44/usr/src/cmd/fs.d/nfs/nfslog/fhtab.h (revision 27242a7c712b654e22134a70356231efc69c8202)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*27242a7cSthurlow  * Common Development and Distribution License (the "License").
6*27242a7cSthurlow  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*27242a7cSthurlow  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*27242a7cSthurlow  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _FHTAB_H
277c478bd9Sstevel@tonic-gate #define	_FHTAB_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Support for the fh mapping file for nfslog.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef __cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * RPC dispatch table for file handles
417c478bd9Sstevel@tonic-gate  * Indexed by program, version, proc
427c478bd9Sstevel@tonic-gate  * Based on NFS dispatch table.
437c478bd9Sstevel@tonic-gate  * Differences: no xdr of args/res.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate struct nfsl_fh_proc_disp {
467c478bd9Sstevel@tonic-gate 	void	(*nfsl_dis_args)();	/* dispatch routine for proc */
477c478bd9Sstevel@tonic-gate 	bool_t	(*xdr_args)();		/* XDR function for arguments */
487c478bd9Sstevel@tonic-gate 	bool_t	(*xdr_res)();		/* XDR function for results */
497c478bd9Sstevel@tonic-gate 	int	args_size;		/* size of arguments struct */
507c478bd9Sstevel@tonic-gate 	int	res_size;		/* size of results struct */
517c478bd9Sstevel@tonic-gate };
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate struct nfsl_fh_vers_disp {
547c478bd9Sstevel@tonic-gate 	int	nfsl_dis_nprocs;			/* number of procs */
557c478bd9Sstevel@tonic-gate 	struct nfsl_fh_proc_disp *nfsl_dis_proc_table;	/* proc array */
567c478bd9Sstevel@tonic-gate };
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate struct nfsl_fh_prog_disp {
597c478bd9Sstevel@tonic-gate 	int	nfsl_dis_prog;		/* program number */
607c478bd9Sstevel@tonic-gate 	int	nfsl_dis_versmin;	/* minimum version number */
617c478bd9Sstevel@tonic-gate 	int	nfsl_dis_nvers;		/* number of version values */
627c478bd9Sstevel@tonic-gate 	struct nfsl_fh_vers_disp *nfsl_dis_vers_table;	/* versions array */
637c478bd9Sstevel@tonic-gate };
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /* key comprised of inode/gen, currenly 8 or 10 bytes */
667c478bd9Sstevel@tonic-gate #define	PRIMARY_KEY_LEN_MAX	16
677c478bd9Sstevel@tonic-gate typedef char	fh_primary_key[PRIMARY_KEY_LEN_MAX];
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /* link key - directory primary key plus name (upto 2 components) */
707c478bd9Sstevel@tonic-gate #define	SECONDARY_KEY_LEN_MAX	(PRIMARY_KEY_LEN_MAX + MAXPATHLEN)
717c478bd9Sstevel@tonic-gate typedef char	fh_secondary_key[SECONDARY_KEY_LEN_MAX];
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * This is the runtime filehandle table entry.   Because an fhandle_t is
757c478bd9Sstevel@tonic-gate  * used for both Version 2 and Version 3, we don't need two different types
767c478bd9Sstevel@tonic-gate  * of entries in the table.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate typedef struct fhlist_ent {
797c478bd9Sstevel@tonic-gate 	fhandle_t fh;		/* filehandle for this component */
807c478bd9Sstevel@tonic-gate 	time32_t mtime;		/* modification time of entry */
817c478bd9Sstevel@tonic-gate 	time32_t atime;		/* access time of entry */
827c478bd9Sstevel@tonic-gate 	fhandle_t dfh;		/* parent filehandle for this component */
837c478bd9Sstevel@tonic-gate 	ushort_t flags;
847c478bd9Sstevel@tonic-gate 	short	reclen;		/* length of record */
857c478bd9Sstevel@tonic-gate 	char	name[MAXPATHLEN];	/* variable record */
867c478bd9Sstevel@tonic-gate } fhlist_ent;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* flags values */
897c478bd9Sstevel@tonic-gate #define	EXPORT_POINT	0x01	/* if this is export point */
907c478bd9Sstevel@tonic-gate #define	NAME_DELETED	0x02	/* is the dir info still valid for this fh? */
917c478bd9Sstevel@tonic-gate #define	PUBLIC_PATH	0x04	/* is the dir info still valid for this fh? */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Information maintained for the secondary key
957c478bd9Sstevel@tonic-gate  * Note that this is a variable length record with 4 variable size fields:
967c478bd9Sstevel@tonic-gate  *	fhkey	- primary key (must be there)
977c478bd9Sstevel@tonic-gate  *	name	- component name (must be there)
987c478bd9Sstevel@tonic-gate  *	next	- next link in list (could be null)
997c478bd9Sstevel@tonic-gate  *	prev	- previous link in list (could be null)
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate #define	MAX_LINK_VARBUF		(3 * SECONDARY_KEY_LEN_MAX)
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate typedef struct linkinfo_ent {
1047c478bd9Sstevel@tonic-gate 	fhandle_t dfh;		/* directory filehandle */
1057c478bd9Sstevel@tonic-gate 	time32_t mtime;		/* modification time of entry */
1067c478bd9Sstevel@tonic-gate 	time32_t atime;		/* access time of entry */
1077c478bd9Sstevel@tonic-gate 	ushort_t flags;
1087c478bd9Sstevel@tonic-gate 	short	reclen;		/* Actual record length */
1097c478bd9Sstevel@tonic-gate 	short	fhkey_offset;	/* offset of fhkey, from head of record */
1107c478bd9Sstevel@tonic-gate 	short	name_offset;	/* offset of name */
1117c478bd9Sstevel@tonic-gate 	short	next_offset;	/* offset of next link key */
1127c478bd9Sstevel@tonic-gate 	short	prev_offset;	/* offset of prev link key */
1137c478bd9Sstevel@tonic-gate 	char	varbuf[MAX_LINK_VARBUF]; /* max size for above */
1147c478bd9Sstevel@tonic-gate } linkinfo_ent;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /* Macros for lengths of the various fields */
1177c478bd9Sstevel@tonic-gate #define	LN_FHKEY_LEN(link)	((link)->name_offset - (link)->fhkey_offset)
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	LN_NAME_LEN(link)	((link)->next_offset - (link)->name_offset)
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	LN_NEXT_LEN(link)	((link)->prev_offset - (link)->next_offset)
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define	LN_PREV_LEN(link)	((link)->reclen - (link)->prev_offset)
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /* Macros for address of the various fields */
1267c478bd9Sstevel@tonic-gate #define	LN_FHKEY(link)	(char *)((uintptr_t)(link) + (link)->fhkey_offset)
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define	LN_NAME(link)	(char *)((uintptr_t)(link) + (link)->name_offset)
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	LN_NEXT(link)	(char *)((uintptr_t)(link) + (link)->next_offset)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #define	LN_PREV(link)	(char *)((uintptr_t)(link) + (link)->prev_offset)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /* Which record can reside in database */
1357c478bd9Sstevel@tonic-gate typedef union {
1367c478bd9Sstevel@tonic-gate 	fhlist_ent	fhlist_rec;
1377c478bd9Sstevel@tonic-gate 	linkinfo_ent	link_rec;
1387c478bd9Sstevel@tonic-gate } db_record;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate void debug_opaque_print(FILE *, void *buf, int size);
1417c478bd9Sstevel@tonic-gate int db_add(char *fhpath, fhandle_t *dfh, char *name, fhandle_t *fh,
1427c478bd9Sstevel@tonic-gate 	uint_t flags);
1437c478bd9Sstevel@tonic-gate fhlist_ent *db_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp,
1447c478bd9Sstevel@tonic-gate 	int *errorp);
1457c478bd9Sstevel@tonic-gate fhlist_ent *db_lookup_link(char *fhpath, fhandle_t *dfh, char *name,
1467c478bd9Sstevel@tonic-gate 	fhlist_ent *fhrecp, int *errorp);
1477c478bd9Sstevel@tonic-gate int db_delete(char *fhpath, fhandle_t *fh);
1487c478bd9Sstevel@tonic-gate int db_delete_link(char *fhpath, fhandle_t *dfh, char *name);
1497c478bd9Sstevel@tonic-gate int db_rename_link(char *fhpath, fhandle_t *from_dfh, char *from_name,
1507c478bd9Sstevel@tonic-gate 	fhandle_t *to_dfh, char *to_name);
1517c478bd9Sstevel@tonic-gate void db_print_all_keys(char *fhpath, fsid_t *fsidp, FILE *fp);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate char *nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate extern fhandle_t	public_fh;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * Macro to determine which fhandle to use - input or public fh
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	NFSLOG_GET_FHANDLE2(fh)						\
1617c478bd9Sstevel@tonic-gate 	(((fh)->fh_len > 0) ? fh : &public_fh)
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * Macro to determine which fhandle to use - input or public fh
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate #define	NFSLOG_GET_FHANDLE3(fh3)					\
1677c478bd9Sstevel@tonic-gate 	(((fh3)->fh3_length == sizeof (fhandle_t)) ?			\
168*27242a7cSthurlow 		(fhandle_t *)&(fh3)->fh3_u.data : &public_fh)
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate #endif
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #endif /* _FHTAB_H */
175