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