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 /*
30*0Sstevel@tonic-gate * Code to maintain the runtime and on-disk filehandle mapping table for
31*0Sstevel@tonic-gate * nfslog.
32*0Sstevel@tonic-gate */
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate #include <assert.h>
35*0Sstevel@tonic-gate #include <errno.h>
36*0Sstevel@tonic-gate #include <nfs/nfs.h>
37*0Sstevel@tonic-gate #include <stdlib.h>
38*0Sstevel@tonic-gate #include <string.h>
39*0Sstevel@tonic-gate #include <strings.h>
40*0Sstevel@tonic-gate #include <syslog.h>
41*0Sstevel@tonic-gate #include <libintl.h>
42*0Sstevel@tonic-gate #include <unistd.h>
43*0Sstevel@tonic-gate #include <nfs/nfs.h>
44*0Sstevel@tonic-gate #include <nfs/nfs_log.h>
45*0Sstevel@tonic-gate #include "fhtab.h"
46*0Sstevel@tonic-gate #include "nfslogd.h"
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate #define ROUNDUP32(val) (((val) + 3) & ~3)
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate #define IS_DOT_FILENAME(name) \
51*0Sstevel@tonic-gate ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate #define PRINT_LINK_DATA(fp, func, dfh, name, str) \
54*0Sstevel@tonic-gate (void) fprintf(fp, "%s: name '%s', dfh ", \
55*0Sstevel@tonic-gate func, (((name) != NULL) ? name : "")); \
56*0Sstevel@tonic-gate debug_opaque_print(fp, dfh, sizeof (*(dfh))); \
57*0Sstevel@tonic-gate (void) fprintf(fp, "%s\n", str);
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate #define PRINT_FULL_DATA(fp, func, dfh, fh, name, str) \
61*0Sstevel@tonic-gate (void) fprintf(fp, "%s: name '%s', dfh ", \
62*0Sstevel@tonic-gate func, (((name) != NULL) ? name : "")); \
63*0Sstevel@tonic-gate debug_opaque_print(fp, dfh, sizeof (*(dfh))); \
64*0Sstevel@tonic-gate if ((fh) != NULL) { \
65*0Sstevel@tonic-gate (void) fprintf(fp, ", fh "); \
66*0Sstevel@tonic-gate debug_opaque_print(fp, fh, sizeof (*(fh))); \
67*0Sstevel@tonic-gate } \
68*0Sstevel@tonic-gate (void) fprintf(fp, "%s\n", str);
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate * export handle cache
72*0Sstevel@tonic-gate */
73*0Sstevel@tonic-gate struct export_handle_cache {
74*0Sstevel@tonic-gate fhandle_t fh;
75*0Sstevel@tonic-gate char *name;
76*0Sstevel@tonic-gate struct export_handle_cache *next;
77*0Sstevel@tonic-gate };
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate static struct export_handle_cache *exp_handle_cache = NULL;
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate extern bool_t nfsl_prin_fh;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate static int fh_add(char *, fhandle_t *, fhandle_t *, char *);
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate static char *get_export_path(fhandle_t *, char *);
86*0Sstevel@tonic-gate static void sprint_fid(char *, uint_t, const fhandle_t *);
87*0Sstevel@tonic-gate static void fh_print_all_keys(char *fhpath, fhandle_t *fh);
88*0Sstevel@tonic-gate static int fh_compare(fhandle_t *fh1, fhandle_t *fh2);
89*0Sstevel@tonic-gate static fhlist_ent *fh_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp,
90*0Sstevel@tonic-gate int *errorp);
91*0Sstevel@tonic-gate static int fh_remove_mc_link(char *fhpath, fhandle_t *dfh, char *name,
92*0Sstevel@tonic-gate char **pathp);
93*0Sstevel@tonic-gate static int fh_remove(char *fhpath, fhandle_t *dfh, char *name, char **pathp);
94*0Sstevel@tonic-gate static int fh_rename(char *fhpath, fhandle_t *from_dfh, char *from_name,
95*0Sstevel@tonic-gate char **from_pathp, fhandle_t *to_dfh, char *to_name);
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate static fhlist_ent *fh_lookup_link(char *fhpath, fhandle_t *dfh, fhandle_t *fh,
98*0Sstevel@tonic-gate char *name, fhlist_ent *fhrecp, int *errorp);
99*0Sstevel@tonic-gate static struct nfsl_fh_proc_disp *nfslog_find_fh_dispatch(
100*0Sstevel@tonic-gate nfslog_request_record *);
101*0Sstevel@tonic-gate static struct export_handle_cache *find_fh_in_export_cache(fhandle_t *fh);
102*0Sstevel@tonic-gate static void add_fh_to_export_cache(fhandle_t *fh, char *path);
103*0Sstevel@tonic-gate static char *update_export_point(char *fhpath, fhandle_t *fh, char *path);
104*0Sstevel@tonic-gate static char *fh_print_absolute(char *fhpath, fhandle_t *fh, char *name);
105*0Sstevel@tonic-gate static void nfslog_null_fhargs(caddr_t *nfsl_args, caddr_t *nfsl_res,
106*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2);
107*0Sstevel@tonic-gate static void nfslog_LOOKUP_calc(fhandle_t *dfh, char *name, fhandle_t *fh,
108*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2, char *str);
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate /*
111*0Sstevel@tonic-gate * NFS VERSION 2
112*0Sstevel@tonic-gate */
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate /*
115*0Sstevel@tonic-gate * Functions for updating the fhtable for fhtoppath and for returning
116*0Sstevel@tonic-gate * the absolute pathname
117*0Sstevel@tonic-gate */
118*0Sstevel@tonic-gate static void nfslog_GETATTR2_fhargs(fhandle_t *,
119*0Sstevel@tonic-gate nfsstat *, char *fhpath, char **, char **);
120*0Sstevel@tonic-gate static void nfslog_SETATTR2_fhargs(nfslog_setattrargs *, nfsstat *,
121*0Sstevel@tonic-gate char *, char **, char **);
122*0Sstevel@tonic-gate static void nfslog_LOOKUP2_fhargs(nfslog_diropargs *, nfslog_diropres *,
123*0Sstevel@tonic-gate char *, char **, char **);
124*0Sstevel@tonic-gate static void nfslog_READLINK2_fhargs(fhandle_t *, nfslog_rdlnres *,
125*0Sstevel@tonic-gate char *, char **, char **);
126*0Sstevel@tonic-gate static void nfslog_READ2_fhargs(nfslog_nfsreadargs *, nfslog_rdresult *,
127*0Sstevel@tonic-gate char *, char **, char **);
128*0Sstevel@tonic-gate static void nfslog_WRITE2_fhargs(nfslog_writeargs *, nfslog_writeresult *,
129*0Sstevel@tonic-gate char *, char **, char **);
130*0Sstevel@tonic-gate static void nfslog_CREATE2_fhargs(nfslog_createargs *, nfslog_diropres*,
131*0Sstevel@tonic-gate char *, char **, char **);
132*0Sstevel@tonic-gate static void nfslog_REMOVE2_fhargs(nfslog_diropargs *, nfsstat *,
133*0Sstevel@tonic-gate char *, char **, char **);
134*0Sstevel@tonic-gate static void nfslog_RENAME2_fhargs(nfslog_rnmargs *, nfsstat *,
135*0Sstevel@tonic-gate char *, char **, char **);
136*0Sstevel@tonic-gate static void nfslog_LINK2_fhargs(nfslog_linkargs *, nfsstat *,
137*0Sstevel@tonic-gate char *, char **, char **);
138*0Sstevel@tonic-gate static void nfslog_SYMLINK2_fhargs(nfslog_symlinkargs *, nfsstat *,
139*0Sstevel@tonic-gate char *, char **, char **);
140*0Sstevel@tonic-gate static void nfslog_READDIR2_fhargs(nfslog_rddirargs *, nfslog_rddirres *,
141*0Sstevel@tonic-gate char *, char **, char **);
142*0Sstevel@tonic-gate static void nfslog_STATFS2_fhargs(fhandle_t *, nfsstat *,
143*0Sstevel@tonic-gate char *, char **, char **);
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate /*
146*0Sstevel@tonic-gate * NFS VERSION 3
147*0Sstevel@tonic-gate *
148*0Sstevel@tonic-gate * Functions for updating the fhtable for fhtoppath
149*0Sstevel@tonic-gate */
150*0Sstevel@tonic-gate static void nfslog_GETATTR3_fhargs(nfs_fh3 *, nfsstat3 *,
151*0Sstevel@tonic-gate char *, char **, char **);
152*0Sstevel@tonic-gate static void nfslog_SETATTR3_fhargs(nfslog_SETATTR3args *, nfsstat3 *,
153*0Sstevel@tonic-gate char *, char **, char **);
154*0Sstevel@tonic-gate static void nfslog_LOOKUP3_fhargs(nfslog_diropargs3 *, nfslog_LOOKUP3res *,
155*0Sstevel@tonic-gate char *, char **, char **);
156*0Sstevel@tonic-gate static void nfslog_ACCESS3_fhargs(nfs_fh3 *, nfsstat3 *,
157*0Sstevel@tonic-gate char *, char **, char **);
158*0Sstevel@tonic-gate static void nfslog_READLINK3_fhargs(nfs_fh3 *, nfslog_READLINK3res *,
159*0Sstevel@tonic-gate char *, char **, char **);
160*0Sstevel@tonic-gate static void nfslog_READ3_fhargs(nfslog_READ3args *, nfslog_READ3res *,
161*0Sstevel@tonic-gate char *, char **, char **);
162*0Sstevel@tonic-gate static void nfslog_WRITE3_fhargs(nfslog_WRITE3args *, nfslog_WRITE3res *,
163*0Sstevel@tonic-gate char *, char **, char **);
164*0Sstevel@tonic-gate static void nfslog_CREATE3_fhargs(nfslog_CREATE3args *, nfslog_CREATE3res *,
165*0Sstevel@tonic-gate char *, char **, char **);
166*0Sstevel@tonic-gate static void nfslog_MKDIR3_fhargs(nfslog_MKDIR3args *, nfslog_MKDIR3res *,
167*0Sstevel@tonic-gate char *, char **, char **);
168*0Sstevel@tonic-gate static void nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args *, nfslog_SYMLINK3res *,
169*0Sstevel@tonic-gate char *, char **, char **);
170*0Sstevel@tonic-gate static void nfslog_MKNOD3_fhargs(nfslog_MKNOD3args *, nfslog_MKNOD3res *,
171*0Sstevel@tonic-gate char *, char **, char **);
172*0Sstevel@tonic-gate static void nfslog_REMOVE3_fhargs(nfslog_REMOVE3args *, nfsstat3 *,
173*0Sstevel@tonic-gate char *, char **, char **);
174*0Sstevel@tonic-gate static void nfslog_RMDIR3_fhargs(nfslog_RMDIR3args *, nfsstat3 *,
175*0Sstevel@tonic-gate char *, char **, char **);
176*0Sstevel@tonic-gate static void nfslog_RENAME3_fhargs(nfslog_RENAME3args *, nfsstat3 *,
177*0Sstevel@tonic-gate char *, char **, char **);
178*0Sstevel@tonic-gate static void nfslog_LINK3_fhargs(nfslog_LINK3args *, nfsstat3 *,
179*0Sstevel@tonic-gate char *, char **, char **);
180*0Sstevel@tonic-gate static void nfslog_READDIR3_fhargs(nfs_fh3 *, nfsstat3 *,
181*0Sstevel@tonic-gate char *, char **, char **);
182*0Sstevel@tonic-gate static void nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args *,
183*0Sstevel@tonic-gate nfslog_READDIRPLUS3res *,
184*0Sstevel@tonic-gate char *, char **, char **);
185*0Sstevel@tonic-gate static void nfslog_FSSTAT3_fhargs(nfs_fh3 *, nfsstat3 *,
186*0Sstevel@tonic-gate char *, char **, char **);
187*0Sstevel@tonic-gate static void nfslog_FSINFO3_fhargs(nfs_fh3 *, nfsstat3 *,
188*0Sstevel@tonic-gate char *, char **, char **);
189*0Sstevel@tonic-gate static void nfslog_PATHCONF3_fhargs(nfs_fh3 *, nfsstat3 *,
190*0Sstevel@tonic-gate char *, char **, char **);
191*0Sstevel@tonic-gate static void nfslog_COMMIT3_fhargs(nfslog_COMMIT3args *, nfsstat3 *,
192*0Sstevel@tonic-gate char *, char **, char **);
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate /*
195*0Sstevel@tonic-gate * NFSLOG VERSION 1
196*0Sstevel@tonic-gate *
197*0Sstevel@tonic-gate * Functions for updating the fhtable for fhtoppath
198*0Sstevel@tonic-gate */
199*0Sstevel@tonic-gate static void nfslog_SHARE_fhargs(nfslog_sharefsargs *, nfslog_sharefsres *,
200*0Sstevel@tonic-gate char *, char **, char **);
201*0Sstevel@tonic-gate static void nfslog_UNSHARE_fhargs(nfslog_sharefsargs *, nfslog_sharefsres *,
202*0Sstevel@tonic-gate char *, char **, char **);
203*0Sstevel@tonic-gate static void nfslog_GETFH_fhargs(nfslog_getfhargs *, nfsstat *,
204*0Sstevel@tonic-gate char *, char **, char **);
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate /*
207*0Sstevel@tonic-gate * Define the actions taken per prog/vers/proc:
208*0Sstevel@tonic-gate *
209*0Sstevel@tonic-gate * In some cases, the nl types are the same as the nfs types and a simple
210*0Sstevel@tonic-gate * bcopy should suffice. Rather that define tens of identical procedures,
211*0Sstevel@tonic-gate * simply define these to bcopy. Similarly this takes care of different
212*0Sstevel@tonic-gate * procs that use same parameter struct.
213*0Sstevel@tonic-gate */
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_fh_proc_v2[] = {
216*0Sstevel@tonic-gate /*
217*0Sstevel@tonic-gate * NFS VERSION 2
218*0Sstevel@tonic-gate */
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate /* RFS_NULL = 0 */
221*0Sstevel@tonic-gate {nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate /* RFS_GETATTR = 1 */
224*0Sstevel@tonic-gate {nfslog_GETATTR2_fhargs, xdr_fhandle, xdr_nfsstat,
225*0Sstevel@tonic-gate sizeof (fhandle_t), sizeof (nfsstat)},
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate /* RFS_SETATTR = 2 */
228*0Sstevel@tonic-gate {nfslog_SETATTR2_fhargs, xdr_nfslog_setattrargs, xdr_nfsstat,
229*0Sstevel@tonic-gate sizeof (nfslog_setattrargs), sizeof (nfsstat)},
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gate /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
232*0Sstevel@tonic-gate {nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate /* RFS_LOOKUP = 4 */
235*0Sstevel@tonic-gate {nfslog_LOOKUP2_fhargs, xdr_nfslog_diropargs, xdr_nfslog_diropres,
236*0Sstevel@tonic-gate sizeof (nfslog_diropargs), sizeof (nfslog_diropres)},
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate /* RFS_READLINK = 5 */
239*0Sstevel@tonic-gate {nfslog_READLINK2_fhargs, xdr_fhandle, xdr_nfslog_rdlnres,
240*0Sstevel@tonic-gate sizeof (fhandle_t), sizeof (nfslog_rdlnres)},
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate /* RFS_READ = 6 */
243*0Sstevel@tonic-gate {nfslog_READ2_fhargs, xdr_nfslog_nfsreadargs, xdr_nfslog_rdresult,
244*0Sstevel@tonic-gate sizeof (nfslog_nfsreadargs), sizeof (nfslog_rdresult)},
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gate /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
247*0Sstevel@tonic-gate {nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate /* RFS_WRITE = 8 */
250*0Sstevel@tonic-gate {nfslog_WRITE2_fhargs, xdr_nfslog_writeargs, xdr_nfslog_writeresult,
251*0Sstevel@tonic-gate sizeof (nfslog_writeargs), sizeof (nfslog_writeresult)},
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gate /* RFS_CREATE = 9 */
254*0Sstevel@tonic-gate {nfslog_CREATE2_fhargs, xdr_nfslog_createargs, xdr_nfslog_diropres,
255*0Sstevel@tonic-gate sizeof (nfslog_createargs), sizeof (nfslog_diropres)},
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate /* RFS_REMOVE = 10 */
258*0Sstevel@tonic-gate {nfslog_REMOVE2_fhargs, xdr_nfslog_diropargs, xdr_nfsstat,
259*0Sstevel@tonic-gate sizeof (nfslog_diropargs), sizeof (nfsstat)},
260*0Sstevel@tonic-gate
261*0Sstevel@tonic-gate /* RFS_RENAME = 11 */
262*0Sstevel@tonic-gate {nfslog_RENAME2_fhargs, xdr_nfslog_rnmargs, xdr_nfsstat,
263*0Sstevel@tonic-gate sizeof (nfslog_rnmargs), sizeof (nfsstat)},
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate /* RFS_LINK = 12 */
266*0Sstevel@tonic-gate {nfslog_LINK2_fhargs, xdr_nfslog_linkargs, xdr_nfsstat,
267*0Sstevel@tonic-gate sizeof (nfslog_linkargs), sizeof (nfsstat)},
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gate /* RFS_SYMLINK = 13 */
270*0Sstevel@tonic-gate {nfslog_SYMLINK2_fhargs, xdr_nfslog_symlinkargs, xdr_nfsstat,
271*0Sstevel@tonic-gate sizeof (nfslog_symlinkargs), sizeof (nfsstat)},
272*0Sstevel@tonic-gate
273*0Sstevel@tonic-gate /* RFS_MKDIR = 14 */
274*0Sstevel@tonic-gate {nfslog_CREATE2_fhargs, xdr_nfslog_createargs, xdr_nfslog_diropres,
275*0Sstevel@tonic-gate sizeof (nfslog_createargs), sizeof (nfslog_diropres)},
276*0Sstevel@tonic-gate
277*0Sstevel@tonic-gate /* RFS_RMDIR = 15 */
278*0Sstevel@tonic-gate {nfslog_REMOVE2_fhargs, xdr_nfslog_diropargs, xdr_nfsstat,
279*0Sstevel@tonic-gate sizeof (nfslog_diropargs), sizeof (nfsstat)},
280*0Sstevel@tonic-gate
281*0Sstevel@tonic-gate /* RFS_READDIR = 16 */
282*0Sstevel@tonic-gate {nfslog_READDIR2_fhargs, xdr_nfslog_rddirargs, xdr_nfslog_rddirres,
283*0Sstevel@tonic-gate sizeof (nfslog_rddirargs), sizeof (nfslog_rddirres)},
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate /* RFS_STATFS = 17 */
286*0Sstevel@tonic-gate {nfslog_STATFS2_fhargs, xdr_fhandle, xdr_nfsstat,
287*0Sstevel@tonic-gate sizeof (fhandle_t), sizeof (nfsstat)},
288*0Sstevel@tonic-gate };
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate /*
292*0Sstevel@tonic-gate * NFS VERSION 3
293*0Sstevel@tonic-gate */
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_fh_proc_v3[] = {
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate /* RFS_NULL = 0 */
298*0Sstevel@tonic-gate {nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
299*0Sstevel@tonic-gate
300*0Sstevel@tonic-gate /* RFS3_GETATTR = 1 */
301*0Sstevel@tonic-gate {nfslog_GETATTR3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
302*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gate /* RFS3_SETATTR = 2 */
305*0Sstevel@tonic-gate {nfslog_SETATTR3_fhargs, xdr_nfslog_SETATTR3args, xdr_nfsstat3,
306*0Sstevel@tonic-gate sizeof (nfslog_SETATTR3args), sizeof (nfsstat3)},
307*0Sstevel@tonic-gate
308*0Sstevel@tonic-gate /* RFS3_LOOKUP = 3 */
309*0Sstevel@tonic-gate {nfslog_LOOKUP3_fhargs, xdr_nfslog_diropargs3, xdr_nfslog_LOOKUP3res,
310*0Sstevel@tonic-gate sizeof (nfslog_diropargs3), sizeof (nfslog_LOOKUP3res)},
311*0Sstevel@tonic-gate
312*0Sstevel@tonic-gate /* RFS3_ACCESS = 4 */
313*0Sstevel@tonic-gate {nfslog_ACCESS3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
314*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gate /* RFS3_READLINK = 5 */
317*0Sstevel@tonic-gate {nfslog_READLINK3_fhargs, xdr_nfs_fh3, xdr_nfslog_READLINK3res,
318*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfslog_READLINK3res)},
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate /* RFS3_READ = 6 */
321*0Sstevel@tonic-gate {nfslog_READ3_fhargs, xdr_nfslog_READ3args, xdr_nfslog_READ3res,
322*0Sstevel@tonic-gate sizeof (nfslog_READ3args), sizeof (nfslog_READ3res)},
323*0Sstevel@tonic-gate
324*0Sstevel@tonic-gate /* RFS3_WRITE = 7 */
325*0Sstevel@tonic-gate {nfslog_WRITE3_fhargs, xdr_nfslog_WRITE3args, xdr_nfslog_WRITE3res,
326*0Sstevel@tonic-gate sizeof (nfslog_WRITE3args), sizeof (nfslog_WRITE3res)},
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate /* RFS3_CREATE = 8 */
329*0Sstevel@tonic-gate {nfslog_CREATE3_fhargs, xdr_nfslog_CREATE3args, xdr_nfslog_CREATE3res,
330*0Sstevel@tonic-gate sizeof (nfslog_CREATE3args), sizeof (nfslog_CREATE3res)},
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate /* RFS3_MKDIR = 9 */
333*0Sstevel@tonic-gate {nfslog_MKDIR3_fhargs, xdr_nfslog_MKDIR3args, xdr_nfslog_MKDIR3res,
334*0Sstevel@tonic-gate sizeof (nfslog_MKDIR3args), sizeof (nfslog_MKDIR3res)},
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate /* RFS3_SYMLINK = 10 */
337*0Sstevel@tonic-gate {nfslog_SYMLINK3_fhargs, xdr_nfslog_SYMLINK3args,
338*0Sstevel@tonic-gate xdr_nfslog_SYMLINK3res,
339*0Sstevel@tonic-gate sizeof (nfslog_SYMLINK3args), sizeof (nfslog_SYMLINK3res)},
340*0Sstevel@tonic-gate
341*0Sstevel@tonic-gate /* RFS3_MKNOD = 11 */
342*0Sstevel@tonic-gate {nfslog_MKNOD3_fhargs, xdr_nfslog_MKNOD3args, xdr_nfslog_MKNOD3res,
343*0Sstevel@tonic-gate sizeof (nfslog_MKNOD3args), sizeof (nfslog_MKNOD3res)},
344*0Sstevel@tonic-gate
345*0Sstevel@tonic-gate /* RFS3_REMOVE = 12 */
346*0Sstevel@tonic-gate {nfslog_REMOVE3_fhargs, xdr_nfslog_REMOVE3args, xdr_nfsstat3,
347*0Sstevel@tonic-gate sizeof (nfslog_REMOVE3args), sizeof (nfsstat3)},
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate /* RFS3_RMDIR = 13 */
350*0Sstevel@tonic-gate {nfslog_RMDIR3_fhargs, xdr_nfslog_RMDIR3args, xdr_nfsstat3,
351*0Sstevel@tonic-gate sizeof (nfslog_RMDIR3args), sizeof (nfsstat3)},
352*0Sstevel@tonic-gate
353*0Sstevel@tonic-gate /* RFS3_RENAME = 14 */
354*0Sstevel@tonic-gate {nfslog_RENAME3_fhargs, xdr_nfslog_RENAME3args, xdr_nfsstat3,
355*0Sstevel@tonic-gate sizeof (nfslog_RENAME3args), sizeof (nfsstat3)},
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate /* RFS3_LINK = 15 */
358*0Sstevel@tonic-gate {nfslog_LINK3_fhargs, xdr_nfslog_LINK3args, xdr_nfsstat3,
359*0Sstevel@tonic-gate sizeof (nfslog_LINK3args), sizeof (nfsstat3)},
360*0Sstevel@tonic-gate
361*0Sstevel@tonic-gate /* RFS3_READDIR = 16 */
362*0Sstevel@tonic-gate {nfslog_READDIR3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
363*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
364*0Sstevel@tonic-gate
365*0Sstevel@tonic-gate /* RFS3_READDIRPLUS = 17 */
366*0Sstevel@tonic-gate {nfslog_READDIRPLUS3_fhargs,
367*0Sstevel@tonic-gate xdr_nfslog_READDIRPLUS3args, xdr_nfslog_READDIRPLUS3res,
368*0Sstevel@tonic-gate sizeof (nfslog_READDIRPLUS3args),
369*0Sstevel@tonic-gate sizeof (nfslog_READDIRPLUS3res)},
370*0Sstevel@tonic-gate
371*0Sstevel@tonic-gate /* RFS3_FSSTAT = 18 */
372*0Sstevel@tonic-gate {nfslog_FSSTAT3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
373*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gate /* RFS3_FSINFO = 19 */
376*0Sstevel@tonic-gate {nfslog_FSINFO3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
377*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
378*0Sstevel@tonic-gate
379*0Sstevel@tonic-gate /* RFS3_PATHCONF = 20 */
380*0Sstevel@tonic-gate {nfslog_PATHCONF3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
381*0Sstevel@tonic-gate sizeof (nfs_fh3), sizeof (nfsstat3)},
382*0Sstevel@tonic-gate
383*0Sstevel@tonic-gate /* RFS3_COMMIT = 21 */
384*0Sstevel@tonic-gate {nfslog_COMMIT3_fhargs, xdr_nfslog_COMMIT3args, xdr_nfsstat3,
385*0Sstevel@tonic-gate sizeof (nfslog_COMMIT3args), sizeof (nfsstat3)},
386*0Sstevel@tonic-gate };
387*0Sstevel@tonic-gate
388*0Sstevel@tonic-gate /*
389*0Sstevel@tonic-gate * NFSLOG VERSION 1
390*0Sstevel@tonic-gate */
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_log_fh_proc_v1[] = {
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate /* NFSLOG_NULL = 0 */
395*0Sstevel@tonic-gate {nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate /* NFSLOG_SHARE = 1 */
398*0Sstevel@tonic-gate {nfslog_SHARE_fhargs, xdr_nfslog_sharefsargs, xdr_nfslog_sharefsres,
399*0Sstevel@tonic-gate sizeof (nfslog_sharefsargs), sizeof (nfslog_sharefsres)},
400*0Sstevel@tonic-gate
401*0Sstevel@tonic-gate /* NFSLOG_UNSHARE = 2 */
402*0Sstevel@tonic-gate {nfslog_UNSHARE_fhargs, xdr_nfslog_sharefsargs, xdr_nfslog_sharefsres,
403*0Sstevel@tonic-gate sizeof (nfslog_sharefsargs), sizeof (nfslog_sharefsres)},
404*0Sstevel@tonic-gate
405*0Sstevel@tonic-gate /* NFSLOG_LOOKUP3 = 3 */
406*0Sstevel@tonic-gate {nfslog_LOOKUP3_fhargs, xdr_nfslog_diropargs3, xdr_nfslog_LOOKUP3res,
407*0Sstevel@tonic-gate sizeof (nfslog_diropargs3), sizeof (nfslog_LOOKUP3res)},
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate /* NFSLOG_GETFH = 4 */
410*0Sstevel@tonic-gate {nfslog_GETFH_fhargs, xdr_nfslog_getfhargs, xdr_nfsstat,
411*0Sstevel@tonic-gate sizeof (nfslog_getfhargs), sizeof (nfsstat)},
412*0Sstevel@tonic-gate };
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate static struct nfsl_fh_vers_disp nfsl_fh_vers_disptable[] = {
415*0Sstevel@tonic-gate {sizeof (nfsl_fh_proc_v2) / sizeof (nfsl_fh_proc_v2[0]),
416*0Sstevel@tonic-gate nfsl_fh_proc_v2},
417*0Sstevel@tonic-gate {sizeof (nfsl_fh_proc_v3) / sizeof (nfsl_fh_proc_v3[0]),
418*0Sstevel@tonic-gate nfsl_fh_proc_v3},
419*0Sstevel@tonic-gate };
420*0Sstevel@tonic-gate
421*0Sstevel@tonic-gate static struct nfsl_fh_vers_disp nfsl_log_fh_vers_disptable[] = {
422*0Sstevel@tonic-gate {sizeof (nfsl_log_fh_proc_v1) / sizeof (nfsl_log_fh_proc_v1[0]),
423*0Sstevel@tonic-gate nfsl_log_fh_proc_v1},
424*0Sstevel@tonic-gate };
425*0Sstevel@tonic-gate
426*0Sstevel@tonic-gate static struct nfsl_fh_prog_disp nfsl_fh_dispatch_table[] = {
427*0Sstevel@tonic-gate {NFS_PROGRAM,
428*0Sstevel@tonic-gate NFS_VERSMIN,
429*0Sstevel@tonic-gate sizeof (nfsl_fh_vers_disptable) /
430*0Sstevel@tonic-gate sizeof (nfsl_fh_vers_disptable[0]),
431*0Sstevel@tonic-gate nfsl_fh_vers_disptable},
432*0Sstevel@tonic-gate {NFSLOG_PROGRAM,
433*0Sstevel@tonic-gate NFSLOG_VERSMIN,
434*0Sstevel@tonic-gate sizeof (nfsl_log_fh_vers_disptable) /
435*0Sstevel@tonic-gate sizeof (nfsl_log_fh_vers_disptable[0]),
436*0Sstevel@tonic-gate nfsl_log_fh_vers_disptable},
437*0Sstevel@tonic-gate };
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gate static int nfsl_fh_dispatch_table_arglen =
440*0Sstevel@tonic-gate sizeof (nfsl_fh_dispatch_table) /
441*0Sstevel@tonic-gate sizeof (nfsl_fh_dispatch_table[0]);
442*0Sstevel@tonic-gate
443*0Sstevel@tonic-gate extern int debug;
444*0Sstevel@tonic-gate
445*0Sstevel@tonic-gate /*
446*0Sstevel@tonic-gate * print the fid into the given string as a series of hex digits.
447*0Sstevel@tonic-gate * XXX Ideally, we'd like to just convert the filehandle into an i-number,
448*0Sstevel@tonic-gate * but the fid encoding is a little tricky (see nfs_fhtovp() and
449*0Sstevel@tonic-gate * ufs_vget()) and may be private to UFS.
450*0Sstevel@tonic-gate */
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate static void
sprint_fid(char * buf,uint_t buflen,const fhandle_t * fh)453*0Sstevel@tonic-gate sprint_fid(char *buf, uint_t buflen, const fhandle_t *fh)
454*0Sstevel@tonic-gate {
455*0Sstevel@tonic-gate int i;
456*0Sstevel@tonic-gate uchar_t byte;
457*0Sstevel@tonic-gate uint_t fhlen;
458*0Sstevel@tonic-gate
459*0Sstevel@tonic-gate /*
460*0Sstevel@tonic-gate * If the filehandle somehow got corrupted, only print the part
461*0Sstevel@tonic-gate * that makes sense.
462*0Sstevel@tonic-gate */
463*0Sstevel@tonic-gate if (fh->fh_len > NFS_FHMAXDATA)
464*0Sstevel@tonic-gate fhlen = NFS_FHMAXDATA;
465*0Sstevel@tonic-gate else
466*0Sstevel@tonic-gate fhlen = fh->fh_len;
467*0Sstevel@tonic-gate assert(2 * fhlen < buflen);
468*0Sstevel@tonic-gate
469*0Sstevel@tonic-gate for (i = 0; i < fhlen; i++) {
470*0Sstevel@tonic-gate byte = fh->fh_data[i];
471*0Sstevel@tonic-gate (void) sprintf(buf + 2 * i, "%02x", byte);
472*0Sstevel@tonic-gate }
473*0Sstevel@tonic-gate }
474*0Sstevel@tonic-gate
475*0Sstevel@tonic-gate static void
fh_print_all_keys(char * fhpath,fhandle_t * fh)476*0Sstevel@tonic-gate fh_print_all_keys(char *fhpath, fhandle_t *fh)
477*0Sstevel@tonic-gate {
478*0Sstevel@tonic-gate if ((fhpath == NULL) || (fh == NULL) || (debug <= 1))
479*0Sstevel@tonic-gate return;
480*0Sstevel@tonic-gate (void) printf("\nBegin all database keys\n");
481*0Sstevel@tonic-gate db_print_all_keys(fhpath, &fh->fh_fsid, stdout);
482*0Sstevel@tonic-gate (void) printf("\nEnd all database keys\n");
483*0Sstevel@tonic-gate }
484*0Sstevel@tonic-gate
485*0Sstevel@tonic-gate #define FH_ADD(path, dfh, fh, name) \
486*0Sstevel@tonic-gate fh_add(path, dfh, fh, name)
487*0Sstevel@tonic-gate
488*0Sstevel@tonic-gate /*
489*0Sstevel@tonic-gate * Add the filehandle "fh", which has the name "name" and lives in
490*0Sstevel@tonic-gate * directory "dfh", to the table "fhlist". "fhlist" will be updated if the
491*0Sstevel@tonic-gate * entry is added to the front of the list.
492*0Sstevel@tonic-gate * Return 0 for success, error code otherwise.
493*0Sstevel@tonic-gate */
494*0Sstevel@tonic-gate static int
fh_add(char * fhpath,fhandle_t * dfh,fhandle_t * fh,char * name)495*0Sstevel@tonic-gate fh_add(char *fhpath, fhandle_t *dfh, fhandle_t *fh, char *name)
496*0Sstevel@tonic-gate {
497*0Sstevel@tonic-gate uint_t flags = 0;
498*0Sstevel@tonic-gate int error;
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gate if (IS_DOT_FILENAME(name)) {
501*0Sstevel@tonic-gate /* we don't insert these to the database but not an error */
502*0Sstevel@tonic-gate if (debug > 3) {
503*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name,
504*0Sstevel@tonic-gate " - no dot files")
505*0Sstevel@tonic-gate }
506*0Sstevel@tonic-gate return (0);
507*0Sstevel@tonic-gate }
508*0Sstevel@tonic-gate if (dfh && (memcmp(fh, dfh, NFS_FHSIZE) == 0)) {
509*0Sstevel@tonic-gate flags |= EXPORT_POINT;
510*0Sstevel@tonic-gate }
511*0Sstevel@tonic-gate
512*0Sstevel@tonic-gate /* Add to database */
513*0Sstevel@tonic-gate error = db_add(fhpath, dfh, name, fh, flags);
514*0Sstevel@tonic-gate if (debug > 1) {
515*0Sstevel@tonic-gate if (error != 0) {
516*0Sstevel@tonic-gate (void) printf("db_add error %s:\n",
517*0Sstevel@tonic-gate ((error >= 0) ? strerror(error) : "Unknown"));
518*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name, "")
519*0Sstevel@tonic-gate } else if (debug > 2) {
520*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name, "")
521*0Sstevel@tonic-gate }
522*0Sstevel@tonic-gate }
523*0Sstevel@tonic-gate return (error);
524*0Sstevel@tonic-gate }
525*0Sstevel@tonic-gate
526*0Sstevel@tonic-gate /*
527*0Sstevel@tonic-gate * fh_compare returns 0 if the file handles match, error code otherwise
528*0Sstevel@tonic-gate */
529*0Sstevel@tonic-gate static int
fh_compare(fhandle_t * fh1,fhandle_t * fh2)530*0Sstevel@tonic-gate fh_compare(fhandle_t *fh1, fhandle_t *fh2)
531*0Sstevel@tonic-gate {
532*0Sstevel@tonic-gate if (memcmp(fh1, fh2, NFS_FHSIZE))
533*0Sstevel@tonic-gate return (errno);
534*0Sstevel@tonic-gate else
535*0Sstevel@tonic-gate return (0);
536*0Sstevel@tonic-gate }
537*0Sstevel@tonic-gate
538*0Sstevel@tonic-gate /*
539*0Sstevel@tonic-gate * Try to find the filehandle "fh" in the table. Returns 0 and the
540*0Sstevel@tonic-gate * corresponding table entry if found, error otherwise.
541*0Sstevel@tonic-gate * If successfull and fhrecpp is non-null then *fhrecpp points to the
542*0Sstevel@tonic-gate * returned record. If *fhrecpp was initially null, that record had
543*0Sstevel@tonic-gate * been malloc'd and must be freed by caller.
544*0Sstevel@tonic-gate */
545*0Sstevel@tonic-gate
546*0Sstevel@tonic-gate static fhlist_ent *
fh_lookup(char * fhpath,fhandle_t * fh,fhlist_ent * fhrecp,int * errorp)547*0Sstevel@tonic-gate fh_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp, int *errorp)
548*0Sstevel@tonic-gate {
549*0Sstevel@tonic-gate if (debug > 3) {
550*0Sstevel@tonic-gate (void) printf("fh_lookup: fh ");
551*0Sstevel@tonic-gate debug_opaque_print(stdout, fh, sizeof (*fh));
552*0Sstevel@tonic-gate (void) printf("\n");
553*0Sstevel@tonic-gate }
554*0Sstevel@tonic-gate return (db_lookup(fhpath, fh, fhrecp, errorp));
555*0Sstevel@tonic-gate }
556*0Sstevel@tonic-gate
557*0Sstevel@tonic-gate /*
558*0Sstevel@tonic-gate * Remove the mc link if exists when removing a regular link.
559*0Sstevel@tonic-gate * Return 0 for success, error code otherwise.
560*0Sstevel@tonic-gate */
561*0Sstevel@tonic-gate static int
fh_remove_mc_link(char * fhpath,fhandle_t * dfh,char * name,char ** pathp)562*0Sstevel@tonic-gate fh_remove_mc_link(char *fhpath, fhandle_t *dfh, char *name, char **pathp)
563*0Sstevel@tonic-gate {
564*0Sstevel@tonic-gate int error;
565*0Sstevel@tonic-gate char *str, *str1;
566*0Sstevel@tonic-gate
567*0Sstevel@tonic-gate /* Delete the multi-component path if exists */
568*0Sstevel@tonic-gate if ((pathp == NULL) || (*pathp == NULL)) {
569*0Sstevel@tonic-gate str = nfslog_get_path(dfh, name, fhpath, "remove_mc_link");
570*0Sstevel@tonic-gate str1 = str;
571*0Sstevel@tonic-gate } else {
572*0Sstevel@tonic-gate str = *pathp;
573*0Sstevel@tonic-gate str1 = NULL;
574*0Sstevel@tonic-gate }
575*0Sstevel@tonic-gate error = db_delete_link(fhpath, &public_fh, str);
576*0Sstevel@tonic-gate if (str1 != NULL)
577*0Sstevel@tonic-gate free(str1);
578*0Sstevel@tonic-gate return (error);
579*0Sstevel@tonic-gate }
580*0Sstevel@tonic-gate
581*0Sstevel@tonic-gate /*
582*0Sstevel@tonic-gate * Remove the link entry from the fh table.
583*0Sstevel@tonic-gate * Return 0 for success, error code otherwise.
584*0Sstevel@tonic-gate */
585*0Sstevel@tonic-gate static int
fh_remove(char * fhpath,fhandle_t * dfh,char * name,char ** pathp)586*0Sstevel@tonic-gate fh_remove(char *fhpath, fhandle_t *dfh, char *name, char **pathp)
587*0Sstevel@tonic-gate {
588*0Sstevel@tonic-gate /*
589*0Sstevel@tonic-gate * disconnect element from list
590*0Sstevel@tonic-gate *
591*0Sstevel@tonic-gate * Remove the link entry for the file. Remove fh entry if last link.
592*0Sstevel@tonic-gate */
593*0Sstevel@tonic-gate if (IS_DOT_FILENAME(name)) {
594*0Sstevel@tonic-gate /* we don't insert these to the database but not an error */
595*0Sstevel@tonic-gate if (debug > 2) {
596*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "fh_remove", dfh, name,
597*0Sstevel@tonic-gate " - no dot files")
598*0Sstevel@tonic-gate }
599*0Sstevel@tonic-gate return (0);
600*0Sstevel@tonic-gate }
601*0Sstevel@tonic-gate if (debug > 2) {
602*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "fh_remove", dfh, name, "")
603*0Sstevel@tonic-gate }
604*0Sstevel@tonic-gate /* Delete the multi-component path if exists */
605*0Sstevel@tonic-gate (void) fh_remove_mc_link(fhpath, dfh, name, pathp);
606*0Sstevel@tonic-gate return (db_delete_link(fhpath, dfh, name));
607*0Sstevel@tonic-gate }
608*0Sstevel@tonic-gate
609*0Sstevel@tonic-gate /*
610*0Sstevel@tonic-gate * fh_rename - renames a link in the database (adds the new one if from link
611*0Sstevel@tonic-gate * did not exist).
612*0Sstevel@tonic-gate * Return 0 for success, error code otherwise.
613*0Sstevel@tonic-gate */
614*0Sstevel@tonic-gate static int
fh_rename(char * fhpath,fhandle_t * from_dfh,char * from_name,char ** from_pathp,fhandle_t * to_dfh,char * to_name)615*0Sstevel@tonic-gate fh_rename(char *fhpath, fhandle_t *from_dfh, char *from_name, char **from_pathp,
616*0Sstevel@tonic-gate fhandle_t *to_dfh, char *to_name)
617*0Sstevel@tonic-gate {
618*0Sstevel@tonic-gate if (debug > 2) {
619*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "fh_rename: from:", from_dfh,
620*0Sstevel@tonic-gate from_name, "")
621*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "fh_rename: to :", to_dfh,
622*0Sstevel@tonic-gate to_name, "")
623*0Sstevel@tonic-gate }
624*0Sstevel@tonic-gate /*
625*0Sstevel@tonic-gate * if any of these are dot files (should not happen), the rename
626*0Sstevel@tonic-gate * becomes a "delete" or "add" operation because the dot files
627*0Sstevel@tonic-gate * don't get in the database
628*0Sstevel@tonic-gate */
629*0Sstevel@tonic-gate if (IS_DOT_FILENAME(to_name)) {
630*0Sstevel@tonic-gate /* it is just a delete op */
631*0Sstevel@tonic-gate if (debug > 2) {
632*0Sstevel@tonic-gate (void) printf("to: no dot files\nDelete from: '%s'\n",
633*0Sstevel@tonic-gate from_name);
634*0Sstevel@tonic-gate }
635*0Sstevel@tonic-gate return (fh_remove(fhpath, from_dfh, from_name, from_pathp));
636*0Sstevel@tonic-gate } else if (IS_DOT_FILENAME(from_name)) {
637*0Sstevel@tonic-gate /* we don't insert these to the database */
638*0Sstevel@tonic-gate if (debug > 2) {
639*0Sstevel@tonic-gate (void) printf("rename - from: no dot files\n");
640*0Sstevel@tonic-gate }
641*0Sstevel@tonic-gate /* can't insert the target, because don't have a handle */
642*0Sstevel@tonic-gate return (EINVAL);
643*0Sstevel@tonic-gate }
644*0Sstevel@tonic-gate /* Delete the multi-component path if exists */
645*0Sstevel@tonic-gate (void) fh_remove_mc_link(fhpath, from_dfh, from_name, from_pathp);
646*0Sstevel@tonic-gate return (db_rename_link(fhpath, from_dfh, from_name, to_dfh, to_name));
647*0Sstevel@tonic-gate }
648*0Sstevel@tonic-gate
649*0Sstevel@tonic-gate /*
650*0Sstevel@tonic-gate * fh_lookup_link - search the fhtable for the link defined by (dfh,name,fh).
651*0Sstevel@tonic-gate * Return 0 and set *fhrecpp to the fhlist item corresponding to it if found,
652*0Sstevel@tonic-gate * or error if not found.
653*0Sstevel@tonic-gate * Possible configurations:
654*0Sstevel@tonic-gate * 1. dfh, fh, name are all non-null: Only exact match accepted.
655*0Sstevel@tonic-gate * 2. dfh,name non-null, fh null: return first match found.
656*0Sstevel@tonic-gate * 3. fh,name non-null, dfh null: return first match found.
657*0Sstevel@tonic-gate * 3. fh non-null, dfh, name null: return first match found.
658*0Sstevel@tonic-gate * If successfull and fhrecpp is non-null then *fhrecpp points to the
659*0Sstevel@tonic-gate * returned record. If *fhrecpp was initially null, that record had
660*0Sstevel@tonic-gate * been malloc'd and must be freed by caller.
661*0Sstevel@tonic-gate */
662*0Sstevel@tonic-gate static fhlist_ent *
fh_lookup_link(char * fhpath,fhandle_t * dfh,fhandle_t * fh,char * name,fhlist_ent * fhrecp,int * errorp)663*0Sstevel@tonic-gate fh_lookup_link(char *fhpath, fhandle_t *dfh, fhandle_t *fh, char *name,
664*0Sstevel@tonic-gate fhlist_ent *fhrecp, int *errorp)
665*0Sstevel@tonic-gate {
666*0Sstevel@tonic-gate fhlist_ent *in_fhrecp = fhrecp;
667*0Sstevel@tonic-gate
668*0Sstevel@tonic-gate if ((name != NULL) && IS_DOT_FILENAME(name)) {
669*0Sstevel@tonic-gate /* we don't insert these to the database but not an error */
670*0Sstevel@tonic-gate if (debug > 2) {
671*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh, name,
672*0Sstevel@tonic-gate " - no dot files\n")
673*0Sstevel@tonic-gate }
674*0Sstevel@tonic-gate *errorp = 0;
675*0Sstevel@tonic-gate return (NULL);
676*0Sstevel@tonic-gate }
677*0Sstevel@tonic-gate if (debug > 3) {
678*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh, name, "")
679*0Sstevel@tonic-gate }
680*0Sstevel@tonic-gate /* Add to database */
681*0Sstevel@tonic-gate if (fh != NULL) {
682*0Sstevel@tonic-gate fhrecp = db_lookup(fhpath, fh, fhrecp, errorp);
683*0Sstevel@tonic-gate if (fhrecp == NULL) {
684*0Sstevel@tonic-gate if (debug > 3)
685*0Sstevel@tonic-gate (void) printf("fh_lookup_link: fh not found\n");
686*0Sstevel@tonic-gate return (NULL);
687*0Sstevel@tonic-gate }
688*0Sstevel@tonic-gate /* Check if name and dfh match, if not search link */
689*0Sstevel@tonic-gate if (((dfh == NULL) || !fh_compare(dfh, &fhrecp->dfh)) &&
690*0Sstevel@tonic-gate ((name == NULL) || (strcmp(name, fhrecp->name) == 0))) {
691*0Sstevel@tonic-gate /* found it */
692*0Sstevel@tonic-gate goto exit;
693*0Sstevel@tonic-gate }
694*0Sstevel@tonic-gate /* Found the primary record, but it's a different link */
695*0Sstevel@tonic-gate if (debug == 3) { /* Only log if >2 but already printed */
696*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh,
697*0Sstevel@tonic-gate name, "")
698*0Sstevel@tonic-gate }
699*0Sstevel@tonic-gate if (debug > 2) {
700*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "Different primary link",
701*0Sstevel@tonic-gate &fhrecp->dfh, fhrecp->name, "")
702*0Sstevel@tonic-gate }
703*0Sstevel@tonic-gate /* can now free the record unless it was supplied by caller */
704*0Sstevel@tonic-gate if (fhrecp != in_fhrecp) {
705*0Sstevel@tonic-gate free(fhrecp);
706*0Sstevel@tonic-gate fhrecp = NULL;
707*0Sstevel@tonic-gate }
708*0Sstevel@tonic-gate }
709*0Sstevel@tonic-gate /* If here, we must search by link */
710*0Sstevel@tonic-gate if ((dfh == NULL) || (name == NULL)) {
711*0Sstevel@tonic-gate if (debug > 2)
712*0Sstevel@tonic-gate (void) printf("fh_lookup_link: invalid params\n");
713*0Sstevel@tonic-gate *errorp = EINVAL;
714*0Sstevel@tonic-gate return (NULL);
715*0Sstevel@tonic-gate }
716*0Sstevel@tonic-gate fhrecp = db_lookup_link(fhpath, dfh, name, fhrecp, errorp);
717*0Sstevel@tonic-gate if (fhrecp == NULL) {
718*0Sstevel@tonic-gate if (debug > 3)
719*0Sstevel@tonic-gate (void) printf("fh_lookup_link: link not found: %s\n",
720*0Sstevel@tonic-gate ((*errorp >= 0) ? strerror(*errorp) : "Unknown"));
721*0Sstevel@tonic-gate return (NULL);
722*0Sstevel@tonic-gate }
723*0Sstevel@tonic-gate /* If all args supplied, check if an exact match */
724*0Sstevel@tonic-gate if ((fh != NULL) && fh_compare(fh, &fhrecp->fh)) {
725*0Sstevel@tonic-gate if (debug > 2) {
726*0Sstevel@tonic-gate PRINT_FULL_DATA(stderr, "fh_lookup_link", dfh, fh,
727*0Sstevel@tonic-gate name, "")
728*0Sstevel@tonic-gate PRINT_LINK_DATA(stderr, "Different primary link",
729*0Sstevel@tonic-gate &fhrecp->dfh, fhrecp->name, "")
730*0Sstevel@tonic-gate }
731*0Sstevel@tonic-gate if (fhrecp != in_fhrecp)
732*0Sstevel@tonic-gate free(fhrecp);
733*0Sstevel@tonic-gate *errorp = EINVAL;
734*0Sstevel@tonic-gate return (NULL);
735*0Sstevel@tonic-gate }
736*0Sstevel@tonic-gate exit:
737*0Sstevel@tonic-gate if (debug > 3)
738*0Sstevel@tonic-gate (void) printf("lookup: found '%s' in fhtable\n", name);
739*0Sstevel@tonic-gate *errorp = 0;
740*0Sstevel@tonic-gate return (fhrecp);
741*0Sstevel@tonic-gate }
742*0Sstevel@tonic-gate
743*0Sstevel@tonic-gate /*
744*0Sstevel@tonic-gate * Export handle cache is maintained if we see an export handle that either
745*0Sstevel@tonic-gate * cannot have the path for it determined, or we failed store it.
746*0Sstevel@tonic-gate * Usually the path of an export handle can be identified in the NFSLOGTAB
747*0Sstevel@tonic-gate * and since every path for that filesystem will be affected, it's worth
748*0Sstevel@tonic-gate * caching the ones we had problem identifying.
749*0Sstevel@tonic-gate */
750*0Sstevel@tonic-gate
751*0Sstevel@tonic-gate /*
752*0Sstevel@tonic-gate * find_fh_in_export_cache - given an export fh, find it in the cache and
753*0Sstevel@tonic-gate * return the handle
754*0Sstevel@tonic-gate */
755*0Sstevel@tonic-gate static struct export_handle_cache *
find_fh_in_export_cache(fhandle_t * fh)756*0Sstevel@tonic-gate find_fh_in_export_cache(fhandle_t *fh)
757*0Sstevel@tonic-gate {
758*0Sstevel@tonic-gate struct export_handle_cache *p;
759*0Sstevel@tonic-gate
760*0Sstevel@tonic-gate for (p = exp_handle_cache; p != NULL; p = p->next) {
761*0Sstevel@tonic-gate if (memcmp(fh, &p->fh, sizeof (*fh)) == 0)
762*0Sstevel@tonic-gate break;
763*0Sstevel@tonic-gate }
764*0Sstevel@tonic-gate return (p);
765*0Sstevel@tonic-gate }
766*0Sstevel@tonic-gate
767*0Sstevel@tonic-gate static void
add_fh_to_export_cache(fhandle_t * fh,char * path)768*0Sstevel@tonic-gate add_fh_to_export_cache(fhandle_t *fh, char *path)
769*0Sstevel@tonic-gate {
770*0Sstevel@tonic-gate struct export_handle_cache *new;
771*0Sstevel@tonic-gate
772*0Sstevel@tonic-gate if ((new = malloc(sizeof (*new))) == NULL) {
773*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
774*0Sstevel@tonic-gate "add_fh_to_export_cache: alloc new for '%s' Error %s\n"),
775*0Sstevel@tonic-gate ((path != NULL) ? path : ""), strerror(errno));
776*0Sstevel@tonic-gate return;
777*0Sstevel@tonic-gate }
778*0Sstevel@tonic-gate if (path != NULL) {
779*0Sstevel@tonic-gate if ((new->name = malloc(strlen(path) + 1)) == NULL) {
780*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
781*0Sstevel@tonic-gate "add_fh_to_export_cache: alloc '%s'"
782*0Sstevel@tonic-gate " Error %s\n"), path, strerror(errno));
783*0Sstevel@tonic-gate free(new);
784*0Sstevel@tonic-gate return;
785*0Sstevel@tonic-gate }
786*0Sstevel@tonic-gate (void) strcpy(new->name, path);
787*0Sstevel@tonic-gate } else {
788*0Sstevel@tonic-gate new->name = NULL;
789*0Sstevel@tonic-gate }
790*0Sstevel@tonic-gate (void) memcpy(&new->fh, fh, sizeof (*fh));
791*0Sstevel@tonic-gate new->next = exp_handle_cache;
792*0Sstevel@tonic-gate exp_handle_cache = new;
793*0Sstevel@tonic-gate }
794*0Sstevel@tonic-gate
795*0Sstevel@tonic-gate /*
796*0Sstevel@tonic-gate * update_export_point - called when the path for fh cannot be determined.
797*0Sstevel@tonic-gate * In the past it called get_export_path() to get the name of the
798*0Sstevel@tonic-gate * export point given a filehandle. This was a hack, since there's no
799*0Sstevel@tonic-gate * reason why the filehandle should be lost.
800*0Sstevel@tonic-gate *
801*0Sstevel@tonic-gate * If a match is found, insert the path to the database.
802*0Sstevel@tonic-gate * Return the inserted fhrecp is found,
803*0Sstevel@tonic-gate * and NULL if not. If it is an exported fs but not in the list, log a
804*0Sstevel@tonic-gate * error.
805*0Sstevel@tonic-gate * If input fhrecp is non-null, it is a valid address for result,
806*0Sstevel@tonic-gate * otherwise malloc it.
807*0Sstevel@tonic-gate */
808*0Sstevel@tonic-gate static char *
update_export_point(char * fhpath,fhandle_t * fh,char * path)809*0Sstevel@tonic-gate update_export_point(char *fhpath, fhandle_t *fh, char *path)
810*0Sstevel@tonic-gate {
811*0Sstevel@tonic-gate struct export_handle_cache *p;
812*0Sstevel@tonic-gate
813*0Sstevel@tonic-gate if ((fh == NULL) || memcmp(&fh->fh_data, &fh->fh_xdata, fh->fh_len)) {
814*0Sstevel@tonic-gate /* either null fh or not the root of a shared directory */
815*0Sstevel@tonic-gate return (NULL);
816*0Sstevel@tonic-gate }
817*0Sstevel@tonic-gate /* Did we already see (and fail) this one? */
818*0Sstevel@tonic-gate if ((p = find_fh_in_export_cache(fh)) != NULL) {
819*0Sstevel@tonic-gate /* Found it! */
820*0Sstevel@tonic-gate if (debug > 2) {
821*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "update_export_point",
822*0Sstevel@tonic-gate fh, ((p->name != NULL) ? p->name : ""), "");
823*0Sstevel@tonic-gate }
824*0Sstevel@tonic-gate if (p->name == NULL)
825*0Sstevel@tonic-gate return (NULL);
826*0Sstevel@tonic-gate /*
827*0Sstevel@tonic-gate * We should not normally be here - only add to cache if
828*0Sstevel@tonic-gate * fh_add failed.
829*0Sstevel@tonic-gate */
830*0Sstevel@tonic-gate if ((path == NULL) &&
831*0Sstevel@tonic-gate ((path = malloc(strlen(p->name) + 1)) == NULL)) {
832*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
833*0Sstevel@tonic-gate "update_export_point: malloc '%s' Error %s"),
834*0Sstevel@tonic-gate p->name, strerror(errno));
835*0Sstevel@tonic-gate return (NULL);
836*0Sstevel@tonic-gate }
837*0Sstevel@tonic-gate (void) strcpy(path, p->name);
838*0Sstevel@tonic-gate return (path);
839*0Sstevel@tonic-gate }
840*0Sstevel@tonic-gate if ((path = get_export_path(fh, path)) == NULL) {
841*0Sstevel@tonic-gate add_fh_to_export_cache(fh, NULL);
842*0Sstevel@tonic-gate return (NULL);
843*0Sstevel@tonic-gate }
844*0Sstevel@tonic-gate /* Found it! */
845*0Sstevel@tonic-gate if (debug > 2) {
846*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "update_export_point", fh, path, "")
847*0Sstevel@tonic-gate }
848*0Sstevel@tonic-gate if (FH_ADD(fhpath, fh, fh, path)) {
849*0Sstevel@tonic-gate /* cache this handle so we don't repeat the search */
850*0Sstevel@tonic-gate add_fh_to_export_cache(fh, path);
851*0Sstevel@tonic-gate }
852*0Sstevel@tonic-gate return (path);
853*0Sstevel@tonic-gate }
854*0Sstevel@tonic-gate
855*0Sstevel@tonic-gate /*
856*0Sstevel@tonic-gate * HACK!!! To get rid of get_export_path() use
857*0Sstevel@tonic-gate */
858*0Sstevel@tonic-gate /* ARGSUSED */
859*0Sstevel@tonic-gate static char *
get_export_path(fhandle_t * fh,char * path)860*0Sstevel@tonic-gate get_export_path(fhandle_t *fh, char *path)
861*0Sstevel@tonic-gate {
862*0Sstevel@tonic-gate return (NULL);
863*0Sstevel@tonic-gate }
864*0Sstevel@tonic-gate
865*0Sstevel@tonic-gate /*
866*0Sstevel@tonic-gate * Return the absolute pathname for the filehandle "fh", using the mapping
867*0Sstevel@tonic-gate * table "fhlist". The caller must free the return string.
868*0Sstevel@tonic-gate * name is an optional dir component name, to be appended at the end
869*0Sstevel@tonic-gate * (if name is non-null, the function assumes the fh is the parent directory)
870*0Sstevel@tonic-gate *
871*0Sstevel@tonic-gate * Note: The original code was recursive, which was much more elegant but
872*0Sstevel@tonic-gate * ran out of stack...
873*0Sstevel@tonic-gate */
874*0Sstevel@tonic-gate
875*0Sstevel@tonic-gate static char *
fh_print_absolute(char * fhpath,fhandle_t * fh,char * name)876*0Sstevel@tonic-gate fh_print_absolute(char *fhpath, fhandle_t *fh, char *name)
877*0Sstevel@tonic-gate {
878*0Sstevel@tonic-gate char *str, *rootname, parent[MAXPATHLEN];
879*0Sstevel@tonic-gate int i, j, k, len, error;
880*0Sstevel@tonic-gate fhlist_ent fhrec, *fhrecp;
881*0Sstevel@tonic-gate fhandle_t prevfh;
882*0Sstevel@tonic-gate int namelen;
883*0Sstevel@tonic-gate
884*0Sstevel@tonic-gate if (debug > 3)
885*0Sstevel@tonic-gate (void) printf("fh_print_absolute: input name '%s'\n",
886*0Sstevel@tonic-gate ((name != NULL) ? name : ""));
887*0Sstevel@tonic-gate /* If name starts with '/' we are done */
888*0Sstevel@tonic-gate if ((name != NULL) && (name[0] == '/')) {
889*0Sstevel@tonic-gate if ((str = strdup(name)) == NULL) {
890*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
891*0Sstevel@tonic-gate "fh_print_absolute: strdup '%s' error %s\n"),
892*0Sstevel@tonic-gate name, strerror(errno));
893*0Sstevel@tonic-gate }
894*0Sstevel@tonic-gate return (str);
895*0Sstevel@tonic-gate }
896*0Sstevel@tonic-gate namelen = ((name != NULL) ? strlen(name) + 2 : 0);
897*0Sstevel@tonic-gate parent[0] = '\0';
898*0Sstevel@tonic-gate
899*0Sstevel@tonic-gate /* remember the last filehandle we've seen */
900*0Sstevel@tonic-gate (void) memcpy((void *) &prevfh, (void *) fh, sizeof (*fh));
901*0Sstevel@tonic-gate fh = &prevfh;
902*0Sstevel@tonic-gate
903*0Sstevel@tonic-gate /* dump all names in reverse order */
904*0Sstevel@tonic-gate while ((fhrecp = fh_lookup(fhpath, fh, &fhrec, &error)) != NULL &&
905*0Sstevel@tonic-gate !(fhrecp->flags & (EXPORT_POINT | PUBLIC_PATH))) {
906*0Sstevel@tonic-gate
907*0Sstevel@tonic-gate if (debug > 3) {
908*0Sstevel@tonic-gate (void) printf("fh_print_absolute: name '%s'%s\n",
909*0Sstevel@tonic-gate fhrecp->name,
910*0Sstevel@tonic-gate ((fhrecp->flags & EXPORT_POINT) ? "root" : ""));
911*0Sstevel@tonic-gate }
912*0Sstevel@tonic-gate if (memcmp(&prevfh, &fhrecp->dfh, sizeof (*fh)) == 0) {
913*0Sstevel@tonic-gate /* dfh == prevfh but not an export point */
914*0Sstevel@tonic-gate if (debug > 1) {
915*0Sstevel@tonic-gate (void) printf(
916*0Sstevel@tonic-gate "fh_print_absolute: fhrec loop:\n");
917*0Sstevel@tonic-gate debug_opaque_print(stdout, fhrecp,
918*0Sstevel@tonic-gate fhrecp->reclen);
919*0Sstevel@tonic-gate }
920*0Sstevel@tonic-gate break;
921*0Sstevel@tonic-gate }
922*0Sstevel@tonic-gate (void) strcat(parent, "/");
923*0Sstevel@tonic-gate (void) strcat(parent, fhrecp->name);
924*0Sstevel@tonic-gate
925*0Sstevel@tonic-gate /* remember the last filehandle we've seen */
926*0Sstevel@tonic-gate (void) memcpy(&prevfh, &fhrecp->dfh, sizeof (fhrecp->dfh));
927*0Sstevel@tonic-gate }
928*0Sstevel@tonic-gate assert(fh == &prevfh);
929*0Sstevel@tonic-gate
930*0Sstevel@tonic-gate if (fhrecp != NULL) {
931*0Sstevel@tonic-gate rootname = fhrecp->name;
932*0Sstevel@tonic-gate } else {
933*0Sstevel@tonic-gate /* Check if export point, just in case... */
934*0Sstevel@tonic-gate /* There should be enough room in parent, leave the '\0' */
935*0Sstevel@tonic-gate rootname = update_export_point(
936*0Sstevel@tonic-gate fhpath, fh, &parent[strlen(parent) + 1]);
937*0Sstevel@tonic-gate }
938*0Sstevel@tonic-gate /* Now need to reverse the order */
939*0Sstevel@tonic-gate if (rootname != NULL) { /* *fhrecp is the export point */
940*0Sstevel@tonic-gate len = strlen(rootname) + 2;
941*0Sstevel@tonic-gate } else {
942*0Sstevel@tonic-gate len = 2 * (NFS_FHMAXDATA + fh->fh_len); /* fid instead */
943*0Sstevel@tonic-gate }
944*0Sstevel@tonic-gate len = ROUNDUP32(len + namelen + strlen(parent));
945*0Sstevel@tonic-gate if ((str = malloc(len)) == NULL) {
946*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
947*0Sstevel@tonic-gate "fh_print_absolute: malloc %d error %s\n"),
948*0Sstevel@tonic-gate len, strerror(errno));
949*0Sstevel@tonic-gate return (NULL);
950*0Sstevel@tonic-gate }
951*0Sstevel@tonic-gate /* first put the export point path in */
952*0Sstevel@tonic-gate if (rootname != NULL) { /* *fhrecp is the export point */
953*0Sstevel@tonic-gate (void) strcpy(str, rootname);
954*0Sstevel@tonic-gate } else {
955*0Sstevel@tonic-gate sprint_fid(str, len, fh);
956*0Sstevel@tonic-gate }
957*0Sstevel@tonic-gate for (k = strlen(str), i = strlen(parent); (k < len) && (i >= 0); i--) {
958*0Sstevel@tonic-gate for (j = i; (j >= 0) && (parent[j] != '/'); j--);
959*0Sstevel@tonic-gate if (j < 0)
960*0Sstevel@tonic-gate break;
961*0Sstevel@tonic-gate (void) strcpy(&str[k], &parent[j]);
962*0Sstevel@tonic-gate k += strlen(&str[k]);
963*0Sstevel@tonic-gate parent[j] = '\0';
964*0Sstevel@tonic-gate }
965*0Sstevel@tonic-gate if ((name != NULL) && ((k + namelen) <= len)) {
966*0Sstevel@tonic-gate str[k] = '/';
967*0Sstevel@tonic-gate (void) strcpy(&str[k + 1], name);
968*0Sstevel@tonic-gate }
969*0Sstevel@tonic-gate if (debug > 3)
970*0Sstevel@tonic-gate (void) printf("fh_print_absolute: path '%s'\n", str);
971*0Sstevel@tonic-gate return (str);
972*0Sstevel@tonic-gate }
973*0Sstevel@tonic-gate
974*0Sstevel@tonic-gate /*
975*0Sstevel@tonic-gate * nfslog_find_fh_dispatch - get the dispatch struct for this request
976*0Sstevel@tonic-gate */
977*0Sstevel@tonic-gate static struct nfsl_fh_proc_disp *
nfslog_find_fh_dispatch(nfslog_request_record * logrec)978*0Sstevel@tonic-gate nfslog_find_fh_dispatch(nfslog_request_record *logrec)
979*0Sstevel@tonic-gate {
980*0Sstevel@tonic-gate nfslog_record_header *logrechdr = &logrec->re_header;
981*0Sstevel@tonic-gate struct nfsl_fh_prog_disp *progtable; /* prog struct */
982*0Sstevel@tonic-gate struct nfsl_fh_vers_disp *verstable; /* version struct */
983*0Sstevel@tonic-gate int i, vers;
984*0Sstevel@tonic-gate
985*0Sstevel@tonic-gate /* Find prog element - search because can't use prog as array index */
986*0Sstevel@tonic-gate for (i = 0; (i < nfsl_fh_dispatch_table_arglen) &&
987*0Sstevel@tonic-gate (logrechdr->rh_prognum != nfsl_fh_dispatch_table[i].nfsl_dis_prog);
988*0Sstevel@tonic-gate i++);
989*0Sstevel@tonic-gate if (i >= nfsl_fh_dispatch_table_arglen) { /* program not logged */
990*0Sstevel@tonic-gate /* not an error */
991*0Sstevel@tonic-gate return (NULL);
992*0Sstevel@tonic-gate }
993*0Sstevel@tonic-gate progtable = &nfsl_fh_dispatch_table[i];
994*0Sstevel@tonic-gate /* Find vers element - no validity check - if here it's valid vers */
995*0Sstevel@tonic-gate vers = logrechdr->rh_version - progtable->nfsl_dis_versmin;
996*0Sstevel@tonic-gate verstable = &progtable->nfsl_dis_vers_table[vers];
997*0Sstevel@tonic-gate /* Find proc element - no validity check - if here it's valid proc */
998*0Sstevel@tonic-gate return (&verstable->nfsl_dis_proc_table[logrechdr->rh_procnum]);
999*0Sstevel@tonic-gate }
1000*0Sstevel@tonic-gate
1001*0Sstevel@tonic-gate /* ARGSUSED */
1002*0Sstevel@tonic-gate static void
nfslog_null_fhargs(caddr_t * nfsl_args,caddr_t * nfsl_res,char * fhpath,char ** pathp1,char ** pathp2)1003*0Sstevel@tonic-gate nfslog_null_fhargs(caddr_t *nfsl_args, caddr_t *nfsl_res,
1004*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1005*0Sstevel@tonic-gate {
1006*0Sstevel@tonic-gate *pathp1 = NULL;
1007*0Sstevel@tonic-gate *pathp2 = NULL;
1008*0Sstevel@tonic-gate }
1009*0Sstevel@tonic-gate
1010*0Sstevel@tonic-gate /*
1011*0Sstevel@tonic-gate * nfslog_LOOKUP_calc - called by both lookup3 and lookup2. Handles the
1012*0Sstevel@tonic-gate * mclookup as well as normal lookups.
1013*0Sstevel@tonic-gate */
1014*0Sstevel@tonic-gate /* ARGSUSED */
1015*0Sstevel@tonic-gate static void
nfslog_LOOKUP_calc(fhandle_t * dfh,char * name,fhandle_t * fh,char * fhpath,char ** pathp1,char ** pathp2,char * str)1016*0Sstevel@tonic-gate nfslog_LOOKUP_calc(fhandle_t *dfh, char *name, fhandle_t *fh,
1017*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2, char *str)
1018*0Sstevel@tonic-gate {
1019*0Sstevel@tonic-gate int error;
1020*0Sstevel@tonic-gate fhlist_ent fhrec;
1021*0Sstevel@tonic-gate char *name1 = NULL;
1022*0Sstevel@tonic-gate
1023*0Sstevel@tonic-gate if (fh == &public_fh) {
1024*0Sstevel@tonic-gate /* a fake lookup to inform us of the public fs path */
1025*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, fh, fh, name)) {
1026*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1027*0Sstevel@tonic-gate "%s: Add Public fs '%s' failed: %s\n"),
1028*0Sstevel@tonic-gate str, name,
1029*0Sstevel@tonic-gate ((error >= 0) ? strerror(error) : "Unknown"));
1030*0Sstevel@tonic-gate }
1031*0Sstevel@tonic-gate if (pathp1 != NULL) {
1032*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, NULL, fhpath, str);
1033*0Sstevel@tonic-gate *pathp2 = NULL;
1034*0Sstevel@tonic-gate }
1035*0Sstevel@tonic-gate return;
1036*0Sstevel@tonic-gate }
1037*0Sstevel@tonic-gate if (pathp1 != NULL) {
1038*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, str);
1039*0Sstevel@tonic-gate *pathp2 = NULL;
1040*0Sstevel@tonic-gate }
1041*0Sstevel@tonic-gate
1042*0Sstevel@tonic-gate /* If public fh mclookup, then insert complete path */
1043*0Sstevel@tonic-gate if (dfh == &public_fh) {
1044*0Sstevel@tonic-gate if (pathp1 != NULL) {
1045*0Sstevel@tonic-gate name = *pathp1;
1046*0Sstevel@tonic-gate } else {
1047*0Sstevel@tonic-gate name = nfslog_get_path(dfh, name, fhpath, str);
1048*0Sstevel@tonic-gate name1 = name;
1049*0Sstevel@tonic-gate }
1050*0Sstevel@tonic-gate }
1051*0Sstevel@tonic-gate if (fh_lookup_link(fhpath, dfh, fh, name, &fhrec, &error) != NULL) {
1052*0Sstevel@tonic-gate /* link already in table */
1053*0Sstevel@tonic-gate if (name1 != NULL)
1054*0Sstevel@tonic-gate free(name1);
1055*0Sstevel@tonic-gate return;
1056*0Sstevel@tonic-gate }
1057*0Sstevel@tonic-gate /* A new link so add it */
1058*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1059*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1060*0Sstevel@tonic-gate "%s: Add fh for '%s' failed: %s\n"), str,
1061*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1062*0Sstevel@tonic-gate }
1063*0Sstevel@tonic-gate if (name1 != NULL)
1064*0Sstevel@tonic-gate free(name1);
1065*0Sstevel@tonic-gate }
1066*0Sstevel@tonic-gate
1067*0Sstevel@tonic-gate /*
1068*0Sstevel@tonic-gate * NFS VERSION 2
1069*0Sstevel@tonic-gate */
1070*0Sstevel@tonic-gate
1071*0Sstevel@tonic-gate /* Functions for updating the fhtable for fhtoppath */
1072*0Sstevel@tonic-gate
1073*0Sstevel@tonic-gate /*
1074*0Sstevel@tonic-gate * nfslog_GETATTR2_fhargs - updates path1 but no fhtable changes
1075*0Sstevel@tonic-gate */
1076*0Sstevel@tonic-gate /* ARGSUSED */
1077*0Sstevel@tonic-gate static void
nfslog_GETATTR2_fhargs(fhandle_t * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1078*0Sstevel@tonic-gate nfslog_GETATTR2_fhargs(fhandle_t *args, nfsstat *res,
1079*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1080*0Sstevel@tonic-gate {
1081*0Sstevel@tonic-gate if (debug > 2) {
1082*0Sstevel@tonic-gate (void) printf("=============\nGETATTR2: fh ");
1083*0Sstevel@tonic-gate debug_opaque_print(stdout, args, sizeof (*args));
1084*0Sstevel@tonic-gate (void) printf("\n");
1085*0Sstevel@tonic-gate }
1086*0Sstevel@tonic-gate if (pathp1 != NULL) {
1087*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1088*0Sstevel@tonic-gate NULL, fhpath, "getattr2");
1089*0Sstevel@tonic-gate *pathp2 = NULL;
1090*0Sstevel@tonic-gate }
1091*0Sstevel@tonic-gate }
1092*0Sstevel@tonic-gate
1093*0Sstevel@tonic-gate /*
1094*0Sstevel@tonic-gate * nfslog_SETATTR2_fhargs - updates path1 but no fhtable changes
1095*0Sstevel@tonic-gate */
1096*0Sstevel@tonic-gate /* ARGSUSED */
1097*0Sstevel@tonic-gate static void
nfslog_SETATTR2_fhargs(nfslog_setattrargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1098*0Sstevel@tonic-gate nfslog_SETATTR2_fhargs(nfslog_setattrargs *args, nfsstat *res,
1099*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1100*0Sstevel@tonic-gate {
1101*0Sstevel@tonic-gate if (debug > 2) {
1102*0Sstevel@tonic-gate (void) printf("=============\nSETATTR2: fh ");
1103*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->saa_fh,
1104*0Sstevel@tonic-gate sizeof (args->saa_fh));
1105*0Sstevel@tonic-gate (void) printf("\n");
1106*0Sstevel@tonic-gate }
1107*0Sstevel@tonic-gate if (pathp1 != NULL) {
1108*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(&args->saa_fh),
1109*0Sstevel@tonic-gate NULL, fhpath, "setattr2");
1110*0Sstevel@tonic-gate *pathp2 = NULL;
1111*0Sstevel@tonic-gate }
1112*0Sstevel@tonic-gate }
1113*0Sstevel@tonic-gate
1114*0Sstevel@tonic-gate /*
1115*0Sstevel@tonic-gate * nfslog_LOOKUP2_fhargs - search the table to ensure we have not added this
1116*0Sstevel@tonic-gate * one already. Note that if the response status was anything but okay,
1117*0Sstevel@tonic-gate * there is no fh to check...
1118*0Sstevel@tonic-gate */
1119*0Sstevel@tonic-gate /* ARGSUSED */
1120*0Sstevel@tonic-gate static void
nfslog_LOOKUP2_fhargs(nfslog_diropargs * args,nfslog_diropres * res,char * fhpath,char ** pathp1,char ** pathp2)1121*0Sstevel@tonic-gate nfslog_LOOKUP2_fhargs(nfslog_diropargs *args, nfslog_diropres *res,
1122*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1123*0Sstevel@tonic-gate {
1124*0Sstevel@tonic-gate char *name;
1125*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1126*0Sstevel@tonic-gate
1127*0Sstevel@tonic-gate dfh = &args->da_fhandle;
1128*0Sstevel@tonic-gate name = args->da_name;
1129*0Sstevel@tonic-gate if (debug > 2) {
1130*0Sstevel@tonic-gate if (res->dr_status == NFS_OK)
1131*0Sstevel@tonic-gate fh = &res->nfslog_diropres_u.dr_ok.drok_fhandle;
1132*0Sstevel@tonic-gate else
1133*0Sstevel@tonic-gate fh = NULL;
1134*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nLOOKUP2",
1135*0Sstevel@tonic-gate dfh, fh, name, "")
1136*0Sstevel@tonic-gate if (res->dr_status != NFS_OK)
1137*0Sstevel@tonic-gate (void) printf("status %d\n", res->dr_status);
1138*0Sstevel@tonic-gate }
1139*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE2(dfh);
1140*0Sstevel@tonic-gate if ((dfh == &public_fh) && (name[0] == '\x80')) {
1141*0Sstevel@tonic-gate /* special mclookup */
1142*0Sstevel@tonic-gate name = &name[1];
1143*0Sstevel@tonic-gate }
1144*0Sstevel@tonic-gate if (res->dr_status != NFS_OK) {
1145*0Sstevel@tonic-gate if (pathp1 != NULL) {
1146*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "lookup2");
1147*0Sstevel@tonic-gate *pathp2 = NULL;
1148*0Sstevel@tonic-gate }
1149*0Sstevel@tonic-gate return;
1150*0Sstevel@tonic-gate }
1151*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE2(&res->nfslog_diropres_u.dr_ok.drok_fhandle);
1152*0Sstevel@tonic-gate nfslog_LOOKUP_calc(dfh, name, fh, fhpath, pathp1, pathp2, "Lookup2");
1153*0Sstevel@tonic-gate }
1154*0Sstevel@tonic-gate
1155*0Sstevel@tonic-gate /*
1156*0Sstevel@tonic-gate * nfslog_READLINK2_fhargs - updates path1 but no fhtable changes
1157*0Sstevel@tonic-gate */
1158*0Sstevel@tonic-gate /* ARGSUSED */
1159*0Sstevel@tonic-gate static void
nfslog_READLINK2_fhargs(fhandle_t * args,nfslog_rdlnres * res,char * fhpath,char ** pathp1,char ** pathp2)1160*0Sstevel@tonic-gate nfslog_READLINK2_fhargs(fhandle_t *args, nfslog_rdlnres *res,
1161*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1162*0Sstevel@tonic-gate {
1163*0Sstevel@tonic-gate if (debug > 2) {
1164*0Sstevel@tonic-gate (void) printf("=============\nREADLINK2: fh ");
1165*0Sstevel@tonic-gate debug_opaque_print(stdout, args, sizeof (*args));
1166*0Sstevel@tonic-gate (void) printf("\n");
1167*0Sstevel@tonic-gate }
1168*0Sstevel@tonic-gate if (pathp1 != NULL) {
1169*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1170*0Sstevel@tonic-gate NULL, fhpath, "readlink2");
1171*0Sstevel@tonic-gate *pathp2 = NULL;
1172*0Sstevel@tonic-gate }
1173*0Sstevel@tonic-gate }
1174*0Sstevel@tonic-gate
1175*0Sstevel@tonic-gate /*
1176*0Sstevel@tonic-gate * nfslog_READ2_fhargs - updates path1 but no fhtable changes
1177*0Sstevel@tonic-gate */
1178*0Sstevel@tonic-gate /* ARGSUSED */
1179*0Sstevel@tonic-gate static void
nfslog_READ2_fhargs(nfslog_nfsreadargs * args,nfslog_rdresult * res,char * fhpath,char ** pathp1,char ** pathp2)1180*0Sstevel@tonic-gate nfslog_READ2_fhargs(nfslog_nfsreadargs *args, nfslog_rdresult *res,
1181*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1182*0Sstevel@tonic-gate {
1183*0Sstevel@tonic-gate if (debug > 2) {
1184*0Sstevel@tonic-gate (void) printf("=============\nREAD2: fh ");
1185*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->ra_fhandle,
1186*0Sstevel@tonic-gate sizeof (args->ra_fhandle));
1187*0Sstevel@tonic-gate (void) printf("\n");
1188*0Sstevel@tonic-gate }
1189*0Sstevel@tonic-gate if (pathp1 != NULL) {
1190*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(
1191*0Sstevel@tonic-gate NFSLOG_GET_FHANDLE2(&args->ra_fhandle),
1192*0Sstevel@tonic-gate NULL, fhpath, "read2");
1193*0Sstevel@tonic-gate *pathp2 = NULL;
1194*0Sstevel@tonic-gate }
1195*0Sstevel@tonic-gate }
1196*0Sstevel@tonic-gate
1197*0Sstevel@tonic-gate /*
1198*0Sstevel@tonic-gate * nfslog_WRITE2_fhargs - updates path1 but no fhtable changes
1199*0Sstevel@tonic-gate */
1200*0Sstevel@tonic-gate /* ARGSUSED */
1201*0Sstevel@tonic-gate static void
nfslog_WRITE2_fhargs(nfslog_writeargs * args,nfslog_writeresult * res,char * fhpath,char ** pathp1,char ** pathp2)1202*0Sstevel@tonic-gate nfslog_WRITE2_fhargs(nfslog_writeargs *args, nfslog_writeresult *res,
1203*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1204*0Sstevel@tonic-gate {
1205*0Sstevel@tonic-gate if (debug > 2) {
1206*0Sstevel@tonic-gate (void) printf("=============\nWRITE2: fh ");
1207*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->waargs_fhandle,
1208*0Sstevel@tonic-gate sizeof (args->waargs_fhandle));
1209*0Sstevel@tonic-gate (void) printf("\n");
1210*0Sstevel@tonic-gate }
1211*0Sstevel@tonic-gate if (pathp1 != NULL) {
1212*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(
1213*0Sstevel@tonic-gate NFSLOG_GET_FHANDLE2(&args->waargs_fhandle),
1214*0Sstevel@tonic-gate NULL, fhpath, "write2");
1215*0Sstevel@tonic-gate *pathp2 = NULL;
1216*0Sstevel@tonic-gate }
1217*0Sstevel@tonic-gate }
1218*0Sstevel@tonic-gate
1219*0Sstevel@tonic-gate /*
1220*0Sstevel@tonic-gate * nfslog_CREATE2_fhargs - if the operation succeeded, we are sure there can
1221*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1222*0Sstevel@tonic-gate */
1223*0Sstevel@tonic-gate /* ARGSUSED */
1224*0Sstevel@tonic-gate static void
nfslog_CREATE2_fhargs(nfslog_createargs * args,nfslog_diropres * res,char * fhpath,char ** pathp1,char ** pathp2)1225*0Sstevel@tonic-gate nfslog_CREATE2_fhargs(nfslog_createargs *args, nfslog_diropres *res,
1226*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1227*0Sstevel@tonic-gate {
1228*0Sstevel@tonic-gate char *name;
1229*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1230*0Sstevel@tonic-gate int error;
1231*0Sstevel@tonic-gate
1232*0Sstevel@tonic-gate name = args->ca_da.da_name;
1233*0Sstevel@tonic-gate dfh = &args->ca_da.da_fhandle;
1234*0Sstevel@tonic-gate if (debug > 2) {
1235*0Sstevel@tonic-gate if (res->dr_status == NFS_OK)
1236*0Sstevel@tonic-gate fh = &res->nfslog_diropres_u.dr_ok.drok_fhandle;
1237*0Sstevel@tonic-gate else
1238*0Sstevel@tonic-gate fh = NULL;
1239*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nCREATE2",
1240*0Sstevel@tonic-gate dfh, fh, name, "")
1241*0Sstevel@tonic-gate if (res->dr_status != NFS_OK)
1242*0Sstevel@tonic-gate (void) printf("status %d\n", res->dr_status);
1243*0Sstevel@tonic-gate }
1244*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE2(dfh);
1245*0Sstevel@tonic-gate if (pathp1 != NULL) {
1246*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "create2");
1247*0Sstevel@tonic-gate *pathp2 = NULL;
1248*0Sstevel@tonic-gate }
1249*0Sstevel@tonic-gate
1250*0Sstevel@tonic-gate if (res->dr_status != NFS_OK)
1251*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1252*0Sstevel@tonic-gate return;
1253*0Sstevel@tonic-gate
1254*0Sstevel@tonic-gate /* A new file handle so add it */
1255*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE2(&res->nfslog_diropres_u.dr_ok.drok_fhandle);
1256*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1257*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1258*0Sstevel@tonic-gate "Create2: Add fh for '%s' failed: %s\n"),
1259*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1260*0Sstevel@tonic-gate }
1261*0Sstevel@tonic-gate }
1262*0Sstevel@tonic-gate
1263*0Sstevel@tonic-gate /*
1264*0Sstevel@tonic-gate * nfslog_REMOVE2_fhargs - if the operation succeeded, remove the link from
1265*0Sstevel@tonic-gate * the fhtable.
1266*0Sstevel@tonic-gate */
1267*0Sstevel@tonic-gate /* ARGSUSED */
1268*0Sstevel@tonic-gate static void
nfslog_REMOVE2_fhargs(nfslog_diropargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1269*0Sstevel@tonic-gate nfslog_REMOVE2_fhargs(nfslog_diropargs *args, nfsstat *res,
1270*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1271*0Sstevel@tonic-gate {
1272*0Sstevel@tonic-gate char *name;
1273*0Sstevel@tonic-gate fhandle_t *dfh;
1274*0Sstevel@tonic-gate int error;
1275*0Sstevel@tonic-gate
1276*0Sstevel@tonic-gate name = args->da_name;
1277*0Sstevel@tonic-gate dfh = &args->da_fhandle;
1278*0Sstevel@tonic-gate if (debug > 2) {
1279*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nREMOVE2", dfh, name, "")
1280*0Sstevel@tonic-gate if (*res != NFS_OK)
1281*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1282*0Sstevel@tonic-gate }
1283*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE2(dfh);
1284*0Sstevel@tonic-gate if (pathp1 != NULL) {
1285*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "remove2");
1286*0Sstevel@tonic-gate *pathp2 = NULL;
1287*0Sstevel@tonic-gate }
1288*0Sstevel@tonic-gate
1289*0Sstevel@tonic-gate if (*res != NFS_OK)
1290*0Sstevel@tonic-gate /* remove failed so nothing to update */
1291*0Sstevel@tonic-gate return;
1292*0Sstevel@tonic-gate
1293*0Sstevel@tonic-gate if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1294*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("Remove2: '%s' failed: %s\n"),
1295*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1296*0Sstevel@tonic-gate }
1297*0Sstevel@tonic-gate }
1298*0Sstevel@tonic-gate
1299*0Sstevel@tonic-gate /*
1300*0Sstevel@tonic-gate * nfsl_RENAME2_fhargs - updates the dfh and name fields for the given fh
1301*0Sstevel@tonic-gate * to change them to the new name.
1302*0Sstevel@tonic-gate */
1303*0Sstevel@tonic-gate /* ARGSUSED */
1304*0Sstevel@tonic-gate static void
nfslog_RENAME2_fhargs(nfslog_rnmargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1305*0Sstevel@tonic-gate nfslog_RENAME2_fhargs(nfslog_rnmargs *args, nfsstat *res,
1306*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1307*0Sstevel@tonic-gate {
1308*0Sstevel@tonic-gate char *from_name, *to_name;
1309*0Sstevel@tonic-gate fhandle_t *from_dfh, *to_dfh;
1310*0Sstevel@tonic-gate int error;
1311*0Sstevel@tonic-gate
1312*0Sstevel@tonic-gate from_name = args->rna_from.da_name;
1313*0Sstevel@tonic-gate from_dfh = &args->rna_from.da_fhandle;
1314*0Sstevel@tonic-gate to_name = args->rna_to.da_name;
1315*0Sstevel@tonic-gate to_dfh = &args->rna_to.da_fhandle;
1316*0Sstevel@tonic-gate if (debug > 2) {
1317*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nRENAME2: from",
1318*0Sstevel@tonic-gate from_dfh, from_name, "")
1319*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "RENAME2: to ", to_dfh,
1320*0Sstevel@tonic-gate to_name, "")
1321*0Sstevel@tonic-gate if (*res != NFS_OK)
1322*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1323*0Sstevel@tonic-gate }
1324*0Sstevel@tonic-gate from_dfh = NFSLOG_GET_FHANDLE2(from_dfh);
1325*0Sstevel@tonic-gate to_dfh = NFSLOG_GET_FHANDLE2(to_dfh);
1326*0Sstevel@tonic-gate if (pathp1 != NULL) {
1327*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(from_dfh, from_name, fhpath,
1328*0Sstevel@tonic-gate "rename2 from");
1329*0Sstevel@tonic-gate *pathp2 = nfslog_get_path(to_dfh, to_name, fhpath,
1330*0Sstevel@tonic-gate "rename2 to");
1331*0Sstevel@tonic-gate }
1332*0Sstevel@tonic-gate
1333*0Sstevel@tonic-gate if (*res != NFS_OK)
1334*0Sstevel@tonic-gate /* rename failed so nothing to update */
1335*0Sstevel@tonic-gate return;
1336*0Sstevel@tonic-gate
1337*0Sstevel@tonic-gate /* Rename the link in the database */
1338*0Sstevel@tonic-gate if (error = fh_rename(fhpath, from_dfh, from_name, pathp1,
1339*0Sstevel@tonic-gate to_dfh, to_name)) {
1340*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1341*0Sstevel@tonic-gate "Rename2: Update from '%s' to '%s' failed: %s\n"),
1342*0Sstevel@tonic-gate from_name, to_name,
1343*0Sstevel@tonic-gate ((error >= 0) ? strerror(error) : "Unknown"));
1344*0Sstevel@tonic-gate }
1345*0Sstevel@tonic-gate }
1346*0Sstevel@tonic-gate
1347*0Sstevel@tonic-gate /*
1348*0Sstevel@tonic-gate * nfslog_LINK2_fhargs - adds link name and fh to fhlist. Note that as a
1349*0Sstevel@tonic-gate * result we may have more than one name for an fh.
1350*0Sstevel@tonic-gate */
1351*0Sstevel@tonic-gate /* ARGSUSED */
1352*0Sstevel@tonic-gate static void
nfslog_LINK2_fhargs(nfslog_linkargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1353*0Sstevel@tonic-gate nfslog_LINK2_fhargs(nfslog_linkargs *args, nfsstat *res,
1354*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1355*0Sstevel@tonic-gate {
1356*0Sstevel@tonic-gate char *name;
1357*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1358*0Sstevel@tonic-gate int error;
1359*0Sstevel@tonic-gate
1360*0Sstevel@tonic-gate fh = &args->la_from;
1361*0Sstevel@tonic-gate name = args->la_to.da_name;
1362*0Sstevel@tonic-gate dfh = &args->la_to.da_fhandle;
1363*0Sstevel@tonic-gate if (debug > 2) {
1364*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nLINK2",
1365*0Sstevel@tonic-gate dfh, fh, name, "")
1366*0Sstevel@tonic-gate if (*res != NFS_OK)
1367*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1368*0Sstevel@tonic-gate }
1369*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE2(dfh);
1370*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE2(fh);
1371*0Sstevel@tonic-gate if (pathp1 != NULL) {
1372*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(fh, NULL, fhpath, "link2 from");
1373*0Sstevel@tonic-gate *pathp2 = nfslog_get_path(dfh, name, fhpath, "link2 to");
1374*0Sstevel@tonic-gate }
1375*0Sstevel@tonic-gate
1376*0Sstevel@tonic-gate if (*res != NFS_OK)
1377*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1378*0Sstevel@tonic-gate return;
1379*0Sstevel@tonic-gate
1380*0Sstevel@tonic-gate /* A new link so add it, have fh_add find the link count */
1381*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1382*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1383*0Sstevel@tonic-gate "Link2: Add fh for '%s' failed: %s\n"),
1384*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1385*0Sstevel@tonic-gate }
1386*0Sstevel@tonic-gate }
1387*0Sstevel@tonic-gate
1388*0Sstevel@tonic-gate /*
1389*0Sstevel@tonic-gate * nfslog_SYMLINK2_fhargs - adds symlink name and fh to fhlist if fh returned.
1390*0Sstevel@tonic-gate */
1391*0Sstevel@tonic-gate /* ARGSUSED */
1392*0Sstevel@tonic-gate static void
nfslog_SYMLINK2_fhargs(nfslog_symlinkargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1393*0Sstevel@tonic-gate nfslog_SYMLINK2_fhargs(nfslog_symlinkargs *args, nfsstat *res,
1394*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1395*0Sstevel@tonic-gate {
1396*0Sstevel@tonic-gate char *name;
1397*0Sstevel@tonic-gate fhandle_t *dfh;
1398*0Sstevel@tonic-gate
1399*0Sstevel@tonic-gate name = args->sla_from.da_name;
1400*0Sstevel@tonic-gate dfh = &args->sla_from.da_fhandle;
1401*0Sstevel@tonic-gate if (debug > 2) {
1402*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nSYMLINK2",
1403*0Sstevel@tonic-gate dfh, name, "")
1404*0Sstevel@tonic-gate }
1405*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE2(dfh);
1406*0Sstevel@tonic-gate if (pathp1 != NULL) {
1407*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "symlink2");
1408*0Sstevel@tonic-gate *pathp2 = NULL;
1409*0Sstevel@tonic-gate }
1410*0Sstevel@tonic-gate }
1411*0Sstevel@tonic-gate
1412*0Sstevel@tonic-gate /*
1413*0Sstevel@tonic-gate * nfslog_READDIR2_fhargs - updates path1 but no fhtable changes
1414*0Sstevel@tonic-gate */
1415*0Sstevel@tonic-gate /* ARGSUSED */
1416*0Sstevel@tonic-gate static void
nfslog_READDIR2_fhargs(nfslog_rddirargs * args,nfslog_rddirres * res,char * fhpath,char ** pathp1,char ** pathp2)1417*0Sstevel@tonic-gate nfslog_READDIR2_fhargs(nfslog_rddirargs *args, nfslog_rddirres *res,
1418*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1419*0Sstevel@tonic-gate {
1420*0Sstevel@tonic-gate if (debug > 2) {
1421*0Sstevel@tonic-gate (void) printf("=============\nREADDIR2: fh ");
1422*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->rda_fh,
1423*0Sstevel@tonic-gate sizeof (args->rda_fh));
1424*0Sstevel@tonic-gate (void) printf("\n");
1425*0Sstevel@tonic-gate }
1426*0Sstevel@tonic-gate if (pathp1 != NULL) {
1427*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(&args->rda_fh),
1428*0Sstevel@tonic-gate NULL, fhpath, "readdir2");
1429*0Sstevel@tonic-gate *pathp2 = NULL;
1430*0Sstevel@tonic-gate }
1431*0Sstevel@tonic-gate }
1432*0Sstevel@tonic-gate
1433*0Sstevel@tonic-gate /*
1434*0Sstevel@tonic-gate * nfslog_STATFS2_fhargs - updates path1 but no fhtable changes
1435*0Sstevel@tonic-gate */
1436*0Sstevel@tonic-gate /* ARGSUSED */
1437*0Sstevel@tonic-gate static void
nfslog_STATFS2_fhargs(fhandle_t * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1438*0Sstevel@tonic-gate nfslog_STATFS2_fhargs(fhandle_t *args, nfsstat *res,
1439*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1440*0Sstevel@tonic-gate {
1441*0Sstevel@tonic-gate if (debug > 2) {
1442*0Sstevel@tonic-gate (void) printf("=============\nSTATFS2: fh ");
1443*0Sstevel@tonic-gate debug_opaque_print(stdout, args, sizeof (*args));
1444*0Sstevel@tonic-gate (void) printf("\n");
1445*0Sstevel@tonic-gate }
1446*0Sstevel@tonic-gate if (pathp1 != NULL) {
1447*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1448*0Sstevel@tonic-gate NULL, fhpath, "statfs2");
1449*0Sstevel@tonic-gate *pathp2 = NULL;
1450*0Sstevel@tonic-gate }
1451*0Sstevel@tonic-gate }
1452*0Sstevel@tonic-gate
1453*0Sstevel@tonic-gate /*
1454*0Sstevel@tonic-gate * NFS VERSION 3
1455*0Sstevel@tonic-gate */
1456*0Sstevel@tonic-gate
1457*0Sstevel@tonic-gate /* Functions for updating the fhtable for fhtoppath */
1458*0Sstevel@tonic-gate
1459*0Sstevel@tonic-gate /*
1460*0Sstevel@tonic-gate * nfslog_GETATTR3_fhargs - updates path1 but no fhtable changes
1461*0Sstevel@tonic-gate */
1462*0Sstevel@tonic-gate /* ARGSUSED */
1463*0Sstevel@tonic-gate static void
nfslog_GETATTR3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1464*0Sstevel@tonic-gate nfslog_GETATTR3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1465*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1466*0Sstevel@tonic-gate {
1467*0Sstevel@tonic-gate if (debug > 2) {
1468*0Sstevel@tonic-gate (void) printf("=============\nGETATTR3: fh ");
1469*0Sstevel@tonic-gate debug_opaque_print(stdout, args, sizeof (*args));
1470*0Sstevel@tonic-gate (void) printf("\n");
1471*0Sstevel@tonic-gate }
1472*0Sstevel@tonic-gate if (pathp1 != NULL) {
1473*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
1474*0Sstevel@tonic-gate fhpath, "getattr3");
1475*0Sstevel@tonic-gate *pathp2 = NULL;
1476*0Sstevel@tonic-gate }
1477*0Sstevel@tonic-gate }
1478*0Sstevel@tonic-gate
1479*0Sstevel@tonic-gate /*
1480*0Sstevel@tonic-gate * nfslog_SETATTR3_fhargs - updates path1 but no fhtable changes
1481*0Sstevel@tonic-gate */
1482*0Sstevel@tonic-gate /* ARGSUSED */
1483*0Sstevel@tonic-gate static void
nfslog_SETATTR3_fhargs(nfslog_SETATTR3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1484*0Sstevel@tonic-gate nfslog_SETATTR3_fhargs(nfslog_SETATTR3args *args, nfsstat3 *res,
1485*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1486*0Sstevel@tonic-gate {
1487*0Sstevel@tonic-gate if (debug > 2) {
1488*0Sstevel@tonic-gate (void) printf("=============\nSETATTR3: fh ");
1489*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->object,
1490*0Sstevel@tonic-gate sizeof (args->object));
1491*0Sstevel@tonic-gate (void) printf("\n");
1492*0Sstevel@tonic-gate }
1493*0Sstevel@tonic-gate if (pathp1 != NULL) {
1494*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object),
1495*0Sstevel@tonic-gate NULL, fhpath, "setattr3");
1496*0Sstevel@tonic-gate *pathp2 = NULL;
1497*0Sstevel@tonic-gate }
1498*0Sstevel@tonic-gate }
1499*0Sstevel@tonic-gate
1500*0Sstevel@tonic-gate /*
1501*0Sstevel@tonic-gate * nfslog_LOOKUP3_fhargs - search the table to ensure we have not added this
1502*0Sstevel@tonic-gate * one already. Note that if the response status was anything but okay,
1503*0Sstevel@tonic-gate * there is no fh to check...
1504*0Sstevel@tonic-gate */
1505*0Sstevel@tonic-gate /* ARGSUSED */
1506*0Sstevel@tonic-gate static void
nfslog_LOOKUP3_fhargs(nfslog_diropargs3 * args,nfslog_LOOKUP3res * res,char * fhpath,char ** pathp1,char ** pathp2)1507*0Sstevel@tonic-gate nfslog_LOOKUP3_fhargs(nfslog_diropargs3 *args, nfslog_LOOKUP3res *res,
1508*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1509*0Sstevel@tonic-gate {
1510*0Sstevel@tonic-gate char *name;
1511*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1512*0Sstevel@tonic-gate
1513*0Sstevel@tonic-gate name = args->name;
1514*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->dir);
1515*0Sstevel@tonic-gate
1516*0Sstevel@tonic-gate if (debug > 2) {
1517*0Sstevel@tonic-gate if (res->status == NFS3_OK)
1518*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(
1519*0Sstevel@tonic-gate &res->nfslog_LOOKUP3res_u.object);
1520*0Sstevel@tonic-gate else
1521*0Sstevel@tonic-gate fh = NULL;
1522*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nLOOKUP3",
1523*0Sstevel@tonic-gate dfh, fh, name, "")
1524*0Sstevel@tonic-gate if (res->status != NFS3_OK)
1525*0Sstevel@tonic-gate (void) printf("status %d\n", res->status);
1526*0Sstevel@tonic-gate }
1527*0Sstevel@tonic-gate if ((dfh == &public_fh) && (name[0] == '\x80')) {
1528*0Sstevel@tonic-gate /* special mclookup */
1529*0Sstevel@tonic-gate name = &name[1];
1530*0Sstevel@tonic-gate }
1531*0Sstevel@tonic-gate if (res->status != NFS3_OK) {
1532*0Sstevel@tonic-gate if (pathp1 != NULL) {
1533*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "lookup3");
1534*0Sstevel@tonic-gate *pathp2 = NULL;
1535*0Sstevel@tonic-gate }
1536*0Sstevel@tonic-gate return;
1537*0Sstevel@tonic-gate }
1538*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&res->nfslog_LOOKUP3res_u.object);
1539*0Sstevel@tonic-gate nfslog_LOOKUP_calc(dfh, name, fh, fhpath, pathp1, pathp2, "Lookup3");
1540*0Sstevel@tonic-gate }
1541*0Sstevel@tonic-gate
1542*0Sstevel@tonic-gate /*
1543*0Sstevel@tonic-gate * nfslog_ACCESS3_fhargs - updates path1 but no fhtable changes
1544*0Sstevel@tonic-gate */
1545*0Sstevel@tonic-gate /* ARGSUSED */
1546*0Sstevel@tonic-gate static void
nfslog_ACCESS3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1547*0Sstevel@tonic-gate nfslog_ACCESS3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1548*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1549*0Sstevel@tonic-gate {
1550*0Sstevel@tonic-gate if (debug > 2) {
1551*0Sstevel@tonic-gate (void) printf("=============\nACCESS3: fh ");
1552*0Sstevel@tonic-gate debug_opaque_print(stdout, args,
1553*0Sstevel@tonic-gate sizeof (*args));
1554*0Sstevel@tonic-gate (void) printf("\n");
1555*0Sstevel@tonic-gate }
1556*0Sstevel@tonic-gate if (pathp1 != NULL) {
1557*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args),
1558*0Sstevel@tonic-gate NULL, fhpath, "access3");
1559*0Sstevel@tonic-gate *pathp2 = NULL;
1560*0Sstevel@tonic-gate }
1561*0Sstevel@tonic-gate }
1562*0Sstevel@tonic-gate
1563*0Sstevel@tonic-gate /*
1564*0Sstevel@tonic-gate * nfslog_READLINK3_fhargs - updates path1 but no fhtable changes
1565*0Sstevel@tonic-gate */
1566*0Sstevel@tonic-gate /* ARGSUSED */
1567*0Sstevel@tonic-gate static void
nfslog_READLINK3_fhargs(nfs_fh3 * args,nfslog_READLINK3res * res,char * fhpath,char ** pathp1,char ** pathp2)1568*0Sstevel@tonic-gate nfslog_READLINK3_fhargs(nfs_fh3 *args, nfslog_READLINK3res *res,
1569*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1570*0Sstevel@tonic-gate {
1571*0Sstevel@tonic-gate if (debug > 2) {
1572*0Sstevel@tonic-gate (void) printf("=============\nREADLINK3: fh ");
1573*0Sstevel@tonic-gate debug_opaque_print(stdout, args, sizeof (*args));
1574*0Sstevel@tonic-gate (void) printf("\n");
1575*0Sstevel@tonic-gate }
1576*0Sstevel@tonic-gate if (pathp1 != NULL) {
1577*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
1578*0Sstevel@tonic-gate fhpath, "readlink3");
1579*0Sstevel@tonic-gate *pathp2 = NULL;
1580*0Sstevel@tonic-gate }
1581*0Sstevel@tonic-gate }
1582*0Sstevel@tonic-gate
1583*0Sstevel@tonic-gate /*
1584*0Sstevel@tonic-gate * nfslog_READ3_fhargs - updates path1 but no fhtable changes
1585*0Sstevel@tonic-gate */
1586*0Sstevel@tonic-gate /* ARGSUSED */
1587*0Sstevel@tonic-gate static void
nfslog_READ3_fhargs(nfslog_READ3args * args,nfslog_READ3res * res,char * fhpath,char ** pathp1,char ** pathp2)1588*0Sstevel@tonic-gate nfslog_READ3_fhargs(nfslog_READ3args *args, nfslog_READ3res *res,
1589*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1590*0Sstevel@tonic-gate {
1591*0Sstevel@tonic-gate if (debug > 2) {
1592*0Sstevel@tonic-gate (void) printf("=============\nREAD3: fh ");
1593*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->file,
1594*0Sstevel@tonic-gate sizeof (args->file));
1595*0Sstevel@tonic-gate (void) printf("\n");
1596*0Sstevel@tonic-gate }
1597*0Sstevel@tonic-gate if (pathp1 != NULL) {
1598*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1599*0Sstevel@tonic-gate NULL, fhpath, "read3");
1600*0Sstevel@tonic-gate *pathp2 = NULL;
1601*0Sstevel@tonic-gate }
1602*0Sstevel@tonic-gate }
1603*0Sstevel@tonic-gate
1604*0Sstevel@tonic-gate /*
1605*0Sstevel@tonic-gate * nfslog_WRITE3_fhargs - updates path1 but no fhtable changes
1606*0Sstevel@tonic-gate */
1607*0Sstevel@tonic-gate /* ARGSUSED */
1608*0Sstevel@tonic-gate static void
nfslog_WRITE3_fhargs(nfslog_WRITE3args * args,nfslog_WRITE3res * res,char * fhpath,char ** pathp1,char ** pathp2)1609*0Sstevel@tonic-gate nfslog_WRITE3_fhargs(nfslog_WRITE3args *args, nfslog_WRITE3res *res,
1610*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1611*0Sstevel@tonic-gate {
1612*0Sstevel@tonic-gate if (debug > 2) {
1613*0Sstevel@tonic-gate (void) printf("=============\nWRITE3: fh ");
1614*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->file,
1615*0Sstevel@tonic-gate sizeof (args->file));
1616*0Sstevel@tonic-gate (void) printf("\n");
1617*0Sstevel@tonic-gate }
1618*0Sstevel@tonic-gate if (pathp1 != NULL) {
1619*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1620*0Sstevel@tonic-gate NULL, fhpath, "write3");
1621*0Sstevel@tonic-gate *pathp2 = NULL;
1622*0Sstevel@tonic-gate }
1623*0Sstevel@tonic-gate }
1624*0Sstevel@tonic-gate
1625*0Sstevel@tonic-gate /*
1626*0Sstevel@tonic-gate * nfslog_CREATE3_fhargs - if the operation succeeded, we are sure there can
1627*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1628*0Sstevel@tonic-gate */
1629*0Sstevel@tonic-gate /* ARGSUSED */
1630*0Sstevel@tonic-gate static void
nfslog_CREATE3_fhargs(nfslog_CREATE3args * args,nfslog_CREATE3res * res,char * fhpath,char ** pathp1,char ** pathp2)1631*0Sstevel@tonic-gate nfslog_CREATE3_fhargs(nfslog_CREATE3args *args, nfslog_CREATE3res *res,
1632*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1633*0Sstevel@tonic-gate {
1634*0Sstevel@tonic-gate char *name;
1635*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1636*0Sstevel@tonic-gate int error;
1637*0Sstevel@tonic-gate
1638*0Sstevel@tonic-gate name = args->where.name;
1639*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1640*0Sstevel@tonic-gate
1641*0Sstevel@tonic-gate if (debug > 2) {
1642*0Sstevel@tonic-gate if (res->status == NFS3_OK)
1643*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(
1644*0Sstevel@tonic-gate &res->nfslog_CREATE3res_u.ok.obj.handle);
1645*0Sstevel@tonic-gate else
1646*0Sstevel@tonic-gate fh = NULL;
1647*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nCREATE3",
1648*0Sstevel@tonic-gate dfh, fh, name, "")
1649*0Sstevel@tonic-gate if (res->status != NFS3_OK)
1650*0Sstevel@tonic-gate (void) printf("status %d\n", res->status);
1651*0Sstevel@tonic-gate }
1652*0Sstevel@tonic-gate if (pathp1 != NULL) {
1653*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "create3");
1654*0Sstevel@tonic-gate *pathp2 = NULL;
1655*0Sstevel@tonic-gate }
1656*0Sstevel@tonic-gate
1657*0Sstevel@tonic-gate if ((res->status != NFS3_OK) ||
1658*0Sstevel@tonic-gate !res->nfslog_CREATE3res_u.ok.obj.handle_follows)
1659*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1660*0Sstevel@tonic-gate return;
1661*0Sstevel@tonic-gate
1662*0Sstevel@tonic-gate /* A new file handle so add it */
1663*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&res->nfslog_CREATE3res_u.ok.obj.handle);
1664*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1665*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1666*0Sstevel@tonic-gate "Create3: Add fh for '%s' failed: %s\n"),
1667*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1668*0Sstevel@tonic-gate }
1669*0Sstevel@tonic-gate }
1670*0Sstevel@tonic-gate
1671*0Sstevel@tonic-gate /*
1672*0Sstevel@tonic-gate * nfslog_MKDIR3_fhargs - if the operation succeeded, we are sure there can
1673*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1674*0Sstevel@tonic-gate */
1675*0Sstevel@tonic-gate /* ARGSUSED */
1676*0Sstevel@tonic-gate static void
nfslog_MKDIR3_fhargs(nfslog_MKDIR3args * args,nfslog_MKDIR3res * res,char * fhpath,char ** pathp1,char ** pathp2)1677*0Sstevel@tonic-gate nfslog_MKDIR3_fhargs(nfslog_MKDIR3args *args, nfslog_MKDIR3res *res,
1678*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1679*0Sstevel@tonic-gate {
1680*0Sstevel@tonic-gate char *name;
1681*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1682*0Sstevel@tonic-gate int error;
1683*0Sstevel@tonic-gate
1684*0Sstevel@tonic-gate name = args->where.name;
1685*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1686*0Sstevel@tonic-gate
1687*0Sstevel@tonic-gate if (debug > 2) {
1688*0Sstevel@tonic-gate if (res->status == NFS3_OK)
1689*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(
1690*0Sstevel@tonic-gate &res->nfslog_MKDIR3res_u.obj.handle);
1691*0Sstevel@tonic-gate else
1692*0Sstevel@tonic-gate fh = NULL;
1693*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nMKDIR3",
1694*0Sstevel@tonic-gate dfh, fh, name, "")
1695*0Sstevel@tonic-gate if (res->status != NFS3_OK)
1696*0Sstevel@tonic-gate (void) printf("status %d\n", res->status);
1697*0Sstevel@tonic-gate }
1698*0Sstevel@tonic-gate if (pathp1 != NULL) {
1699*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "mkdir3");
1700*0Sstevel@tonic-gate *pathp2 = NULL;
1701*0Sstevel@tonic-gate }
1702*0Sstevel@tonic-gate
1703*0Sstevel@tonic-gate if ((res->status != NFS3_OK) ||
1704*0Sstevel@tonic-gate !res->nfslog_MKDIR3res_u.obj.handle_follows)
1705*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1706*0Sstevel@tonic-gate return;
1707*0Sstevel@tonic-gate
1708*0Sstevel@tonic-gate /* A new file handle so add it */
1709*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&res->nfslog_MKDIR3res_u.obj.handle);
1710*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1711*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1712*0Sstevel@tonic-gate "Mkdir3: Add fh for '%s' failed: %s\n"),
1713*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1714*0Sstevel@tonic-gate }
1715*0Sstevel@tonic-gate }
1716*0Sstevel@tonic-gate
1717*0Sstevel@tonic-gate /*
1718*0Sstevel@tonic-gate * nfslog_REMOVE3_fhargs - if the operation succeeded, remove the link from
1719*0Sstevel@tonic-gate * the fhtable.
1720*0Sstevel@tonic-gate */
1721*0Sstevel@tonic-gate /* ARGSUSED */
1722*0Sstevel@tonic-gate static void
nfslog_REMOVE3_fhargs(nfslog_REMOVE3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1723*0Sstevel@tonic-gate nfslog_REMOVE3_fhargs(nfslog_REMOVE3args *args, nfsstat3 *res,
1724*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1725*0Sstevel@tonic-gate {
1726*0Sstevel@tonic-gate char *name;
1727*0Sstevel@tonic-gate fhandle_t *dfh;
1728*0Sstevel@tonic-gate int error;
1729*0Sstevel@tonic-gate
1730*0Sstevel@tonic-gate name = args->object.name;
1731*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->object.dir);
1732*0Sstevel@tonic-gate
1733*0Sstevel@tonic-gate if (debug > 2) {
1734*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nREMOVE3", dfh, name, "")
1735*0Sstevel@tonic-gate if (*res != NFS3_OK)
1736*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1737*0Sstevel@tonic-gate }
1738*0Sstevel@tonic-gate if (pathp1 != NULL) {
1739*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "remove3");
1740*0Sstevel@tonic-gate *pathp2 = NULL;
1741*0Sstevel@tonic-gate }
1742*0Sstevel@tonic-gate
1743*0Sstevel@tonic-gate if (*res != NFS3_OK)
1744*0Sstevel@tonic-gate /* remove failed so nothing to update */
1745*0Sstevel@tonic-gate return;
1746*0Sstevel@tonic-gate
1747*0Sstevel@tonic-gate if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1748*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("Remove3: '%s' failed: %s\n"),
1749*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1750*0Sstevel@tonic-gate }
1751*0Sstevel@tonic-gate }
1752*0Sstevel@tonic-gate
1753*0Sstevel@tonic-gate /*
1754*0Sstevel@tonic-gate * nfslog_RMDIR3_fhargs - if the operation succeeded, remove the link from
1755*0Sstevel@tonic-gate * the fhtable.
1756*0Sstevel@tonic-gate */
1757*0Sstevel@tonic-gate /* ARGSUSED */
1758*0Sstevel@tonic-gate static void
nfslog_RMDIR3_fhargs(nfslog_RMDIR3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1759*0Sstevel@tonic-gate nfslog_RMDIR3_fhargs(nfslog_RMDIR3args *args, nfsstat3 *res,
1760*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1761*0Sstevel@tonic-gate {
1762*0Sstevel@tonic-gate char *name;
1763*0Sstevel@tonic-gate fhandle_t *dfh;
1764*0Sstevel@tonic-gate int error;
1765*0Sstevel@tonic-gate
1766*0Sstevel@tonic-gate name = args->object.name;
1767*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->object.dir);
1768*0Sstevel@tonic-gate
1769*0Sstevel@tonic-gate if (debug > 2) {
1770*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nRMDIR3", dfh, name, "")
1771*0Sstevel@tonic-gate if (*res != NFS3_OK)
1772*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1773*0Sstevel@tonic-gate }
1774*0Sstevel@tonic-gate if (pathp1 != NULL) {
1775*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "rmdir3");
1776*0Sstevel@tonic-gate *pathp2 = NULL;
1777*0Sstevel@tonic-gate }
1778*0Sstevel@tonic-gate
1779*0Sstevel@tonic-gate if (*res != NFS3_OK)
1780*0Sstevel@tonic-gate /* rmdir failed so nothing to update */
1781*0Sstevel@tonic-gate return;
1782*0Sstevel@tonic-gate
1783*0Sstevel@tonic-gate if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1784*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("Rmdir3: '%s' failed: %s\n"),
1785*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1786*0Sstevel@tonic-gate }
1787*0Sstevel@tonic-gate }
1788*0Sstevel@tonic-gate
1789*0Sstevel@tonic-gate /*
1790*0Sstevel@tonic-gate * nfslog_RENAME3_fhargs - if the operation succeeded, update the existing
1791*0Sstevel@tonic-gate * fhtable entry to point to new dir and name.
1792*0Sstevel@tonic-gate */
1793*0Sstevel@tonic-gate /* ARGSUSED */
1794*0Sstevel@tonic-gate static void
nfslog_RENAME3_fhargs(nfslog_RENAME3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1795*0Sstevel@tonic-gate nfslog_RENAME3_fhargs(nfslog_RENAME3args *args, nfsstat3 *res,
1796*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1797*0Sstevel@tonic-gate {
1798*0Sstevel@tonic-gate char *from_name, *to_name;
1799*0Sstevel@tonic-gate fhandle_t *from_dfh, *to_dfh;
1800*0Sstevel@tonic-gate int error;
1801*0Sstevel@tonic-gate
1802*0Sstevel@tonic-gate from_name = args->from.name;
1803*0Sstevel@tonic-gate from_dfh = NFSLOG_GET_FHANDLE3(&args->from.dir);
1804*0Sstevel@tonic-gate to_name = args->to.name;
1805*0Sstevel@tonic-gate to_dfh = NFSLOG_GET_FHANDLE3(&args->to.dir);
1806*0Sstevel@tonic-gate
1807*0Sstevel@tonic-gate if (debug > 2) {
1808*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nRENAME3: from",
1809*0Sstevel@tonic-gate from_dfh, from_name, "")
1810*0Sstevel@tonic-gate PRINT_LINK_DATA(stdout, "=============\nRENAME3: to ",
1811*0Sstevel@tonic-gate to_dfh, to_name, "")
1812*0Sstevel@tonic-gate if (*res != NFS3_OK)
1813*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1814*0Sstevel@tonic-gate }
1815*0Sstevel@tonic-gate if (pathp1 != NULL) {
1816*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(from_dfh, from_name, fhpath,
1817*0Sstevel@tonic-gate "rename3 from");
1818*0Sstevel@tonic-gate *pathp2 = nfslog_get_path(to_dfh, to_name, fhpath,
1819*0Sstevel@tonic-gate "rename3 to");
1820*0Sstevel@tonic-gate }
1821*0Sstevel@tonic-gate if (*res != NFS3_OK)
1822*0Sstevel@tonic-gate /* rename failed so nothing to update */
1823*0Sstevel@tonic-gate return;
1824*0Sstevel@tonic-gate
1825*0Sstevel@tonic-gate if (error = fh_rename(fhpath, from_dfh, from_name, pathp1,
1826*0Sstevel@tonic-gate to_dfh, to_name)) {
1827*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1828*0Sstevel@tonic-gate "Rename3: Update from '%s' to '%s' failed: %s\n"),
1829*0Sstevel@tonic-gate from_name, to_name,
1830*0Sstevel@tonic-gate ((error >= 0) ? strerror(error) : "Unknown"));
1831*0Sstevel@tonic-gate }
1832*0Sstevel@tonic-gate }
1833*0Sstevel@tonic-gate
1834*0Sstevel@tonic-gate /*
1835*0Sstevel@tonic-gate * nfslog_LINK3_fhargs - if the operation succeeded, we are sure there can
1836*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1837*0Sstevel@tonic-gate */
1838*0Sstevel@tonic-gate /* ARGSUSED */
1839*0Sstevel@tonic-gate static void
nfslog_LINK3_fhargs(nfslog_LINK3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1840*0Sstevel@tonic-gate nfslog_LINK3_fhargs(nfslog_LINK3args *args, nfsstat3 *res,
1841*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1842*0Sstevel@tonic-gate {
1843*0Sstevel@tonic-gate char *name;
1844*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1845*0Sstevel@tonic-gate int error;
1846*0Sstevel@tonic-gate
1847*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&args->file);
1848*0Sstevel@tonic-gate name = args->link.name;
1849*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->link.dir);
1850*0Sstevel@tonic-gate
1851*0Sstevel@tonic-gate if (debug > 2) {
1852*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nLINK3",
1853*0Sstevel@tonic-gate dfh, fh, name, "")
1854*0Sstevel@tonic-gate if (*res != NFS3_OK)
1855*0Sstevel@tonic-gate (void) printf("status %d\n", *res);
1856*0Sstevel@tonic-gate }
1857*0Sstevel@tonic-gate if (pathp1 != NULL) {
1858*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(fh, NULL, fhpath, "link3 from");
1859*0Sstevel@tonic-gate *pathp2 = nfslog_get_path(dfh, name, fhpath, "link3 to");
1860*0Sstevel@tonic-gate }
1861*0Sstevel@tonic-gate
1862*0Sstevel@tonic-gate if (*res != NFS3_OK)
1863*0Sstevel@tonic-gate /* link failed so nothing to add */
1864*0Sstevel@tonic-gate return;
1865*0Sstevel@tonic-gate
1866*0Sstevel@tonic-gate /* A new link so add it, have fh_add find link count */
1867*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1868*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1869*0Sstevel@tonic-gate "Link3: Add fh for '%s' failed: %s\n"),
1870*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1871*0Sstevel@tonic-gate }
1872*0Sstevel@tonic-gate }
1873*0Sstevel@tonic-gate
1874*0Sstevel@tonic-gate /*
1875*0Sstevel@tonic-gate * nfslog_MKNOD3_fhargs - if the operation succeeded, we are sure there can
1876*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1877*0Sstevel@tonic-gate */
1878*0Sstevel@tonic-gate /* ARGSUSED */
1879*0Sstevel@tonic-gate static void
nfslog_MKNOD3_fhargs(nfslog_MKNOD3args * args,nfslog_MKNOD3res * res,char * fhpath,char ** pathp1,char ** pathp2)1880*0Sstevel@tonic-gate nfslog_MKNOD3_fhargs(nfslog_MKNOD3args *args, nfslog_MKNOD3res *res,
1881*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1882*0Sstevel@tonic-gate {
1883*0Sstevel@tonic-gate char *name;
1884*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1885*0Sstevel@tonic-gate int error;
1886*0Sstevel@tonic-gate
1887*0Sstevel@tonic-gate name = args->where.name;
1888*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1889*0Sstevel@tonic-gate
1890*0Sstevel@tonic-gate if (debug > 2) {
1891*0Sstevel@tonic-gate if (res->status == NFS3_OK)
1892*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(
1893*0Sstevel@tonic-gate &res->nfslog_MKNOD3res_u.obj.handle);
1894*0Sstevel@tonic-gate else
1895*0Sstevel@tonic-gate fh = NULL;
1896*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nMKNOD3",
1897*0Sstevel@tonic-gate dfh, fh, name, "")
1898*0Sstevel@tonic-gate if (res->status != NFS3_OK)
1899*0Sstevel@tonic-gate (void) printf("status %d\n", res->status);
1900*0Sstevel@tonic-gate }
1901*0Sstevel@tonic-gate if (pathp1 != NULL) {
1902*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "mknod3");
1903*0Sstevel@tonic-gate *pathp2 = NULL;
1904*0Sstevel@tonic-gate }
1905*0Sstevel@tonic-gate if ((res->status != NFS3_OK) ||
1906*0Sstevel@tonic-gate !res->nfslog_MKNOD3res_u.obj.handle_follows)
1907*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1908*0Sstevel@tonic-gate return;
1909*0Sstevel@tonic-gate
1910*0Sstevel@tonic-gate /* A new file handle so add it */
1911*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&res->nfslog_MKNOD3res_u.obj.handle);
1912*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1913*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("Mknod3: Add fh for '%s' failed: %s\n"),
1914*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1915*0Sstevel@tonic-gate }
1916*0Sstevel@tonic-gate }
1917*0Sstevel@tonic-gate
1918*0Sstevel@tonic-gate /*
1919*0Sstevel@tonic-gate * nfslog_SYMLINK3_fhargs - if the operation succeeded, we are sure there can
1920*0Sstevel@tonic-gate * be no such link in the fhtable, so just add it.
1921*0Sstevel@tonic-gate */
1922*0Sstevel@tonic-gate /* ARGSUSED */
1923*0Sstevel@tonic-gate static void
nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args * args,nfslog_SYMLINK3res * res,char * fhpath,char ** pathp1,char ** pathp2)1924*0Sstevel@tonic-gate nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args *args, nfslog_SYMLINK3res *res,
1925*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1926*0Sstevel@tonic-gate {
1927*0Sstevel@tonic-gate char *name;
1928*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1929*0Sstevel@tonic-gate int error;
1930*0Sstevel@tonic-gate
1931*0Sstevel@tonic-gate name = args->where.name;
1932*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1933*0Sstevel@tonic-gate
1934*0Sstevel@tonic-gate if (debug > 2) {
1935*0Sstevel@tonic-gate if (res->status == NFS3_OK)
1936*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(
1937*0Sstevel@tonic-gate &res->nfslog_SYMLINK3res_u.obj.handle);
1938*0Sstevel@tonic-gate else
1939*0Sstevel@tonic-gate fh = NULL;
1940*0Sstevel@tonic-gate PRINT_FULL_DATA(stdout, "=============\nSYMLINK3",
1941*0Sstevel@tonic-gate dfh, fh, name, "")
1942*0Sstevel@tonic-gate if (res->status != NFS3_OK)
1943*0Sstevel@tonic-gate (void) printf("status %d\n", res->status);
1944*0Sstevel@tonic-gate }
1945*0Sstevel@tonic-gate if (pathp1 != NULL) {
1946*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(dfh, name, fhpath, "symlink3");
1947*0Sstevel@tonic-gate *pathp2 = NULL;
1948*0Sstevel@tonic-gate }
1949*0Sstevel@tonic-gate
1950*0Sstevel@tonic-gate if ((res->status != NFS3_OK) ||
1951*0Sstevel@tonic-gate !res->nfslog_SYMLINK3res_u.obj.handle_follows)
1952*0Sstevel@tonic-gate /* no returned fh so nothing to add */
1953*0Sstevel@tonic-gate return;
1954*0Sstevel@tonic-gate
1955*0Sstevel@tonic-gate /* A new file handle so add it */
1956*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&res->nfslog_SYMLINK3res_u.obj.handle);
1957*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, dfh, fh, name)) {
1958*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
1959*0Sstevel@tonic-gate "Symlink3: Add fh for '%s' failed: %s\n"),
1960*0Sstevel@tonic-gate name, ((error >= 0) ? strerror(error) : "Unknown"));
1961*0Sstevel@tonic-gate }
1962*0Sstevel@tonic-gate }
1963*0Sstevel@tonic-gate
1964*0Sstevel@tonic-gate /*
1965*0Sstevel@tonic-gate * nfslog_READDIR3_fhargs - updates path1 but no fhtable changes
1966*0Sstevel@tonic-gate */
1967*0Sstevel@tonic-gate /* ARGSUSED */
1968*0Sstevel@tonic-gate static void
nfslog_READDIR3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1969*0Sstevel@tonic-gate nfslog_READDIR3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1970*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1971*0Sstevel@tonic-gate {
1972*0Sstevel@tonic-gate if (debug > 2) {
1973*0Sstevel@tonic-gate (void) printf("=============\nREADDIR3: fh ");
1974*0Sstevel@tonic-gate debug_opaque_print(stdout, args,
1975*0Sstevel@tonic-gate sizeof (*args));
1976*0Sstevel@tonic-gate (void) printf("\n");
1977*0Sstevel@tonic-gate }
1978*0Sstevel@tonic-gate if (pathp1 != NULL) {
1979*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args),
1980*0Sstevel@tonic-gate NULL, fhpath, "readdir3");
1981*0Sstevel@tonic-gate *pathp2 = NULL;
1982*0Sstevel@tonic-gate }
1983*0Sstevel@tonic-gate }
1984*0Sstevel@tonic-gate
1985*0Sstevel@tonic-gate /*
1986*0Sstevel@tonic-gate * nfslog_READDIRPLUS3_fhargs - updates path1 but no fhtable changes
1987*0Sstevel@tonic-gate */
1988*0Sstevel@tonic-gate /* ARGSUSED */
1989*0Sstevel@tonic-gate static void
nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args * args,nfslog_READDIRPLUS3res * res,char * fhpath,char ** pathp1,char ** pathp2)1990*0Sstevel@tonic-gate nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args *args,
1991*0Sstevel@tonic-gate nfslog_READDIRPLUS3res *res,
1992*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
1993*0Sstevel@tonic-gate {
1994*0Sstevel@tonic-gate char *name;
1995*0Sstevel@tonic-gate fhandle_t *dfh, *fh;
1996*0Sstevel@tonic-gate nfslog_entryplus3 *ep;
1997*0Sstevel@tonic-gate
1998*0Sstevel@tonic-gate if (debug > 2) {
1999*0Sstevel@tonic-gate (void) printf("=============\nREADDIRPLUS3: fh ");
2000*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->dir,
2001*0Sstevel@tonic-gate sizeof (args->dir));
2002*0Sstevel@tonic-gate (void) printf("\n");
2003*0Sstevel@tonic-gate }
2004*0Sstevel@tonic-gate if (pathp1 != NULL) {
2005*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->dir),
2006*0Sstevel@tonic-gate NULL, fhpath, "readdirplus3");
2007*0Sstevel@tonic-gate *pathp2 = NULL;
2008*0Sstevel@tonic-gate }
2009*0Sstevel@tonic-gate
2010*0Sstevel@tonic-gate if (res->status == NFS3_OK) {
2011*0Sstevel@tonic-gate
2012*0Sstevel@tonic-gate dfh = NFSLOG_GET_FHANDLE3(&args->dir);
2013*0Sstevel@tonic-gate
2014*0Sstevel@tonic-gate /*
2015*0Sstevel@tonic-gate * Loop through the fh/name pair and add them
2016*0Sstevel@tonic-gate * to the mappings.
2017*0Sstevel@tonic-gate */
2018*0Sstevel@tonic-gate for (ep = res->nfslog_READDIRPLUS3res_u.ok.reply.entries;
2019*0Sstevel@tonic-gate ep != NULL;
2020*0Sstevel@tonic-gate ep = ep->nextentry) {
2021*0Sstevel@tonic-gate
2022*0Sstevel@tonic-gate name = ep->name;
2023*0Sstevel@tonic-gate
2024*0Sstevel@tonic-gate fh = NFSLOG_GET_FHANDLE3(&ep->name_handle.handle);
2025*0Sstevel@tonic-gate
2026*0Sstevel@tonic-gate nfslog_LOOKUP_calc(dfh, name, fh,
2027*0Sstevel@tonic-gate fhpath, NULL, NULL,
2028*0Sstevel@tonic-gate "ReaddirPlus3");
2029*0Sstevel@tonic-gate }
2030*0Sstevel@tonic-gate }
2031*0Sstevel@tonic-gate }
2032*0Sstevel@tonic-gate
2033*0Sstevel@tonic-gate /*
2034*0Sstevel@tonic-gate * nfslog_FSSTAT3_fhargs - updates path1 but no fhtable changes
2035*0Sstevel@tonic-gate */
2036*0Sstevel@tonic-gate /* ARGSUSED */
2037*0Sstevel@tonic-gate static void
nfslog_FSSTAT3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2038*0Sstevel@tonic-gate nfslog_FSSTAT3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2039*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2040*0Sstevel@tonic-gate {
2041*0Sstevel@tonic-gate if (debug > 2) {
2042*0Sstevel@tonic-gate (void) printf("=============\nFSSTAT3: fh ");
2043*0Sstevel@tonic-gate debug_opaque_print(stdout, args,
2044*0Sstevel@tonic-gate sizeof (*args));
2045*0Sstevel@tonic-gate (void) printf("\n");
2046*0Sstevel@tonic-gate }
2047*0Sstevel@tonic-gate if (pathp1 != NULL) {
2048*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2049*0Sstevel@tonic-gate fhpath, "fsstat3");
2050*0Sstevel@tonic-gate *pathp2 = NULL;
2051*0Sstevel@tonic-gate }
2052*0Sstevel@tonic-gate }
2053*0Sstevel@tonic-gate
2054*0Sstevel@tonic-gate /*
2055*0Sstevel@tonic-gate * nfslog_FSINFO3_fhargs - updates path1 but no fhtable changes
2056*0Sstevel@tonic-gate */
2057*0Sstevel@tonic-gate /* ARGSUSED */
2058*0Sstevel@tonic-gate static void
nfslog_FSINFO3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2059*0Sstevel@tonic-gate nfslog_FSINFO3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2060*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2061*0Sstevel@tonic-gate {
2062*0Sstevel@tonic-gate if (debug > 2) {
2063*0Sstevel@tonic-gate (void) printf("=============\nFSINFO3: fh ");
2064*0Sstevel@tonic-gate debug_opaque_print(stdout, args,
2065*0Sstevel@tonic-gate sizeof (*args));
2066*0Sstevel@tonic-gate (void) printf("\n");
2067*0Sstevel@tonic-gate }
2068*0Sstevel@tonic-gate if (pathp1 != NULL) {
2069*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2070*0Sstevel@tonic-gate fhpath, "fsinfo3");
2071*0Sstevel@tonic-gate *pathp2 = NULL;
2072*0Sstevel@tonic-gate }
2073*0Sstevel@tonic-gate }
2074*0Sstevel@tonic-gate
2075*0Sstevel@tonic-gate /*
2076*0Sstevel@tonic-gate * nfslog_PATHCONF3_fhargs - updates path1 but no fhtable changes
2077*0Sstevel@tonic-gate */
2078*0Sstevel@tonic-gate /* ARGSUSED */
2079*0Sstevel@tonic-gate static void
nfslog_PATHCONF3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2080*0Sstevel@tonic-gate nfslog_PATHCONF3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2081*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2082*0Sstevel@tonic-gate {
2083*0Sstevel@tonic-gate if (debug > 2) {
2084*0Sstevel@tonic-gate (void) printf("=============\nPATHCONF3: fh ");
2085*0Sstevel@tonic-gate debug_opaque_print(stdout, args,
2086*0Sstevel@tonic-gate sizeof (*args));
2087*0Sstevel@tonic-gate (void) printf("\n");
2088*0Sstevel@tonic-gate }
2089*0Sstevel@tonic-gate if (pathp1 != NULL) {
2090*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2091*0Sstevel@tonic-gate fhpath, "pathconf3");
2092*0Sstevel@tonic-gate *pathp2 = NULL;
2093*0Sstevel@tonic-gate }
2094*0Sstevel@tonic-gate }
2095*0Sstevel@tonic-gate
2096*0Sstevel@tonic-gate /*
2097*0Sstevel@tonic-gate * nfslog_COMMIT3_fhargs - updates path1 but no fhtable changes
2098*0Sstevel@tonic-gate */
2099*0Sstevel@tonic-gate /* ARGSUSED */
2100*0Sstevel@tonic-gate static void
nfslog_COMMIT3_fhargs(nfslog_COMMIT3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2101*0Sstevel@tonic-gate nfslog_COMMIT3_fhargs(nfslog_COMMIT3args *args, nfsstat3 *res,
2102*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2103*0Sstevel@tonic-gate {
2104*0Sstevel@tonic-gate if (debug > 2) {
2105*0Sstevel@tonic-gate (void) printf("=============\nCOMMIT3: fh ");
2106*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->file,
2107*0Sstevel@tonic-gate sizeof (args->file));
2108*0Sstevel@tonic-gate (void) printf("\n");
2109*0Sstevel@tonic-gate }
2110*0Sstevel@tonic-gate if (pathp1 != NULL) {
2111*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
2112*0Sstevel@tonic-gate NULL, fhpath, "commit3");
2113*0Sstevel@tonic-gate *pathp2 = NULL;
2114*0Sstevel@tonic-gate }
2115*0Sstevel@tonic-gate }
2116*0Sstevel@tonic-gate
2117*0Sstevel@tonic-gate /*
2118*0Sstevel@tonic-gate * NFSLOG VERSION 1
2119*0Sstevel@tonic-gate */
2120*0Sstevel@tonic-gate
2121*0Sstevel@tonic-gate /*
2122*0Sstevel@tonic-gate * nfslog_SHARE_fhargs - adds export path and handle to fhlist
2123*0Sstevel@tonic-gate */
2124*0Sstevel@tonic-gate /* ARGSUSED */
2125*0Sstevel@tonic-gate static void
nfslog_SHARE_fhargs(nfslog_sharefsargs * args,nfslog_sharefsres * res,char * fhpath,char ** pathp1,char ** pathp2)2126*0Sstevel@tonic-gate nfslog_SHARE_fhargs(nfslog_sharefsargs *args, nfslog_sharefsres *res,
2127*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2128*0Sstevel@tonic-gate {
2129*0Sstevel@tonic-gate fhlist_ent fhrec;
2130*0Sstevel@tonic-gate fhandle_t *fh;
2131*0Sstevel@tonic-gate int error;
2132*0Sstevel@tonic-gate
2133*0Sstevel@tonic-gate if (debug > 2) {
2134*0Sstevel@tonic-gate (void) printf(
2135*0Sstevel@tonic-gate "=============\nSHARE: name '%s', fh ", args->sh_path);
2136*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->sh_fh_buf,
2137*0Sstevel@tonic-gate sizeof (fhandle_t));
2138*0Sstevel@tonic-gate (void) printf("\n");
2139*0Sstevel@tonic-gate }
2140*0Sstevel@tonic-gate
2141*0Sstevel@tonic-gate fh = &args->sh_fh_buf;
2142*0Sstevel@tonic-gate
2143*0Sstevel@tonic-gate /*
2144*0Sstevel@tonic-gate * This bcopy is done because the fh_data for the export/share directory
2145*0Sstevel@tonic-gate * is not meaningful with respect to the database keys. Therefore, we
2146*0Sstevel@tonic-gate * copy the export or fh_xdata fid to the fh_data so that a reasonable
2147*0Sstevel@tonic-gate * entry will be added in the data base.
2148*0Sstevel@tonic-gate */
2149*0Sstevel@tonic-gate bcopy(fh->fh_xdata, fh->fh_data, fh->fh_xlen);
2150*0Sstevel@tonic-gate
2151*0Sstevel@tonic-gate /* If debug print the database */
2152*0Sstevel@tonic-gate if (debug > 10) {
2153*0Sstevel@tonic-gate fh_print_all_keys(fhpath, fh);
2154*0Sstevel@tonic-gate }
2155*0Sstevel@tonic-gate if (fh_lookup_link(fhpath, fh, fh,
2156*0Sstevel@tonic-gate args->sh_path, &fhrec, &error) == NULL) {
2157*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, fh, fh, args->sh_path)) {
2158*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
2159*0Sstevel@tonic-gate "Share: Add fh for '%s' failed: %s\n"),
2160*0Sstevel@tonic-gate args->sh_path, ((error >= 0) ?
2161*0Sstevel@tonic-gate strerror(error) : "Unknown"));
2162*0Sstevel@tonic-gate }
2163*0Sstevel@tonic-gate }
2164*0Sstevel@tonic-gate if (pathp1 != NULL) {
2165*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(fh, NULL, fhpath, "share");
2166*0Sstevel@tonic-gate *pathp2 = NULL;
2167*0Sstevel@tonic-gate }
2168*0Sstevel@tonic-gate }
2169*0Sstevel@tonic-gate
2170*0Sstevel@tonic-gate /*
2171*0Sstevel@tonic-gate * nfslog_UNSHARE_fhargs - remove export path and handle from fhlist
2172*0Sstevel@tonic-gate */
2173*0Sstevel@tonic-gate /* ARGSUSED */
2174*0Sstevel@tonic-gate static void
nfslog_UNSHARE_fhargs(nfslog_sharefsargs * args,nfslog_sharefsres * res,char * fhpath,char ** pathp1,char ** pathp2)2175*0Sstevel@tonic-gate nfslog_UNSHARE_fhargs(nfslog_sharefsargs *args, nfslog_sharefsres *res,
2176*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2177*0Sstevel@tonic-gate {
2178*0Sstevel@tonic-gate fhandle_t *fh;
2179*0Sstevel@tonic-gate int error;
2180*0Sstevel@tonic-gate
2181*0Sstevel@tonic-gate if (debug > 2) {
2182*0Sstevel@tonic-gate (void) printf("=============\nUNSHARE: name '%s', fh ",
2183*0Sstevel@tonic-gate args->sh_path);
2184*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->sh_fh_buf,
2185*0Sstevel@tonic-gate sizeof (fhandle_t));
2186*0Sstevel@tonic-gate (void) printf("\n");
2187*0Sstevel@tonic-gate }
2188*0Sstevel@tonic-gate
2189*0Sstevel@tonic-gate fh = &args->sh_fh_buf;
2190*0Sstevel@tonic-gate
2191*0Sstevel@tonic-gate /*
2192*0Sstevel@tonic-gate * This bcopy is done because the fh_data for the export/share directory
2193*0Sstevel@tonic-gate * is not meaningful with respect to the database keys. Therefore, we
2194*0Sstevel@tonic-gate * copy the export or fh_xdata fid to the fh_data so that a reasonable
2195*0Sstevel@tonic-gate * entry will be added in the data base.
2196*0Sstevel@tonic-gate */
2197*0Sstevel@tonic-gate bcopy(fh->fh_xdata, fh->fh_data, fh->fh_xlen);
2198*0Sstevel@tonic-gate
2199*0Sstevel@tonic-gate /* If debug print the database */
2200*0Sstevel@tonic-gate if (debug > 10) {
2201*0Sstevel@tonic-gate fh_print_all_keys(fhpath, fh);
2202*0Sstevel@tonic-gate }
2203*0Sstevel@tonic-gate if (pathp1 != NULL) {
2204*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(fh, NULL, fhpath, "share");
2205*0Sstevel@tonic-gate *pathp2 = NULL;
2206*0Sstevel@tonic-gate }
2207*0Sstevel@tonic-gate if (error = fh_remove(fhpath, fh, args->sh_path, pathp1)) {
2208*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("Unshare: '%s' failed: %s\n"),
2209*0Sstevel@tonic-gate args->sh_path, ((error >= 0) ? strerror(error) :
2210*0Sstevel@tonic-gate "Unknown"));
2211*0Sstevel@tonic-gate }
2212*0Sstevel@tonic-gate }
2213*0Sstevel@tonic-gate
2214*0Sstevel@tonic-gate /* ARGSUSED */
2215*0Sstevel@tonic-gate static void
nfslog_GETFH_fhargs(nfslog_getfhargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)2216*0Sstevel@tonic-gate nfslog_GETFH_fhargs(nfslog_getfhargs *args, nfsstat *res,
2217*0Sstevel@tonic-gate char *fhpath, char **pathp1, char **pathp2)
2218*0Sstevel@tonic-gate {
2219*0Sstevel@tonic-gate fhlist_ent fhrec;
2220*0Sstevel@tonic-gate fhandle_t *fh;
2221*0Sstevel@tonic-gate int error;
2222*0Sstevel@tonic-gate
2223*0Sstevel@tonic-gate if (debug > 2) {
2224*0Sstevel@tonic-gate (void) printf("=============\nGETFH3: name '%s', fh ",
2225*0Sstevel@tonic-gate args->gfh_path);
2226*0Sstevel@tonic-gate debug_opaque_print(stdout, &args->gfh_fh_buf,
2227*0Sstevel@tonic-gate sizeof (fhandle_t));
2228*0Sstevel@tonic-gate (void) printf("\n");
2229*0Sstevel@tonic-gate }
2230*0Sstevel@tonic-gate
2231*0Sstevel@tonic-gate fh = &args->gfh_fh_buf;
2232*0Sstevel@tonic-gate
2233*0Sstevel@tonic-gate /* If debug print the database */
2234*0Sstevel@tonic-gate if (debug > 10) {
2235*0Sstevel@tonic-gate fh_print_all_keys(fhpath, fh);
2236*0Sstevel@tonic-gate }
2237*0Sstevel@tonic-gate if (fh_lookup_link(fhpath, fh, fh,
2238*0Sstevel@tonic-gate args->gfh_path, &fhrec, &error) == NULL) {
2239*0Sstevel@tonic-gate if (error = FH_ADD(fhpath, fh, fh, args->gfh_path)) {
2240*0Sstevel@tonic-gate syslog(LOG_ERR, gettext(
2241*0Sstevel@tonic-gate "Getfh: Add fh for '%s' failed: %s\n"),
2242*0Sstevel@tonic-gate args->gfh_path, ((error >= 0) ?
2243*0Sstevel@tonic-gate strerror(error) : "Unknown"));
2244*0Sstevel@tonic-gate }
2245*0Sstevel@tonic-gate }
2246*0Sstevel@tonic-gate if (pathp1 != NULL) {
2247*0Sstevel@tonic-gate *pathp1 = nfslog_get_path(fh, NULL, fhpath, "getfh");
2248*0Sstevel@tonic-gate *pathp2 = NULL;
2249*0Sstevel@tonic-gate }
2250*0Sstevel@tonic-gate }
2251*0Sstevel@tonic-gate
2252*0Sstevel@tonic-gate /*
2253*0Sstevel@tonic-gate * Exported function
2254*0Sstevel@tonic-gate */
2255*0Sstevel@tonic-gate
2256*0Sstevel@tonic-gate /*
2257*0Sstevel@tonic-gate * nfslog_get_path - gets the path for this file. fh must be supplied,
2258*0Sstevel@tonic-gate * name may be null. If name is supplied, fh is assumed to be a directory
2259*0Sstevel@tonic-gate * filehandle, with name as its component. fhpath is the generic path for the
2260*0Sstevel@tonic-gate * fhtopath table and prtstr is the name of the caller (for debug purposes).
2261*0Sstevel@tonic-gate * Returns the malloc'd path. The caller must free it later.
2262*0Sstevel@tonic-gate */
2263*0Sstevel@tonic-gate char *
nfslog_get_path(fhandle_t * fh,char * name,char * fhpath,char * prtstr)2264*0Sstevel@tonic-gate nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr)
2265*0Sstevel@tonic-gate {
2266*0Sstevel@tonic-gate char *pathp = fh_print_absolute(fhpath, fh, name);
2267*0Sstevel@tonic-gate
2268*0Sstevel@tonic-gate if (debug > 3) {
2269*0Sstevel@tonic-gate (void) printf(" %s: path '%s', fh ", prtstr, pathp);
2270*0Sstevel@tonic-gate debug_opaque_print(stdout, fh, sizeof (*fh));
2271*0Sstevel@tonic-gate (void) printf("\n");
2272*0Sstevel@tonic-gate }
2273*0Sstevel@tonic-gate return (pathp);
2274*0Sstevel@tonic-gate }
2275*0Sstevel@tonic-gate
2276*0Sstevel@tonic-gate /*
2277*0Sstevel@tonic-gate * nfslog_process_fh_rec - updates the fh table based on the rpc req
2278*0Sstevel@tonic-gate * Return 0 for success, error otherwise. If success return the path
2279*0Sstevel@tonic-gate * for the input file handle(s) if so indicated.
2280*0Sstevel@tonic-gate */
2281*0Sstevel@tonic-gate int
nfslog_process_fh_rec(struct nfslog_lr * lrp,char * fhpath,char ** pathp1,char ** pathp2,bool_t return_path)2282*0Sstevel@tonic-gate nfslog_process_fh_rec(struct nfslog_lr *lrp, char *fhpath, char **pathp1,
2283*0Sstevel@tonic-gate char **pathp2, bool_t return_path)
2284*0Sstevel@tonic-gate {
2285*0Sstevel@tonic-gate struct nfsl_fh_proc_disp *disp;
2286*0Sstevel@tonic-gate nfslog_request_record *logrec = &lrp->log_record;
2287*0Sstevel@tonic-gate nfslog_record_header *logrechdr = &logrec->re_header;
2288*0Sstevel@tonic-gate
2289*0Sstevel@tonic-gate if ((disp = nfslog_find_fh_dispatch(logrec)) != NULL) {
2290*0Sstevel@tonic-gate /*
2291*0Sstevel@tonic-gate * Allocate space for the args and results and decode
2292*0Sstevel@tonic-gate */
2293*0Sstevel@tonic-gate logrec->re_rpc_arg = calloc(1, disp->args_size);
2294*0Sstevel@tonic-gate
2295*0Sstevel@tonic-gate if (!(*disp->xdr_args)(&lrp->xdrs, logrec->re_rpc_arg)) {
2296*0Sstevel@tonic-gate free(logrec->re_rpc_arg);
2297*0Sstevel@tonic-gate logrec->re_rpc_arg = NULL;
2298*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("argument decode failed"));
2299*0Sstevel@tonic-gate return (FALSE);
2300*0Sstevel@tonic-gate }
2301*0Sstevel@tonic-gate /* used later for free of data structures */
2302*0Sstevel@tonic-gate lrp->xdrargs = disp->xdr_args;
2303*0Sstevel@tonic-gate
2304*0Sstevel@tonic-gate logrec->re_rpc_res = calloc(1, disp->res_size);
2305*0Sstevel@tonic-gate if (!(*disp->xdr_res)(&lrp->xdrs, logrec->re_rpc_res)) {
2306*0Sstevel@tonic-gate free(logrec->re_rpc_res);
2307*0Sstevel@tonic-gate logrec->re_rpc_res = NULL;
2308*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("results decode failed"));
2309*0Sstevel@tonic-gate return (FALSE);
2310*0Sstevel@tonic-gate }
2311*0Sstevel@tonic-gate /* used later for free of data structures */
2312*0Sstevel@tonic-gate lrp->xdrres = disp->xdr_res;
2313*0Sstevel@tonic-gate
2314*0Sstevel@tonic-gate /*
2315*0Sstevel@tonic-gate * Process the operation within the context of the file handle
2316*0Sstevel@tonic-gate * mapping process
2317*0Sstevel@tonic-gate */
2318*0Sstevel@tonic-gate if (return_path) {
2319*0Sstevel@tonic-gate (*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2320*0Sstevel@tonic-gate logrec->re_rpc_res, fhpath, pathp1, pathp2);
2321*0Sstevel@tonic-gate } else {
2322*0Sstevel@tonic-gate if ((logrechdr->rh_version == NFS_VERSION &&
2323*0Sstevel@tonic-gate logrechdr->rh_procnum == RFS_LINK) ||
2324*0Sstevel@tonic-gate (logrechdr->rh_version == NFS_V3 &&
2325*0Sstevel@tonic-gate logrechdr->rh_procnum == NFSPROC3_LINK)) {
2326*0Sstevel@tonic-gate
2327*0Sstevel@tonic-gate (*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2328*0Sstevel@tonic-gate logrec->re_rpc_res,
2329*0Sstevel@tonic-gate fhpath, pathp1, pathp2);
2330*0Sstevel@tonic-gate } else {
2331*0Sstevel@tonic-gate (*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2332*0Sstevel@tonic-gate logrec->re_rpc_res,
2333*0Sstevel@tonic-gate fhpath, NULL, NULL);
2334*0Sstevel@tonic-gate }
2335*0Sstevel@tonic-gate }
2336*0Sstevel@tonic-gate return (TRUE);
2337*0Sstevel@tonic-gate } else {
2338*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("procedure unknown"));
2339*0Sstevel@tonic-gate return (FALSE);
2340*0Sstevel@tonic-gate }
2341*0Sstevel@tonic-gate }
2342