xref: /illumos-gate/usr/src/cmd/fs.d/nfs/nfslog/fhtab.h (revision 2a8bcb4e)
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 /*
307c478bd9Sstevel@tonic-gate  * Support for the fh mapping file for nfslog.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef __cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * RPC dispatch table for file handles
397c478bd9Sstevel@tonic-gate  * Indexed by program, version, proc
407c478bd9Sstevel@tonic-gate  * Based on NFS dispatch table.
417c478bd9Sstevel@tonic-gate  * Differences: no xdr of args/res.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate struct nfsl_fh_proc_disp {
447c478bd9Sstevel@tonic-gate 	void	(*nfsl_dis_args)();	/* dispatch routine for proc */
457c478bd9Sstevel@tonic-gate 	bool_t	(*xdr_args)();		/* XDR function for arguments */
467c478bd9Sstevel@tonic-gate 	bool_t	(*xdr_res)();		/* XDR function for results */
477c478bd9Sstevel@tonic-gate 	int	args_size;		/* size of arguments struct */
487c478bd9Sstevel@tonic-gate 	int	res_size;		/* size of results struct */
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate struct nfsl_fh_vers_disp {
527c478bd9Sstevel@tonic-gate 	int	nfsl_dis_nprocs;			/* number of procs */
537c478bd9Sstevel@tonic-gate 	struct nfsl_fh_proc_disp *nfsl_dis_proc_table;	/* proc array */
547c478bd9Sstevel@tonic-gate };
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate struct nfsl_fh_prog_disp {
577c478bd9Sstevel@tonic-gate 	int	nfsl_dis_prog;		/* program number */
587c478bd9Sstevel@tonic-gate 	int	nfsl_dis_versmin;	/* minimum version number */
597c478bd9Sstevel@tonic-gate 	int	nfsl_dis_nvers;		/* number of version values */
607c478bd9Sstevel@tonic-gate 	struct nfsl_fh_vers_disp *nfsl_dis_vers_table;	/* versions array */
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /* key comprised of inode/gen, currenly 8 or 10 bytes */
647c478bd9Sstevel@tonic-gate #define	PRIMARY_KEY_LEN_MAX	16
657c478bd9Sstevel@tonic-gate typedef char	fh_primary_key[PRIMARY_KEY_LEN_MAX];
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /* link key - directory primary key plus name (upto 2 components) */
687c478bd9Sstevel@tonic-gate #define	SECONDARY_KEY_LEN_MAX	(PRIMARY_KEY_LEN_MAX + MAXPATHLEN)
697c478bd9Sstevel@tonic-gate typedef char	fh_secondary_key[SECONDARY_KEY_LEN_MAX];
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * This is the runtime filehandle table entry.   Because an fhandle_t is
737c478bd9Sstevel@tonic-gate  * used for both Version 2 and Version 3, we don't need two different types
747c478bd9Sstevel@tonic-gate  * of entries in the table.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate typedef struct fhlist_ent {
777c478bd9Sstevel@tonic-gate 	fhandle_t fh;		/* filehandle for this component */
787c478bd9Sstevel@tonic-gate 	time32_t mtime;		/* modification time of entry */
797c478bd9Sstevel@tonic-gate 	time32_t atime;		/* access time of entry */
807c478bd9Sstevel@tonic-gate 	fhandle_t dfh;		/* parent filehandle for this component */
817c478bd9Sstevel@tonic-gate 	ushort_t flags;
827c478bd9Sstevel@tonic-gate 	short	reclen;		/* length of record */
837c478bd9Sstevel@tonic-gate 	char	name[MAXPATHLEN];	/* variable record */
847c478bd9Sstevel@tonic-gate } fhlist_ent;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* flags values */
877c478bd9Sstevel@tonic-gate #define	EXPORT_POINT	0x01	/* if this is export point */
887c478bd9Sstevel@tonic-gate #define	NAME_DELETED	0x02	/* is the dir info still valid for this fh? */
897c478bd9Sstevel@tonic-gate #define	PUBLIC_PATH	0x04	/* is the dir info still valid for this fh? */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Information maintained for the secondary key
937c478bd9Sstevel@tonic-gate  * Note that this is a variable length record with 4 variable size fields:
947c478bd9Sstevel@tonic-gate  *	fhkey	- primary key (must be there)
957c478bd9Sstevel@tonic-gate  *	name	- component name (must be there)
967c478bd9Sstevel@tonic-gate  *	next	- next link in list (could be null)
977c478bd9Sstevel@tonic-gate  *	prev	- previous link in list (could be null)
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	MAX_LINK_VARBUF		(3 * SECONDARY_KEY_LEN_MAX)
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate typedef struct linkinfo_ent {
1027c478bd9Sstevel@tonic-gate 	fhandle_t dfh;		/* directory filehandle */
1037c478bd9Sstevel@tonic-gate 	time32_t mtime;		/* modification time of entry */
1047c478bd9Sstevel@tonic-gate 	time32_t atime;		/* access time of entry */
1057c478bd9Sstevel@tonic-gate 	ushort_t flags;
1067c478bd9Sstevel@tonic-gate 	short	reclen;		/* Actual record length */
1077c478bd9Sstevel@tonic-gate 	short	fhkey_offset;	/* offset of fhkey, from head of record */
1087c478bd9Sstevel@tonic-gate 	short	name_offset;	/* offset of name */
1097c478bd9Sstevel@tonic-gate 	short	next_offset;	/* offset of next link key */
1107c478bd9Sstevel@tonic-gate 	short	prev_offset;	/* offset of prev link key */
1117c478bd9Sstevel@tonic-gate 	char	varbuf[MAX_LINK_VARBUF]; /* max size for above */
1127c478bd9Sstevel@tonic-gate } linkinfo_ent;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /* Macros for lengths of the various fields */
1157c478bd9Sstevel@tonic-gate #define	LN_FHKEY_LEN(link)	((link)->name_offset - (link)->fhkey_offset)
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	LN_NAME_LEN(link)	((link)->next_offset - (link)->name_offset)
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	LN_NEXT_LEN(link)	((link)->prev_offset - (link)->next_offset)
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	LN_PREV_LEN(link)	((link)->reclen - (link)->prev_offset)
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /* Macros for address of the various fields */
1247c478bd9Sstevel@tonic-gate #define	LN_FHKEY(link)	(char *)((uintptr_t)(link) + (link)->fhkey_offset)
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	LN_NAME(link)	(char *)((uintptr_t)(link) + (link)->name_offset)
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define	LN_NEXT(link)	(char *)((uintptr_t)(link) + (link)->next_offset)
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	LN_PREV(link)	(char *)((uintptr_t)(link) + (link)->prev_offset)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /* Which record can reside in database */
1337c478bd9Sstevel@tonic-gate typedef union {
1347c478bd9Sstevel@tonic-gate 	fhlist_ent	fhlist_rec;
1357c478bd9Sstevel@tonic-gate 	linkinfo_ent	link_rec;
1367c478bd9Sstevel@tonic-gate } db_record;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate void debug_opaque_print(FILE *, void *buf, int size);
1397c478bd9Sstevel@tonic-gate int db_add(char *fhpath, fhandle_t *dfh, char *name, fhandle_t *fh,
1407c478bd9Sstevel@tonic-gate 	uint_t flags);
1417c478bd9Sstevel@tonic-gate fhlist_ent *db_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp,
1427c478bd9Sstevel@tonic-gate 	int *errorp);
1437c478bd9Sstevel@tonic-gate fhlist_ent *db_lookup_link(char *fhpath, fhandle_t *dfh, char *name,
1447c478bd9Sstevel@tonic-gate 	fhlist_ent *fhrecp, int *errorp);
1457c478bd9Sstevel@tonic-gate int db_delete(char *fhpath, fhandle_t *fh);
1467c478bd9Sstevel@tonic-gate int db_delete_link(char *fhpath, fhandle_t *dfh, char *name);
1477c478bd9Sstevel@tonic-gate int db_rename_link(char *fhpath, fhandle_t *from_dfh, char *from_name,
1487c478bd9Sstevel@tonic-gate 	fhandle_t *to_dfh, char *to_name);
1497c478bd9Sstevel@tonic-gate void db_print_all_keys(char *fhpath, fsid_t *fsidp, FILE *fp);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate char *nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate extern fhandle_t	public_fh;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Macro to determine which fhandle to use - input or public fh
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate #define	NFSLOG_GET_FHANDLE2(fh)						\
1597c478bd9Sstevel@tonic-gate 	(((fh)->fh_len > 0) ? fh : &public_fh)
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Macro to determine which fhandle to use - input or public fh
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate #define	NFSLOG_GET_FHANDLE3(fh3)					\
1657c478bd9Sstevel@tonic-gate 	(((fh3)->fh3_length == sizeof (fhandle_t)) ?			\
166*27242a7cSthurlow 		(fhandle_t *)&(fh3)->fh3_u.data : &public_fh)
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate #endif
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #endif /* _FHTAB_H */
173