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