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