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