Whamcloud - gitweb
b=11512
[fs/lustre-release.git] / libsysio / tests / sysio_stubs.c
1 #define _BSD_SOURCE
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <sys/uio.h>
10 #include <sys/mount.h>
11 #include <sys/stat.h>
12 #include <sys/statvfs.h>
13 #include <sys/queue.h>
14
15 #include "xtio.h"
16 #include "sysio.h"
17 #include "test_driver.h"
18
19 /*
20  * ################################################
21  * # Function stubs                               #
22  * #  These allow all of the different commands   #
23  * #  to be called with the same format           #
24  * ################################################
25  */
26
27 int test_do_setdebug(int argc, char **argv) 
28 {
29   int level;
30
31   if (argc != 1) {
32     DBG(2, fprintf(outfp, "Invalid number of args (%d) for setdebug\n",
33                    argc));
34     return INVALID_ARGS;
35   }
36
37   level = atoi(argv[0]);
38
39   if (level < 0) {
40     DBG(2, fprintf(outfp, "Invalid debug level %d\n", level));
41     return INVALID_ARGS;
42   }
43   
44   debug_level = level;
45   return SUCCESS;
46 }
47
48 int test_do_printline(int argc, char **argv) 
49 {
50   int on;
51
52   
53   if (argc != 1) {
54     DBG(2, fprintf(outfp, "Invalid number of args (%d) for printline\n",
55                    argc));
56     return INVALID_ARGS;
57   }
58
59   on = atoi(argv[0]);
60   if (on)
61     print_line = 1;
62   else
63     print_line = 0;
64
65   return SUCCESS;
66 }
67
68 /*
69 int test_do_setoutput(int argc, char **argv)
70 {
71   FILE *newfp;
72
73   if (argc != 1) {
74     fprintf(outfp, "Invalid number of args (%d) for setoutput\n",
75             argc);
76     return -1;
77   }
78
79   newfp = fopen(argv[0], "w");
80   if (!newfp) {
81     fprintf(outfp, "Unable to open new output file %s\n", argv[0]);
82     return -1;
83   }
84
85   outfp = newfp;
86
87   return 0;
88 }
89
90 */
91
92
93 int test_do_fillbuff(int argc, char **argv) 
94 {
95   char *typestr, *buf;
96   void *valptr;
97   int size, type, index, offset;
98
99   if (argc != 5) {
100     DBG(2, 
101         fprintf(outfp, 
102                 "fillbuff requires a value, a type, a size, an offset, and the target buffer\n"));
103     fprintf(stderr, "fillbuff requires 5 args, you gave %d\n", argc);
104     return INVALID_ARGS;
105   }
106
107   offset = get_obj(argv[3]);
108   if (offset < 0) {
109     DBG(2, fprintf(outfp, "Do not understand offset %s\n", argv[3]));
110     return INVALID_VAR;
111   }
112
113   index = get_obj(argv[4]);
114   if (index < 0) {
115     DBG(2, fprintf(outfp, "Can't find buffer at %s\n", argv[4]));
116     return INVALID_VAR;
117   }
118   buf = (char *)(buflist[index]->buf)+offset;
119
120   DBG(4, fprintf(outfp, "Buffer start is at %p\n", (void *)buflist[index]));
121
122   typestr = argv[1];
123   size = get_obj(argv[2]);
124   if (size < 0) {
125     DBG(2, fprintf(outfp, "Unable to understand size %s\n", argv[2]));
126     return INVALID_VAR;
127   }
128   
129   if ( (!strcmp(typestr, "UINT")) || (!strcmp(typestr, "SINT")) ){
130     int val = get_obj(argv[0]);
131     valptr = &val;
132     type = UINT;
133     if (val < 0) { /* FIX THIS */
134       DBG(2, fprintf(outfp, "Can't understand value %s\n", argv[0]));
135       return INVALID_VAR;
136     }
137     DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %x\n",
138                    size, buf, *((int *)valptr)));
139     memcpy(buf, valptr, size);
140          
141   } else if (!strcmp(typestr,"STR")) {
142     type = STR;
143     valptr = argv[0];
144     DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %s\n",
145                    size, buf, (char *)valptr));
146     memcpy(buf, valptr, size);
147   } else if (!strcmp(typestr, "PTR")) {
148     unsigned long val;
149     int index = get_obj(argv[0]);
150     if (index < 0) {
151       DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[0]));
152       return INVALID_VAR;
153     }
154     
155     val = (unsigned long)buflist[index]->buf;
156     valptr = &val;
157     DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %p\n",
158                    size, buf, valptr));
159     memcpy(buf, valptr, size);
160   } else {
161     DBG(2, fprintf(outfp, "Unknown type %s.  Valid types are UINT, STR, and PTR\n", 
162                    typestr));
163     fprintf(stderr, "Unknown type %s.  Valid types are UINT, STR, and PTR\n", 
164                    typestr);
165     return INVALID_ARGS;
166   }
167  
168   return SUCCESS;
169 }
170     
171
172 #define STR_TYPE       1
173 #define INT_TYPE       2
174 #define SHORT_TYPE     3
175 #define CHAR_TYPE      4
176 #define LONG_TYPE      5
177
178 void print_partial(char *buf, int offset, int len, int type)
179 {
180   int i;
181
182   if (type == STR_TYPE) {
183     sprintf(output, "%s%s", output, (char *)(buf+offset));
184     DBG(4, fprintf(outfp, "Printing str %s\n", (char *)(buf+offset)));
185   } else {
186     if (type == SHORT_TYPE) {
187       for (i = 0; i < len; i+= 2) {
188         short *ibuf = (short *)(buf + offset + i);
189         sprintf(output, "%s%#04x ", output, *ibuf);
190         DBG(4, fprintf(outfp, "Printing short %#04x\n", *ibuf));
191       }
192     } else if (type == CHAR_TYPE) {
193       for (i = 0; i < len; i++) {
194         short *ibuf = (short *)(buf+offset+i);
195         sprintf(output, "%s%#02x ", output, (*ibuf & 0x00ff));
196         DBG(4, fprintf(outfp, "Printing char %c\n", (*ibuf & 0x00ff)));
197       }
198     } else if (type == INT_TYPE) {
199       for (i = 0; i < len; i+= 4) {
200         int *ibuf = (int *)(buf + offset + i);
201         sprintf(output, "%s%#08x ", output, *ibuf);
202         DBG(4, fprintf(outfp, "Printing int %#08x\n", *ibuf));
203       }
204     } else {
205       for (i = 0; i < len; i += 8) {
206         unsigned long *lbuf = (unsigned long *)(buf + offset +i);
207         sprintf(output, "%s%#08lx ", output, *lbuf);
208         DBG(4, fprintf(outfp, "Printing int %#016lx\n", *lbuf));
209       }
210     } 
211   }
212 }
213       
214 int test_do_printbuf(int argc, char **argv)
215 {
216   int index, i, type, offset, len;
217   struct buf_t *buf_st;
218   void *buf;
219   char *typestr;
220   struct var_mapping *mobj;
221
222   if (argv[0][0] == '$') {
223     if (argv[0][1] == '$') {
224       sprintf(output, "\n%#010x", (unsigned int)last_ret_val);
225       return SUCCESS;
226     } else if (!strcmp("errno", &argv[0][1])) {
227       sprintf(output, "\n%#010x", my_errno);
228       return SUCCESS;
229     }
230   }
231
232   mobj = get_map(argv[0]);
233   if (mobj == NULL) {
234     DBG(2, fprintf(outfp, "Can't get var at %s\n", argv[0]));
235     return INVALID_VAR;
236   }
237
238   if (mobj->type == UINT)
239     sprintf(output, "\n%#010x", mobj->obj);
240   else if (mobj->type == SINT)
241     sprintf(output, "%d", mobj->obj);
242   else if ((mobj->type == STR) || (mobj->type == PTR)) {
243     index = mobj->obj;
244
245     buf_st = buflist[index];
246     DBG(2, fprintf(outfp, "buf_st is %p:\n", (void *)buf_st));
247     buf = buf_st->buf;
248     DBG(2, fprintf(outfp, "buf %s:\n", argv[0]));
249     if (mobj->type == STR) {
250       sprintf(output, "\n%s", (char *)buf);
251      } else {
252        sprintf(output,"%s\n", output);
253        DBG(2, fprintf(outfp, "buf_st->len is %d, buf is %p\n", buf_st->len, buf));
254        if (argc == 1) {
255          for (i = 0; i < buf_st->len/4; i++) 
256            DBG(2, fprintf(outfp, "%#x ", ((int *)buf)[i]));
257            sprintf(output, "%s%#x ", output, ((int *)buf)[i]);
258          
259        }
260
261        for (i = 1; i < argc; i++) {
262          offset = get_obj(argv[i++]);
263          len = get_obj(argv[i++]);
264          if ((offset < 0) || (len < 0)) {
265            DBG(2, fprintf(outfp, "Invalid offset (%s) or len (%s)\n",
266                           argv[i-2], argv[i-1]));
267            return INVALID_VAR;
268          }
269          typestr = argv[i];
270          if (!strcmp("STR", typestr))
271            type = STR_TYPE;
272          else if (!strcmp("INT", typestr))
273            type = INT_TYPE;
274          else if (!strcmp("SHORT", typestr))
275            type = SHORT_TYPE;
276          else if (!strcmp("CHAR", typestr))
277            type = CHAR_TYPE;
278          else if (!strcmp("LONG", typestr))
279            type = LONG_TYPE;
280          else {
281            DBG(2, fprintf(outfp, "Unable to understand type %s\n",
282                           typestr));
283            return INVALID_ARGS;
284          }
285          print_partial(buf, offset, len, type);
286        }
287      }
288   }
289   DBG(3, fprintf(outfp, "output: %s \n", output));
290   return SUCCESS;
291 }
292
293 int test_do_mount(int argc, char **argv) 
294 {
295   if (argc != 2) {
296     DBG(2, fprintf(outfp, "Invalid number of args (%d) for test_do_mount\n",
297                    argc));
298     return INVALID_ARGS;
299   }
300
301   DBG(4, fprintf(outfp, "Calling mount with from %s and to %s\n",
302                  argv[0], argv[1]));
303   last_ret_val = sysio_mount(argv[0], argv[1]);
304   my_errno = errno;
305   last_type = SINT;
306   return SUCCESS;
307 }
308
309 int test_do_clear(int argc, char **argv) 
310 {
311   int index;
312   struct buf_t *buf;
313
314   if (argc != 1) {
315     DBG(2, fprintf(outfp, "Invalid number of args (%d) for clear\n",
316                    argc));
317     return INVALID_ARGS;
318   }
319   index = get_obj(argv[0]);
320   if (index < 0) {
321     fprintf(outfp, "Unable to locate buffer %s\n",
322            argv[0]);
323     return -1;
324   }
325   buf = buflist[index];
326   bzero(buf->buf, buf->len);
327
328   return SUCCESS;
329 }
330
331 int test_do_list(int argc, char **argv) 
332 {
333   char *buf;
334
335   if ((argc) && (argc != 1)) {
336     DBG(2, fprintf(outfp, "Invalid number of args (%d) for list\n",
337                    argc));
338     return INVALID_ARGS;
339   }
340
341   DBG(5,fprintf(outfp, "In test_do_list with args %p\n", (void *)argv));
342   if (!argv) {
343     buf = getcwd(NULL, 0);
344     DBG(4, fprintf(outfp, "Calling list with dir of %s\n", buf));
345     last_ret_val =  sysio_list(buf);
346     my_errno = errno;
347     free(buf);
348     return SUCCESS;
349   } 
350     
351   last_type = SINT;
352   return sysio_list(*argv);
353 }
354
355 /*
356  * Initlizes sysio library.  Will use default initlization
357  * unless arguments are given
358  */
359 int test_do_init(int argc, char **argv) 
360 {
361   if (argc > 0) {
362     char *rdriver;
363     char *mpath;
364     int mflags, rsize, msize;
365     if (argc != 3) {
366       DBG(2, fprintf(outfp, "Invalid number of args (%d) for init\n",
367                      argc));
368       return INVALID_ARGS;
369     } 
370
371     rdriver = get_str(argv[0]);
372     rsize = strlen(rdriver)+1;
373     if (rsize > 75) {
374       DBG(2, fprintf(outfp, "%s too long for root driver\n", rdriver));
375       return INVALID_ARGS;
376     }
377     bzero(root_driver, 75);
378     memcpy(root_driver, rdriver, rsize);
379     
380     mpath = get_str(argv[1]);
381     msize = strlen(mpath)+1;
382     if (msize > 250) {
383       DBG(2, fprintf(outfp, "%s too long for mount path\n", mpath));
384       return INVALID_ARGS;
385     }
386     bzero(mntpath, 250);
387     memcpy(mntpath, mpath, msize);
388     
389     mflags = get_obj(argv[2]);
390     if (mflags == -1) {
391       DBG(2, fprintf(outfp, "Invalid flags argument %s\n", argv[2]));
392       return INVALID_ARGS;
393     } 
394   }
395   
396   DBG(5, fprintf(outfp, "In test_do_init\n"));
397   last_type = SINT;
398   DBG(3, fprintf(outfp, "initializing\n"));
399   return initilize_sysio();
400 }
401
402
403 /*
404  * Returns 1 if the machine is big-endian, 0
405  * otherwise
406  */
407 int get_endian(int argc, char **argv) 
408 {
409   int x = 1;
410   
411   if ((argc) || (argv)) {
412     DBG(2, fprintf(outfp, "Expected no args for test_do_endian\n"));
413     return INVALID_ARGS;
414   }
415
416   if(*(char *)&x == 1) {
417     /* little-endian, return 0 */
418     last_ret_val= 0;
419   } else {
420     /* big endian, return 1 */
421     last_ret_val= 1;
422   }
423   last_type = UINT;
424   return SUCCESS;
425 }
426
427 int do_setbuf(int argc, char **argv)
428 {
429         int val, size, index, offset;
430         void *buf;
431
432         if (argc != 4) {
433                 DBG(2, fprintf(outfp, "Need val, size, buffer, and offset for setbuf\n"));
434                 return INVALID_ARGS;
435         }
436         val = get_obj(argv[0]);
437         if (val < 0) {
438                 DBG(2, fprintf(outfp, "Unable to understand val of %s\n",
439                                                                          argv[0]));
440                 return INVALID_VAR;
441         }
442
443         size = get_obj(argv[1]);
444         if( size <=0 ) {
445                 DBG(2, fprintf(outfp, "Size of %s is invalid\n", argv[1]));
446                 return INVALID_VAR;
447         }
448
449   index = get_obj(argv[2]);
450   if (index < 0) {
451     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
452                    argv[2]));
453     return INVALID_VAR;
454   }
455
456   buf = buflist[index]->buf;
457
458         offset = get_obj(argv[3]);
459         
460         if (offset < 0) {
461     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3]));
462     return INVALID_ARGS;
463   }
464         
465         buf = (void *)((char *)buf +offset);
466
467         memset(buf, val, size);
468
469         return SUCCESS;
470 }
471
472                                 
473 int get_sizeof(int argc, char **argv) 
474 {
475   char *type;
476   int size;
477
478   if (argc != 1) {
479     DBG(2, fprintf(outfp, "Number of args (%d) invalid for sizeof\n",
480                    argc));
481     return INVALID_ARGS;
482   }
483
484   type = argv[0];
485
486   if (!strcmp(type, "char")) 
487     size =  sizeof(char);
488   else if (!strcmp(type, "int"))
489     size =  sizeof(int);
490   else if (!strcmp(type, "long"))
491     size =  sizeof(long);
492   else if (!strcmp(type, "flock"))
493     size =  sizeof(struct flock);
494   else if (!strcmp(type, "stat"))
495     size =  sizeof(struct stat);
496   else if (!strcmp(type, "statvfs"))
497     size =  sizeof(struct statvfs);
498   else if (!strcmp(type, "iovec"))
499     size =  sizeof(struct iovec);
500  else if (!strcmp(type, "xtvec"))
501     size =  sizeof(struct xtvec);
502   else
503     return INVALID_ARGS;
504
505   DBG(2, fprintf(outfp, "Size is %d\n", size));
506
507   last_type = UINT;
508   last_ret_val = size;
509   return SUCCESS;
510 }
511
512 int test_do_exit(int argc, char **argv) 
513 {
514   int val = 0;
515
516   if (argc) {
517     /* 
518      * If argc is given, need to return the value of
519      * the passed in variable 
520      */
521     val = get_obj(argv[0]);
522   }
523     
524   /*
525    * Clean up.
526    */
527   _sysio_shutdown();
528
529   if (argc)
530     DBG(3, printf("Exiting with %d from %s\n", val, argv[0]));
531
532   exit(val);
533
534   return 0;
535 }
536
537 int get_buffer(int argc, char **argv) 
538 {
539   int size, align;
540   struct buf_t *buf;
541
542   if (argc == 1) /* Just put size, not alignment */
543     align = 16;
544   else if (argc == 2)
545     align = get_obj(argv[1]);
546   else {
547     DBG(2, fprintf(outfp, "Number of args (%d) invalid for alloc\n",
548                    argc));
549     return INVALID_ARGS;
550   }
551     
552   size = get_obj(argv[0]);
553   if (size < 0) {
554     DBG(2, fprintf(outfp, "Invalid size %s\n", argv[0]));
555     return INVALID_ARGS;
556   }
557
558   DBG(3, fprintf(outfp, "Getting buffer of size %d and aligned at %d\n",
559                  size, align));
560   buf = (struct buf_t *)malloc(sizeof(struct buf_t));
561   buf->buf = alloc_buff32(size, align);
562   buf->len = size;
563   buflist[next] = buf;
564   DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n",
565                  (void *)buf, buf->buf, next));
566   next++;
567
568   last_type = PTR;
569   last_ret_val = next-1;
570   return SUCCESS;
571 }
572
573 int free_buffer(int argc, char **argv) 
574 {
575   int index;
576   char *name = argv[0];
577   
578   if (argc != 1) {
579     DBG(2, fprintf(outfp, "Number of args (%d) invalid for free\n",
580                    argc));
581     return INVALID_ARGS;
582   }
583
584   /* 
585    * Assume that there is one arg and it 
586    * is a variable name which maps to an
587    * index into the buffer array 
588    */  
589    index = get_obj(name);
590    if (index < 0) {
591      DBG(2, fprintf(outfp, "Can't find buffer %s\n",
592                     name));
593      return INVALID_VAR;
594    }
595    DBG(4, fprintf(outfp, "Freeing buffer at index %d\n", index));
596    free(buflist[index]);
597
598    free_obj(name);
599    return SUCCESS;
600 }
601
602 int cmp_bufs(int argc, char **argv) 
603 {
604   int res, index1, index2;
605   char *buf1, *buf2;
606
607   if (argc != 2) {
608     fprintf(outfp, "Need two buffers to compare\n");
609     return INVALID_ARGS;
610   } 
611
612   index1 = get_obj(argv[0]);
613   if (index1 < 0) {
614     fprintf(outfp, "Unable to locate buffer %s\n",
615            argv[0]);
616     return INVALID_VAR;
617   }
618   buf1 = buflist[index1]->buf;
619
620   index2 = get_obj(argv[1]);
621   if (index2 < 0) {
622     fprintf(outfp, "Unable to locate buffer %s\n",
623            argv[1]);
624     return INVALID_VAR;
625   }
626
627   buf2 = buflist[index2]->buf;
628   last_ret_val = strcmp(buf1, buf2);
629
630   DBG(3, fprintf(outfp, "strcmp returned %d\n", res));
631   return SUCCESS;
632 }
633
634 int test_do_chdir(int argc, char **argv) 
635 {
636   if (argc != 1) {
637     DBG(2, fprintf(outfp, "Number of args (%d) invalid for chdir\n",
638                    argc));
639     return INVALID_ARGS;
640   }
641   last_type = SINT;
642   return sysio_chdir(argv[0]);
643 }
644
645
646 int test_do_chmod(int argc, char **argv) 
647 {
648   if (argc != 2) {
649     DBG(2, fprintf(outfp, "Number of args (%d) invalid for chmod\n",
650                    argc));
651     return INVALID_ARGS;
652   }
653   last_type = SINT;
654   return sysio_chmod(argv[0], argv[1]);
655 }
656
657 int test_do_chown(int argc, char **argv) 
658 {
659   if (argc != 2) {
660     DBG(2, fprintf(outfp, "Number of args (%d) invalid for chown\n",
661                    argc));
662     return INVALID_ARGS;
663   }
664   last_type = SINT;
665   return sysio_chown(argv[0], argv[1]);
666 }
667
668 int test_do_open(int argc, char **argv) 
669
670   char *name = argv[0];
671   int flags = O_RDWR;
672
673   if (argc > 1) 
674     flags = get_obj(argv[1]);
675
676   if (name[0] == '$') {
677     int index = get_obj(name);
678
679     if (index < 0) {
680       DBG(2, fprintf(outfp, "Unable to find buffer at %s\n",
681                      name));
682       return INVALID_VAR;
683     }
684
685     name = buflist[index]->buf;
686   }
687
688   DBG(4,  fprintf(outfp, "Opening file %s with flags %d\n", name, flags));
689   if (argc == 2)
690     return sysio_open(name, flags);
691   else if (argc == 3)
692     return sysio_open3(name, flags, argv[2]);
693   else {
694     DBG(2, fprintf(outfp, "Invalid number of arguments (%d)\n", argc));
695     return INVALID_ARGS;
696   }
697   last_type = UINT;
698   return SUCCESS;
699 }
700
701 int test_do_close(int argc, char **argv) 
702 {
703   int fd;
704   char *name = argv[0];
705
706   if (argc != 1) {
707     DBG(2, fprintf(outfp, "Number of args (%d) invalid for close\n",
708                    argc));
709     return INVALID_ARGS;
710   }
711
712   /* 
713    * Assume that there is one arg and it 
714    * is a variable name which maps to a file
715    * descriptor 
716    */
717   fd = get_obj(name);
718   if (fd < 0) {
719     DBG(2, fprintf(outfp, "Unable to map var %s to anything\n", name));
720     return INVALID_VAR;
721   }
722   sysio_close(fd);
723   free_obj(name);
724   return SUCCESS;
725 }
726
727 int test_do_dup(int argc, char **argv) 
728 {
729   int fd;
730   char *var_name = argv[0];
731
732   if (argc != 1) {
733     DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup\n",
734                    argc));
735     return INVALID_ARGS;
736   }
737
738
739   fd = get_obj(var_name);
740   if (fd < 0) {
741     DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name));
742     return INVALID_VAR;
743   }
744
745   last_ret_val = dup(fd);
746   my_errno = errno;
747   last_type = SINT;
748
749   return SUCCESS;
750 }
751
752 int test_do_dup2(int argc, char **argv) 
753 {
754   int fd1, fd2;
755   char *var_name1 = argv[0];
756   char *var_name2 = argv[1];
757
758   if (argc != 2) {
759     DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup2\n",
760                    argc));
761     return INVALID_ARGS;
762   }
763
764   fd1 = get_obj(var_name1);
765   if (fd1 < 0) {
766     DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name1));
767     return INVALID_VAR;
768   }
769
770   fd2 = get_obj(var_name2);
771   if (fd2 < 0) {
772     DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name2));
773     return INVALID_VAR;
774   }
775
776   last_ret_val = dup2(fd1, fd2);
777   my_errno = errno;
778   last_type = SINT;
779
780   return SUCCESS;
781 }
782
783 struct cmd_map fcntl_cmds[] = {
784   { "F_DUPFD", F_DUPFD, 3 },
785   { "F_GETFD", F_GETFD, 2 },
786   { "F_SETFD", F_SETFD, 3 },
787   { "F_GETFL", F_GETFL, 2 },
788   { "F_SETFL", F_SETFL, 3 },
789   { "F_SETLK", F_SETLK, 3 },
790   { "F_SETLKW", F_SETLKW, 3 },
791   { "F_GETLK", F_GETLK, 3 },
792 #if defined __USE_BSD || defined __USE_XOPEN2K
793   { "F_GETOWN", F_GETOWN, 2 },
794   { "F_SETOWN", F_SETOWN, 3 },
795 #endif
796 #ifdef __USE_GNU
797   { "F_GETSIG", F_GETSIG, 2 },
798   { "F_SETSIG", F_SETSIG, 3 },
799   { "F_SETLEASE", F_SETLEASE, 3},
800   { "F_GETLEASE", F_GETLEASE, 2},
801   { "F_NOTIFY", F_NOTIFY, 3} ,
802 #endif
803   { NULL, -1, 0 }
804 };
805
806 struct cmd_map* get_cmd(char *cmd_name, int argc)
807 {
808   int i =0;
809
810   while (fcntl_cmds[i].cmd_name) {
811     if (!strcmp(fcntl_cmds[i].cmd_name, cmd_name)) {
812       if (fcntl_cmds[i].num_args == argc)
813         return &fcntl_cmds[i];
814       else
815         return NULL;
816     }
817     i++;
818   }
819   return NULL;
820 }
821
822 int test_do_fcntl(int argc, char **argv)
823 {
824   
825   struct cmd_map *cmd;
826   int fd;
827
828   /* 
829    * get_cmd translates a symbolic command into
830    * into its numerical equivalent. It also
831    * verifies that the number of args is the
832    * correct number for the command. It returns
833    * NULL on failure
834    */
835   cmd = get_cmd(argv[1], argc);
836   if (!cmd) {
837     DBG(2, fprintf(outfp, "Unable to get command %s\n", argv[1]));
838     return INVALID_ARGS;
839   }
840
841   fd = get_obj(argv[0]);
842   if (fd < 0) {
843     DBG(2, fprintf(outfp, "Unable to map %s to file descriptor \n", argv[0]));
844     return INVALID_VAR;
845   }
846
847   if (argc > 2)
848     last_ret_val =  sysio_fcntl(fd, cmd, argv[2]);
849   else
850     last_ret_val = sysio_fcntl(fd, cmd, NULL);
851   DBG(4, fprintf(outfp, "Got return value of %d\n", (int)last_ret_val));
852   my_errno = errno;
853   last_type = SINT;
854
855   return SUCCESS;
856 }
857
858 int test_do_fstat(int argc, char **argv)
859 {
860   int fd, index;
861   void *buf;
862
863   if (argc != 2) {
864     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for fstat\n",
865                    argc));
866     return INVALID_ARGS;
867   }
868
869   fd = get_obj(argv[0]);
870
871   if (fd < 0) {
872     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
873                    argv[0]));
874     return INVALID_VAR;
875   }
876
877   index = get_obj(argv[1]);
878   if (index < 0) {
879     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
880                    argv[1]));
881     return INVALID_VAR;
882   }
883   
884   buf = buflist[index]->buf;
885   
886   last_ret_val = sysio_fstat(fd, buf);
887   my_errno = errno;
888   last_type = SINT;
889   
890   return SUCCESS;
891 }
892
893 int test_do_lstat(int argc, char **argv)
894 {
895   char *name = argv[0];
896   int index;
897   void *buf;
898
899   if (argc != 2) {
900     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for lstat\n",
901                    argc));
902     return INVALID_ARGS;
903   }
904
905   index = get_obj(argv[1]);
906   if (index < 0) {
907     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
908                    argv[1]));
909     return INVALID_VAR;
910   }
911   
912   buf = buflist[index]->buf;
913   last_type = SINT;  
914
915   return sysio_lstat(name, buf);
916 }
917
918 int test_do_fsync(int argc, char **argv)
919 {
920   int fd;
921
922   if (argc != 1) {
923     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fsync\n", argc));
924     return INVALID_ARGS;
925   }
926
927   
928   fd = get_obj(argv[0]);
929
930   if (fd < 0) {
931     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
932                    argv[0]));
933     return INVALID_VAR;
934   }
935
936   last_ret_val = fsync(fd);
937   my_errno = errno;
938   last_type = SINT;  
939
940   return SUCCESS;
941 }
942
943
944 int test_do_fdatasync(int argc, char **argv)
945 {
946   int fd;
947
948   if (argc != 1) {
949     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fdatasync\n", argc));
950     return INVALID_ARGS;
951   }
952
953   
954   fd = get_obj(argv[0]);
955
956   if (fd < 0) {
957     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
958                    argv[0]));
959     return INVALID_VAR;
960   }
961
962   last_ret_val = fdatasync(fd);
963   my_errno = errno;
964   last_type = SINT;
965
966   return SUCCESS;
967 }
968
969
970 int test_do_ftruncate(int argc, char **argv)
971 {
972   int fd;
973   off_t length;
974
975   if (argc != 2) {
976     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ftruncate\n", argc));
977     return INVALID_ARGS;
978   }
979
980   
981   fd = get_obj(argv[0]);
982
983   if (fd < 0) {
984     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
985                    argv[0]));
986     return INVALID_VAR;
987   }
988
989   length = (off_t)get_obj(argv[1]);
990
991   DBG(3, fprintf(outfp, "Setting file %d to %d\n", fd, (int) length));
992
993   last_ret_val = ftruncate(fd, length);
994   my_errno = errno;
995   last_type = SINT;
996
997   return SUCCESS;
998 }
999
1000 int test_do_getcwd(int argc, char **argv)
1001 {
1002   char *buf;
1003   int size, index;
1004
1005   if (argc != 2) {
1006     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getcwd\n", argc));
1007     return INVALID_ARGS;
1008   }
1009
1010   index = get_obj(argv[0]);
1011   if (index < 0) {
1012     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1013                    argv[1]));
1014     return INVALID_VAR;
1015   }
1016
1017   buf = buflist[index]->buf;
1018
1019   size = get_obj(argv[1]);
1020
1021   DBG(4, fprintf(outfp, "Getting cwd with buffer size of %d\n", size));
1022
1023   last_ret_val = 0;
1024   if (!getcwd(buf, size)) {
1025       last_ret_val = -1;
1026       if (errno == ERANGE) {
1027           DBG(2, fprintf(outfp, "Need a bigger buffer!\n"));
1028       }
1029   }
1030  
1031   my_errno = errno;
1032
1033   
1034   DBG(3, fprintf(outfp, "cwd: %s\n", buf));
1035   last_type = SINT;
1036
1037   return SUCCESS;
1038 }
1039
1040 int test_do_lseek(int argc, char **argv)
1041 {
1042   int fd, whence;
1043   off_t offset;
1044
1045   
1046   if (argc != 3) {
1047     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to lseek\n", argc));
1048     return INVALID_ARGS;
1049   }
1050
1051   
1052   fd = get_obj(argv[0]);
1053
1054   if (fd < 0) {
1055     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1056                    argv[0]));
1057     return INVALID_VAR;
1058   }
1059
1060   offset = (off_t)get_obj(argv[1]);
1061   whence = get_obj(argv[2]);
1062
1063   if (whence < 0 ) {
1064     DBG(2, fprintf(outfp, "Not familiar with whence of %s\n",
1065                    argv[2]));
1066     return INVALID_ARGS;
1067   }
1068
1069   last_ret_val = lseek(fd, offset, whence);
1070   my_errno = errno;
1071   last_type = SINT;
1072
1073   return SUCCESS;
1074 }
1075
1076 int test_do_getdirentries(int argc, char **argv) 
1077 {
1078   int fd, nbytes;
1079   int bufindex;
1080   off_t basep;
1081   char *buf;
1082   struct var_mapping *base_map;
1083
1084   if (argc != 4) {
1085     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getdirentries\n", argc));
1086     return INVALID_ARGS;
1087   }
1088
1089   fd = get_obj(argv[0]);
1090
1091   if (fd < 0) {
1092     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1093                    argv[0]));
1094     return INVALID_VAR;
1095   }
1096
1097   bufindex = get_obj(argv[1]);
1098    
1099   if (bufindex < 0) {
1100     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1101                    argv[1]));
1102     return INVALID_VAR;
1103   }
1104
1105   buf = buflist[bufindex]->buf;
1106
1107   nbytes = get_obj(argv[2]);
1108
1109   if (nbytes < 0) {
1110     DBG(2, fprintf(outfp, "I don't understand %s\n",
1111                    argv[2]));
1112     return INVALID_ARGS;
1113   }
1114
1115   base_map = get_map(argv[3]);
1116   if (!base_map) {
1117     DBG(3, fprintf(outfp, "Resetting basep\n"));
1118     /* 
1119      * Assume that this is the first getdirentries call
1120      * and we need to setup the base pointer
1121      */
1122     basep = 0;
1123   } else 
1124     basep = base_map->obj;
1125       
1126   DBG(3, fprintf(outfp, "basep is (starting) %d\n", (int) basep));
1127   last_ret_val = sysio_getdirentries(fd, buf, nbytes, &basep);
1128   if (base_map)
1129     base_map->obj = basep;
1130   else
1131     store_result(argv[3]+1, basep);
1132   DBG(3, fprintf(outfp, "basep is (ending) %d\n", (int) basep));
1133   my_errno = errno;
1134   last_type = SINT;
1135
1136   return SUCCESS;
1137 }
1138
1139 int test_do_mkdir(int argc, char **argv)
1140 {
1141   if (argc !=2) {
1142     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to mkdir\n", argc));
1143     return INVALID_ARGS;
1144   }
1145
1146   last_type = SINT;
1147   return sysio_mkdir(argv[0], argv[1]);
1148 }
1149
1150 int test_do_creat(int argc, char **argv)
1151 {
1152   if (argc !=2) {
1153     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to creat\n", argc));
1154     return INVALID_ARGS;
1155   }
1156
1157   last_type = UINT;
1158   return sysio_creat(argv[0], argv[1]);
1159 }
1160
1161 int test_do_stat(int argc, char **argv)
1162 {
1163   int index;
1164   void *buf;
1165   char *str;
1166
1167   if (argc != 2) {
1168     fprintf(outfp, "Invalid number of arguments (%d) for stat\n",
1169            argc);
1170     return -1;
1171   }
1172
1173
1174   index = get_obj(argv[1]);
1175   if (index < 0) {
1176     fprintf(outfp, "Unable to find buffer assocated with %s\n",
1177            argv[1]);
1178   }
1179   
1180   buf = buflist[index]->buf;
1181   last_type = SINT;
1182   
1183   str = get_str(argv[0]);
1184   return sysio_stat(str, buf);
1185 }
1186
1187 int test_do_statvfs(int argc, char **argv)
1188 {
1189   int index;
1190   void *buf;
1191
1192   if (argc != 2) {
1193     fprintf(outfp, "Invalid number of arguments (%d) for statvfs\n",
1194            argc);
1195     return -1;
1196   }
1197
1198
1199   index = get_obj(argv[1]);
1200   if (index < 0) {
1201     fprintf(outfp, "Unable to find buffer assocated with %s\n",
1202            argv[1]);
1203   }
1204   
1205   buf = buflist[index]->buf;
1206   last_type = SINT;
1207   
1208   return sysio_statvfs(argv[0], buf);
1209 }
1210
1211 int test_do_fstatvfs(int argc, char **argv)
1212 {
1213   int index, fd;
1214   void *buf;
1215
1216   if (argc != 2) {
1217     fprintf(outfp, "Invalid number of arguments (%d) for fstatvfs\n",
1218            argc);
1219     return -1;
1220   }
1221
1222   
1223   fd = get_obj(argv[0]);
1224
1225   if (fd < 0) {
1226     fprintf(outfp, "Unable to find file assocated with %s\n",
1227            argv[0]);
1228   }
1229
1230
1231   index = get_obj(argv[1]);
1232   if (index < 0) {
1233     fprintf(outfp, "Unable to find buffer assocated with %s\n",
1234            argv[1]);
1235   }
1236   
1237   buf = buflist[index]->buf;
1238   last_type = SINT;
1239   
1240   return sysio_fstatvfs(fd, buf);
1241 }
1242
1243 int test_do_truncate(int argc, char **argv)
1244 {
1245   off_t length;
1246
1247   if (argc != 2) {
1248     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to truncate\n", argc));
1249     return INVALID_ARGS;
1250   }
1251   
1252   length = (off_t)get_obj(argv[1]);
1253
1254   DBG(3, fprintf(outfp, "Setting file %s to %d\n", argv[0], (int) length));
1255
1256   last_ret_val = truncate(argv[0], length);
1257   my_errno = errno;
1258   last_type = SINT;
1259
1260   return SUCCESS;
1261 }
1262
1263 int test_do_rmdir(int argc, char **argv)
1264 {
1265
1266   if (argc != 1) {
1267     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to rmdir\n", argc));
1268     return INVALID_ARGS;
1269   }
1270
1271   DBG(3, fprintf(outfp, "Removing dir %s\n", argv[0]));
1272
1273   last_ret_val = rmdir(argv[0]);
1274   my_errno = errno;
1275   last_type = SINT;
1276
1277   return SUCCESS;
1278 }
1279
1280 int test_do_symlink(int argc, char **argv)
1281 {
1282   if (argc != 2) {
1283     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to symlink\n", argc));
1284     return INVALID_ARGS;
1285   }
1286
1287   DBG(3, fprintf(outfp, "Linking %s to %s\n", argv[0], argv[1]));
1288
1289   last_ret_val = symlink(argv[0], argv[1]);
1290   if (last_ret_val) {
1291     if (errno < 0) 
1292       errno = errno*-1;
1293     my_perror("symlink");
1294   } 
1295   my_errno = errno;
1296   last_type = SINT;
1297
1298   return SUCCESS;
1299 }
1300
1301
1302 struct cmd_map ioctl_cmds[] = {
1303 #if 0
1304   { "BLKROSET", BLKROSET, 3 },
1305   { "BLKROGET", BLKROGET, 3 },
1306   { "BLKRRPART", BLKRRPART, 3 },
1307   { "BLKGETSIZE", BLKGETSIZE, 3 },
1308   { "BLKRASET", BLKRASET, 3 },
1309   { "BLKRAGET", BLKRAGET, 3 },
1310   { "BLKSECTSET", BLKSECTSET, 3 },
1311   { "BLKSECTGET", BLKSECTGET, 3 },
1312   { "BLKSSZGET", BLKSSZGET, 3 },
1313   { "BLKGETLASTSECT", BLKGETLASTSECT, 3 },
1314   { "BLKSETLASTSECT", BLKSETLASTSECT, 3 },
1315   { "BLKBSZGET", BLKBSZGET, 3 },
1316   { "BLKBSZSET", BLKBSZSET, 3 },
1317   { "FIBMAP", FIBMAP, 3 },
1318   { "FIGETBSZ", FIGETBSZ, 3},
1319 #endif
1320   { NULL, -1, 0 }
1321 };
1322
1323 int get_ioctl_cmd(char *cmd) 
1324 {
1325   int i = 0;
1326
1327   while (ioctl_cmds[i].cmd_name != NULL) {
1328     if (strcmp(ioctl_cmds[i].cmd_name, cmd))
1329       i++;
1330     else
1331       return ioctl_cmds[i].cmd;
1332   }
1333
1334   return -1;
1335 }
1336
1337 int test_do_ioctl(int argc, char **argv)
1338 {
1339   int fd, cmd;
1340
1341   if (argc != 3) {
1342     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ioctl\n", argc));
1343     return INVALID_ARGS;
1344   }
1345
1346
1347   fd = get_obj(argv[0]);
1348   if (fd < 0) {
1349     DBG(2, fprintf(outfp, "Unable to find file %s\n", argv[0]));
1350     return INVALID_VAR;
1351   }
1352
1353   cmd = get_ioctl_cmd(argv[1]);
1354   if (cmd == -1) {
1355     DBG(2, fprintf(outfp, "Do not understand command %s\n", argv[1]));
1356     return INVALID_ARGS;
1357   }
1358
1359   DBG(3, fprintf(outfp, "Executing command %s\n", argv[1]));
1360
1361   last_ret_val = ioctl(fd, cmd, argv[2]);
1362   my_errno = errno;
1363   if (last_ret_val) 
1364     my_perror("ioctl");
1365   last_type = SINT;
1366
1367   return SUCCESS;
1368 }
1369
1370 int test_do_unlink(int argc, char **argv)
1371 {
1372   if (argc != 1) {
1373     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to unlink\n", argc));
1374     return INVALID_ARGS;
1375   }
1376
1377   DBG(4, fprintf(outfp, "Unlinking %s\n", argv[0]));
1378
1379   last_ret_val = unlink(argv[0]);
1380   my_errno = errno;
1381   if (last_ret_val) 
1382     my_perror("unlink");
1383   last_type = SINT;
1384
1385   return SUCCESS;
1386 }
1387
1388 int test_do_umask(int argc, char **argv)
1389 {
1390   mode_t old_mask;
1391
1392   if (argc != 1) {
1393     DBG(2, fprintf(outfp, "Incorrect number of args (%d) for umask\n", argc));
1394     return INVALID_ARGS;
1395   }
1396
1397   last_ret_val = old_mask = sysio_umask(argv[0]);
1398   my_errno = errno;
1399   DBG(3, fprintf(outfp, "Previous umask was %o\n", old_mask));
1400   last_type = UINT;
1401   
1402   return SUCCESS;
1403 }
1404
1405 int test_do_iowait(int argc, char **argv)
1406 {
1407   long err;
1408   ioid_t ioid;
1409
1410   if (argc != 1) {
1411     DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iowait\n", argc));
1412     return INVALID_ARGS;
1413   }
1414
1415   err = get_obj(argv[0]);
1416   if (err < 0) {
1417     DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0]));
1418     return INVALID_VAR;
1419   }
1420   
1421   ioid = (ioid_t)err;
1422
1423   last_ret_val =  iowait(ioid);
1424   my_errno = errno;
1425   if (last_ret_val < 0) {
1426     my_perror("iowait");
1427   }
1428   last_type = SINT;
1429
1430   return SUCCESS;
1431 }
1432
1433 int test_do_iodone(int argc, char **argv)
1434 {
1435   long err;
1436   ioid_t ioid;
1437
1438   if (argc != 1) {
1439     DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iodone\n", argc));
1440     return INVALID_ARGS;
1441   }
1442
1443   err = get_obj(argv[0]);
1444   if (err < 0) {
1445     DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0]));
1446     return INVALID_VAR;
1447   }
1448   ioid = (ioid_t)err;
1449
1450   last_ret_val =  iowait(ioid);
1451   if (last_ret_val < 0) {
1452     my_perror("iodone");
1453   }
1454   my_errno = errno;
1455   last_type = SINT;
1456
1457   return SUCCESS;
1458
1459 }
1460
1461 int test_do_ipread(int argc, char **argv) 
1462 {
1463   int fd, index, count, offset;
1464   char *buf;
1465
1466   if (argc != 4) {
1467     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipread\n", argc));
1468     return INVALID_ARGS;
1469   }
1470
1471   fd = get_obj(argv[0]);
1472   if (fd < 0) {
1473     DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0]));
1474     return INVALID_VAR;
1475   }
1476
1477   index = get_obj(argv[1]);
1478   if (index < 0) {
1479     DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1]));
1480     return INVALID_VAR;
1481   }
1482
1483   buf = buflist[index]->buf;
1484
1485   count = get_obj(argv[2]);
1486   if (count < 0) {
1487     DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2]));
1488     return INVALID_ARGS;
1489   }
1490
1491   offset = get_obj(argv[3]);
1492   if (offset < 0) {
1493     DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[3]));
1494     return INVALID_ARGS;
1495   }
1496
1497   last_ret_val = (long)ipread(fd, buf, count, offset);
1498   if (last_ret_val < 0) {
1499     my_perror("ipread");
1500   }
1501   my_errno = errno;
1502   last_type = SINT;
1503
1504   return SUCCESS;
1505 }
1506
1507 int test_do_iread(int argc, char **argv) 
1508 {
1509   int fd, index, count;
1510   char *buf;
1511
1512   if (argc != 3) {
1513     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iread\n", argc));
1514     return INVALID_ARGS;
1515   }
1516
1517   fd = get_obj(argv[0]);
1518   if (fd < 0) {
1519     DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0]));
1520     return INVALID_VAR;
1521   }
1522
1523   index = get_obj(argv[1]);
1524   if (index < 0) {
1525     DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1]));
1526     return INVALID_VAR;
1527   }
1528
1529   buf = buflist[index]->buf;
1530
1531   count = get_obj(argv[2]);
1532   if (count < 0) {
1533     DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2]));
1534     return INVALID_ARGS;
1535   }
1536
1537   last_ret_val = (long) iread(fd, buf, count);
1538   if (last_ret_val < 0) {
1539     my_perror("iread");
1540   }
1541   my_errno = errno;
1542   last_type = SINT;
1543
1544   return SUCCESS;
1545 }
1546
1547
1548 int test_do_ipreadv(int argc, char **argv)
1549 {
1550   int fd, count, index;
1551   off_t offset;
1552   char *buf;
1553   struct iovec *iov;
1554
1555   if (argc != 4) {
1556     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipreadv\n", argc));
1557     return INVALID_ARGS;
1558   }
1559
1560   fd = get_obj(argv[0]);
1561
1562   if (fd < 0) {
1563     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1564     return INVALID_VAR;
1565   }
1566
1567   index = get_obj(argv[1]);
1568
1569   if (index < 0) {
1570     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1571     return INVALID_VAR;
1572   }
1573
1574   buf = buflist[index]->buf;
1575
1576   iov = (struct iovec *)buf;
1577   count = get_obj(argv[2]);
1578
1579   if (count < 0) {
1580     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1581     return INVALID_ARGS;
1582   }
1583
1584   offset = get_obj(argv[3]);
1585   if (offset < 0) {
1586     DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3]));
1587     return INVALID_ARGS;
1588   }
1589
1590   DBG(3, fprintf(outfp, "ipreadv(fd: %d vector:{iov_base: %p iov_len %d} count: %d offset: %d\n",
1591                  fd, iov->iov_base, (int)iov->iov_len, count, (int) offset)); 
1592
1593   last_ret_val = (long) ipreadv(fd, iov, count, offset);
1594   if (last_ret_val < 0)
1595     my_perror("ipreadv");
1596   my_errno = errno;
1597   last_type = SINT;
1598
1599   return SUCCESS;
1600 }
1601
1602
1603 int test_do_preadv(int argc, char **argv)
1604 {
1605   int fd, count, index;
1606   off_t offset;
1607   char *buf;
1608   struct iovec *iov;
1609
1610   if (argc != 4) {
1611     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to preadv\n", argc));
1612     return INVALID_ARGS;
1613   }
1614
1615   fd = get_obj(argv[0]);
1616
1617   if (fd < 0) {
1618     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1619     return INVALID_VAR;
1620   }
1621
1622   index = get_obj(argv[1]);
1623
1624   if (index < 0) {
1625     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1626     return INVALID_VAR;
1627   }
1628
1629   buf = buflist[index]->buf;
1630
1631   iov = (struct iovec *)buf;
1632   count = get_obj(argv[2]);
1633
1634   if (count < 0) {
1635     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1636     return INVALID_ARGS;
1637   }
1638
1639   offset = get_obj(argv[3]);
1640   if (offset < 0) {
1641     DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3]));
1642     return INVALID_ARGS;
1643   }
1644
1645   DBG(3, fprintf(outfp, "preadv(fd: %d vector:{iov_base: %p iov_len %d} count: %d offset: %d\n",
1646                  fd, iov->iov_base, (int) iov->iov_len, count, (int) offset)); 
1647
1648   last_ret_val = preadv(fd, iov, count, offset);
1649   my_errno = errno;
1650   if (last_ret_val < 0)
1651     my_perror("preadv");
1652   last_type = SINT;
1653
1654   return SUCCESS;
1655 }
1656
1657
1658 int test_do_pread(int argc, char **argv)
1659 {
1660   int fd, count, index, numbytes, offset;
1661   char *buf;
1662
1663   if (argc != 4) {
1664     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pread\n", argc));
1665     return INVALID_ARGS;
1666   }
1667
1668   
1669   fd = get_obj(argv[0]);
1670
1671   if (fd < 0) {
1672     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1673                    argv[0]));
1674     return INVALID_VAR;
1675   }
1676   
1677   index = get_obj(argv[1]);
1678     
1679   if (index < 0) {
1680     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1681                    argv[1]));
1682     return INVALID_VAR;
1683   }
1684
1685   buf = buflist[index]->buf;
1686
1687   count = get_obj(argv[2]);
1688   if (count < 0) {
1689     DBG(2, fprintf(outfp, "Unable to understand count of %s\n", argv[1]));
1690     return INVALID_ARGS;
1691   }
1692
1693   offset = get_obj(argv[3]);
1694   if (count < 0) {
1695     DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[2]));
1696     return INVALID_ARGS;
1697   }
1698
1699
1700   last_ret_val = numbytes = (int) pread(fd, buf, count, offset);
1701   my_errno = errno;
1702   DBG(4, fprintf(outfp, "Read %d bytes out of %d starting at offset %x\n", 
1703                  numbytes, count, offset));
1704   DBG(3, fprintf(outfp, "Got %s\n", buf));
1705   last_type = SINT;
1706
1707   return SUCCESS;
1708 }
1709
1710
1711 int test_do_ireadv(int argc, char **argv)
1712 {
1713   int fd, count, index;
1714   char *buf;
1715   struct iovec *iov;
1716
1717   if (argc != 3) {
1718     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadv\n", argc));
1719     return INVALID_ARGS;
1720   }
1721
1722   fd = get_obj(argv[0]);
1723
1724   if (fd < 0) {
1725     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1726     return INVALID_VAR;
1727   }
1728
1729   index = get_obj(argv[1]);
1730
1731   if (index < 0) {
1732     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1733     return INVALID_VAR;
1734   }
1735
1736   buf = buflist[index]->buf;
1737
1738   iov = (struct iovec *)buf;
1739   count = get_obj(argv[2]);
1740
1741   if (count < 0) {
1742     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1743     return INVALID_ARGS;
1744   }
1745
1746   DBG(3, fprintf(outfp, "ireadv (fd: %d, vector:{ iov_base: %p iov_len %d }, count: %d\n",
1747                  fd, iov->iov_base, (int)iov->iov_len, count)); 
1748
1749   last_ret_val = (long) ireadv(fd, iov, count);
1750   if (last_ret_val < 0)
1751     my_perror("ireadv");
1752   my_errno = errno;
1753   last_type = SINT;
1754
1755   return SUCCESS;
1756 }
1757
1758 int test_do_readv(int argc, char **argv)
1759 {
1760   int fd, count, index;
1761   char *buf;
1762   struct iovec *iov;
1763
1764   if (argc != 3) {
1765     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readv\n", argc));
1766     return INVALID_ARGS;
1767   }
1768
1769   fd = get_obj(argv[0]);
1770
1771   if (fd < 0) {
1772     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1773     return INVALID_VAR;
1774   }
1775
1776   index = get_obj(argv[1]);
1777
1778   if (index < 0) {
1779     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1780     return INVALID_VAR;
1781   }
1782
1783   buf = buflist[index]->buf;
1784
1785   iov = (struct iovec *)buf;
1786   count = get_obj(argv[2]);
1787
1788   if (count < 0) {
1789     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1790     return INVALID_ARGS;
1791   }
1792
1793   DBG(3, fprintf(outfp, "ireadv (fd: %d, vector:{ iov_base: %p iov_len %d }, count: %d\n",
1794                  fd, iov->iov_base, (int)iov->iov_len, count)); 
1795
1796   last_ret_val = readv(fd, iov, count);
1797   if (last_ret_val < 0)
1798     my_perror("readv");
1799   my_errno = errno;
1800   last_type = SINT;
1801
1802   return SUCCESS;
1803 }
1804
1805 int test_do_read(int argc, char **argv)
1806 {
1807   int fd, count, index, numbytes=0;
1808   char *buf;
1809
1810   if (argc < 3) {
1811     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to read\n", argc));
1812     return INVALID_ARGS;
1813   }
1814
1815   
1816   fd = get_obj(argv[0]);
1817
1818   if (fd < 0) {
1819     DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1820                    argv[0]));
1821     return INVALID_VAR;
1822   }
1823   
1824   index = get_obj(argv[1]);
1825   
1826   
1827   if (index < 0) {
1828     DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1829                    argv[1]));
1830     return INVALID_VAR;
1831   }
1832
1833   buf = buflist[index]->buf;
1834
1835   count = get_obj(argv[2]);
1836
1837   if ( (argc == 4) && (!strcmp(argv[3], "delay")) ){
1838     int i;
1839     /* Wait a little while for input */
1840     for (i=0; i < count; i++) {
1841       sleep(0.005);
1842       numbytes += (int) read(fd, buf, 1);
1843       last_ret_val = numbytes;
1844       
1845     }
1846   } else {
1847     last_ret_val = numbytes = (int) read(fd, buf, count);
1848   }
1849   my_errno = errno;
1850
1851   DBG(3, fprintf(outfp, "Read %d bytes out of %d\n", numbytes, count));
1852   DBG(3, fprintf(outfp, "Got %s\n", buf));
1853   last_type = SINT;
1854
1855   return SUCCESS;
1856 }
1857
1858 int test_do_ipwritev(int argc, char **argv)
1859 {
1860   int fd, count, index, offset;
1861   char *buf;
1862   struct iovec *iov;
1863
1864   if (argc != 4) {
1865     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwritev\n", argc));
1866     return INVALID_ARGS;
1867   }
1868
1869   fd = get_obj(argv[0]);
1870
1871   if (fd < 0) {
1872     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1873     return INVALID_VAR;
1874   }
1875
1876   index = get_obj(argv[1]);
1877
1878   if (index < 0) {
1879     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1880     return INVALID_VAR;
1881   }
1882
1883   buf = buflist[index]->buf;
1884
1885   iov = (struct iovec *)buf;
1886
1887   count = get_obj(argv[2]);
1888   if (count < 0) {
1889     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1890     return INVALID_ARGS;
1891   }
1892
1893   offset = get_obj(argv[3]);
1894   if (offset < 0) {
1895     DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1896     return INVALID_ARGS;
1897   }
1898
1899   DBG(3, fprintf(outfp, 
1900                  "ipwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d, offset: %d\n",
1901                  fd, iov->iov_base, (int)iov->iov_len, count, offset)); 
1902
1903   last_ret_val = (long) ipwritev(fd, iov, count, offset);
1904   my_errno = errno;
1905   if (last_ret_val < 0)
1906     my_perror("ipwritev");
1907   last_type = SINT;
1908
1909   return SUCCESS;
1910 }
1911
1912 int test_do_ipwrite(int argc, char **argv)
1913 {
1914   int fd, count, index, offset;
1915   char *buf;
1916
1917   if (argc != 4) {
1918     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwrite\n", argc));
1919     return INVALID_ARGS;
1920   }
1921
1922   fd = get_obj(argv[0]);
1923
1924   if (fd < 0) {
1925     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1926     return INVALID_VAR;
1927   }
1928
1929   index = get_obj(argv[1]);
1930
1931   if (index < 0) {
1932     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1933     return INVALID_VAR;
1934   }
1935
1936   buf = buflist[index]->buf;
1937
1938   count = get_obj(argv[2]);
1939   if (count < 0) {
1940     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1941     return INVALID_ARGS;
1942   }
1943
1944   offset = get_obj(argv[3]);
1945   if (offset < 0) {
1946     DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1947     return INVALID_ARGS;
1948   }
1949
1950   last_ret_val = (long) ipwrite(fd, buf, count, offset);
1951   if (last_ret_val < 0)
1952     my_perror("ipwrite");
1953   my_errno = errno;
1954   last_type = SINT;
1955
1956   return SUCCESS;
1957 }
1958
1959 int test_do_pwritev(int argc, char **argv)
1960 {
1961   int fd, count, index, offset;
1962   char *buf;
1963   struct iovec *iov;
1964
1965   if (argc != 4) {
1966     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwritev\n", argc));
1967     return INVALID_ARGS;
1968   }
1969
1970   fd = get_obj(argv[0]);
1971
1972   if (fd < 0) {
1973     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1974     return INVALID_VAR;
1975   }
1976
1977   index = get_obj(argv[1]);
1978
1979   if (index < 0) {
1980     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1981     return INVALID_VAR;
1982   }
1983
1984   buf = buflist[index]->buf;
1985
1986   iov = (struct iovec *)buf;
1987
1988   count = get_obj(argv[2]);
1989   if (count < 0) {
1990     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1991     return INVALID_ARGS;
1992   }
1993
1994   offset = get_obj(argv[3]);
1995   if (offset < 0) {
1996     DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1997     return INVALID_ARGS;
1998   }
1999
2000
2001   DBG(3, fprintf(outfp, 
2002                  "pwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d, offset: %d\n",
2003                  fd, iov->iov_base, (int)iov->iov_len, count, offset)); 
2004
2005   last_ret_val = (long) pwritev(fd, iov, count, offset);
2006   if (last_ret_val < 0)
2007     my_perror("ipwritev");
2008   my_errno = errno;
2009   last_type = SINT;
2010   
2011   return SUCCESS;
2012 }
2013
2014 int test_do_pwrite(int argc, char **argv)
2015 {
2016   int fd, count, index, offset;
2017   char *buf;
2018
2019   if (argc != 4) {
2020     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwrite\n", argc));
2021     return INVALID_ARGS;
2022   }
2023
2024   fd = get_obj(argv[0]);
2025
2026   if (fd < 0) {
2027     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2028     return INVALID_VAR;
2029   }
2030
2031   index = get_obj(argv[1]);
2032
2033   if (index < 0) {
2034     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2035     return INVALID_VAR;
2036   }
2037
2038   buf = buflist[index]->buf;
2039
2040   count = get_obj(argv[2]);
2041   if (count < 0) {
2042     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2043     return INVALID_ARGS;
2044   }
2045
2046   offset = get_obj(argv[3]);
2047   if (offset < 0) {
2048     DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
2049     return INVALID_ARGS;
2050   }
2051
2052   last_ret_val = pwrite(fd, buf, count, offset);
2053   my_errno = errno;
2054   if (last_ret_val < 0)
2055     my_perror("pwrite");
2056   last_type = SINT;
2057
2058   return SUCCESS;
2059 }
2060
2061
2062 int test_do_iwritev(int argc, char **argv)
2063 {
2064   int fd, count, index;
2065   char *buf;
2066   struct iovec *iov;
2067
2068   if (argc != 3) {
2069     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritev\n", argc));
2070     return INVALID_ARGS;
2071   }
2072
2073   fd = get_obj(argv[0]);
2074
2075   if (fd < 0) {
2076     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2077     return INVALID_VAR;
2078   }
2079
2080   index = get_obj(argv[1]);
2081
2082   if (index < 0) {
2083     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2084     return INVALID_VAR;
2085   }
2086
2087   buf = buflist[index]->buf;
2088
2089   iov = (struct iovec *)buf;
2090
2091   count = get_obj(argv[2]);
2092   if (count < 0) {
2093     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2094     return INVALID_ARGS;
2095   }
2096
2097   DBG(3, fprintf(outfp, "iwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d\n",
2098                  fd, iov->iov_base, (int)iov->iov_len, count)); 
2099
2100   last_ret_val = (long) iwritev(fd, iov, count);
2101   my_errno = errno;
2102   if (last_ret_val < 0)
2103     my_perror("iwritev");
2104   last_type = SINT;
2105
2106   return SUCCESS;
2107 }
2108
2109 int test_do_iwrite(int argc, char **argv)
2110 {
2111   int fd, count, index;
2112   char *buf;
2113
2114   if (argc != 3) {
2115     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwrite\n", argc));
2116     return INVALID_ARGS;
2117   }
2118
2119   fd = get_obj(argv[0]);
2120
2121   if (fd < 0) {
2122     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2123     return INVALID_VAR;
2124   }
2125
2126   index = get_obj(argv[1]);
2127
2128   if (index < 0) {
2129     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2130     return INVALID_VAR;
2131   }
2132
2133   buf = buflist[index]->buf;
2134
2135   count = get_obj(argv[2]);
2136   if (count < 0) {
2137     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2138     return INVALID_ARGS;
2139   }
2140
2141   last_ret_val = (long) iwrite(fd, buf, count);
2142   my_errno = errno;
2143   if (last_ret_val < 0)
2144     my_perror("iwrite");
2145   last_type = SINT;
2146
2147   return SUCCESS;
2148 }
2149
2150
2151 int test_do_write(int argc, char **argv)
2152 {
2153   int fd, count, index, err;
2154   char *buf;
2155
2156   if (argc != 3) {
2157     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to write\n", argc));
2158     return INVALID_ARGS;
2159   }
2160
2161   fd = get_obj(argv[0]);
2162
2163   if (fd < 0) {
2164     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2165     return INVALID_VAR;
2166   }
2167
2168   index = get_obj(argv[1]);
2169
2170   if (index < 0) {
2171     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2172     return INVALID_VAR;
2173   }
2174
2175   buf = buflist[index]->buf;
2176
2177   count = get_obj(argv[2]);
2178   if (count < 0) {
2179     DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2180     return INVALID_ARGS;
2181   }
2182
2183   DBG(4, fprintf(outfp, "Writing out %d bytes (%s) using fd of %x\n",
2184                  count, buf, fd));
2185   err = write(fd, buf, count);
2186   if (err < 0)
2187     my_perror("write");
2188
2189   last_ret_val = err;
2190   my_errno = errno;
2191   last_type = SINT;
2192
2193   return SUCCESS;
2194 }
2195
2196
2197 int test_do_writev(int argc, char **argv)
2198 {
2199   int fd, count, index;
2200   char *buf;
2201   struct iovec *iov;
2202
2203   if (argc != 3) {
2204     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writev\n", argc));
2205     return INVALID_ARGS;
2206   }
2207
2208   fd = get_obj(argv[0]);
2209
2210   if (fd < 0) {
2211     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2212     return INVALID_ARGS;
2213   }
2214
2215   index = get_obj(argv[1]);
2216
2217   if (index < 0) {
2218     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2219     return INVALID_VAR;
2220   }
2221
2222   buf = buflist[index]->buf;
2223
2224   iov = (struct iovec *)buf;
2225   count = get_obj(argv[2]);
2226
2227   if (count < 0) {
2228     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2229     return INVALID_ARGS;
2230   }
2231
2232   DBG(3, fprintf(outfp, "writev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d\n",
2233                  fd, iov->iov_base, (int)iov->iov_len, count)); 
2234
2235   last_ret_val = writev(fd, iov, count);
2236   if (last_ret_val < 0)
2237     my_perror("writev");
2238   my_errno = errno;
2239   last_type = SINT;
2240
2241   return SUCCESS;
2242 }
2243
2244 int test_do_mknod(int argc, char **argv) 
2245 {
2246   int dev;
2247
2248   if (argc != 3) {
2249     DBG(2, fprintf(outfp, "Invalid number of args (%d) for mknod\n", argc));
2250     return INVALID_ARGS;
2251   }
2252
2253   dev = get_obj(argv[2]);
2254   if (dev < 0) {
2255     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2256     return INVALID_ARGS;
2257   }
2258   last_type = SINT;
2259
2260   
2261   return sysio_mknod(argv[0], argv[1], (dev_t) dev);
2262 }
2263
2264 int test_do_umount(int argc, char **argv) 
2265 {
2266   int err;
2267
2268   if (argc != 1) {
2269     DBG(2, fprintf(outfp, "Invalid number (%d) of args for umount\n", argc));
2270     return INVALID_ARGS;
2271   }
2272
2273   err = umount(argv[0]);
2274   if (err)
2275     my_perror("umount");
2276
2277   my_errno = errno;
2278   last_ret_val = err;
2279   last_type = SINT;
2280
2281   return SUCCESS;
2282 }
2283  
2284 int test_do_init_iovec(int argc, char **argv)
2285 {
2286         int iov_index, buf_index;
2287         int offset, len, pos;
2288         struct iovec *iov_ptr;
2289         char *base_ptr;
2290
2291         if (argc != 5) {
2292                 DBG(2, fprintf(outfp, "Need buffer, offset, len, array pos, and iov pointer\n"));
2293                 return INVALID_ARGS;
2294         }
2295
2296         if ((buf_index = get_obj(argv[0])) < 0) {
2297                 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[0]));
2298                 return INVALID_VAR;
2299         }
2300         base_ptr = buflist[buf_index]->buf;
2301
2302         if ((offset = get_obj(argv[1])) < 0) {
2303                 DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[1]));
2304                 return INVALID_VAR;
2305         }
2306         
2307         if ((len = get_obj(argv[2])) < 0) {
2308                 DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[2]));
2309                 return INVALID_VAR;
2310         }
2311         
2312         if ((pos = get_obj(argv[3])) < 0) {
2313                 DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[3]));
2314                 return INVALID_VAR;
2315         }
2316
2317         if ((iov_index = get_obj(argv[4])) < 0) {
2318                 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[4]));
2319                 return INVALID_VAR;
2320         }
2321         iov_ptr = (struct iovec *)(buflist[iov_index]->buf);    
2322
2323         iov_ptr[pos].iov_len = len;
2324         iov_ptr[pos].iov_base = (void *)(base_ptr + offset);
2325         
2326         DBG(3, fprintf(outfp, "iov_ptr.len is %d and base is %p\n", 
2327                        (int)iov_ptr[pos].iov_len, iov_ptr[pos].iov_base));
2328    my_errno = errno;
2329   last_type = PTR;
2330
2331         return SUCCESS;
2332 }
2333
2334
2335 int test_do_init_xtvec(int argc, char **argv)
2336 {
2337         int xtv_index;
2338         int offset, len, pos;
2339         struct xtvec *xtv_ptr;
2340
2341         if (argc != 4) {
2342                 DBG(2, fprintf(outfp, "Need offset, len, array pos, and xtv pointer\n"));
2343                 return INVALID_ARGS;
2344         }
2345
2346         if ((offset = get_obj(argv[0])) < 0) {
2347                 DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[0]));
2348                 return INVALID_VAR;
2349         }
2350         
2351         if ((len = get_obj(argv[1])) < 0) {
2352                 DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[1]));
2353                 return INVALID_VAR;
2354         }
2355         
2356         if ((pos = get_obj(argv[2])) < 0) {
2357                 DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[2]));
2358                 return INVALID_VAR;
2359         }
2360
2361         if ((xtv_index = get_obj(argv[3])) < 0) {
2362                 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[3]));
2363                 return INVALID_VAR;
2364         }
2365         xtv_ptr = (struct xtvec *)(buflist[xtv_index]->buf);    
2366
2367         xtv_ptr[pos].xtv_len = len;
2368         xtv_ptr[pos].xtv_off = offset;
2369         
2370         DBG(3, fprintf(outfp, "xtv_ptr.len is %d and offset is %d\n", 
2371                        (int)xtv_ptr[pos].xtv_len, (int)xtv_ptr[pos].xtv_off));
2372
2373         my_errno = errno;
2374   last_type = PTR;
2375
2376         return SUCCESS;
2377 }
2378
2379 int test_do_writex(int argc, char **argv)
2380 {
2381   int fd, iov_count, xtv_count,index;
2382   char *buf;
2383   struct iovec *iov;
2384         struct xtvec *xtv;
2385
2386   if (argc != 5) {
2387     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writex\n", argc));
2388     return INVALID_ARGS;
2389   }
2390
2391   fd = get_obj(argv[0]);
2392
2393   if (fd < 0) {
2394     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2395     return INVALID_ARGS;
2396   }
2397
2398   index = get_obj(argv[1]);
2399
2400   if (index < 0) {
2401     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2402     return INVALID_VAR;
2403   }
2404
2405   buf = buflist[index]->buf;
2406
2407   iov = (struct iovec *)buf;
2408   iov_count = get_obj(argv[2]);
2409
2410   if (iov_count < 0) {
2411     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2412     return INVALID_ARGS;
2413   }
2414
2415   index = get_obj(argv[3]);
2416
2417   if (index < 0) {
2418     DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2419     return INVALID_VAR;
2420   }
2421
2422   buf = buflist[index]->buf;
2423
2424   xtv = (struct xtvec *)buf;
2425   xtv_count = get_obj(argv[4]);
2426
2427   if (xtv_count < 0) {
2428     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2429     return INVALID_ARGS;
2430   }
2431
2432   DBG(3, fprintf(outfp, "writex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n",
2433                  fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); 
2434
2435   last_ret_val = writex(fd, iov, iov_count, xtv, xtv_count);
2436   if (last_ret_val < 0)
2437     my_perror("writex");
2438   my_errno = errno;
2439   last_type = SINT;
2440
2441   return SUCCESS;
2442 }
2443
2444
2445 int test_do_iwritex(int argc, char **argv)
2446 {
2447   int fd, iov_count, xtv_count,index;
2448   char *buf;
2449   struct iovec *iov;
2450         struct xtvec *xtv;
2451
2452   if (argc != 5) {
2453     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritex\n", argc));
2454     return INVALID_ARGS;
2455   }
2456
2457   fd = get_obj(argv[0]);
2458
2459   if (fd < 0) {
2460     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2461     return INVALID_ARGS;
2462   }
2463
2464   index = get_obj(argv[1]);
2465
2466   if (index < 0) {
2467     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2468     return INVALID_VAR;
2469   }
2470
2471   buf = buflist[index]->buf;
2472
2473   iov = (struct iovec *)buf;
2474   iov_count = get_obj(argv[2]);
2475
2476   if (iov_count < 0) {
2477     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2478     return INVALID_ARGS;
2479   }
2480
2481   index = get_obj(argv[3]);
2482
2483   if (index < 0) {
2484     DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2485     return INVALID_VAR;
2486   }
2487
2488   buf = buflist[index]->buf;
2489
2490   xtv = (struct xtvec *)buf;
2491   xtv_count = get_obj(argv[4]);
2492
2493   if (xtv_count < 0) {
2494     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2495     return INVALID_ARGS;
2496   }
2497
2498   DBG(3, fprintf(outfp, "iwritex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n",
2499                  fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); 
2500
2501   last_ret_val = (long) iwritex(fd, iov, iov_count, xtv, xtv_count);
2502   if (last_ret_val < 0)
2503     my_perror("iwritex");
2504   my_errno = errno;
2505   last_type = SINT;
2506
2507         return SUCCESS;
2508 }
2509
2510
2511 int test_do_readx(int argc, char **argv)
2512 {
2513   int fd, iov_count, xtv_count,index;
2514   char *buf;
2515   struct iovec *iov;
2516         struct xtvec *xtv;
2517
2518   if (argc != 5) {
2519     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readx\n", argc));
2520     return INVALID_ARGS;
2521   }
2522
2523   fd = get_obj(argv[0]);
2524
2525   if (fd < 0) {
2526     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2527     return INVALID_ARGS;
2528   }
2529
2530   index = get_obj(argv[1]);
2531
2532   if (index < 0) {
2533     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2534     return INVALID_VAR;
2535   }
2536
2537   buf = buflist[index]->buf;
2538
2539   iov = (struct iovec *)buf;
2540   iov_count = get_obj(argv[2]);
2541
2542   if (iov_count < 0) {
2543     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2544     return INVALID_ARGS;
2545   }
2546
2547   index = get_obj(argv[3]);
2548
2549   if (index < 0) {
2550     DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2551     return INVALID_VAR;
2552   }
2553
2554   buf = buflist[index]->buf;
2555
2556   xtv = (struct xtvec *)buf;
2557   xtv_count = get_obj(argv[4]);
2558
2559   if (xtv_count < 0) {
2560     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2561     return INVALID_ARGS;
2562   }
2563
2564   DBG(3, fprintf(outfp, "readx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n",
2565                  fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); 
2566
2567   last_ret_val = readx(fd, iov, iov_count, xtv, xtv_count);
2568   if (last_ret_val < 0)
2569     my_perror("readx");
2570   my_errno = errno;
2571   last_type = SINT;
2572
2573   return SUCCESS;
2574 }
2575
2576
2577 int test_do_ireadx(int argc, char **argv)
2578 {
2579   int fd, iov_count, xtv_count,index;
2580   char *buf;
2581   struct iovec *iov;
2582         struct xtvec *xtv;
2583
2584   if (argc != 5) {
2585     DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadx\n", argc));
2586     return INVALID_ARGS;
2587   }
2588
2589   fd = get_obj(argv[0]);
2590
2591   if (fd < 0) {
2592     DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2593     return INVALID_ARGS;
2594   }
2595
2596   index = get_obj(argv[1]);
2597
2598   if (index < 0) {
2599     DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2600     return INVALID_VAR;
2601   }
2602
2603   buf = buflist[index]->buf;
2604
2605   iov = (struct iovec *)buf;
2606   iov_count = get_obj(argv[2]);
2607
2608   if (iov_count < 0) {
2609     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2610     return INVALID_ARGS;
2611   }
2612
2613   index = get_obj(argv[3]);
2614
2615   if (index < 0) {
2616     DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2617     return INVALID_VAR;
2618   }
2619
2620   buf = buflist[index]->buf;
2621
2622   xtv = (struct xtvec *)buf;
2623   xtv_count = get_obj(argv[4]);
2624
2625   if (xtv_count < 0) {
2626     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2627     return INVALID_ARGS;
2628   }
2629
2630   DBG(3, fprintf(outfp, "ireadx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n",
2631                  fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); 
2632
2633   last_ret_val = (long) ireadx(fd, iov, iov_count, xtv, xtv_count);
2634   if (last_ret_val < 0)
2635     my_perror("ireadx");
2636   my_errno = errno;
2637   last_type = SINT;
2638
2639         return SUCCESS;
2640 }
2641
2642
2643 int do_checkbuf(int argc, char **argv)
2644 {
2645          int size, val, index, i, offset;
2646          int *ref_buf, *buf;
2647         
2648         if (argc != 4) {
2649                 DBG(2, fprintf(outfp, "Need buffer, val, and offset for checkbuf\n"));
2650                 return INVALID_ARGS;
2651         }
2652
2653         index = get_obj(argv[0]);
2654
2655   if (index < 0) {
2656     DBG(2, fprintf(outfp, "Unable to find buf described by %s\n", argv[0]));
2657     return INVALID_VAR;
2658   }
2659
2660   buf = (int *)buflist[index]->buf;     
2661
2662
2663         size = get_obj(argv[1]);
2664
2665         if (size < 0) {
2666     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[1]));
2667     return INVALID_ARGS;
2668   }
2669
2670         val = get_obj(argv[2]);
2671         
2672   if (val < 0) {
2673     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2674     return INVALID_ARGS;
2675   }
2676
2677         
2678         offset = get_obj(argv[3]);
2679         
2680         if (offset < 0) {
2681     DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3]));
2682     return INVALID_ARGS;
2683   }
2684         
2685
2686         ref_buf = (int *)malloc(size);
2687         memset((void *)ref_buf, val, size);
2688
2689         last_ret_val =0;
2690         buf = (int *)((char *)buf + offset);
2691         for (i=0; (unsigned)i < size/sizeof(int); i++) {
2692                 if (buf[i] != ref_buf[i]) {
2693                         DBG(2, fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x\n",
2694                                                                                  i, buf[i], ref_buf[i]));
2695                         fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x (val was %d)\n",
2696                                                                                  i, buf[i], ref_buf[i], val);
2697                         last_ret_val = 1;
2698                         break;
2699                 }
2700         }
2701
2702   my_errno = errno;
2703   last_type = SINT;
2704
2705         return SUCCESS;
2706 }