1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <stdio.h>
28*7c478bd9Sstevel@tonic-gate #include <errno.h>
29*7c478bd9Sstevel@tonic-gate #include <malloc.h>
30*7c478bd9Sstevel@tonic-gate #include <strings.h>
31*7c478bd9Sstevel@tonic-gate #include <stddef.h>
32*7c478bd9Sstevel@tonic-gate #include <search.h>
33*7c478bd9Sstevel@tonic-gate #include <syslog.h>
34*7c478bd9Sstevel@tonic-gate #include <libintl.h>
35*7c478bd9Sstevel@tonic-gate #include <unistd.h>
36*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
37*7c478bd9Sstevel@tonic-gate #include <netconfig.h>
38*7c478bd9Sstevel@tonic-gate #include <netdir.h>
39*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_sec.h>
40*7c478bd9Sstevel@tonic-gate #include <nfs/export.h>
41*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
42*7c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
43*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
44*7c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
45*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
46*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h>
47*7c478bd9Sstevel@tonic-gate #include <assert.h>
48*7c478bd9Sstevel@tonic-gate #include "fhtab.h"
49*7c478bd9Sstevel@tonic-gate #include "nfslogd.h"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * How long should an entry stay in the list before being forced
53*7c478bd9Sstevel@tonic-gate  * out and a trans log entry printed
54*7c478bd9Sstevel@tonic-gate  */
55*7c478bd9Sstevel@tonic-gate #define	TRANS_ENTRY_TIMEOUT	60
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate extern char *addrtoname(void *);
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate struct transentry {
60*7c478bd9Sstevel@tonic-gate 	struct transentry *next;
61*7c478bd9Sstevel@tonic-gate 	struct transentry *prev;
62*7c478bd9Sstevel@tonic-gate 	timestruc32_t	starttime;	/* when did transaction start? */
63*7c478bd9Sstevel@tonic-gate 	timestruc32_t	lastupdate;	/* last operation for this entry */
64*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_READ		1
65*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_WRITE	2
66*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_SETATTR	3
67*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_REMOVE	4
68*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_MKDIR	5
69*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_CREATE	6
70*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_RMDIR	7
71*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_RENAME	8
72*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_MKNOD	9
73*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_LINK		10
74*7c478bd9Sstevel@tonic-gate #define	TRANS_OPER_SYMLINK	11
75*7c478bd9Sstevel@tonic-gate 	uchar_t		optype;		/* read, write, ...? */
76*7c478bd9Sstevel@tonic-gate #define	TRANS_DATATYPE_NA		/* not applicable data type */
77*7c478bd9Sstevel@tonic-gate #define	TRANS_DATATYPE_ASCII	0	/* transfer done as ascii */
78*7c478bd9Sstevel@tonic-gate #define	TRANS_DATATYPE_BINARY	1	/* transfer done as binary */
79*7c478bd9Sstevel@tonic-gate 	uchar_t		datatype;
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate  * Action taken by server before transfer was made -- noaction,
82*7c478bd9Sstevel@tonic-gate  * compressed, tar or uncompressed.
83*7c478bd9Sstevel@tonic-gate  */
84*7c478bd9Sstevel@tonic-gate #define	TRANS_OPTION_NOACTION	0
85*7c478bd9Sstevel@tonic-gate 	uchar_t		transoption;
86*7c478bd9Sstevel@tonic-gate 	char		*pathname;
87*7c478bd9Sstevel@tonic-gate 	struct netbuf	*pnb;
88*7c478bd9Sstevel@tonic-gate 	uid_t		uid;
89*7c478bd9Sstevel@tonic-gate 	int		nfsvers;
90*7c478bd9Sstevel@tonic-gate 	char		*netid;
91*7c478bd9Sstevel@tonic-gate 	char		*principal_name;
92*7c478bd9Sstevel@tonic-gate 	uint64_t	totalbytes;	/* total operated upon in history */
93*7c478bd9Sstevel@tonic-gate 	union {
94*7c478bd9Sstevel@tonic-gate 		fhandle_t fh;
95*7c478bd9Sstevel@tonic-gate 		nfs_fh3 fh3;
96*7c478bd9Sstevel@tonic-gate 	} fh_u;
97*7c478bd9Sstevel@tonic-gate };
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file {
100*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file	*next;	/* next file in list */
101*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file	*prev;	/* next file in list */
102*7c478bd9Sstevel@tonic-gate 	int	refcnt;		/* number of references to this struct */
103*7c478bd9Sstevel@tonic-gate 	char	*path;		/* pathname of file */
104*7c478bd9Sstevel@tonic-gate 	FILE	*fp;		/* file pointer */
105*7c478bd9Sstevel@tonic-gate 	/* timestamp of the last transaction processed for this file */
106*7c478bd9Sstevel@tonic-gate 	timestruc32_t	lasttrans_timestamp;
107*7c478bd9Sstevel@tonic-gate 	/* 'current' time that last trans was processed */
108*7c478bd9Sstevel@tonic-gate 	time_t		last_trans_read;
109*7c478bd9Sstevel@tonic-gate 	uint32_t trans_to_log;	/* transactions that are to be logged */
110*7c478bd9Sstevel@tonic-gate 	uint32_t trans_output_type;
111*7c478bd9Sstevel@tonic-gate 	struct transentry *te_list_v3_read;
112*7c478bd9Sstevel@tonic-gate 	struct transentry *te_list_v3_write;
113*7c478bd9Sstevel@tonic-gate 	struct transentry *te_list_v2_read;
114*7c478bd9Sstevel@tonic-gate 	struct transentry *te_list_v2_write;
115*7c478bd9Sstevel@tonic-gate };
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate static struct nfslog_trans_file *trans_file_head = NULL;
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate static void nfslog_print_trans_logentry(struct transentry *,
120*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *);
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate static struct netbuf *
netbufdup(struct netbuf * pnb)124*7c478bd9Sstevel@tonic-gate netbufdup(struct netbuf *pnb)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate 	struct netbuf *pnewnb;
127*7c478bd9Sstevel@tonic-gate 	uint32_t	size;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	size = offsetof(struct netbuf, buf);
130*7c478bd9Sstevel@tonic-gate 	size += pnb->len;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	if ((pnewnb = (struct netbuf *)malloc(sizeof (*pnewnb))) == NULL)
133*7c478bd9Sstevel@tonic-gate 		return (NULL);
134*7c478bd9Sstevel@tonic-gate 	if ((pnewnb->buf = malloc(pnb->len)) == NULL) {
135*7c478bd9Sstevel@tonic-gate 		free(pnewnb);
136*7c478bd9Sstevel@tonic-gate 		return (NULL);
137*7c478bd9Sstevel@tonic-gate 	}
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	pnewnb->maxlen = pnb->maxlen;
140*7c478bd9Sstevel@tonic-gate 	pnewnb->len = pnb->len;
141*7c478bd9Sstevel@tonic-gate 	bcopy(pnb->buf, pnewnb->buf, pnb->len);
142*7c478bd9Sstevel@tonic-gate 	return (pnewnb);
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate static void
freenetbuf(struct netbuf * pnb)146*7c478bd9Sstevel@tonic-gate freenetbuf(struct netbuf *pnb)
147*7c478bd9Sstevel@tonic-gate {
148*7c478bd9Sstevel@tonic-gate 	free(pnb->buf);
149*7c478bd9Sstevel@tonic-gate 	free(pnb);
150*7c478bd9Sstevel@tonic-gate }
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate static struct transentry *
create_te()153*7c478bd9Sstevel@tonic-gate create_te()
154*7c478bd9Sstevel@tonic-gate {
155*7c478bd9Sstevel@tonic-gate 	struct transentry *pte;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	if ((pte = (struct transentry *)calloc(1, sizeof (*pte))) == NULL) {
158*7c478bd9Sstevel@tonic-gate 		/* failure message or action */
159*7c478bd9Sstevel@tonic-gate 		return (NULL);
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	pte->next = pte->prev = NULL;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	return (pte);
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate static struct transentry *
insert_te(struct transentry * te_list,struct transentry * entry)168*7c478bd9Sstevel@tonic-gate insert_te(
169*7c478bd9Sstevel@tonic-gate 	struct transentry *te_list,
170*7c478bd9Sstevel@tonic-gate 	struct transentry *entry)
171*7c478bd9Sstevel@tonic-gate {
172*7c478bd9Sstevel@tonic-gate 	struct transentry *pte;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	/*
175*7c478bd9Sstevel@tonic-gate 	 * First check for any non-filehandle comparisons that may be needed.
176*7c478bd9Sstevel@tonic-gate 	 */
177*7c478bd9Sstevel@tonic-gate 	switch (entry->optype) {
178*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_REMOVE:
179*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_RENAME:
180*7c478bd9Sstevel@tonic-gate 		for (pte = te_list->next; pte != te_list; pte = pte->next) {
181*7c478bd9Sstevel@tonic-gate 			/* if path names match, then return */
182*7c478bd9Sstevel@tonic-gate 			if (strcmp(pte->pathname, entry->pathname) == 0) {
183*7c478bd9Sstevel@tonic-gate 				return (pte);
184*7c478bd9Sstevel@tonic-gate 			}
185*7c478bd9Sstevel@tonic-gate 		}
186*7c478bd9Sstevel@tonic-gate 		return (NULL);
187*7c478bd9Sstevel@tonic-gate 	default:
188*7c478bd9Sstevel@tonic-gate 		break;
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	for (pte = te_list->next; pte != te_list; pte = pte->next) {
192*7c478bd9Sstevel@tonic-gate 		/* If the file handles match, then we have a hit */
193*7c478bd9Sstevel@tonic-gate 		if (entry->nfsvers == NFS_VERSION) {
194*7c478bd9Sstevel@tonic-gate 			if (bcmp(&(pte->fh_u.fh), &(entry->fh_u.fh),
195*7c478bd9Sstevel@tonic-gate 				sizeof (fhandle_t)) == 0) {
196*7c478bd9Sstevel@tonic-gate 				switch (entry->optype) {
197*7c478bd9Sstevel@tonic-gate 				case TRANS_OPER_READ:
198*7c478bd9Sstevel@tonic-gate 				case TRANS_OPER_WRITE:
199*7c478bd9Sstevel@tonic-gate 					if (pte->uid ==	entry->uid) {
200*7c478bd9Sstevel@tonic-gate 						return (pte);
201*7c478bd9Sstevel@tonic-gate 					}
202*7c478bd9Sstevel@tonic-gate 					break;
203*7c478bd9Sstevel@tonic-gate 				default:
204*7c478bd9Sstevel@tonic-gate 					return (pte);
205*7c478bd9Sstevel@tonic-gate 				}
206*7c478bd9Sstevel@tonic-gate 			}
207*7c478bd9Sstevel@tonic-gate 		} else {
208*7c478bd9Sstevel@tonic-gate 			if (pte->fh_u.fh3.fh3_length ==
209*7c478bd9Sstevel@tonic-gate 				entry->fh_u.fh3.fh3_length &&
210*7c478bd9Sstevel@tonic-gate 				bcmp(pte->fh_u.fh3.fh3_u.data,
211*7c478bd9Sstevel@tonic-gate 					entry->fh_u.fh3.fh3_u.data,
212*7c478bd9Sstevel@tonic-gate 					pte->fh_u.fh3.fh3_length) == 0)
213*7c478bd9Sstevel@tonic-gate 				switch (entry->optype) {
214*7c478bd9Sstevel@tonic-gate 				case TRANS_OPER_READ:
215*7c478bd9Sstevel@tonic-gate 				case TRANS_OPER_WRITE:
216*7c478bd9Sstevel@tonic-gate 					if (pte->uid ==	entry->uid) {
217*7c478bd9Sstevel@tonic-gate 						return (pte);
218*7c478bd9Sstevel@tonic-gate 					}
219*7c478bd9Sstevel@tonic-gate 					break;
220*7c478bd9Sstevel@tonic-gate 				default:
221*7c478bd9Sstevel@tonic-gate 					return (pte);
222*7c478bd9Sstevel@tonic-gate 				}
223*7c478bd9Sstevel@tonic-gate 		}
224*7c478bd9Sstevel@tonic-gate 	}
225*7c478bd9Sstevel@tonic-gate 	/*
226*7c478bd9Sstevel@tonic-gate 	 * XXX - should compare more of the information to make sure
227*7c478bd9Sstevel@tonic-gate 	 * it is a match.
228*7c478bd9Sstevel@tonic-gate 	 */
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	/*
231*7c478bd9Sstevel@tonic-gate 	 * other operation types do not generate an entry for
232*7c478bd9Sstevel@tonic-gate 	 * further analysis
233*7c478bd9Sstevel@tonic-gate 	 */
234*7c478bd9Sstevel@tonic-gate 	switch (entry->optype) {
235*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_READ:
236*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_WRITE:
237*7c478bd9Sstevel@tonic-gate 		break;
238*7c478bd9Sstevel@tonic-gate 	default:
239*7c478bd9Sstevel@tonic-gate 		return (NULL);
240*7c478bd9Sstevel@tonic-gate 	}
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	insque(entry, te_list);
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	return (NULL); /* NULL signifies insertion and no record found */
245*7c478bd9Sstevel@tonic-gate }
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate static void
remove_te(struct transentry * pte)248*7c478bd9Sstevel@tonic-gate remove_te(struct transentry *pte)
249*7c478bd9Sstevel@tonic-gate {
250*7c478bd9Sstevel@tonic-gate 	if (pte->next)
251*7c478bd9Sstevel@tonic-gate 		remque(pte);
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	if (pte->principal_name) free(pte->principal_name);
254*7c478bd9Sstevel@tonic-gate 	if (pte->pathname) free(pte->pathname);
255*7c478bd9Sstevel@tonic-gate 	if (pte->pnb) freenetbuf(pte->pnb);
256*7c478bd9Sstevel@tonic-gate 	if (pte->netid) free(pte->netid);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	free(pte);
259*7c478bd9Sstevel@tonic-gate }
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate /*
262*7c478bd9Sstevel@tonic-gate  * nfslog_trans_file_free - frees a record
263*7c478bd9Sstevel@tonic-gate  */
264*7c478bd9Sstevel@tonic-gate static void
nfslog_trans_file_free(struct nfslog_trans_file * transrec)265*7c478bd9Sstevel@tonic-gate nfslog_trans_file_free(struct nfslog_trans_file *transrec)
266*7c478bd9Sstevel@tonic-gate {
267*7c478bd9Sstevel@tonic-gate 	if (transrec == NULL)
268*7c478bd9Sstevel@tonic-gate 		return;
269*7c478bd9Sstevel@tonic-gate 	if (transrec->path != NULL) {
270*7c478bd9Sstevel@tonic-gate 		if (debug)
271*7c478bd9Sstevel@tonic-gate 			(void) printf("freeing transpath '%s'\n",
272*7c478bd9Sstevel@tonic-gate 				transrec->path);
273*7c478bd9Sstevel@tonic-gate 		free(transrec->path);
274*7c478bd9Sstevel@tonic-gate 	}
275*7c478bd9Sstevel@tonic-gate 	free(transrec);
276*7c478bd9Sstevel@tonic-gate }
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate /*
279*7c478bd9Sstevel@tonic-gate  * On success returns a pointer to the trans_file that matches
280*7c478bd9Sstevel@tonic-gate  * 'path', 'output_type' and 'transtolog'.  The reference count for this
281*7c478bd9Sstevel@tonic-gate  * object is incremented as well.
282*7c478bd9Sstevel@tonic-gate  * Returns NULL if it is not in the list.
283*7c478bd9Sstevel@tonic-gate  */
284*7c478bd9Sstevel@tonic-gate static struct nfslog_trans_file *
nfslog_trans_file_find(char * path,uint32_t output_type,uint32_t transtolog)285*7c478bd9Sstevel@tonic-gate nfslog_trans_file_find(
286*7c478bd9Sstevel@tonic-gate 	char *path,
287*7c478bd9Sstevel@tonic-gate 	uint32_t output_type,
288*7c478bd9Sstevel@tonic-gate 	uint32_t transtolog)
289*7c478bd9Sstevel@tonic-gate {
290*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tfp;
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	for (tfp = trans_file_head; tfp != NULL; tfp = tfp->next) {
293*7c478bd9Sstevel@tonic-gate 		if ((strcmp(path, tfp->path) == 0) &&
294*7c478bd9Sstevel@tonic-gate 		    (output_type == tfp->trans_output_type) &&
295*7c478bd9Sstevel@tonic-gate 		    (transtolog == tfp->trans_to_log)) {
296*7c478bd9Sstevel@tonic-gate 			if (debug)
297*7c478bd9Sstevel@tonic-gate 				(void) printf("Found transfile '%s'\n", path);
298*7c478bd9Sstevel@tonic-gate 			(tfp->refcnt)++;
299*7c478bd9Sstevel@tonic-gate 			return (tfp);
300*7c478bd9Sstevel@tonic-gate 		}
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate 	return (NULL);
303*7c478bd9Sstevel@tonic-gate }
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate  * nfslog_close_trans_file - decrements the reference count on
308*7c478bd9Sstevel@tonic-gate  * this object. On last reference it closes transfile and
309*7c478bd9Sstevel@tonic-gate  * frees resources
310*7c478bd9Sstevel@tonic-gate  */
311*7c478bd9Sstevel@tonic-gate static void
nfslog_close_trans_file(struct nfslog_trans_file * tf)312*7c478bd9Sstevel@tonic-gate nfslog_close_trans_file(struct nfslog_trans_file *tf)
313*7c478bd9Sstevel@tonic-gate {
314*7c478bd9Sstevel@tonic-gate 	assert(tf != NULL);
315*7c478bd9Sstevel@tonic-gate 	assert(tf->refcnt > 0);
316*7c478bd9Sstevel@tonic-gate 	if (tf->refcnt > 1) {
317*7c478bd9Sstevel@tonic-gate 		(tf->refcnt)--;
318*7c478bd9Sstevel@tonic-gate 		return;
319*7c478bd9Sstevel@tonic-gate 	}
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 	if (tf->fp != NULL) {
322*7c478bd9Sstevel@tonic-gate 		(void) fsync(fileno(tf->fp));
323*7c478bd9Sstevel@tonic-gate 		(void) fclose(tf->fp);
324*7c478bd9Sstevel@tonic-gate 	}
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 	/*
327*7c478bd9Sstevel@tonic-gate 	 * Disconnect from list
328*7c478bd9Sstevel@tonic-gate 	 */
329*7c478bd9Sstevel@tonic-gate 	tf->prev->next = tf->next;
330*7c478bd9Sstevel@tonic-gate 	if (tf->next != NULL)
331*7c478bd9Sstevel@tonic-gate 		tf->next->prev = tf->prev;
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	/*
334*7c478bd9Sstevel@tonic-gate 	 * Adjust the head of the list if appropriate
335*7c478bd9Sstevel@tonic-gate 	 */
336*7c478bd9Sstevel@tonic-gate 	if (tf == trans_file_head)
337*7c478bd9Sstevel@tonic-gate 		trans_file_head = tf->next;
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 	nfslog_trans_file_free(tf);
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate  * nfslog_open_trans_file - open the output trans file and mallocs.
344*7c478bd9Sstevel@tonic-gate  * The object is then inserted at the beginning of the global
345*7c478bd9Sstevel@tonic-gate  * transfile list.
346*7c478bd9Sstevel@tonic-gate  *	Returns 0 for success, error else.
347*7c478bd9Sstevel@tonic-gate  *
348*7c478bd9Sstevel@tonic-gate  * *error contains the last error encountered on this object. It can
349*7c478bd9Sstevel@tonic-gate  * be used to avoid reporting the same error endlessly, by comparing
350*7c478bd9Sstevel@tonic-gate  * the current error to the last error. It is reset to the current error
351*7c478bd9Sstevel@tonic-gate  * code on return.
352*7c478bd9Sstevel@tonic-gate  */
353*7c478bd9Sstevel@tonic-gate void *
nfslog_open_trans_file(char * transpath,uint32_t output_type,uint32_t transtolog,int * error)354*7c478bd9Sstevel@tonic-gate nfslog_open_trans_file(
355*7c478bd9Sstevel@tonic-gate 	char *transpath,
356*7c478bd9Sstevel@tonic-gate 	uint32_t output_type,
357*7c478bd9Sstevel@tonic-gate 	uint32_t transtolog,
358*7c478bd9Sstevel@tonic-gate 	int *error)
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate 	int			preverror = *error;
361*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file	*transrec;
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate 	transrec = nfslog_trans_file_find(transpath, output_type, transtolog);
364*7c478bd9Sstevel@tonic-gate 	if (transrec != NULL)
365*7c478bd9Sstevel@tonic-gate 		return (transrec);
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate 	if ((transrec = malloc(sizeof (*transrec))) == NULL) {
368*7c478bd9Sstevel@tonic-gate 		*error = errno;
369*7c478bd9Sstevel@tonic-gate 		if (*error != preverror) {
370*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("nfslog_open_trans_file: %s"),
371*7c478bd9Sstevel@tonic-gate 				strerror(*error));
372*7c478bd9Sstevel@tonic-gate 		}
373*7c478bd9Sstevel@tonic-gate 		return (NULL);
374*7c478bd9Sstevel@tonic-gate 	}
375*7c478bd9Sstevel@tonic-gate 	bzero(transrec, sizeof (*transrec));
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	if ((transrec->path = strdup(transpath)) == NULL) {
378*7c478bd9Sstevel@tonic-gate 		*error = errno;
379*7c478bd9Sstevel@tonic-gate 		if (*error != preverror) {
380*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("nfslog_open_trans_file: %s"),
381*7c478bd9Sstevel@tonic-gate 				strerror(*error));
382*7c478bd9Sstevel@tonic-gate 		}
383*7c478bd9Sstevel@tonic-gate 		nfslog_trans_file_free(transrec);
384*7c478bd9Sstevel@tonic-gate 		return (NULL);
385*7c478bd9Sstevel@tonic-gate 	}
386*7c478bd9Sstevel@tonic-gate 
387*7c478bd9Sstevel@tonic-gate 	if ((transrec->fp = fopen(transpath, "a")) == NULL) {
388*7c478bd9Sstevel@tonic-gate 		*error = errno;
389*7c478bd9Sstevel@tonic-gate 		if (*error != preverror) {
390*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("Cannot open '%s': %s"),
391*7c478bd9Sstevel@tonic-gate 				transpath, strerror(*error));
392*7c478bd9Sstevel@tonic-gate 		}
393*7c478bd9Sstevel@tonic-gate 		nfslog_trans_file_free(transrec);
394*7c478bd9Sstevel@tonic-gate 		return (NULL);
395*7c478bd9Sstevel@tonic-gate 	}
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v3_read =
398*7c478bd9Sstevel@tonic-gate 		(struct transentry *)malloc(sizeof (struct transentry));
399*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v3_write =
400*7c478bd9Sstevel@tonic-gate 		(struct transentry *)malloc(sizeof (struct transentry));
401*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v2_read =
402*7c478bd9Sstevel@tonic-gate 		(struct transentry *)malloc(sizeof (struct transentry));
403*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v2_write =
404*7c478bd9Sstevel@tonic-gate 		(struct transentry *)malloc(sizeof (struct transentry));
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate 	if (transrec->te_list_v3_read == NULL ||
407*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v3_write == NULL ||
408*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v2_read == NULL ||
409*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v2_write == NULL) {
410*7c478bd9Sstevel@tonic-gate 		if (transrec->te_list_v3_read)
411*7c478bd9Sstevel@tonic-gate 			free(transrec->te_list_v3_read);
412*7c478bd9Sstevel@tonic-gate 		if (transrec->te_list_v3_write)
413*7c478bd9Sstevel@tonic-gate 			free(transrec->te_list_v3_write);
414*7c478bd9Sstevel@tonic-gate 		if (transrec->te_list_v2_read)
415*7c478bd9Sstevel@tonic-gate 			free(transrec->te_list_v2_read);
416*7c478bd9Sstevel@tonic-gate 		if (transrec->te_list_v2_write)
417*7c478bd9Sstevel@tonic-gate 			free(transrec->te_list_v2_write);
418*7c478bd9Sstevel@tonic-gate 		nfslog_close_trans_file(transrec);
419*7c478bd9Sstevel@tonic-gate 		return (NULL);
420*7c478bd9Sstevel@tonic-gate 	}
421*7c478bd9Sstevel@tonic-gate 
422*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v3_read->next =
423*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v3_read->prev = transrec->te_list_v3_read;
424*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v3_write->next =
425*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v3_write->prev = transrec->te_list_v3_write;
426*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v2_read->next =
427*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v2_read->prev = transrec->te_list_v2_read;
428*7c478bd9Sstevel@tonic-gate 	transrec->te_list_v2_write->next =
429*7c478bd9Sstevel@tonic-gate 		transrec->te_list_v2_write->prev = transrec->te_list_v2_write;
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate 	/*
432*7c478bd9Sstevel@tonic-gate 	 * Indicate what transaction types to log
433*7c478bd9Sstevel@tonic-gate 	 */
434*7c478bd9Sstevel@tonic-gate 	transrec->trans_to_log = transtolog;
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 	/*
437*7c478bd9Sstevel@tonic-gate 	 * Indicate whether to print 'full' or 'basic' version
438*7c478bd9Sstevel@tonic-gate 	 * of the transactions
439*7c478bd9Sstevel@tonic-gate 	 */
440*7c478bd9Sstevel@tonic-gate 	transrec->trans_output_type = output_type;
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate 	/*
443*7c478bd9Sstevel@tonic-gate 	 * Insert at the beginning of the list.
444*7c478bd9Sstevel@tonic-gate 	 */
445*7c478bd9Sstevel@tonic-gate 	transrec->next = trans_file_head;
446*7c478bd9Sstevel@tonic-gate 	if (trans_file_head != NULL)
447*7c478bd9Sstevel@tonic-gate 		trans_file_head->prev = transrec;
448*7c478bd9Sstevel@tonic-gate 	trans_file_head = transrec->prev = transrec;
449*7c478bd9Sstevel@tonic-gate 
450*7c478bd9Sstevel@tonic-gate 	transrec->refcnt = 1;
451*7c478bd9Sstevel@tonic-gate 
452*7c478bd9Sstevel@tonic-gate 	transrec->lasttrans_timestamp.tv_sec = 0;
453*7c478bd9Sstevel@tonic-gate 	transrec->lasttrans_timestamp.tv_nsec = 0;
454*7c478bd9Sstevel@tonic-gate 	transrec->last_trans_read = time(0);
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 	if (debug)
457*7c478bd9Sstevel@tonic-gate 		(void) printf("New transfile '%s'\n", transrec->path);
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 	return (transrec);
460*7c478bd9Sstevel@tonic-gate }
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate void
nfslog_process_trans_timeout(struct nfslog_trans_file * tf,uint32_t force_flush)463*7c478bd9Sstevel@tonic-gate nfslog_process_trans_timeout(
464*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
465*7c478bd9Sstevel@tonic-gate 	uint32_t force_flush)
466*7c478bd9Sstevel@tonic-gate {
467*7c478bd9Sstevel@tonic-gate 	struct transentry *pte;
468*7c478bd9Sstevel@tonic-gate 	time_t cur_time = time(0);
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate 	/*
471*7c478bd9Sstevel@tonic-gate 	 * If we have not seen a transaction on this file for
472*7c478bd9Sstevel@tonic-gate 	 * a long time, then we need to flush everything out since
473*7c478bd9Sstevel@tonic-gate 	 * we may not be getting anything else in for awhile.
474*7c478bd9Sstevel@tonic-gate 	 */
475*7c478bd9Sstevel@tonic-gate 	if (difftime(cur_time, tf->last_trans_read) >
476*7c478bd9Sstevel@tonic-gate 		(2 * MAX(TRANS_ENTRY_TIMEOUT, idle_time)))
477*7c478bd9Sstevel@tonic-gate 		force_flush = TRUE;
478*7c478bd9Sstevel@tonic-gate 
479*7c478bd9Sstevel@tonic-gate restart1:
480*7c478bd9Sstevel@tonic-gate 	for (pte = tf->te_list_v3_read->next;
481*7c478bd9Sstevel@tonic-gate 		pte != tf->te_list_v3_read;
482*7c478bd9Sstevel@tonic-gate 		pte = pte->next) {
483*7c478bd9Sstevel@tonic-gate 		if (force_flush == TRUE ||
484*7c478bd9Sstevel@tonic-gate 			(difftime(tf->lasttrans_timestamp.tv_sec,
485*7c478bd9Sstevel@tonic-gate 				pte->lastupdate.tv_sec) >
486*7c478bd9Sstevel@tonic-gate 			MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
487*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
488*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
489*7c478bd9Sstevel@tonic-gate 			goto restart1;
490*7c478bd9Sstevel@tonic-gate 		}
491*7c478bd9Sstevel@tonic-gate 	}
492*7c478bd9Sstevel@tonic-gate restart2:
493*7c478bd9Sstevel@tonic-gate 	for (pte = tf->te_list_v3_write->next;
494*7c478bd9Sstevel@tonic-gate 		pte != tf->te_list_v3_write;
495*7c478bd9Sstevel@tonic-gate 		pte = pte->next) {
496*7c478bd9Sstevel@tonic-gate 		if (force_flush == TRUE ||
497*7c478bd9Sstevel@tonic-gate 			(difftime(tf->lasttrans_timestamp.tv_sec,
498*7c478bd9Sstevel@tonic-gate 				pte->lastupdate.tv_sec) >
499*7c478bd9Sstevel@tonic-gate 			MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
500*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
501*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
502*7c478bd9Sstevel@tonic-gate 			goto restart2;
503*7c478bd9Sstevel@tonic-gate 		}
504*7c478bd9Sstevel@tonic-gate 	}
505*7c478bd9Sstevel@tonic-gate restart3:
506*7c478bd9Sstevel@tonic-gate 	for (pte = tf->te_list_v2_read->next;
507*7c478bd9Sstevel@tonic-gate 		pte != tf->te_list_v2_read;
508*7c478bd9Sstevel@tonic-gate 		pte = pte->next) {
509*7c478bd9Sstevel@tonic-gate 		if (force_flush == TRUE ||
510*7c478bd9Sstevel@tonic-gate 			(difftime(tf->lasttrans_timestamp.tv_sec,
511*7c478bd9Sstevel@tonic-gate 				pte->lastupdate.tv_sec) >
512*7c478bd9Sstevel@tonic-gate 			MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
513*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
514*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
515*7c478bd9Sstevel@tonic-gate 			goto restart3;
516*7c478bd9Sstevel@tonic-gate 		}
517*7c478bd9Sstevel@tonic-gate 	}
518*7c478bd9Sstevel@tonic-gate restart4:
519*7c478bd9Sstevel@tonic-gate 	for (pte = tf->te_list_v2_write->next;
520*7c478bd9Sstevel@tonic-gate 		pte != tf->te_list_v2_write;
521*7c478bd9Sstevel@tonic-gate 		pte = pte->next) {
522*7c478bd9Sstevel@tonic-gate 		if (force_flush == TRUE ||
523*7c478bd9Sstevel@tonic-gate 			(difftime(tf->lasttrans_timestamp.tv_sec,
524*7c478bd9Sstevel@tonic-gate 				pte->lastupdate.tv_sec) >
525*7c478bd9Sstevel@tonic-gate 			MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
526*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
527*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
528*7c478bd9Sstevel@tonic-gate 			goto restart4;
529*7c478bd9Sstevel@tonic-gate 		}
530*7c478bd9Sstevel@tonic-gate 	}
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate 	(void) fflush(tf->fp);
533*7c478bd9Sstevel@tonic-gate }
534*7c478bd9Sstevel@tonic-gate 
535*7c478bd9Sstevel@tonic-gate /*
536*7c478bd9Sstevel@tonic-gate  * Flushes outstanding transactions to disk, and closes
537*7c478bd9Sstevel@tonic-gate  * the transaction log.
538*7c478bd9Sstevel@tonic-gate  */
539*7c478bd9Sstevel@tonic-gate void
nfslog_close_transactions(void ** transcookie)540*7c478bd9Sstevel@tonic-gate nfslog_close_transactions(void **transcookie)
541*7c478bd9Sstevel@tonic-gate {
542*7c478bd9Sstevel@tonic-gate 	assert(*transcookie != NULL);
543*7c478bd9Sstevel@tonic-gate 	nfslog_process_trans_timeout(
544*7c478bd9Sstevel@tonic-gate 		(struct nfslog_trans_file *)(*transcookie), TRUE);
545*7c478bd9Sstevel@tonic-gate 	nfslog_close_trans_file((struct nfslog_trans_file *)(*transcookie));
546*7c478bd9Sstevel@tonic-gate 	*transcookie = NULL;
547*7c478bd9Sstevel@tonic-gate }
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_read(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)550*7c478bd9Sstevel@tonic-gate trans_read(
551*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
552*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
553*7c478bd9Sstevel@tonic-gate 	char *fhpath,
554*7c478bd9Sstevel@tonic-gate 	char *path1)
555*7c478bd9Sstevel@tonic-gate {
556*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
557*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
558*7c478bd9Sstevel@tonic-gate 	/* LINTED */
559*7c478bd9Sstevel@tonic-gate 	nfslog_nfsreadargs *args = (nfslog_nfsreadargs *)logrec->re_rpc_arg;
560*7c478bd9Sstevel@tonic-gate 	/* LINTED */
561*7c478bd9Sstevel@tonic-gate 	nfslog_rdresult *res = (nfslog_rdresult *)logrec->re_rpc_res;
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate 	if (res->r_status != NFS_OK)
564*7c478bd9Sstevel@tonic-gate 		return (NULL);
565*7c478bd9Sstevel@tonic-gate 
566*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
567*7c478bd9Sstevel@tonic-gate 		return (NULL);
568*7c478bd9Sstevel@tonic-gate 
569*7c478bd9Sstevel@tonic-gate 	if (!path1) {
570*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(&args->ra_fhandle,
571*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "trans_read");
572*7c478bd9Sstevel@tonic-gate 	} else {
573*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
574*7c478bd9Sstevel@tonic-gate 	}
575*7c478bd9Sstevel@tonic-gate 
576*7c478bd9Sstevel@tonic-gate 	/* prep the struct for insertion */
577*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
578*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
579*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_READ;
580*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
581*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
582*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
583*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
584*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
585*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
586*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
587*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
588*7c478bd9Sstevel@tonic-gate 	else
589*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
590*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = res->nfslog_rdresult_u.r_ok.rrok_count;
591*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->ra_fhandle));
592*7c478bd9Sstevel@tonic-gate 
593*7c478bd9Sstevel@tonic-gate 	if (res->nfslog_rdresult_u.r_ok.rrok_count <
594*7c478bd9Sstevel@tonic-gate 		res->nfslog_rdresult_u.r_ok.filesize) {
595*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v2_read, newte)) {
596*7c478bd9Sstevel@tonic-gate 			/* free this since entry was found (not inserted) */
597*7c478bd9Sstevel@tonic-gate 			remove_te(newte);
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 			pte->totalbytes +=
600*7c478bd9Sstevel@tonic-gate 				res->nfslog_rdresult_u.r_ok.rrok_count;
601*7c478bd9Sstevel@tonic-gate 
602*7c478bd9Sstevel@tonic-gate 			if (pte->lastupdate.tv_sec <=
603*7c478bd9Sstevel@tonic-gate 				logrec->re_header.rh_timestamp.tv_sec)
604*7c478bd9Sstevel@tonic-gate 				pte->lastupdate =
605*7c478bd9Sstevel@tonic-gate 					logrec->re_header.rh_timestamp;
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate 			if (pte->totalbytes <
608*7c478bd9Sstevel@tonic-gate 				res->nfslog_rdresult_u.r_ok.filesize) {
609*7c478bd9Sstevel@tonic-gate 				pte = NULL; /* prevent printing of log entry */
610*7c478bd9Sstevel@tonic-gate 			}
611*7c478bd9Sstevel@tonic-gate 		}
612*7c478bd9Sstevel@tonic-gate 	} else {
613*7c478bd9Sstevel@tonic-gate 		pte = newte; /* print a log record - complete file read */
614*7c478bd9Sstevel@tonic-gate 	}
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	return (pte);
617*7c478bd9Sstevel@tonic-gate }
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_write(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)620*7c478bd9Sstevel@tonic-gate trans_write(
621*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
622*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
623*7c478bd9Sstevel@tonic-gate 	char *fhpath,
624*7c478bd9Sstevel@tonic-gate 	char *path1)
625*7c478bd9Sstevel@tonic-gate {
626*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
627*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
628*7c478bd9Sstevel@tonic-gate 	/* LINTED */
629*7c478bd9Sstevel@tonic-gate 	nfslog_writeargs *args = (nfslog_writeargs *)logrec->re_rpc_arg;
630*7c478bd9Sstevel@tonic-gate 	/* LINTED */
631*7c478bd9Sstevel@tonic-gate 	nfslog_writeresult *res = (nfslog_writeresult *)logrec->re_rpc_res;
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate 	if (res->wr_status != NFS_OK)
634*7c478bd9Sstevel@tonic-gate 		return (NULL);
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
637*7c478bd9Sstevel@tonic-gate 		return (NULL);
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate 	if (!path1) {
640*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(&args->waargs_fhandle,
641*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "trans_write");
642*7c478bd9Sstevel@tonic-gate 	} else {
643*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
644*7c478bd9Sstevel@tonic-gate 	}
645*7c478bd9Sstevel@tonic-gate 
646*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
647*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
648*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_WRITE;
649*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
650*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
651*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
652*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
653*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
654*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
655*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
656*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
657*7c478bd9Sstevel@tonic-gate 	else
658*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
659*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = args->waargs_totcount;
660*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->waargs_fhandle));
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
663*7c478bd9Sstevel@tonic-gate 		/*
664*7c478bd9Sstevel@tonic-gate 		 * if the write would have increased the total byte count
665*7c478bd9Sstevel@tonic-gate 		 * over the filesize, then generate a log entry and remove
666*7c478bd9Sstevel@tonic-gate 		 * the write record and insert the new one.
667*7c478bd9Sstevel@tonic-gate 		 */
668*7c478bd9Sstevel@tonic-gate 		if (pte->totalbytes + args->waargs_totcount >
669*7c478bd9Sstevel@tonic-gate 			res->nfslog_writeresult_u.wr_size) {
670*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
671*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
672*7c478bd9Sstevel@tonic-gate 			(void) insert_te(tf->te_list_v2_write, newte);
673*7c478bd9Sstevel@tonic-gate 			pte = NULL;
674*7c478bd9Sstevel@tonic-gate 		} else {
675*7c478bd9Sstevel@tonic-gate 			/* free this since entry was found (not inserted) */
676*7c478bd9Sstevel@tonic-gate 			remove_te(newte);
677*7c478bd9Sstevel@tonic-gate 
678*7c478bd9Sstevel@tonic-gate 			pte->totalbytes += args->waargs_totcount;
679*7c478bd9Sstevel@tonic-gate 
680*7c478bd9Sstevel@tonic-gate 			if (pte->lastupdate.tv_sec <=
681*7c478bd9Sstevel@tonic-gate 				logrec->re_header.rh_timestamp.tv_sec) {
682*7c478bd9Sstevel@tonic-gate 				pte->lastupdate =
683*7c478bd9Sstevel@tonic-gate 					logrec->re_header.rh_timestamp;
684*7c478bd9Sstevel@tonic-gate 			}
685*7c478bd9Sstevel@tonic-gate 			pte = NULL; /* prevent printing of log entry */
686*7c478bd9Sstevel@tonic-gate 		}
687*7c478bd9Sstevel@tonic-gate 	}
688*7c478bd9Sstevel@tonic-gate 	return (pte);
689*7c478bd9Sstevel@tonic-gate }
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_setattr(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)692*7c478bd9Sstevel@tonic-gate trans_setattr(
693*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
694*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
695*7c478bd9Sstevel@tonic-gate 	char *fhpath,
696*7c478bd9Sstevel@tonic-gate 	char *path1)
697*7c478bd9Sstevel@tonic-gate {
698*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
699*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
700*7c478bd9Sstevel@tonic-gate 	/* LINTED */
701*7c478bd9Sstevel@tonic-gate 	nfslog_setattrargs *args = (nfslog_setattrargs *)logrec->re_rpc_arg;
702*7c478bd9Sstevel@tonic-gate 	/* LINTED */
703*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
704*7c478bd9Sstevel@tonic-gate 
705*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
706*7c478bd9Sstevel@tonic-gate 		return (NULL);
707*7c478bd9Sstevel@tonic-gate 
708*7c478bd9Sstevel@tonic-gate 	if (args->saa_sa.sa_size == (uint32_t)-1)
709*7c478bd9Sstevel@tonic-gate 		return (NULL);
710*7c478bd9Sstevel@tonic-gate 	/*
711*7c478bd9Sstevel@tonic-gate 	 * should check the size of the file to see if it
712*7c478bd9Sstevel@tonic-gate 	 * is being truncated below current eof.  if so
713*7c478bd9Sstevel@tonic-gate 	 * a record should be generated.... XXX
714*7c478bd9Sstevel@tonic-gate 	 */
715*7c478bd9Sstevel@tonic-gate 	if (args->saa_sa.sa_size != 0)
716*7c478bd9Sstevel@tonic-gate 		return (NULL);
717*7c478bd9Sstevel@tonic-gate 
718*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
719*7c478bd9Sstevel@tonic-gate 		return (NULL);
720*7c478bd9Sstevel@tonic-gate 
721*7c478bd9Sstevel@tonic-gate 	if (!path1) {
722*7c478bd9Sstevel@tonic-gate 		newte->pathname  = nfslog_get_path(&args->saa_fh, NULL,
723*7c478bd9Sstevel@tonic-gate 			fhpath,	"trans_setattr2");
724*7c478bd9Sstevel@tonic-gate 	} else {
725*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
726*7c478bd9Sstevel@tonic-gate 	}
727*7c478bd9Sstevel@tonic-gate 
728*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
729*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
730*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_SETATTR;
731*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
732*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
733*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
734*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
735*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
736*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
737*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
738*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
739*7c478bd9Sstevel@tonic-gate 	else
740*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
741*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
742*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->saa_fh));
743*7c478bd9Sstevel@tonic-gate 
744*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
745*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
746*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
747*7c478bd9Sstevel@tonic-gate 	}
748*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_read, newte)) {
749*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
750*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
751*7c478bd9Sstevel@tonic-gate 	}
752*7c478bd9Sstevel@tonic-gate 
753*7c478bd9Sstevel@tonic-gate 	return (newte);
754*7c478bd9Sstevel@tonic-gate }
755*7c478bd9Sstevel@tonic-gate 
756*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_create(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)757*7c478bd9Sstevel@tonic-gate trans_create(
758*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
759*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
760*7c478bd9Sstevel@tonic-gate 	char *fhpath,
761*7c478bd9Sstevel@tonic-gate 	char *path1)
762*7c478bd9Sstevel@tonic-gate {
763*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
764*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
765*7c478bd9Sstevel@tonic-gate 	/* LINTED */
766*7c478bd9Sstevel@tonic-gate 	nfslog_createargs *args = (nfslog_createargs *)logrec->re_rpc_arg;
767*7c478bd9Sstevel@tonic-gate 	/* LINTED */
768*7c478bd9Sstevel@tonic-gate 	nfslog_diropres *res = (nfslog_diropres *)logrec->re_rpc_res;
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate 	if (res->dr_status != NFS_OK)
771*7c478bd9Sstevel@tonic-gate 		return (NULL);
772*7c478bd9Sstevel@tonic-gate 
773*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
774*7c478bd9Sstevel@tonic-gate 		return (NULL);
775*7c478bd9Sstevel@tonic-gate 
776*7c478bd9Sstevel@tonic-gate 	if (!path1) {
777*7c478bd9Sstevel@tonic-gate 		newte->pathname =
778*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(&args->ca_da.da_fhandle,
779*7c478bd9Sstevel@tonic-gate 				args->ca_da.da_name,
780*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_create2");
781*7c478bd9Sstevel@tonic-gate 	} else {
782*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
783*7c478bd9Sstevel@tonic-gate 	}
784*7c478bd9Sstevel@tonic-gate 
785*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
786*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
787*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_CREATE;
788*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
789*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
790*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
791*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
792*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
793*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
794*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
795*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
796*7c478bd9Sstevel@tonic-gate 	else
797*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
798*7c478bd9Sstevel@tonic-gate 
799*7c478bd9Sstevel@tonic-gate 	if (args->ca_sa.sa_size == (uint32_t)-1)
800*7c478bd9Sstevel@tonic-gate 		newte->totalbytes = 0;
801*7c478bd9Sstevel@tonic-gate 	else
802*7c478bd9Sstevel@tonic-gate 		newte->totalbytes = args->ca_sa.sa_size;
803*7c478bd9Sstevel@tonic-gate 
804*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(
805*7c478bd9Sstevel@tonic-gate 		&res->nfslog_diropres_u.dr_ok.drok_fhandle));
806*7c478bd9Sstevel@tonic-gate 
807*7c478bd9Sstevel@tonic-gate 	/*
808*7c478bd9Sstevel@tonic-gate 	 * if the file is being truncated on create, we need to flush
809*7c478bd9Sstevel@tonic-gate 	 * any outstanding read/write transactions
810*7c478bd9Sstevel@tonic-gate 	 */
811*7c478bd9Sstevel@tonic-gate 	if (args->ca_sa.sa_size != (uint32_t)-1) {
812*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v2_write, newte)) {
813*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
814*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
815*7c478bd9Sstevel@tonic-gate 		}
816*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v2_read, newte)) {
817*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
818*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
819*7c478bd9Sstevel@tonic-gate 		}
820*7c478bd9Sstevel@tonic-gate 	}
821*7c478bd9Sstevel@tonic-gate 
822*7c478bd9Sstevel@tonic-gate 	return (newte);
823*7c478bd9Sstevel@tonic-gate }
824*7c478bd9Sstevel@tonic-gate 
825*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_remove(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)826*7c478bd9Sstevel@tonic-gate trans_remove(
827*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
828*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
829*7c478bd9Sstevel@tonic-gate 	char *fhpath,
830*7c478bd9Sstevel@tonic-gate 	char *path1)
831*7c478bd9Sstevel@tonic-gate {
832*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
833*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
834*7c478bd9Sstevel@tonic-gate 	/* LINTED */
835*7c478bd9Sstevel@tonic-gate 	nfslog_diropargs *args = (nfslog_diropargs *)logrec->re_rpc_arg;
836*7c478bd9Sstevel@tonic-gate 	/* LINTED */
837*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
838*7c478bd9Sstevel@tonic-gate 
839*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
840*7c478bd9Sstevel@tonic-gate 		return (NULL);
841*7c478bd9Sstevel@tonic-gate 
842*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
843*7c478bd9Sstevel@tonic-gate 		return (NULL);
844*7c478bd9Sstevel@tonic-gate 
845*7c478bd9Sstevel@tonic-gate 	if (!path1) {
846*7c478bd9Sstevel@tonic-gate 		char *name = args->da_name;
847*7c478bd9Sstevel@tonic-gate 		fhandle_t *dfh = &args->da_fhandle;
848*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(dfh, name,
849*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_remove2");
850*7c478bd9Sstevel@tonic-gate 	} else {
851*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
852*7c478bd9Sstevel@tonic-gate 	}
853*7c478bd9Sstevel@tonic-gate 
854*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
855*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
856*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_REMOVE;
857*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
858*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
859*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
860*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
861*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
862*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
863*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
864*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
865*7c478bd9Sstevel@tonic-gate 	else
866*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
867*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
868*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->da_fhandle));
869*7c478bd9Sstevel@tonic-gate 
870*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
871*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
872*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
873*7c478bd9Sstevel@tonic-gate 	}
874*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_read, newte)) {
875*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
876*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
877*7c478bd9Sstevel@tonic-gate 	}
878*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
879*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
880*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
881*7c478bd9Sstevel@tonic-gate 	}
882*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_read, newte)) {
883*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
884*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
885*7c478bd9Sstevel@tonic-gate 	}
886*7c478bd9Sstevel@tonic-gate 
887*7c478bd9Sstevel@tonic-gate 	return (newte);
888*7c478bd9Sstevel@tonic-gate }
889*7c478bd9Sstevel@tonic-gate 
890*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mkdir(nfslog_request_record * logrec,char * fhpath,char * path1)891*7c478bd9Sstevel@tonic-gate trans_mkdir(
892*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
893*7c478bd9Sstevel@tonic-gate 	char *fhpath,
894*7c478bd9Sstevel@tonic-gate 	char *path1)
895*7c478bd9Sstevel@tonic-gate {
896*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
897*7c478bd9Sstevel@tonic-gate 	/* LINTED */
898*7c478bd9Sstevel@tonic-gate 	nfslog_createargs *args = (nfslog_createargs *)logrec->re_rpc_arg;
899*7c478bd9Sstevel@tonic-gate 	/* LINTED */
900*7c478bd9Sstevel@tonic-gate 	nfslog_diropres *res = (nfslog_diropres *)logrec->re_rpc_res;
901*7c478bd9Sstevel@tonic-gate 
902*7c478bd9Sstevel@tonic-gate 	if (res->dr_status != NFS_OK)
903*7c478bd9Sstevel@tonic-gate 		return (NULL);
904*7c478bd9Sstevel@tonic-gate 
905*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
906*7c478bd9Sstevel@tonic-gate 		return (NULL);
907*7c478bd9Sstevel@tonic-gate 
908*7c478bd9Sstevel@tonic-gate 	if (!path1) {
909*7c478bd9Sstevel@tonic-gate 		nfslog_diropargs *dargs = &args->ca_da;
910*7c478bd9Sstevel@tonic-gate 		char *name = dargs->da_name;
911*7c478bd9Sstevel@tonic-gate 		fhandle_t *dfh = &dargs->da_fhandle;
912*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(dfh, name,
913*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_mkdir2");
914*7c478bd9Sstevel@tonic-gate 	} else {
915*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
916*7c478bd9Sstevel@tonic-gate 	}
917*7c478bd9Sstevel@tonic-gate 
918*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
919*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
920*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_MKDIR;
921*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
922*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
923*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
924*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
925*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
926*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
927*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
928*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
929*7c478bd9Sstevel@tonic-gate 	else
930*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
931*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
932*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->ca_da.da_fhandle));
933*7c478bd9Sstevel@tonic-gate 
934*7c478bd9Sstevel@tonic-gate 	return (newte);
935*7c478bd9Sstevel@tonic-gate }
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rmdir(nfslog_request_record * logrec,char * fhpath,char * path1)938*7c478bd9Sstevel@tonic-gate trans_rmdir(
939*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
940*7c478bd9Sstevel@tonic-gate 	char *fhpath,
941*7c478bd9Sstevel@tonic-gate 	char *path1)
942*7c478bd9Sstevel@tonic-gate {
943*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
944*7c478bd9Sstevel@tonic-gate 	/* LINTED */
945*7c478bd9Sstevel@tonic-gate 	nfslog_diropargs *args = (nfslog_diropargs *)logrec->re_rpc_arg;
946*7c478bd9Sstevel@tonic-gate 	/* LINTED */
947*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
948*7c478bd9Sstevel@tonic-gate 
949*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
950*7c478bd9Sstevel@tonic-gate 		return (NULL);
951*7c478bd9Sstevel@tonic-gate 
952*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
953*7c478bd9Sstevel@tonic-gate 		return (NULL);
954*7c478bd9Sstevel@tonic-gate 
955*7c478bd9Sstevel@tonic-gate 	if (!path1) {
956*7c478bd9Sstevel@tonic-gate 		char *name = args->da_name;
957*7c478bd9Sstevel@tonic-gate 		fhandle_t *dfh = &args->da_fhandle;
958*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(dfh, name,
959*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_rmdir2");
960*7c478bd9Sstevel@tonic-gate 	} else {
961*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
962*7c478bd9Sstevel@tonic-gate 	}
963*7c478bd9Sstevel@tonic-gate 
964*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
965*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
966*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_RMDIR;
967*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
968*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
969*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
970*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
971*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
972*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
973*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
974*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
975*7c478bd9Sstevel@tonic-gate 	else
976*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
977*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
978*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->da_fhandle));
979*7c478bd9Sstevel@tonic-gate 
980*7c478bd9Sstevel@tonic-gate 	return (newte);
981*7c478bd9Sstevel@tonic-gate }
982*7c478bd9Sstevel@tonic-gate 
983*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rename(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1,char * path2)984*7c478bd9Sstevel@tonic-gate trans_rename(
985*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
986*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
987*7c478bd9Sstevel@tonic-gate 	char *fhpath,
988*7c478bd9Sstevel@tonic-gate 	char *path1,
989*7c478bd9Sstevel@tonic-gate 	char *path2)
990*7c478bd9Sstevel@tonic-gate {
991*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
992*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
993*7c478bd9Sstevel@tonic-gate 	/* LINTED */
994*7c478bd9Sstevel@tonic-gate 	nfslog_rnmargs *args = (nfslog_rnmargs *)logrec->re_rpc_arg;
995*7c478bd9Sstevel@tonic-gate 	/* LINTED */
996*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
997*7c478bd9Sstevel@tonic-gate 	char *tpath1 = NULL;
998*7c478bd9Sstevel@tonic-gate 	char *tpath2 = NULL;
999*7c478bd9Sstevel@tonic-gate 
1000*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1001*7c478bd9Sstevel@tonic-gate 		return (NULL);
1002*7c478bd9Sstevel@tonic-gate 
1003*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1004*7c478bd9Sstevel@tonic-gate 		return (NULL);
1005*7c478bd9Sstevel@tonic-gate 
1006*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1007*7c478bd9Sstevel@tonic-gate 		char *from_name, *to_name;
1008*7c478bd9Sstevel@tonic-gate 		fhandle_t *from_dfh, *to_dfh;
1009*7c478bd9Sstevel@tonic-gate 
1010*7c478bd9Sstevel@tonic-gate 		from_name = args->rna_from.da_name;
1011*7c478bd9Sstevel@tonic-gate 		from_dfh = &args->rna_from.da_fhandle;
1012*7c478bd9Sstevel@tonic-gate 		to_name = args->rna_to.da_name;
1013*7c478bd9Sstevel@tonic-gate 		to_dfh = &args->rna_to.da_fhandle;
1014*7c478bd9Sstevel@tonic-gate 
1015*7c478bd9Sstevel@tonic-gate 		path1 = tpath1 = nfslog_get_path(from_dfh, from_name,
1016*7c478bd9Sstevel@tonic-gate 			fhpath,	"trans_rename from");
1017*7c478bd9Sstevel@tonic-gate 		path2 = tpath2 = nfslog_get_path(to_dfh, to_name,
1018*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_rename to");
1019*7c478bd9Sstevel@tonic-gate 	}
1020*7c478bd9Sstevel@tonic-gate 
1021*7c478bd9Sstevel@tonic-gate 	newte->pathname = path1; /* no need to strdup here */
1022*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1023*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1024*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_RENAME;
1025*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1026*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1027*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1028*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1029*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
1030*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1031*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1032*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1033*7c478bd9Sstevel@tonic-gate 	else
1034*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1035*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1036*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->rna_from.da_fhandle));
1037*7c478bd9Sstevel@tonic-gate 
1038*7c478bd9Sstevel@tonic-gate 	/* switch path names for the file for renames */
1039*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
1040*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1041*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1042*7c478bd9Sstevel@tonic-gate 	}
1043*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_read, newte)) {
1044*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1045*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1046*7c478bd9Sstevel@tonic-gate 	}
1047*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
1048*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1049*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1050*7c478bd9Sstevel@tonic-gate 	}
1051*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_read, newte)) {
1052*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1053*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1054*7c478bd9Sstevel@tonic-gate 	}
1055*7c478bd9Sstevel@tonic-gate 
1056*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1057*7c478bd9Sstevel@tonic-gate 	/* check for NULL malloc */
1058*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", path1, path2);
1059*7c478bd9Sstevel@tonic-gate 
1060*7c478bd9Sstevel@tonic-gate 	if (tpath1) {
1061*7c478bd9Sstevel@tonic-gate 		free(tpath1);
1062*7c478bd9Sstevel@tonic-gate 		free(tpath2);
1063*7c478bd9Sstevel@tonic-gate 	}
1064*7c478bd9Sstevel@tonic-gate 
1065*7c478bd9Sstevel@tonic-gate 	return (newte);
1066*7c478bd9Sstevel@tonic-gate }
1067*7c478bd9Sstevel@tonic-gate 
1068*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_link(nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1069*7c478bd9Sstevel@tonic-gate trans_link(
1070*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1071*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1072*7c478bd9Sstevel@tonic-gate 	char *path1,
1073*7c478bd9Sstevel@tonic-gate 	char *path2)
1074*7c478bd9Sstevel@tonic-gate {
1075*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1076*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1077*7c478bd9Sstevel@tonic-gate 	nfslog_linkargs *args = (nfslog_linkargs *)logrec->re_rpc_arg;
1078*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1079*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
1080*7c478bd9Sstevel@tonic-gate 	char *tpath1 = NULL;
1081*7c478bd9Sstevel@tonic-gate 	char *tpath2 = NULL;
1082*7c478bd9Sstevel@tonic-gate 
1083*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1084*7c478bd9Sstevel@tonic-gate 		return (NULL);
1085*7c478bd9Sstevel@tonic-gate 
1086*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1087*7c478bd9Sstevel@tonic-gate 		return (NULL);
1088*7c478bd9Sstevel@tonic-gate 
1089*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1090*7c478bd9Sstevel@tonic-gate 		fhandle_t *fh = &args->la_from;
1091*7c478bd9Sstevel@tonic-gate 		char *name = args->la_to.da_name;
1092*7c478bd9Sstevel@tonic-gate 		fhandle_t *dfh = &args->la_to.da_fhandle;
1093*7c478bd9Sstevel@tonic-gate 
1094*7c478bd9Sstevel@tonic-gate 		path1 = tpath1 = nfslog_get_path(fh, NULL,
1095*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_link from");
1096*7c478bd9Sstevel@tonic-gate 		path2 = tpath2 = nfslog_get_path(dfh, name,
1097*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_link to");
1098*7c478bd9Sstevel@tonic-gate 	}
1099*7c478bd9Sstevel@tonic-gate 
1100*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1101*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1102*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_LINK;
1103*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1104*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1105*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1106*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1107*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
1108*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1109*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1110*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1111*7c478bd9Sstevel@tonic-gate 	else
1112*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1113*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1114*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->la_from));
1115*7c478bd9Sstevel@tonic-gate 
1116*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1117*7c478bd9Sstevel@tonic-gate 	/* check for NULL malloc */
1118*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", path1, path2);
1119*7c478bd9Sstevel@tonic-gate 
1120*7c478bd9Sstevel@tonic-gate 	if (tpath1) {
1121*7c478bd9Sstevel@tonic-gate 		free(tpath1);
1122*7c478bd9Sstevel@tonic-gate 		free(tpath2);
1123*7c478bd9Sstevel@tonic-gate 	}
1124*7c478bd9Sstevel@tonic-gate 
1125*7c478bd9Sstevel@tonic-gate 	return (newte);
1126*7c478bd9Sstevel@tonic-gate }
1127*7c478bd9Sstevel@tonic-gate 
1128*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_symlink(nfslog_request_record * logrec,char * fhpath,char * path1)1129*7c478bd9Sstevel@tonic-gate trans_symlink(
1130*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1131*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1132*7c478bd9Sstevel@tonic-gate 	char *path1)
1133*7c478bd9Sstevel@tonic-gate {
1134*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1135*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1136*7c478bd9Sstevel@tonic-gate 	nfslog_symlinkargs *args = (nfslog_symlinkargs *)logrec->re_rpc_arg;
1137*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1138*7c478bd9Sstevel@tonic-gate 	nfsstat *res = (nfsstat *)logrec->re_rpc_res;
1139*7c478bd9Sstevel@tonic-gate 	char *tpath1 = NULL;
1140*7c478bd9Sstevel@tonic-gate 
1141*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1142*7c478bd9Sstevel@tonic-gate 		return (NULL);
1143*7c478bd9Sstevel@tonic-gate 
1144*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1145*7c478bd9Sstevel@tonic-gate 		return (NULL);
1146*7c478bd9Sstevel@tonic-gate 
1147*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1148*7c478bd9Sstevel@tonic-gate 		char *name = args->sla_from.da_name;
1149*7c478bd9Sstevel@tonic-gate 		fhandle_t *dfh = &args->sla_from.da_fhandle;
1150*7c478bd9Sstevel@tonic-gate 
1151*7c478bd9Sstevel@tonic-gate 		path1 = tpath1 = nfslog_get_path(dfh, name,
1152*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_symlink");
1153*7c478bd9Sstevel@tonic-gate 	}
1154*7c478bd9Sstevel@tonic-gate 
1155*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1156*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1157*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_SYMLINK;
1158*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1159*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1160*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1161*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1162*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_VERSION;
1163*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1164*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1165*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1166*7c478bd9Sstevel@tonic-gate 	else
1167*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1168*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1169*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->sla_from.da_fhandle));
1170*7c478bd9Sstevel@tonic-gate 
1171*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(path1) +
1172*7c478bd9Sstevel@tonic-gate 		strlen(args->sla_tnm) + 3);
1173*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", path1, args->sla_tnm);
1174*7c478bd9Sstevel@tonic-gate 
1175*7c478bd9Sstevel@tonic-gate 	if (tpath1)
1176*7c478bd9Sstevel@tonic-gate 		free(tpath1);
1177*7c478bd9Sstevel@tonic-gate 
1178*7c478bd9Sstevel@tonic-gate 	return (newte);
1179*7c478bd9Sstevel@tonic-gate }
1180*7c478bd9Sstevel@tonic-gate 
1181*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_read3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1182*7c478bd9Sstevel@tonic-gate trans_read3(
1183*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1184*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1185*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1186*7c478bd9Sstevel@tonic-gate 	char *path1)
1187*7c478bd9Sstevel@tonic-gate {
1188*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1189*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1190*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1191*7c478bd9Sstevel@tonic-gate 	nfslog_READ3args *args = (nfslog_READ3args *)logrec->re_rpc_arg;
1192*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1193*7c478bd9Sstevel@tonic-gate 	nfslog_READ3res *res = (nfslog_READ3res *)logrec->re_rpc_res;
1194*7c478bd9Sstevel@tonic-gate 
1195*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1196*7c478bd9Sstevel@tonic-gate 		return (NULL);
1197*7c478bd9Sstevel@tonic-gate 
1198*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1199*7c478bd9Sstevel@tonic-gate 		return (NULL);
1200*7c478bd9Sstevel@tonic-gate 
1201*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1202*7c478bd9Sstevel@tonic-gate 		fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->file);
1203*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(fh, NULL,
1204*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_read3");
1205*7c478bd9Sstevel@tonic-gate 	} else {
1206*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1207*7c478bd9Sstevel@tonic-gate 	}
1208*7c478bd9Sstevel@tonic-gate 
1209*7c478bd9Sstevel@tonic-gate 	/* prep the struct for insertion */
1210*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1211*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1212*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_READ;
1213*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1214*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1215*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1216*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1217*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1218*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1219*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1220*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1221*7c478bd9Sstevel@tonic-gate 	else
1222*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1223*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = res->nfslog_READ3res_u.ok.count;
1224*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->file;
1225*7c478bd9Sstevel@tonic-gate 
1226*7c478bd9Sstevel@tonic-gate 	if (res->nfslog_READ3res_u.ok.count <
1227*7c478bd9Sstevel@tonic-gate 		res->nfslog_READ3res_u.ok.filesize) {
1228*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v3_read, newte)) {
1229*7c478bd9Sstevel@tonic-gate 			/* free this since entry was found (not inserted) */
1230*7c478bd9Sstevel@tonic-gate 			remove_te(newte);
1231*7c478bd9Sstevel@tonic-gate 
1232*7c478bd9Sstevel@tonic-gate 			pte->totalbytes += res->nfslog_READ3res_u.ok.count;
1233*7c478bd9Sstevel@tonic-gate 
1234*7c478bd9Sstevel@tonic-gate 			if (pte->lastupdate.tv_sec <=
1235*7c478bd9Sstevel@tonic-gate 				logrec->re_header.rh_timestamp.tv_sec)
1236*7c478bd9Sstevel@tonic-gate 				pte->lastupdate =
1237*7c478bd9Sstevel@tonic-gate 					logrec->re_header.rh_timestamp;
1238*7c478bd9Sstevel@tonic-gate 
1239*7c478bd9Sstevel@tonic-gate 			if (pte->totalbytes <
1240*7c478bd9Sstevel@tonic-gate 				res->nfslog_READ3res_u.ok.filesize) {
1241*7c478bd9Sstevel@tonic-gate 				pte = NULL; /* prevent printing of log entry */
1242*7c478bd9Sstevel@tonic-gate 			}
1243*7c478bd9Sstevel@tonic-gate 		}
1244*7c478bd9Sstevel@tonic-gate 	} else {
1245*7c478bd9Sstevel@tonic-gate 		pte = newte; /* print a log record - complete file read */
1246*7c478bd9Sstevel@tonic-gate 	}
1247*7c478bd9Sstevel@tonic-gate 
1248*7c478bd9Sstevel@tonic-gate 	return (pte);
1249*7c478bd9Sstevel@tonic-gate }
1250*7c478bd9Sstevel@tonic-gate 
1251*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_write3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1252*7c478bd9Sstevel@tonic-gate trans_write3(
1253*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1254*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1255*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1256*7c478bd9Sstevel@tonic-gate 	char *path1)
1257*7c478bd9Sstevel@tonic-gate {
1258*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1259*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1260*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1261*7c478bd9Sstevel@tonic-gate 	nfslog_WRITE3args *args = (nfslog_WRITE3args *)logrec->re_rpc_arg;
1262*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1263*7c478bd9Sstevel@tonic-gate 	nfslog_WRITE3res *res = (nfslog_WRITE3res *)logrec->re_rpc_res;
1264*7c478bd9Sstevel@tonic-gate 
1265*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1266*7c478bd9Sstevel@tonic-gate 		return (NULL);
1267*7c478bd9Sstevel@tonic-gate 
1268*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1269*7c478bd9Sstevel@tonic-gate 		return (NULL);
1270*7c478bd9Sstevel@tonic-gate 
1271*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1272*7c478bd9Sstevel@tonic-gate 		fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->file);
1273*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(fh, NULL,
1274*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_write3");
1275*7c478bd9Sstevel@tonic-gate 	} else {
1276*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1277*7c478bd9Sstevel@tonic-gate 	}
1278*7c478bd9Sstevel@tonic-gate 
1279*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1280*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1281*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_WRITE;
1282*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1283*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1284*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1285*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1286*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1287*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1288*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1289*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1290*7c478bd9Sstevel@tonic-gate 	else
1291*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1292*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = res->nfslog_WRITE3res_u.ok.count;
1293*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->file;
1294*7c478bd9Sstevel@tonic-gate 
1295*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
1296*7c478bd9Sstevel@tonic-gate 		/*
1297*7c478bd9Sstevel@tonic-gate 		 * if the write would have increased the total byte count
1298*7c478bd9Sstevel@tonic-gate 		 * over the filesize, then generate a log entry and remove
1299*7c478bd9Sstevel@tonic-gate 		 * the write record and insert the new one.
1300*7c478bd9Sstevel@tonic-gate 		 */
1301*7c478bd9Sstevel@tonic-gate 		if (pte->totalbytes + res->nfslog_WRITE3res_u.ok.count >
1302*7c478bd9Sstevel@tonic-gate 			res->nfslog_WRITE3res_u.ok.filesize) {
1303*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
1304*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
1305*7c478bd9Sstevel@tonic-gate 			(void) insert_te(tf->te_list_v3_write, newte);
1306*7c478bd9Sstevel@tonic-gate 			pte = NULL;
1307*7c478bd9Sstevel@tonic-gate 		} else {
1308*7c478bd9Sstevel@tonic-gate 			/* free this since entry was found (not inserted) */
1309*7c478bd9Sstevel@tonic-gate 			remove_te(newte);
1310*7c478bd9Sstevel@tonic-gate 
1311*7c478bd9Sstevel@tonic-gate 			pte->totalbytes += res->nfslog_WRITE3res_u.ok.count;
1312*7c478bd9Sstevel@tonic-gate 
1313*7c478bd9Sstevel@tonic-gate 			if (pte->lastupdate.tv_sec <=
1314*7c478bd9Sstevel@tonic-gate 				logrec->re_header.rh_timestamp.tv_sec) {
1315*7c478bd9Sstevel@tonic-gate 				pte->lastupdate =
1316*7c478bd9Sstevel@tonic-gate 					logrec->re_header.rh_timestamp;
1317*7c478bd9Sstevel@tonic-gate 			}
1318*7c478bd9Sstevel@tonic-gate 			pte = NULL; /* prevent printing of log entry */
1319*7c478bd9Sstevel@tonic-gate 		}
1320*7c478bd9Sstevel@tonic-gate 	}
1321*7c478bd9Sstevel@tonic-gate 	return (pte);
1322*7c478bd9Sstevel@tonic-gate }
1323*7c478bd9Sstevel@tonic-gate 
1324*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_setattr3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1325*7c478bd9Sstevel@tonic-gate trans_setattr3(
1326*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1327*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1328*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1329*7c478bd9Sstevel@tonic-gate 	char *path1)
1330*7c478bd9Sstevel@tonic-gate {
1331*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1332*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1333*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1334*7c478bd9Sstevel@tonic-gate 	nfslog_SETATTR3args *args = (nfslog_SETATTR3args *)logrec->re_rpc_arg;
1335*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1336*7c478bd9Sstevel@tonic-gate 	nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1337*7c478bd9Sstevel@tonic-gate 
1338*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1339*7c478bd9Sstevel@tonic-gate 		return (NULL);
1340*7c478bd9Sstevel@tonic-gate 
1341*7c478bd9Sstevel@tonic-gate 	if (!args->size.set_it)
1342*7c478bd9Sstevel@tonic-gate 		return (NULL);
1343*7c478bd9Sstevel@tonic-gate 	/*
1344*7c478bd9Sstevel@tonic-gate 	 * should check the size of the file to see if it
1345*7c478bd9Sstevel@tonic-gate 	 * is being truncated below current eof.  if so
1346*7c478bd9Sstevel@tonic-gate 	 * a record should be generated.... XXX
1347*7c478bd9Sstevel@tonic-gate 	 */
1348*7c478bd9Sstevel@tonic-gate 	if (args->size.size != 0)
1349*7c478bd9Sstevel@tonic-gate 		return (NULL);
1350*7c478bd9Sstevel@tonic-gate 
1351*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1352*7c478bd9Sstevel@tonic-gate 		return (NULL);
1353*7c478bd9Sstevel@tonic-gate 
1354*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1355*7c478bd9Sstevel@tonic-gate 		fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->object);
1356*7c478bd9Sstevel@tonic-gate 		newte->pathname = nfslog_get_path(fh, NULL,
1357*7c478bd9Sstevel@tonic-gate 			fhpath, "trans_setattr3");
1358*7c478bd9Sstevel@tonic-gate 	} else {
1359*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1360*7c478bd9Sstevel@tonic-gate 	}
1361*7c478bd9Sstevel@tonic-gate 
1362*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1363*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1364*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_SETATTR;
1365*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1366*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1367*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1368*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1369*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1370*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1371*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1372*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1373*7c478bd9Sstevel@tonic-gate 	else
1374*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1375*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1376*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->object;
1377*7c478bd9Sstevel@tonic-gate 
1378*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
1379*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1380*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1381*7c478bd9Sstevel@tonic-gate 	}
1382*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_read, newte)) {
1383*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1384*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1385*7c478bd9Sstevel@tonic-gate 	}
1386*7c478bd9Sstevel@tonic-gate 
1387*7c478bd9Sstevel@tonic-gate 	return (newte);
1388*7c478bd9Sstevel@tonic-gate }
1389*7c478bd9Sstevel@tonic-gate 
1390*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_create3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1391*7c478bd9Sstevel@tonic-gate trans_create3(
1392*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1393*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1394*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1395*7c478bd9Sstevel@tonic-gate 	char *path1)
1396*7c478bd9Sstevel@tonic-gate {
1397*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1398*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1399*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1400*7c478bd9Sstevel@tonic-gate 	nfslog_CREATE3args *args = (nfslog_CREATE3args *)logrec->re_rpc_arg;
1401*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1402*7c478bd9Sstevel@tonic-gate 	nfslog_CREATE3res *res = (nfslog_CREATE3res *)logrec->re_rpc_res;
1403*7c478bd9Sstevel@tonic-gate 
1404*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1405*7c478bd9Sstevel@tonic-gate 		return (NULL);
1406*7c478bd9Sstevel@tonic-gate 
1407*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1408*7c478bd9Sstevel@tonic-gate 		return (NULL);
1409*7c478bd9Sstevel@tonic-gate 
1410*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1411*7c478bd9Sstevel@tonic-gate 		newte->pathname =
1412*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1413*7c478bd9Sstevel@tonic-gate 				args->where.name,
1414*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_create3");
1415*7c478bd9Sstevel@tonic-gate 	} else {
1416*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1417*7c478bd9Sstevel@tonic-gate 	}
1418*7c478bd9Sstevel@tonic-gate 
1419*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1420*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1421*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_CREATE;
1422*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1423*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1424*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1425*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1426*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1427*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1428*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1429*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1430*7c478bd9Sstevel@tonic-gate 	else
1431*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1432*7c478bd9Sstevel@tonic-gate 
1433*7c478bd9Sstevel@tonic-gate 	if (!args->how.nfslog_createhow3_u.size.set_it)
1434*7c478bd9Sstevel@tonic-gate 		newte->totalbytes = 0;
1435*7c478bd9Sstevel@tonic-gate 	else
1436*7c478bd9Sstevel@tonic-gate 		newte->totalbytes =
1437*7c478bd9Sstevel@tonic-gate 			args->how.nfslog_createhow3_u.size.size;
1438*7c478bd9Sstevel@tonic-gate 
1439*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->where.dir;
1440*7c478bd9Sstevel@tonic-gate 
1441*7c478bd9Sstevel@tonic-gate 	if (args->how.nfslog_createhow3_u.size.set_it) {
1442*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v3_write, newte)) {
1443*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
1444*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
1445*7c478bd9Sstevel@tonic-gate 		}
1446*7c478bd9Sstevel@tonic-gate 		if (pte = insert_te(tf->te_list_v3_read, newte)) {
1447*7c478bd9Sstevel@tonic-gate 			nfslog_print_trans_logentry(pte, tf);
1448*7c478bd9Sstevel@tonic-gate 			remove_te(pte);
1449*7c478bd9Sstevel@tonic-gate 		}
1450*7c478bd9Sstevel@tonic-gate 	}
1451*7c478bd9Sstevel@tonic-gate 
1452*7c478bd9Sstevel@tonic-gate 	return (newte);
1453*7c478bd9Sstevel@tonic-gate }
1454*7c478bd9Sstevel@tonic-gate 
1455*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_remove3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1456*7c478bd9Sstevel@tonic-gate trans_remove3(
1457*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1458*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1459*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1460*7c478bd9Sstevel@tonic-gate 	char *path1)
1461*7c478bd9Sstevel@tonic-gate {
1462*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1463*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1464*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1465*7c478bd9Sstevel@tonic-gate 	nfslog_REMOVE3args *args = (nfslog_REMOVE3args *)logrec->re_rpc_arg;
1466*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1467*7c478bd9Sstevel@tonic-gate 	nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1468*7c478bd9Sstevel@tonic-gate 
1469*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1470*7c478bd9Sstevel@tonic-gate 		return (NULL);
1471*7c478bd9Sstevel@tonic-gate 
1472*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1473*7c478bd9Sstevel@tonic-gate 		return (NULL);
1474*7c478bd9Sstevel@tonic-gate 
1475*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1476*7c478bd9Sstevel@tonic-gate 		newte->pathname =
1477*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object.dir),
1478*7c478bd9Sstevel@tonic-gate 				args->object.name,
1479*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_remove3");
1480*7c478bd9Sstevel@tonic-gate 	} else {
1481*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1482*7c478bd9Sstevel@tonic-gate 	}
1483*7c478bd9Sstevel@tonic-gate 
1484*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1485*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1486*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_REMOVE;
1487*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1488*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1489*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1490*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1491*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1492*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1493*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1494*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1495*7c478bd9Sstevel@tonic-gate 	else
1496*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1497*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1498*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->object.dir;
1499*7c478bd9Sstevel@tonic-gate 
1500*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
1501*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1502*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1503*7c478bd9Sstevel@tonic-gate 	}
1504*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_read, newte)) {
1505*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1506*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1507*7c478bd9Sstevel@tonic-gate 	}
1508*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
1509*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1510*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1511*7c478bd9Sstevel@tonic-gate 	}
1512*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_read, newte)) {
1513*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1514*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1515*7c478bd9Sstevel@tonic-gate 	}
1516*7c478bd9Sstevel@tonic-gate 
1517*7c478bd9Sstevel@tonic-gate 	return (newte);
1518*7c478bd9Sstevel@tonic-gate }
1519*7c478bd9Sstevel@tonic-gate 
1520*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mkdir3(nfslog_request_record * logrec,char * fhpath,char * path1)1521*7c478bd9Sstevel@tonic-gate trans_mkdir3(
1522*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1523*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1524*7c478bd9Sstevel@tonic-gate 	char *path1)
1525*7c478bd9Sstevel@tonic-gate {
1526*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1527*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1528*7c478bd9Sstevel@tonic-gate 	nfslog_MKDIR3args *args = (nfslog_MKDIR3args *)logrec->re_rpc_arg;
1529*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1530*7c478bd9Sstevel@tonic-gate 	nfslog_MKDIR3res *res = (nfslog_MKDIR3res *)logrec->re_rpc_res;
1531*7c478bd9Sstevel@tonic-gate 
1532*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1533*7c478bd9Sstevel@tonic-gate 		return (NULL);
1534*7c478bd9Sstevel@tonic-gate 
1535*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1536*7c478bd9Sstevel@tonic-gate 		return (NULL);
1537*7c478bd9Sstevel@tonic-gate 
1538*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1539*7c478bd9Sstevel@tonic-gate 		newte->pathname =
1540*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1541*7c478bd9Sstevel@tonic-gate 				args->where.name,
1542*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_mkdir3");
1543*7c478bd9Sstevel@tonic-gate 	} else {
1544*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1545*7c478bd9Sstevel@tonic-gate 	}
1546*7c478bd9Sstevel@tonic-gate 
1547*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1548*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1549*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_MKDIR;
1550*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1551*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1552*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1553*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1554*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1555*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1556*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1557*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1558*7c478bd9Sstevel@tonic-gate 	else
1559*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1560*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1561*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->where.dir;
1562*7c478bd9Sstevel@tonic-gate 
1563*7c478bd9Sstevel@tonic-gate 	return (newte);
1564*7c478bd9Sstevel@tonic-gate }
1565*7c478bd9Sstevel@tonic-gate 
1566*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rmdir3(nfslog_request_record * logrec,char * fhpath,char * path1)1567*7c478bd9Sstevel@tonic-gate trans_rmdir3(
1568*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1569*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1570*7c478bd9Sstevel@tonic-gate 	char *path1)
1571*7c478bd9Sstevel@tonic-gate {
1572*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1573*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1574*7c478bd9Sstevel@tonic-gate 	nfslog_RMDIR3args *args = (nfslog_RMDIR3args *)logrec->re_rpc_arg;
1575*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1576*7c478bd9Sstevel@tonic-gate 	nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1577*7c478bd9Sstevel@tonic-gate 
1578*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1579*7c478bd9Sstevel@tonic-gate 		return (NULL);
1580*7c478bd9Sstevel@tonic-gate 
1581*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1582*7c478bd9Sstevel@tonic-gate 		return (NULL);
1583*7c478bd9Sstevel@tonic-gate 
1584*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1585*7c478bd9Sstevel@tonic-gate 		newte->pathname =
1586*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object.dir),
1587*7c478bd9Sstevel@tonic-gate 				args->object.name,
1588*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_rmdir3");
1589*7c478bd9Sstevel@tonic-gate 	} else {
1590*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1591*7c478bd9Sstevel@tonic-gate 	}
1592*7c478bd9Sstevel@tonic-gate 
1593*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1594*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1595*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_RMDIR;
1596*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1597*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1598*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1599*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1600*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1601*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1602*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1603*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1604*7c478bd9Sstevel@tonic-gate 	else
1605*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1606*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1607*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->object.dir;
1608*7c478bd9Sstevel@tonic-gate 
1609*7c478bd9Sstevel@tonic-gate 	return (newte);
1610*7c478bd9Sstevel@tonic-gate }
1611*7c478bd9Sstevel@tonic-gate 
1612*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rename3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1,char * path2)1613*7c478bd9Sstevel@tonic-gate trans_rename3(
1614*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1615*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf,
1616*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1617*7c478bd9Sstevel@tonic-gate 	char *path1,
1618*7c478bd9Sstevel@tonic-gate 	char *path2)
1619*7c478bd9Sstevel@tonic-gate {
1620*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1621*7c478bd9Sstevel@tonic-gate 	struct transentry *pte = NULL;
1622*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1623*7c478bd9Sstevel@tonic-gate 	nfslog_RENAME3args *args = (nfslog_RENAME3args *)logrec->re_rpc_arg;
1624*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1625*7c478bd9Sstevel@tonic-gate 	nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1626*7c478bd9Sstevel@tonic-gate 	char *tpath1 = NULL;
1627*7c478bd9Sstevel@tonic-gate 	char *tpath2 = NULL;
1628*7c478bd9Sstevel@tonic-gate 
1629*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1630*7c478bd9Sstevel@tonic-gate 		return (NULL);
1631*7c478bd9Sstevel@tonic-gate 
1632*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1633*7c478bd9Sstevel@tonic-gate 		return (NULL);
1634*7c478bd9Sstevel@tonic-gate 
1635*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1636*7c478bd9Sstevel@tonic-gate 		path1 = tpath1 =
1637*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->from.dir),
1638*7c478bd9Sstevel@tonic-gate 				args->from.name, fhpath, "trans_rename3 from");
1639*7c478bd9Sstevel@tonic-gate 		path2 = tpath2 =
1640*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->to.dir),
1641*7c478bd9Sstevel@tonic-gate 				args->to.name, fhpath, "trans_rename3 to");
1642*7c478bd9Sstevel@tonic-gate 	}
1643*7c478bd9Sstevel@tonic-gate 
1644*7c478bd9Sstevel@tonic-gate 	newte->pathname = path1; /* no need to strdup here */
1645*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1646*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1647*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_RENAME;
1648*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1649*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1650*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1651*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1652*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1653*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1654*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1655*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1656*7c478bd9Sstevel@tonic-gate 	else
1657*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1658*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1659*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->from.dir;
1660*7c478bd9Sstevel@tonic-gate 
1661*7c478bd9Sstevel@tonic-gate 	/* switch path names for the file for renames */
1662*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_write, newte)) {
1663*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1664*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1665*7c478bd9Sstevel@tonic-gate 	}
1666*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v3_read, newte)) {
1667*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1668*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1669*7c478bd9Sstevel@tonic-gate 	}
1670*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_write, newte)) {
1671*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1672*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1673*7c478bd9Sstevel@tonic-gate 	}
1674*7c478bd9Sstevel@tonic-gate 	if (pte = insert_te(tf->te_list_v2_read, newte)) {
1675*7c478bd9Sstevel@tonic-gate 		free(pte->pathname);
1676*7c478bd9Sstevel@tonic-gate 		pte->pathname = strdup(path2);
1677*7c478bd9Sstevel@tonic-gate 	}
1678*7c478bd9Sstevel@tonic-gate 
1679*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1680*7c478bd9Sstevel@tonic-gate 	/* check for NULL malloc */
1681*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", path1, path2);
1682*7c478bd9Sstevel@tonic-gate 
1683*7c478bd9Sstevel@tonic-gate 	if (tpath1) {
1684*7c478bd9Sstevel@tonic-gate 		free(tpath1);
1685*7c478bd9Sstevel@tonic-gate 		free(tpath2);
1686*7c478bd9Sstevel@tonic-gate 	}
1687*7c478bd9Sstevel@tonic-gate 
1688*7c478bd9Sstevel@tonic-gate 	return (newte);
1689*7c478bd9Sstevel@tonic-gate }
1690*7c478bd9Sstevel@tonic-gate 
1691*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mknod3(nfslog_request_record * logrec,char * fhpath,char * path1)1692*7c478bd9Sstevel@tonic-gate trans_mknod3(
1693*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1694*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1695*7c478bd9Sstevel@tonic-gate 	char *path1)
1696*7c478bd9Sstevel@tonic-gate {
1697*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1698*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1699*7c478bd9Sstevel@tonic-gate 	nfslog_MKNOD3args *args = (nfslog_MKNOD3args *)logrec->re_rpc_arg;
1700*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1701*7c478bd9Sstevel@tonic-gate 	nfslog_MKNOD3res *res = (nfslog_MKNOD3res *)logrec->re_rpc_res;
1702*7c478bd9Sstevel@tonic-gate 
1703*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1704*7c478bd9Sstevel@tonic-gate 		return (NULL);
1705*7c478bd9Sstevel@tonic-gate 
1706*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1707*7c478bd9Sstevel@tonic-gate 		return (NULL);
1708*7c478bd9Sstevel@tonic-gate 
1709*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1710*7c478bd9Sstevel@tonic-gate 		newte->pathname =
1711*7c478bd9Sstevel@tonic-gate 			nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1712*7c478bd9Sstevel@tonic-gate 				args->where.name,
1713*7c478bd9Sstevel@tonic-gate 				fhpath, "trans_mknod3");
1714*7c478bd9Sstevel@tonic-gate 	} else {
1715*7c478bd9Sstevel@tonic-gate 		newte->pathname = strdup(path1);
1716*7c478bd9Sstevel@tonic-gate 	}
1717*7c478bd9Sstevel@tonic-gate 
1718*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1719*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1720*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_MKNOD;
1721*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1722*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1723*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1724*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1725*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1726*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1727*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1728*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1729*7c478bd9Sstevel@tonic-gate 	else
1730*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1731*7c478bd9Sstevel@tonic-gate 
1732*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1733*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->where.dir;
1734*7c478bd9Sstevel@tonic-gate 
1735*7c478bd9Sstevel@tonic-gate 	return (newte);
1736*7c478bd9Sstevel@tonic-gate }
1737*7c478bd9Sstevel@tonic-gate 
1738*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_link3(nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1739*7c478bd9Sstevel@tonic-gate trans_link3(
1740*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1741*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1742*7c478bd9Sstevel@tonic-gate 	char *path1,
1743*7c478bd9Sstevel@tonic-gate 	char *path2)
1744*7c478bd9Sstevel@tonic-gate {
1745*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1746*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1747*7c478bd9Sstevel@tonic-gate 	nfslog_LINK3args *args = (nfslog_LINK3args *)logrec->re_rpc_arg;
1748*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1749*7c478bd9Sstevel@tonic-gate 	nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1750*7c478bd9Sstevel@tonic-gate 
1751*7c478bd9Sstevel@tonic-gate 	char *tpath1 = NULL;
1752*7c478bd9Sstevel@tonic-gate 	char *tpath2 = NULL;
1753*7c478bd9Sstevel@tonic-gate 
1754*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1755*7c478bd9Sstevel@tonic-gate 		return (NULL);
1756*7c478bd9Sstevel@tonic-gate 
1757*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1758*7c478bd9Sstevel@tonic-gate 		return (NULL);
1759*7c478bd9Sstevel@tonic-gate 
1760*7c478bd9Sstevel@tonic-gate 	if (!path1) {
1761*7c478bd9Sstevel@tonic-gate 		tpath1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1762*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "trans_link3 from");
1763*7c478bd9Sstevel@tonic-gate 		tpath2 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->link.dir),
1764*7c478bd9Sstevel@tonic-gate 			args->link.name, fhpath, "trans_link3 to");
1765*7c478bd9Sstevel@tonic-gate 		path1 = tpath1;
1766*7c478bd9Sstevel@tonic-gate 		path2 = tpath2;
1767*7c478bd9Sstevel@tonic-gate 	}
1768*7c478bd9Sstevel@tonic-gate 
1769*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1770*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1771*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_LINK;
1772*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1773*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1774*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1775*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1776*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1777*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1778*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1779*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1780*7c478bd9Sstevel@tonic-gate 	else
1781*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1782*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1783*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->file;
1784*7c478bd9Sstevel@tonic-gate 
1785*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1786*7c478bd9Sstevel@tonic-gate 	/* check for NULL malloc */
1787*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", path1, path2);
1788*7c478bd9Sstevel@tonic-gate 
1789*7c478bd9Sstevel@tonic-gate 	if (tpath1) {
1790*7c478bd9Sstevel@tonic-gate 		free(tpath1);
1791*7c478bd9Sstevel@tonic-gate 		free(tpath2);
1792*7c478bd9Sstevel@tonic-gate 	}
1793*7c478bd9Sstevel@tonic-gate 
1794*7c478bd9Sstevel@tonic-gate 	return (newte);
1795*7c478bd9Sstevel@tonic-gate }
1796*7c478bd9Sstevel@tonic-gate 
1797*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_symlink3(nfslog_request_record * logrec,char * fhpath,char * path1)1798*7c478bd9Sstevel@tonic-gate trans_symlink3(
1799*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *logrec,
1800*7c478bd9Sstevel@tonic-gate 	char *fhpath,
1801*7c478bd9Sstevel@tonic-gate 	char *path1)
1802*7c478bd9Sstevel@tonic-gate {
1803*7c478bd9Sstevel@tonic-gate 	struct transentry *newte;
1804*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1805*7c478bd9Sstevel@tonic-gate 	nfslog_SYMLINK3args *args = (nfslog_SYMLINK3args *)logrec->re_rpc_arg;
1806*7c478bd9Sstevel@tonic-gate 	/* LINTED */
1807*7c478bd9Sstevel@tonic-gate 	nfslog_SYMLINK3res *res = (nfslog_SYMLINK3res *)logrec->re_rpc_res;
1808*7c478bd9Sstevel@tonic-gate 	char *name;
1809*7c478bd9Sstevel@tonic-gate 
1810*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK)
1811*7c478bd9Sstevel@tonic-gate 		return (NULL);
1812*7c478bd9Sstevel@tonic-gate 
1813*7c478bd9Sstevel@tonic-gate 	if ((newte = create_te()) == NULL)
1814*7c478bd9Sstevel@tonic-gate 		return (NULL);
1815*7c478bd9Sstevel@tonic-gate 
1816*7c478bd9Sstevel@tonic-gate 	if (path1) {
1817*7c478bd9Sstevel@tonic-gate 		name = strdup(path1);
1818*7c478bd9Sstevel@tonic-gate 	} else {
1819*7c478bd9Sstevel@tonic-gate 		name = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1820*7c478bd9Sstevel@tonic-gate 			args->where.name, fhpath, "trans_symlink3");
1821*7c478bd9Sstevel@tonic-gate 	}
1822*7c478bd9Sstevel@tonic-gate 
1823*7c478bd9Sstevel@tonic-gate 	newte->starttime = logrec->re_header.rh_timestamp;
1824*7c478bd9Sstevel@tonic-gate 	newte->lastupdate = logrec->re_header.rh_timestamp;
1825*7c478bd9Sstevel@tonic-gate 	newte->optype = TRANS_OPER_SYMLINK;
1826*7c478bd9Sstevel@tonic-gate 	newte->datatype = TRANS_DATATYPE_BINARY;
1827*7c478bd9Sstevel@tonic-gate 	newte->transoption = TRANS_OPTION_NOACTION;
1828*7c478bd9Sstevel@tonic-gate 	newte->pnb = netbufdup(&(logrec->re_ipaddr));
1829*7c478bd9Sstevel@tonic-gate 	newte->uid = logrec->re_header.rh_uid;
1830*7c478bd9Sstevel@tonic-gate 	newte->nfsvers = NFS_V3;
1831*7c478bd9Sstevel@tonic-gate 	newte->netid = strdup(logrec->re_netid);
1832*7c478bd9Sstevel@tonic-gate 	if (logrec->re_principal_name)
1833*7c478bd9Sstevel@tonic-gate 		newte->principal_name = strdup(logrec->re_principal_name);
1834*7c478bd9Sstevel@tonic-gate 	else
1835*7c478bd9Sstevel@tonic-gate 		newte->principal_name = NULL;
1836*7c478bd9Sstevel@tonic-gate 	newte->totalbytes = 0;
1837*7c478bd9Sstevel@tonic-gate 	newte->fh_u.fh3 = args->where.dir;
1838*7c478bd9Sstevel@tonic-gate 
1839*7c478bd9Sstevel@tonic-gate 	newte->pathname = (char *)malloc(strlen(name) +
1840*7c478bd9Sstevel@tonic-gate 		strlen(args->symlink_data) + 3);
1841*7c478bd9Sstevel@tonic-gate 	/* check for NULL malloc */
1842*7c478bd9Sstevel@tonic-gate 	(void) sprintf(newte->pathname, "%s->%s", name, args->symlink_data);
1843*7c478bd9Sstevel@tonic-gate 
1844*7c478bd9Sstevel@tonic-gate 	free(name);
1845*7c478bd9Sstevel@tonic-gate 
1846*7c478bd9Sstevel@tonic-gate 	return (newte);
1847*7c478bd9Sstevel@tonic-gate }
1848*7c478bd9Sstevel@tonic-gate 
1849*7c478bd9Sstevel@tonic-gate /*
1850*7c478bd9Sstevel@tonic-gate  * nfslog_process_trans_rec - processes the record in the buffer and outputs
1851*7c478bd9Sstevel@tonic-gate  *	to the trans log.
1852*7c478bd9Sstevel@tonic-gate  * Return 0 for success, errno else.
1853*7c478bd9Sstevel@tonic-gate  */
1854*7c478bd9Sstevel@tonic-gate int
nfslog_process_trans_rec(void * transcookie,nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1855*7c478bd9Sstevel@tonic-gate nfslog_process_trans_rec(void *transcookie, nfslog_request_record *logrec,
1856*7c478bd9Sstevel@tonic-gate 	char *fhpath, char *path1, char *path2)
1857*7c478bd9Sstevel@tonic-gate {
1858*7c478bd9Sstevel@tonic-gate 	struct transentry	*pte = NULL;
1859*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf = (struct nfslog_trans_file *)transcookie;
1860*7c478bd9Sstevel@tonic-gate 
1861*7c478bd9Sstevel@tonic-gate 	/* ignore programs other than nfs */
1862*7c478bd9Sstevel@tonic-gate 	if (logrec->re_header.rh_prognum != NFS_PROGRAM)
1863*7c478bd9Sstevel@tonic-gate 		return (0);
1864*7c478bd9Sstevel@tonic-gate 
1865*7c478bd9Sstevel@tonic-gate 	/* update the timestamp for use later in the timeout sequences */
1866*7c478bd9Sstevel@tonic-gate 	if (tf->lasttrans_timestamp.tv_sec <
1867*7c478bd9Sstevel@tonic-gate 		logrec->re_header.rh_timestamp.tv_sec)
1868*7c478bd9Sstevel@tonic-gate 		tf->lasttrans_timestamp =
1869*7c478bd9Sstevel@tonic-gate 			logrec->re_header.rh_timestamp;
1870*7c478bd9Sstevel@tonic-gate 
1871*7c478bd9Sstevel@tonic-gate 	/* current time of this processing */
1872*7c478bd9Sstevel@tonic-gate 	tf->last_trans_read = time(0);
1873*7c478bd9Sstevel@tonic-gate 
1874*7c478bd9Sstevel@tonic-gate 	/* ignore anything that is not a read or write */
1875*7c478bd9Sstevel@tonic-gate 	switch (logrec->re_header.rh_version) {
1876*7c478bd9Sstevel@tonic-gate 	case NFS_VERSION:
1877*7c478bd9Sstevel@tonic-gate 		switch (logrec->re_header.rh_procnum) {
1878*7c478bd9Sstevel@tonic-gate 		case RFS_READ:
1879*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_READ)
1880*7c478bd9Sstevel@tonic-gate 				pte = trans_read(logrec, tf, fhpath, path1);
1881*7c478bd9Sstevel@tonic-gate 			break;
1882*7c478bd9Sstevel@tonic-gate 		case RFS_WRITE:
1883*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_WRITE)
1884*7c478bd9Sstevel@tonic-gate 				pte = trans_write(logrec, tf, fhpath, path1);
1885*7c478bd9Sstevel@tonic-gate 			break;
1886*7c478bd9Sstevel@tonic-gate 		case RFS_SETATTR:
1887*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_SETATTR)
1888*7c478bd9Sstevel@tonic-gate 				pte = trans_setattr(logrec, tf,
1889*7c478bd9Sstevel@tonic-gate 					fhpath, path1);
1890*7c478bd9Sstevel@tonic-gate 			break;
1891*7c478bd9Sstevel@tonic-gate 		case RFS_REMOVE:
1892*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_REMOVE)
1893*7c478bd9Sstevel@tonic-gate 				pte = trans_remove(logrec, tf,	fhpath, path1);
1894*7c478bd9Sstevel@tonic-gate 			break;
1895*7c478bd9Sstevel@tonic-gate 		case RFS_MKDIR:
1896*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_MKDIR)
1897*7c478bd9Sstevel@tonic-gate 				pte = trans_mkdir(logrec, fhpath, path1);
1898*7c478bd9Sstevel@tonic-gate 			break;
1899*7c478bd9Sstevel@tonic-gate 		case RFS_RMDIR:
1900*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_RMDIR)
1901*7c478bd9Sstevel@tonic-gate 				pte = trans_rmdir(logrec, fhpath, path1);
1902*7c478bd9Sstevel@tonic-gate 			break;
1903*7c478bd9Sstevel@tonic-gate 		case RFS_CREATE:
1904*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_CREATE)
1905*7c478bd9Sstevel@tonic-gate 				pte = trans_create(logrec, tf, fhpath, path1);
1906*7c478bd9Sstevel@tonic-gate 			break;
1907*7c478bd9Sstevel@tonic-gate 		case RFS_RENAME:
1908*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_RENAME)
1909*7c478bd9Sstevel@tonic-gate 				pte = trans_rename(logrec, tf,
1910*7c478bd9Sstevel@tonic-gate 					fhpath, path1, path2);
1911*7c478bd9Sstevel@tonic-gate 			break;
1912*7c478bd9Sstevel@tonic-gate 		case RFS_LINK:
1913*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_LINK)
1914*7c478bd9Sstevel@tonic-gate 				pte = trans_link(logrec, fhpath, path1, path2);
1915*7c478bd9Sstevel@tonic-gate 			break;
1916*7c478bd9Sstevel@tonic-gate 		case RFS_SYMLINK:
1917*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_SYMLINK)
1918*7c478bd9Sstevel@tonic-gate 				pte = trans_symlink(logrec, fhpath, path1);
1919*7c478bd9Sstevel@tonic-gate 			break;
1920*7c478bd9Sstevel@tonic-gate 		default:
1921*7c478bd9Sstevel@tonic-gate 			break;
1922*7c478bd9Sstevel@tonic-gate 		}
1923*7c478bd9Sstevel@tonic-gate 		break;
1924*7c478bd9Sstevel@tonic-gate 	case NFS_V3:
1925*7c478bd9Sstevel@tonic-gate 		switch (logrec->re_header.rh_procnum) {
1926*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_READ:
1927*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_READ)
1928*7c478bd9Sstevel@tonic-gate 				pte = trans_read3(logrec, tf, fhpath, path1);
1929*7c478bd9Sstevel@tonic-gate 			break;
1930*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_WRITE:
1931*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_WRITE)
1932*7c478bd9Sstevel@tonic-gate 				pte = trans_write3(logrec, tf, fhpath, path1);
1933*7c478bd9Sstevel@tonic-gate 			break;
1934*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_SETATTR:
1935*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_SETATTR)
1936*7c478bd9Sstevel@tonic-gate 				pte = trans_setattr3(logrec, tf,
1937*7c478bd9Sstevel@tonic-gate 					fhpath, path1);
1938*7c478bd9Sstevel@tonic-gate 			break;
1939*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_REMOVE:
1940*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_REMOVE)
1941*7c478bd9Sstevel@tonic-gate 				pte = trans_remove3(logrec, tf,
1942*7c478bd9Sstevel@tonic-gate 					fhpath, path1);
1943*7c478bd9Sstevel@tonic-gate 			break;
1944*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_MKDIR:
1945*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_MKDIR)
1946*7c478bd9Sstevel@tonic-gate 				pte = trans_mkdir3(logrec, fhpath, path1);
1947*7c478bd9Sstevel@tonic-gate 			break;
1948*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_RMDIR:
1949*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_RMDIR)
1950*7c478bd9Sstevel@tonic-gate 				pte = trans_rmdir3(logrec, fhpath, path1);
1951*7c478bd9Sstevel@tonic-gate 			break;
1952*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_CREATE:
1953*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_CREATE)
1954*7c478bd9Sstevel@tonic-gate 				pte = trans_create3(logrec, tf,
1955*7c478bd9Sstevel@tonic-gate 					fhpath, path1);
1956*7c478bd9Sstevel@tonic-gate 			break;
1957*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_RENAME:
1958*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_RENAME)
1959*7c478bd9Sstevel@tonic-gate 				pte = trans_rename3(logrec, tf,
1960*7c478bd9Sstevel@tonic-gate 					fhpath, path1, path2);
1961*7c478bd9Sstevel@tonic-gate 			break;
1962*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_MKNOD:
1963*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_MKNOD)
1964*7c478bd9Sstevel@tonic-gate 				pte = trans_mknod3(logrec, fhpath, path1);
1965*7c478bd9Sstevel@tonic-gate 			break;
1966*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_LINK:
1967*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_LINK)
1968*7c478bd9Sstevel@tonic-gate 				pte = trans_link3(logrec,
1969*7c478bd9Sstevel@tonic-gate 					fhpath, path1, path2);
1970*7c478bd9Sstevel@tonic-gate 			break;
1971*7c478bd9Sstevel@tonic-gate 		case NFSPROC3_SYMLINK:
1972*7c478bd9Sstevel@tonic-gate 			if (tf->trans_to_log & TRANSTOLOG_OPER_SYMLINK)
1973*7c478bd9Sstevel@tonic-gate 				pte = trans_symlink3(logrec, fhpath, path1);
1974*7c478bd9Sstevel@tonic-gate 			break;
1975*7c478bd9Sstevel@tonic-gate 		default:
1976*7c478bd9Sstevel@tonic-gate 			break;
1977*7c478bd9Sstevel@tonic-gate 		}
1978*7c478bd9Sstevel@tonic-gate 		break;
1979*7c478bd9Sstevel@tonic-gate 	default:
1980*7c478bd9Sstevel@tonic-gate 		break;
1981*7c478bd9Sstevel@tonic-gate 	}
1982*7c478bd9Sstevel@tonic-gate 
1983*7c478bd9Sstevel@tonic-gate 	if (pte != NULL) {
1984*7c478bd9Sstevel@tonic-gate 		nfslog_print_trans_logentry(pte, tf);
1985*7c478bd9Sstevel@tonic-gate 		remove_te(pte);
1986*7c478bd9Sstevel@tonic-gate 	}
1987*7c478bd9Sstevel@tonic-gate 
1988*7c478bd9Sstevel@tonic-gate 	return (0);
1989*7c478bd9Sstevel@tonic-gate }
1990*7c478bd9Sstevel@tonic-gate 
1991*7c478bd9Sstevel@tonic-gate static void
nfslog_print_trans_logentry(struct transentry * pte,struct nfslog_trans_file * tf)1992*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(struct transentry *pte,
1993*7c478bd9Sstevel@tonic-gate 	struct nfslog_trans_file *tf)
1994*7c478bd9Sstevel@tonic-gate {
1995*7c478bd9Sstevel@tonic-gate 	char *remotehost;
1996*7c478bd9Sstevel@tonic-gate 	char datatype;
1997*7c478bd9Sstevel@tonic-gate 	char transoption;
1998*7c478bd9Sstevel@tonic-gate 	char *optype;
1999*7c478bd9Sstevel@tonic-gate 	char *prin;
2000*7c478bd9Sstevel@tonic-gate 	int prinid;
2001*7c478bd9Sstevel@tonic-gate 	char nfs_ident[32];
2002*7c478bd9Sstevel@tonic-gate 
2003*7c478bd9Sstevel@tonic-gate 	remotehost = addrtoname(pte->pnb->buf);
2004*7c478bd9Sstevel@tonic-gate 
2005*7c478bd9Sstevel@tonic-gate 	datatype = (pte->datatype == TRANS_DATATYPE_BINARY ? 'b' : 'a');
2006*7c478bd9Sstevel@tonic-gate 	transoption = (pte->transoption == TRANS_OPTION_NOACTION ? '_' : '?');
2007*7c478bd9Sstevel@tonic-gate 
2008*7c478bd9Sstevel@tonic-gate 	if (tf->trans_output_type == TRANSLOG_BASIC) {
2009*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nfs_ident, "nfs");
2010*7c478bd9Sstevel@tonic-gate 	} else {
2011*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nfs_ident,
2012*7c478bd9Sstevel@tonic-gate 			(pte->nfsvers == NFS_V3 ? "nfs3-" : "nfs-"));
2013*7c478bd9Sstevel@tonic-gate 		(void) strcat(nfs_ident, pte->netid);
2014*7c478bd9Sstevel@tonic-gate 	}
2015*7c478bd9Sstevel@tonic-gate 
2016*7c478bd9Sstevel@tonic-gate 	switch (pte->optype) {
2017*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_READ:
2018*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2019*7c478bd9Sstevel@tonic-gate 			"read" : "o");
2020*7c478bd9Sstevel@tonic-gate 		break;
2021*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_WRITE:
2022*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2023*7c478bd9Sstevel@tonic-gate 			"write" : "i");
2024*7c478bd9Sstevel@tonic-gate 		break;
2025*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_REMOVE:
2026*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2027*7c478bd9Sstevel@tonic-gate 			"remove" : "?");
2028*7c478bd9Sstevel@tonic-gate 		break;
2029*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_MKDIR:
2030*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2031*7c478bd9Sstevel@tonic-gate 			"mkdir" : "?");
2032*7c478bd9Sstevel@tonic-gate 		break;
2033*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_CREATE:
2034*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2035*7c478bd9Sstevel@tonic-gate 			"create" : "?");
2036*7c478bd9Sstevel@tonic-gate 		break;
2037*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_RMDIR:
2038*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2039*7c478bd9Sstevel@tonic-gate 			"rmdir" : "?");
2040*7c478bd9Sstevel@tonic-gate 		break;
2041*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_SETATTR:
2042*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2043*7c478bd9Sstevel@tonic-gate 			"setattr" : "?");
2044*7c478bd9Sstevel@tonic-gate 		break;
2045*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_RENAME:
2046*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2047*7c478bd9Sstevel@tonic-gate 			"rename" : "?");
2048*7c478bd9Sstevel@tonic-gate 		break;
2049*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_MKNOD:
2050*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2051*7c478bd9Sstevel@tonic-gate 			"mknod" : "?");
2052*7c478bd9Sstevel@tonic-gate 		break;
2053*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_LINK:
2054*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2055*7c478bd9Sstevel@tonic-gate 			"link" : "?");
2056*7c478bd9Sstevel@tonic-gate 		break;
2057*7c478bd9Sstevel@tonic-gate 	case TRANS_OPER_SYMLINK:
2058*7c478bd9Sstevel@tonic-gate 		optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2059*7c478bd9Sstevel@tonic-gate 			"symlink" : "?");
2060*7c478bd9Sstevel@tonic-gate 		break;
2061*7c478bd9Sstevel@tonic-gate 	default:
2062*7c478bd9Sstevel@tonic-gate 		optype = "?";
2063*7c478bd9Sstevel@tonic-gate 		break;
2064*7c478bd9Sstevel@tonic-gate 	}
2065*7c478bd9Sstevel@tonic-gate 	if (strcmp(pte->principal_name, "") == 0) {
2066*7c478bd9Sstevel@tonic-gate 		prinid = 0;
2067*7c478bd9Sstevel@tonic-gate 		prin = "*";
2068*7c478bd9Sstevel@tonic-gate 	} else {
2069*7c478bd9Sstevel@tonic-gate 		prinid = 1;
2070*7c478bd9Sstevel@tonic-gate 		prin = pte->principal_name;
2071*7c478bd9Sstevel@tonic-gate 	}
2072*7c478bd9Sstevel@tonic-gate 	(void) fprintf(tf->fp,
2073*7c478bd9Sstevel@tonic-gate 		"%.24s %d %s %d %s %c %c %s %c %ld %s %d %s\n",
2074*7c478bd9Sstevel@tonic-gate 		ctime((time_t *)&pte->starttime.tv_sec),
2075*7c478bd9Sstevel@tonic-gate 		pte->lastupdate.tv_sec - pte->starttime.tv_sec,
2076*7c478bd9Sstevel@tonic-gate 		remotehost,
2077*7c478bd9Sstevel@tonic-gate 		(uint32_t)pte->totalbytes,
2078*7c478bd9Sstevel@tonic-gate 		pte->pathname,
2079*7c478bd9Sstevel@tonic-gate 		datatype,
2080*7c478bd9Sstevel@tonic-gate 		transoption,
2081*7c478bd9Sstevel@tonic-gate 		optype,
2082*7c478bd9Sstevel@tonic-gate 		'r', /* anonymous == 'a', guest == 'g', real == 'r'), */
2083*7c478bd9Sstevel@tonic-gate 		pte->uid,
2084*7c478bd9Sstevel@tonic-gate 		nfs_ident,
2085*7c478bd9Sstevel@tonic-gate 		/* authenticated - fill in kerb/security? */
2086*7c478bd9Sstevel@tonic-gate 		prinid,
2087*7c478bd9Sstevel@tonic-gate 		/* authenticated ? authuser : "*" */
2088*7c478bd9Sstevel@tonic-gate 		prin);
2089*7c478bd9Sstevel@tonic-gate }
2090