Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / rfs_3_ops.c
1 #ifndef lint
2 static char sfs_3_opsSid[] = "@(#)sfs_3_ops.c   2.1     97/10/23";
3 #endif
4
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23
24 /*****************************************************************
25  *                                                               *
26  *      Copyright 1991,1992  Legato Systems, Inc.                *
27  *      Copyright 1991,1992  Auspex Systems, Inc.                *
28  *      Copyright 1991,1992  Data General Corporation            *
29  *      Copyright 1991,1992  Digital Equipment Corporation       *
30  *      Copyright 1991,1992  Interphase Corporation              *
31  *      Copyright 1991,1992  Sun Microsystems, Inc.              *
32  *                                                               *
33  *****************************************************************/
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <errno.h>
39
40 #include <sys/types.h>
41 #include <sys/stat.h>
42
43 #include <unistd.h>
44 #include "sfs_c_def.h"
45 #include "rfs_c_def.h"
46
47 #define TRY_SETARG_FAST
48 #define TRY_SETRES_FAST
49 extern fh_map_t * lookup_fh (char * trace_fh);
50 extern void print_result(void);
51
52 char * lookup_fhandle(char * fhandle)
53 {
54         fh_map_t * fh;
55         fh = lookup_fh(fhandle);
56         RFS_ASSERT (fh);
57         return ((char *)&fh->play_fh);
58 }
59
60
61 #define setarg_fhandle(fhp) \
62         fh_map_t * fh; \
63         t = strstr (line, "fh");        \
64         RFS_ASSERT (t);                         \
65         t += 3;                                         \
66         fh = lookup_fh(t);                      \
67         RFS_ASSERT (fh);                        \
68         (void) memmove((char *)fhp, &(fh->play_fh),                     \
69                                                                        sizeof (nfs_fh3));       \
70         t+=TRACE_FH_SIZE+1;
71         //t = strchr (t, ' '); t++; \
72
73 void setarg_getattr (int index, char * line, GETATTR3args * args)
74 {
75         char * t;
76 #ifdef TRY_SETARG_FAST
77         memcpy (&args->object, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
78 #else
79         setarg_fhandle(&args->object);
80 #endif
81 }
82
83 struct ladtime * adjust_time (struct timeval tm, int * sec, int * usec)
84 {
85         struct ladtime trace_pkt_time;
86         static struct ladtime trace_arg_time;
87         struct timeval curtmp;
88         struct ladtime cur;
89
90         /* not sure whether sec ==0 means anything special, do not adjust the timestamp for this */
91         if (*sec ==0) {
92                 RFS_ASSERT (0);
93                 RFS_ASSERT (*usec == 0);
94                 trace_arg_time.sec = 0;
95                 trace_arg_time.usec = 0;
96                 return (&trace_arg_time);
97         }
98         trace_pkt_time.sec = tm.tv_sec;
99         trace_pkt_time.usec = tm.tv_usec;
100
101         trace_arg_time.sec = *sec;
102         trace_arg_time.usec = *usec;
103
104         gettimeofday(&curtmp, NULL);
105         cur.sec = curtmp.tv_sec;
106         cur.usec = curtmp.tv_usec;
107
108         //fprintf (stderr, "trace_pkt_time %d.%d trace_arg_time %d.%d cur %d.%d\n", trace_pkt_time.sec, trace_pkt_time.usec, trace_arg_time.sec, trace_arg_time.usec, cur.sec, cur.usec);
109
110         ADDTIME (trace_arg_time, cur);
111         //fprintf(stderr, "after add, %d.%d\n", trace_arg_time.sec, trace_arg_time.usec);
112         RFS_ASSERT (LARGERTIME (trace_arg_time, trace_pkt_time));
113         SUBTIME (trace_arg_time, trace_pkt_time);
114         return (&trace_arg_time);
115 }
116
117 char * parse_create_mode(char * t, createmode3 * mode)
118 {
119         *mode = UNCHECKED;
120         return (t+2);
121         /* anyway, we can not get concrete result from the trace, just chose this mode */
122         RFS_ASSERT (0);
123 }
124
125 char * parse_sattr3(char * t, sattr3 * args, sattrguard3 * guard, int index)
126 {
127         int i,j;
128         struct ladtime * tm;
129
130         /* set the default value of SETATTR3args->*/
131     args->mode.set_it = FALSE;
132     args->uid.set_it = FALSE;
133     args->gid.set_it = FALSE;
134     args->size.set_it = FALSE;
135     args->atime.set_it = FALSE;
136     args->mtime.set_it = FALSE;
137
138         //fprintf(stderr, "parse_sattr: line %s\n", t);
139         while (1) {
140                 if (!strncmp (t, "mode", 4)) {
141                         t+=5;
142                         sscanf(t, "%x", &i); 
143                         args->mode.set_it = TRUE;
144                         args->mode.mode = i;            // (uint32_t) 0666;
145                 } else if (!strncmp (t, "ctime", 5)) {
146                         RFS_ASSERT (guard);
147                         t+=6;
148                         RFS_ASSERT (strncmp(t, "SERVER", 6));
149                         sscanf (t, "%d.%d", &i, &j);
150                         tm = adjust_time (dep_tab[index].timestamp, &i, &j);
151 #ifndef IGNORE_SETATTR_CTIME
152                         guard->check = TRUE;
153 #endif
154                         guard->obj_ctime.seconds = tm->sec;
155                         guard->obj_ctime.nseconds = tm->usec*1000;
156                 } else if (!strncmp (t, "atime", 5)) {
157                         t+=6;
158                         if (!strncmp(t, "SERVER", 6)) {
159                                 args->atime.set_it = SET_TO_SERVER_TIME;
160                         } else {
161                                 args->atime.set_it = SET_TO_CLIENT_TIME;
162                                 sscanf (t, "%d.%d", &i, &j);
163                                 if (i==0) {
164                                         RFS_ASSERT (j==0);
165                                         args->atime.atime.seconds = 0;
166                                         args->atime.atime.nseconds = 0;
167                                 } else {
168                                         tm = adjust_time (dep_tab[index].timestamp, &i, &j);
169                                         args->atime.atime.seconds = tm->sec;
170                                         args->atime.atime.nseconds = tm->usec * 1000;
171                                 }
172                         }
173                 } else if (!strncmp (t, "mtime", 5)) {
174                         t+=6;
175                         if (!strncmp(t, "SERVER", 6)) {
176                                 args->mtime.set_it = SET_TO_SERVER_TIME;
177                         } else {
178                                 args->mtime.set_it = SET_TO_CLIENT_TIME;
179                                 sscanf (t, "%d.%d", &i, &j);
180                                 if (i==0) {
181                                         RFS_ASSERT (j==0);
182                                         args->mtime.mtime.seconds = 0;
183                                         args->mtime.mtime.nseconds = 0;
184                                 } else {
185                                         tm = adjust_time (dep_tab[index].timestamp, &i, &j);
186                                         args->mtime.set_it = TRUE;
187                                         args->mtime.mtime.seconds = tm->sec;
188                                         args->mtime.mtime.nseconds = tm->usec * 1000;
189                                 }
190                         }
191                 } else if (!strncmp (t, "size", 4)) {
192                                 t+=5;
193                         sscanf(t, "%x", &i); 
194                         args->size.set_it = TRUE;
195                         args->size.size._p._u = (uint32_t) 0;
196                         args->size.size._p._l = (uint32_t) i;
197                 } else if (!strncmp (t, "gid", 3)) {
198                         t+=4;
199                         sscanf(t, "%x", &i); 
200                         args->gid.set_it = TRUE;
201 #ifdef TAKE_CARE_SETATTR_GID
202                         args->gid.gid = i;
203 #else
204                         args->gid.gid = 513;
205 #endif
206                 } else if ( !strncmp (t, "uid", 3)) {
207                         t+=4;
208                         sscanf(t, "%x", &i); 
209                         args->uid.set_it = TRUE;
210 #ifdef TAKE_CARE_SETATTR_UID
211                         args->uid.uid = i;
212 #else
213                         args->uid.uid = 513;
214 #endif
215                 } else if (!strncmp (t, "con", 3)) {
216                         break;
217                 } else if (!strncmp (t, "sdata", 5)) {
218                         break;
219                 } else {
220                         fprintf(stderr, "parse_sattr t: %s\n", t);
221                         RFS_ASSERT (0);
222                 }
223
224                 while (*t!=' ')
225                         t++;
226                 t++;
227         }
228         return t;
229 }
230
231 char * parse_name (char * t, char * buf)
232 {
233         int i;
234         if (!strncmp(t, "fn2", 3))
235                 t+=4;
236         else if (!strncmp(t, "fn", 2))
237                 t+=3;
238         else if (!strncmp(t, "name2", 5))
239                 t+=6;
240         else if (!strncmp(t, "name", 4))
241                 t+=5;
242         else if (!strncmp(t, "sdata", 5))
243                 t+=6;
244         else {
245                 fprintf(stderr, "%s\n", t);
246                 RFS_ASSERT (0);
247         }
248
249         RFS_ASSERT (*t=='"');
250         t++;
251         i = 0;
252         while (*t!='"')
253                 buf[i++] = *t++; // ??? name buffer?    
254         RFS_ASSERT ((*t)=='"');
255         buf[i] = 0;
256         return (t+2);
257 }
258
259 char * parse_access_mode (char * line, int * mode)
260 {
261         *mode = ACCESS3_READ;   
262         return line+2;
263         /* anyway the information in the trace is not enough, so we just make up something */
264 }
265
266 char * parse_stable_mode (char * line, stable_how * mode)
267 {
268         switch (*line) {
269         case 'U': *mode = UNSTABLE;
270                           break;
271         case 'F': *mode = FILE_SYNC;
272                           break;
273         case 'D': *mode = DATA_SYNC;
274                           break;
275         default:
276                 RFS_ASSERT (0);
277         }
278         return line +2;
279 }
280
281
282 void setarg_setattr (int index, char * line, SETATTR3args * args)
283 {
284         char * t;
285         int i, j;
286         
287 #ifdef TRY_SETARG_FAST
288         memcpy (&args->object, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
289         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
290         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
291 #else
292         setarg_fhandle(&args->object);
293 #endif
294
295         args->guard.check = FALSE;
296         t = parse_sattr3 (t, &(args->new_attributes), &(args->guard), index);
297 }
298
299 void setarg_lookup (int index, char * line, LOOKUP3args * args, char * Cur_filename)
300 {
301         char * t;
302 #ifdef TRY_SETARG_FAST
303         memcpy (&args->what.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
304         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
305         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
306 #else
307         setarg_fhandle(&args->what.dir)
308 #endif
309         t = parse_name (t, Cur_filename);
310         args->what.name = Cur_filename;
311 }
312
313 void setarg_access (int index, char * line, ACCESS3args * args)
314 {
315         char * t;
316
317 #ifdef TRY_SETARG_FAST
318         memcpy (&args->object, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
319         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
320         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
321 #else
322         setarg_fhandle(&args->object);
323 #endif
324
325         parse_access_mode (t, &args->access);   //ACCESS3_MODIFY;       // ??? the actual parameter can be different
326 }
327
328 void setarg_readlink (int index, char * line, READLINK3args * args)
329 {
330         char * t;
331 #ifdef TRY_SETARG_FAST
332         memcpy (&args->symlink, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
333         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
334         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
335 #else
336         setarg_fhandle (&args->symlink);
337 #endif
338 }
339
340 void setarg_read (int index, char * line, READ3args * args, char * buf)
341 {
342         char * t;
343         int i;
344 #ifdef TRY_SETARG_FAST
345         memcpy (&args->file, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
346         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
347         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
348 #else
349         setarg_fhandle (&args->file);
350 #endif
351
352         if (line[TRACE_VERSION_POS]=='3') {
353                 t = strstr (t, "off");
354                 RFS_ASSERT (t);
355                 t+=4;
356         } else {
357                 t = strstr (t, "offset");
358                 RFS_ASSERT (t);
359                 t+=7;
360         }
361         sscanf (t, "%x", &i);
362
363         RFS_ASSERT (i>=0 && i<0x7FFFFFFF)
364         args->offset._p._u = 0;
365         args->offset._p._l = i;
366 #ifdef SEQUEN_READ
367         if (index>=memory_trace_index.head)
368                 args->offset._p._l = (index-memory_trace_index.head)*4096;
369 #endif
370         t = strstr (t, "count");
371         RFS_ASSERT (t);
372         t+=6;
373         sscanf (t, "%x", &i);
374
375         RFS_ASSERT (i <= 32768);
376         if (i > NFS_MAXDATA) {
377                 read_data_owe += (i-NFS_MAXDATA);
378                 read_data_adjust_times ++;
379                 if (read_data_owe > 1073741824) {
380                         read_data_owe -= 1073741824;
381                         read_data_owe_GB ++;
382                 }
383                 
384                 //printf ("adjust read count from %d to %d\n", i, NFS_MAXDATA);
385                 i = NFS_MAXDATA;
386         }
387         read_data_total += i;
388         if (read_data_total > 1073741824) {
389                 read_data_total -= 1073741824;
390                 read_data_total_GB ++;
391         }
392
393         args->count = i;
394 }
395
396 void setarg_write (int index, char * line, WRITE3args * args, char * buf)
397 {
398         char * t;
399         int i;
400 #ifdef TRY_SETARG_FAST
401         memcpy (&args->file, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
402         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
403         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
404 #else
405         setarg_fhandle (&args->file);
406 #endif
407
408         //fprintf (stderr, "process write: %s\n", line);
409         if (line[TRACE_VERSION_POS]=='3') {
410                 t = strstr (t, "off");
411                 RFS_ASSERT (t);
412                 t+=4;
413         } else {
414                 RFS_ASSERT (line[TRACE_VERSION_POS]=='2');
415                 t = strstr (t, "offset");
416                 RFS_ASSERT (t);
417                 t+=7;
418         }
419
420         sscanf (t, "%x", &i);
421         RFS_ASSERT (i>=0 && i<0x7FFFFFFF)
422         args->offset._p._u = 0;
423         args->offset._p._l = i;
424
425         t = strstr (t, "count");
426         RFS_ASSERT (t);
427         t+=6;
428         sscanf (t, "%x", &i);
429         RFS_ASSERT (i <= 32768);
430         if (i > NFS_MAXDATA) {
431                 write_data_owe += (i-NFS_MAXDATA);
432                 if (write_data_owe > 1073741824) {
433                         write_data_owe -= 1073741824;
434                         write_data_owe_GB ++;
435                 }
436                 write_data_adjust_times ++;
437                 //printf ("adjust write count from %d to %d\n", i, NFS_MAXDATA);
438                 i = NFS_MAXDATA;
439         }
440         write_data_total += i;
441         if (write_data_total > 1073741824) {
442                 write_data_total -= 1073741824;
443                 write_data_total_GB ++;
444         }
445
446         RFS_ASSERT (i < MAX_BUF1_SIZE-128);     /* 128 is some random safe number to add */
447         args->count = i;
448
449         if (line[TRACE_VERSION_POS]==3) {
450                 t = strstr (t, "stable");
451                 RFS_ASSERT (t);
452                 t+=7;
453                 parse_stable_mode(t, &args->stable);    /* *t can be F, U, etc */ 
454         } else
455                 args->stable = UNSTABLE;
456         args->data.data_len = args->count;
457         args->data.data_val = buf;
458 }
459
460 void setarg_create (int index, char * line, CREATE3args * args, char * Cur_filename)
461 {
462         char * t;
463         //fprintf(stderr, "process create %s\n", line);
464 #ifdef TRY_SETARG_FAST
465         memcpy (&args->where.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
466         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
467         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
468 #else
469         setarg_fhandle (&args->where.dir);
470 #endif
471         t = parse_name (t, Cur_filename);
472         args->where.name = Cur_filename;
473         if (line[TRACE_VERSION_POS]=='3') {
474                 RFS_ASSERT (!strncmp(t, "how", 3));
475                 t+=4;
476         t = parse_create_mode (t, &args->how.mode);
477         } else
478                 args->how.mode = UNCHECKED;
479         t = parse_sattr3 (t, &(args->how.createhow3_u.obj_attributes), NULL, index);
480 }
481
482 void setarg_mkdir (int index, char * line, MKDIR3args * args, char * Cur_filename)
483 {
484         char * t;
485 #ifdef TRY_SETARG_FAST
486         memcpy (&args->where.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
487         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
488         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
489 #else
490         setarg_fhandle (&args->where.dir);
491 #endif
492         t = parse_name (t, Cur_filename);
493         args->where.name = Cur_filename;
494         t = parse_sattr3 (t, &(args->attributes), NULL, index);
495 }
496
497 void setarg_symlink(int index, char * line, SYMLINK3args * args, char * Cur_filename, char * sym_data)
498 {
499         char * t;
500 #ifdef TRY_SETARG_FAST
501         memcpy (&args->where.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
502         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
503         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
504 #else
505         setarg_fhandle (&args->where.dir);
506 #endif
507         t = parse_name (t, Cur_filename);
508         args->where.name = Cur_filename;
509         if (line[TRACE_VERSION_POS]=='2') {
510                 t = parse_name (t, sym_data);
511                 t = parse_sattr3 (t, &(args->symlink.symlink_attributes), NULL, index);
512         } else {
513                 t = parse_sattr3 (t, &(args->symlink.symlink_attributes), NULL, index);
514                 t = parse_name (t, sym_data);
515         }
516     args->symlink.symlink_data = sym_data;
517 }
518
519 void setarg_mknod(int index, char * line, MKNOD3args * args, char * Cur_filename)
520 {
521         RFS_ASSERT (0);
522
523 #ifdef notdef
524         /* set up the arguments */
525     (void) memmove((char *) &args.where.dir, (char *) &Cur_file_ptr->dir->fh3,
526                 sizeof (nfs_fh3));
527     args.where.name = Cur_filename;
528     args.what.type = NF3FIFO;
529     args.what.mknoddata3_u.pipe_attributes.mode.set_it = TRUE;
530     args.what.mknoddata3_u.pipe_attributes.mode.mode = (NFSMODE_FIFO | 0777);
531     args.what.mknoddata3_u.pipe_attributes.uid.set_it = TRUE;
532     args.what.mknoddata3_u.pipe_attributes.uid.uid = Cur_uid;
533     args.what.mknoddata3_u.pipe_attributes.gid.set_it = TRUE;
534     args.what.mknoddata3_u.pipe_attributes.gid.gid = Cur_gid;
535     args.what.mknoddata3_u.pipe_attributes.size.set_it = TRUE;
536     args.what.mknoddata3_u.pipe_attributes.size.size._p._u = (uint32_t) 0;
537     args.what.mknoddata3_u.pipe_attributes.size.size._p._l =
538                                                         (uint32_t) 512;
539     args.what.mknoddata3_u.pipe_attributes.atime.set_it = TRUE;
540     args.what.mknoddata3_u.pipe_attributes.atime.atime.seconds =
541                                                         Cur_time.esec;
542     args.what.mknoddata3_u.pipe_attributes.atime.atime.nseconds =
543                                                         Cur_time.usec * 1000;
544     args.what.mknoddata3_u.pipe_attributes.mtime.set_it = TRUE;
545     args.what.mknoddata3_u.pipe_attributes.mtime.mtime.seconds =
546                                                                 Cur_time.esec;
547     args.what.mknoddata3_u.pipe_attributes.mtime.mtime.nseconds =
548                                                         Cur_time.usec * 1000;
549 #endif
550 }
551
552 void setarg_remove (int index, char * line, REMOVE3args * args, char * Cur_filename)
553 {
554         char * t;
555 #ifdef TRY_SETARG_FAST
556         memcpy (&args->object.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
557         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
558         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
559 #else
560         setarg_fhandle(&args->object.dir)
561 #endif
562         t = parse_name (t, Cur_filename);
563         args->object.name = Cur_filename;
564 }
565
566 void setarg_rmdir (int index, char * line, RMDIR3args * args, char * Cur_filename)
567 {
568         char * t;
569 #ifdef TRY_SETARG_FAST
570         memcpy (&args->object.dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
571         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
572         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
573 #else
574         setarg_fhandle(&args->object.dir)
575 #endif
576         t = parse_name (t, Cur_filename);
577         args->object.name = Cur_filename;
578 }
579
580 void setarg_rename (int index, char * line, RENAME3args * args, char * fromname, char * toname)
581 {
582         char * t;
583 #ifdef TRY_SETARG_FAST
584         memcpy (&args->from.dir, &dep_tab[index].fh_2->play_fh, sizeof(nfs_fh3));
585         //t = dep_tab[index].trace_fh_2 + TRACE_FH_SIZE+1;
586         t = strchr(dep_tab[index].trace_fh_2, ' '); t++; 
587 #else
588         setarg_fhandle(&args->from.dir)
589 #endif
590         t = parse_name (t, fromname);
591         args->from.name = fromname;
592
593         t = strstr (t, "fh2");  
594         RFS_ASSERT (t);                         
595         t += 4;                                         
596         memmove((char *)&args->to.dir, lookup_fhandle(t), sizeof (nfs_fh3));    
597         t+=65;
598
599         t = parse_name (t, toname);
600         args->to.name = toname;
601 }
602
603 void setarg_link (int index, char * line, LINK3args * args, char * Cur_filename)
604 {
605         char * t;
606
607 #ifdef TRY_SETARG_FAST
608         memcpy (&args->file, &dep_tab[index].fh_2->play_fh, sizeof(nfs_fh3));
609         //t = dep_tab[index].trace_fh_2 + TRACE_FH_SIZE+1;
610         t = strchr(dep_tab[index].trace_fh_2, ' '); t++; 
611 #else
612         setarg_fhandle(&args->file)
613 #endif
614
615         t = strstr (t, "fh2");  
616         RFS_ASSERT (t);                         
617         t += 4;                                         
618         memmove((char *)&args->link.dir, lookup_fhandle(t), sizeof (nfs_fh3));  
619         t+=65;
620
621         t = parse_name (t, Cur_filename);
622         args->link.name = Cur_filename;
623 }
624
625 void  setarg_readdir (int index, char * line, READDIR3args * args)
626 {
627         char * t;
628
629 #ifdef TRY_SETARG_FAST
630         memcpy (&args->dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
631         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
632         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
633 #else
634         setarg_fhandle(&args->dir);
635 #endif
636         /* args->cookieverf is notset, it is not implemented in the linux-2.4.7 */
637         sscanf(t, "cookie %d count %d", &args->cookie._p._l, &args->count);
638     (void) memset((char *) args->cookieverf, '\0', NFS3_COOKIEVERFSIZE);
639         args->cookie._p._u = (uint32_t) 0;
640 }
641
642 void  setarg_readdirplus (int index, char * line, READDIRPLUS3args * args)
643 {
644         char * t;
645
646 #ifdef TRY_SETARG_FAST
647         memcpy (&args->dir, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
648         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
649         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
650 #else
651         setarg_fhandle(&args->dir);
652 #endif
653         /* args->cookieverf is notset, it is not implemented in the linux-2.4.7 */
654         sscanf(t, "cookie %d count %d maxcnt", &args->cookie._p._l, &args->dircount, &args->maxcount);
655     (void) memset((char *) args->cookieverf, '\0', NFS3_COOKIEVERFSIZE);
656         args->cookie._p._u = (uint32_t) 0;
657
658 #ifdef notdef
659     /* set up the arguments */
660     (void) memmove((char *) &args.dir, (char *) &Cur_file_ptr->dir->fh3,
661                 sizeof (nfs_fh3));
662     args.cookie._p._l = args.cookie._p._u = (uint32_t) 0;
663     (void) memset((char *) args.cookieverf, '\0', NFS3_COOKIEVERFSIZE);
664         args.dircount = DEFAULT_MAX_BUFSIZE;
665         args.maxcount = DEFAULT_MAX_BUFSIZE;
666 #endif
667 }
668
669 void setarg_fsstat (int index, char * line, FSSTAT3args * args)
670 {
671         char * t;
672         setarg_fhandle(&args->fsroot);
673 }
674
675 void setarg_fsinfo (int index, char * line, FSINFO3args * args)
676 {
677         char * t;
678         setarg_fhandle(&args->fsroot);
679 }
680
681 void setarg_pathconf (int index, char * line, PATHCONF3args * args)
682 {
683         char * t;
684 #ifdef TRY_SETARG_FAST
685         memcpy (&args->object, &dep_tab[index].fh->play_fh, sizeof(nfs_fh3));
686         //t = dep_tab[index].trace_fh + TRACE_FH_SIZE+1;
687         t = strchr(dep_tab[index].trace_fh, ' '); t++; 
688 #else
689         setarg_fhandle(&args->object);
690 #endif
691 }
692
693 void setarg_commit (int index, char * line, COMMIT3args * args)
694 {
695         RFS_ASSERT (0);
696
697 #ifdef notdef
698         /* set up the arguments */
699         (void) memmove((char *) &args.file, (char *) &Cur_file_ptr->fh3,
700                    sizeof (nfs_fh3));
701         args.offset._p._u = args.offset._p._l = (uint32_t) 0;
702         args.count = Cur_file_ptr->attributes3.size._p._l;
703 #endif
704 }
705
706 void setbuf_void (char * buf)
707 {
708         return;
709 }
710
711 void setbuf_invalid (char * buf)
712 {
713         RFS_ASSERT (0);
714 }
715
716 void setres_lookup (LOOKUP3res * reply)
717 {
718 #ifndef TRY_SETRES_FAST
719     (void) memset((char *) &(reply->resok.object), '\0', sizeof (nfs_fh3));
720 #endif
721 }
722
723 void setres_readlink (READLINK3res * reply, char * sym_data)
724 {
725     /* Have lower layers fill in the data directly. */
726     reply->resok.data = sym_data;
727 }
728
729 void setres_read (READ3res * reply, char * buf)
730 {
731         /* Have lower layers fill in the data directly.  */
732         reply->resok.data.data_len = 0;
733         reply->resok.data.data_val = buf;
734 }
735
736 void setres_readdir (READDIR3res * reply, entry3 * entry_stream)
737 {
738 #ifndef TRY_SETRES_FAST
739     /* Have lower layers fill in the data directly.  */
740     (void) memset((char *) reply, '\0', sizeof (READDIR3res));
741     (void) memset((char *) entry_stream, '\0',
742                                         sizeof (entry3) * SFS_MAXDIRENTS);
743 #endif
744     reply->resok.count = SFS_MAXDIRENTS;
745     reply->resok.reply.entries = entry_stream;
746 }
747
748 void setres_readdirplus (READDIRPLUS3res * reply, entryplus3 * entry_stream)
749 {
750 #ifndef TRY_SETRES_FAST
751     (void) memset((char *) reply, '\0', sizeof (READDIRPLUS3res));
752         //printf ("sizeof(entryplus3) %d SFS_MAXDIRENT %d\n", sizeof (entryplus3), SFS_MAXDIRENTS);
753     (void) memset((char *) entry_stream, '\0',
754                                 sizeof (entryplus3) * SFS_MAXDIRENTS);
755 #endif
756     reply->resok.count = SFS_MAXDIRENTS;
757     reply->resok.reply.entries = entry_stream;
758 }
759
760 #define NFSPROC3_INVALID -1
761 /* the array is indexed by sfs operation number */
762 rfs_op_type rfs_Ops[TOTAL] = {
763 {NFSPROC3_NULL,         setbuf_void,            setbuf_void, xdr_void, xdr_void},
764 {NFSPROC3_GETATTR,      setarg_getattr,         setbuf_void, xdr_GETATTR3args, xdr_GETATTR3res},
765 {NFSPROC3_SETATTR,      setarg_setattr,         setbuf_void, xdr_SETATTR3args, xdr_SETATTR3res},
766 {NFSPROC3_INVALID,      setbuf_invalid,         setbuf_invalid, NULL, NULL},
767 {NFSPROC3_LOOKUP,       setarg_lookup,          setres_lookup, xdr_LOOKUP3args, xdr_LOOKUP3res},
768 {NFSPROC3_READLINK, setarg_readlink,    setres_readlink, xdr_READLINK3args, xdr_READLINK3res},
769 {NFSPROC3_READ,         setarg_read,            setres_read, xdr_READ3args, xdr_READ3res},
770 {NFSPROC3_INVALID,      setbuf_invalid,         setbuf_invalid, NULL, NULL},
771 {NFSPROC3_WRITE,        setarg_write,           setbuf_void, xdr_WRITE3args, xdr_WRITE3res},
772 {NFSPROC3_CREATE,       setarg_create,          setbuf_void, xdr_CREATE3args, xdr_CREATE3res},
773 {NFSPROC3_REMOVE,       setarg_remove,          setbuf_void, xdr_REMOVE3args, xdr_REMOVE3res},
774 {NFSPROC3_RENAME,       setarg_rename,          setbuf_void, xdr_RENAME3args, xdr_RENAME3res},
775 {NFSPROC3_LINK,         setarg_link,            setbuf_void, xdr_LINK3args, xdr_LINK3res},
776 {NFSPROC3_SYMLINK,      setarg_symlink,         setbuf_void, xdr_SYMLINK3args, xdr_SYMLINK3res},
777 {NFSPROC3_MKDIR,        setarg_mkdir,           setbuf_void, xdr_MKDIR3args, xdr_MKDIR3res},
778 {NFSPROC3_RMDIR,        setarg_rmdir,           setbuf_void, xdr_RMDIR3args, xdr_RMDIR3res},
779 {NFSPROC3_READDIR,      setarg_readdir,         setres_readdir, xdr_READDIR3args, xdr_READDIR3res},
780 {NFSPROC3_FSSTAT,       setarg_fsstat,          setbuf_void, xdr_FSSTAT3args, xdr_FSSTAT3res},
781 {NFSPROC3_ACCESS,       setarg_access,          setbuf_void, xdr_ACCESS3args, xdr_ACCESS3res},
782 {NFSPROC3_COMMIT,       setarg_commit,          setbuf_void, xdr_COMMIT3args, xdr_COMMIT3res},
783 {NFSPROC3_FSINFO,       setarg_fsinfo,          setbuf_void,  xdr_FSINFO3args, xdr_FSINFO3res},
784 {NFSPROC3_MKNOD,        setarg_mknod,           setbuf_void, xdr_MKNOD3args, xdr_MKNOD3res},
785 {NFSPROC3_PATHCONF, setarg_pathconf,    setbuf_void, xdr_PATHCONF3args, xdr_PATHCONF3res},
786 {NFSPROC3_READDIRPLUS, setarg_readdirplus, setres_readdirplus, xdr_READDIRPLUS3args, xdr_READDIRPLUS3res}};
787
788 /*
789  * --------------------  NFS ops vector --------------------
790  */
791 /*
792  * per operation information
793  */
794 sfs_op_type nfsv3_Ops[] = {
795
796 /* name        mix    op    call  no  req  req  req  results */
797 /*             pcnt  class  targ call pcnt cnt  targ         */
798
799  { "null",        0, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
800  { "getattr",    11, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
801  { "setattr",     1, Write,   0,  0,  0.0,  0,   0,  { 0, }},
802  { "root",        0, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
803  { "lookup",     27, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
804  { "readlink",    7, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
805  { "read",       18, Read,    0,  0,  0.0,  0,   0,  { 0, }},
806  { "wrcache",     0, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
807  { "write",       9, Write,   0,  0,  0.0,  0,   0,  { 0, }},
808  { "create",      1, Write,   0,  0,  0.0,  0,   0,  { 0, }},
809  { "remove",      1, Write,   0,  0,  0.0,  0,   0,  { 0, }},
810  { "rename",      0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
811  { "link",        0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
812  { "symlink",     0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
813  { "mkdir",       0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
814  { "rmdir",       0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
815  { "readdir",     2, Read,    0,  0,  0.0,  0,   0,  { 0, }},
816  { "fsstat",      1, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
817  { "access",      7, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
818  { "commit",      5, Write,   0,  0,  0.0,  0,   0,  { 0, }},
819  { "fsinfo",      1, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
820  { "mknod",       0, Write,   0,  0,  0.0,  0,   0,  { 0, }},
821  { "pathconf",    0, Lookup,  0,  0,  0.0,  0,   0,  { 0, }},
822  { "readdirplus", 9, Read,   0,  0,  0.0,  0,   0,  { 0, }},
823  { "TOTAL",     100, Lookup,  0,  0,  0.0,  0,   0,  { 0, }}
824 };
825
826 sfs_op_type *Ops;
827