xref: /titanic_41/usr/src/cmd/fs.d/nfs/nfslog/fhtab.h (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _FHTAB_H
28 #define	_FHTAB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Support for the fh mapping file for nfslog.
34  */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * RPC dispatch table for file handles
42  * Indexed by program, version, proc
43  * Based on NFS dispatch table.
44  * Differences: no xdr of args/res.
45  */
46 struct nfsl_fh_proc_disp {
47 	void	(*nfsl_dis_args)();	/* dispatch routine for proc */
48 	bool_t	(*xdr_args)();		/* XDR function for arguments */
49 	bool_t	(*xdr_res)();		/* XDR function for results */
50 	int	args_size;		/* size of arguments struct */
51 	int	res_size;		/* size of results struct */
52 };
53 
54 struct nfsl_fh_vers_disp {
55 	int	nfsl_dis_nprocs;			/* number of procs */
56 	struct nfsl_fh_proc_disp *nfsl_dis_proc_table;	/* proc array */
57 };
58 
59 struct nfsl_fh_prog_disp {
60 	int	nfsl_dis_prog;		/* program number */
61 	int	nfsl_dis_versmin;	/* minimum version number */
62 	int	nfsl_dis_nvers;		/* number of version values */
63 	struct nfsl_fh_vers_disp *nfsl_dis_vers_table;	/* versions array */
64 };
65 
66 /* key comprised of inode/gen, currenly 8 or 10 bytes */
67 #define	PRIMARY_KEY_LEN_MAX	16
68 typedef char	fh_primary_key[PRIMARY_KEY_LEN_MAX];
69 
70 /* link key - directory primary key plus name (upto 2 components) */
71 #define	SECONDARY_KEY_LEN_MAX	(PRIMARY_KEY_LEN_MAX + MAXPATHLEN)
72 typedef char	fh_secondary_key[SECONDARY_KEY_LEN_MAX];
73 
74 /*
75  * This is the runtime filehandle table entry.   Because an fhandle_t is
76  * used for both Version 2 and Version 3, we don't need two different types
77  * of entries in the table.
78  */
79 typedef struct fhlist_ent {
80 	fhandle_t fh;		/* filehandle for this component */
81 	time32_t mtime;		/* modification time of entry */
82 	time32_t atime;		/* access time of entry */
83 	fhandle_t dfh;		/* parent filehandle for this component */
84 	ushort_t flags;
85 	short	reclen;		/* length of record */
86 	char	name[MAXPATHLEN];	/* variable record */
87 } fhlist_ent;
88 
89 /* flags values */
90 #define	EXPORT_POINT	0x01	/* if this is export point */
91 #define	NAME_DELETED	0x02	/* is the dir info still valid for this fh? */
92 #define	PUBLIC_PATH	0x04	/* is the dir info still valid for this fh? */
93 
94 /*
95  * Information maintained for the secondary key
96  * Note that this is a variable length record with 4 variable size fields:
97  *	fhkey	- primary key (must be there)
98  *	name	- component name (must be there)
99  *	next	- next link in list (could be null)
100  *	prev	- previous link in list (could be null)
101  */
102 #define	MAX_LINK_VARBUF		(3 * SECONDARY_KEY_LEN_MAX)
103 
104 typedef struct linkinfo_ent {
105 	fhandle_t dfh;		/* directory filehandle */
106 	time32_t mtime;		/* modification time of entry */
107 	time32_t atime;		/* access time of entry */
108 	ushort_t flags;
109 	short	reclen;		/* Actual record length */
110 	short	fhkey_offset;	/* offset of fhkey, from head of record */
111 	short	name_offset;	/* offset of name */
112 	short	next_offset;	/* offset of next link key */
113 	short	prev_offset;	/* offset of prev link key */
114 	char	varbuf[MAX_LINK_VARBUF]; /* max size for above */
115 } linkinfo_ent;
116 
117 /* Macros for lengths of the various fields */
118 #define	LN_FHKEY_LEN(link)	((link)->name_offset - (link)->fhkey_offset)
119 
120 #define	LN_NAME_LEN(link)	((link)->next_offset - (link)->name_offset)
121 
122 #define	LN_NEXT_LEN(link)	((link)->prev_offset - (link)->next_offset)
123 
124 #define	LN_PREV_LEN(link)	((link)->reclen - (link)->prev_offset)
125 
126 /* Macros for address of the various fields */
127 #define	LN_FHKEY(link)	(char *)((uintptr_t)(link) + (link)->fhkey_offset)
128 
129 #define	LN_NAME(link)	(char *)((uintptr_t)(link) + (link)->name_offset)
130 
131 #define	LN_NEXT(link)	(char *)((uintptr_t)(link) + (link)->next_offset)
132 
133 #define	LN_PREV(link)	(char *)((uintptr_t)(link) + (link)->prev_offset)
134 
135 /* Which record can reside in database */
136 typedef union {
137 	fhlist_ent	fhlist_rec;
138 	linkinfo_ent	link_rec;
139 } db_record;
140 
141 void debug_opaque_print(FILE *, void *buf, int size);
142 int db_add(char *fhpath, fhandle_t *dfh, char *name, fhandle_t *fh,
143 	uint_t flags);
144 fhlist_ent *db_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp,
145 	int *errorp);
146 fhlist_ent *db_lookup_link(char *fhpath, fhandle_t *dfh, char *name,
147 	fhlist_ent *fhrecp, int *errorp);
148 int db_delete(char *fhpath, fhandle_t *fh);
149 int db_delete_link(char *fhpath, fhandle_t *dfh, char *name);
150 int db_rename_link(char *fhpath, fhandle_t *from_dfh, char *from_name,
151 	fhandle_t *to_dfh, char *to_name);
152 void db_print_all_keys(char *fhpath, fsid_t *fsidp, FILE *fp);
153 
154 char *nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr);
155 
156 extern fhandle_t	public_fh;
157 
158 /*
159  * Macro to determine which fhandle to use - input or public fh
160  */
161 #define	NFSLOG_GET_FHANDLE2(fh)						\
162 	(((fh)->fh_len > 0) ? fh : &public_fh)
163 
164 /*
165  * Macro to determine which fhandle to use - input or public fh
166  */
167 #define	NFSLOG_GET_FHANDLE3(fh3)					\
168 	(((fh3)->fh3_length == sizeof (fhandle_t)) ?			\
169 		&(fh3)->fh3_u.nfs_fh3_i.fh3_i : &public_fh)
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* _FHTAB_H */
176