10 #include <sys/mount.h>
12 #include <sys/statvfs.h>
13 #include <sys/queue.h>
17 #include "test_driver.h"
20 * ################################################
22 * # These allow all of the different commands #
23 * # to be called with the same format #
24 * ################################################
27 int test_do_setdebug(int argc, char **argv)
32 DBG(2, fprintf(outfp, "Invalid number of args (%d) for setdebug\n",
37 level = atoi(argv[0]);
40 DBG(2, fprintf(outfp, "Invalid debug level %d\n", level));
48 int test_do_printline(int argc, char **argv)
54 DBG(2, fprintf(outfp, "Invalid number of args (%d) for printline\n",
69 int test_do_setoutput(int argc, char **argv)
74 fprintf(outfp, "Invalid number of args (%d) for setoutput\n",
79 newfp = fopen(argv[0], "w");
81 fprintf(outfp, "Unable to open new output file %s\n", argv[0]);
93 int test_do_fillbuff(int argc, char **argv)
97 int size, type, index, offset;
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);
107 offset = get_obj(argv[3]);
109 DBG(2, fprintf(outfp, "Do not understand offset %s\n", argv[3]));
113 index = get_obj(argv[4]);
115 DBG(2, fprintf(outfp, "Can't find buffer at %s\n", argv[4]));
118 buf = (char *)(buflist[index]->buf)+offset;
120 DBG(4, fprintf(outfp, "Buffer start is at %p\n", (void *)buflist[index]));
123 size = get_obj(argv[2]);
125 DBG(2, fprintf(outfp, "Unable to understand size %s\n", argv[2]));
129 if ( (!strcmp(typestr, "UINT")) || (!strcmp(typestr, "SINT")) ){
130 int val = get_obj(argv[0]);
133 if (val < 0) { /* FIX THIS */
134 DBG(2, fprintf(outfp, "Can't understand value %s\n", argv[0]));
137 DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %x\n",
138 size, buf, *((int *)valptr)));
139 memcpy(buf, valptr, size);
141 } else if (!strcmp(typestr,"STR")) {
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")) {
149 int index = get_obj(argv[0]);
151 DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[0]));
155 val = (unsigned long)buflist[index]->buf;
157 DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %p\n",
159 memcpy(buf, valptr, size);
161 DBG(2, fprintf(outfp, "Unknown type %s. Valid types are UINT, STR, and PTR\n",
163 fprintf(stderr, "Unknown type %s. Valid types are UINT, STR, and PTR\n",
178 void print_partial(char *buf, int offset, int len, int type)
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)));
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));
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)));
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));
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));
214 int test_do_printbuf(int argc, char **argv)
216 int index, i, type, offset, len;
217 struct buf_t *buf_st;
220 struct var_mapping *mobj;
222 if (argv[0][0] == '$') {
223 if (argv[0][1] == '$') {
224 sprintf(output, "\n%#010x", (unsigned int)last_ret_val);
226 } else if (!strcmp("errno", &argv[0][1])) {
227 sprintf(output, "\n%#010x", my_errno);
232 mobj = get_map(argv[0]);
234 DBG(2, fprintf(outfp, "Can't get var at %s\n", argv[0]));
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)) {
245 buf_st = buflist[index];
246 DBG(2, fprintf(outfp, "buf_st is %p:\n", (void *)buf_st));
248 DBG(2, fprintf(outfp, "buf %s:\n", argv[0]));
249 if (mobj->type == STR) {
250 sprintf(output, "\n%s", (char *)buf);
252 sprintf(output,"%s\n", output);
253 DBG(2, fprintf(outfp, "buf_st->len is %d, buf is %p\n", buf_st->len, buf));
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]);
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]));
270 if (!strcmp("STR", typestr))
272 else if (!strcmp("INT", typestr))
274 else if (!strcmp("SHORT", typestr))
276 else if (!strcmp("CHAR", typestr))
278 else if (!strcmp("LONG", typestr))
281 DBG(2, fprintf(outfp, "Unable to understand type %s\n",
285 print_partial(buf, offset, len, type);
289 DBG(3, fprintf(outfp, "output: %s \n", output));
293 int test_do_mount(int argc, char **argv)
296 DBG(2, fprintf(outfp, "Invalid number of args (%d) for test_do_mount\n",
301 DBG(4, fprintf(outfp, "Calling mount with from %s and to %s\n",
303 last_ret_val = sysio_mount(argv[0], argv[1]);
309 int test_do_clear(int argc, char **argv)
315 DBG(2, fprintf(outfp, "Invalid number of args (%d) for clear\n",
319 index = get_obj(argv[0]);
321 fprintf(outfp, "Unable to locate buffer %s\n",
325 buf = buflist[index];
326 bzero(buf->buf, buf->len);
331 int test_do_list(int argc, char **argv)
335 if ((argc) && (argc != 1)) {
336 DBG(2, fprintf(outfp, "Invalid number of args (%d) for list\n",
341 DBG(5,fprintf(outfp, "In test_do_list with args %p\n", (void *)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);
352 return sysio_list(*argv);
356 * Initlizes sysio library. Will use default initlization
357 * unless arguments are given
359 int test_do_init(int argc, char **argv)
364 int mflags, rsize, msize;
366 DBG(2, fprintf(outfp, "Invalid number of args (%d) for init\n",
371 rdriver = get_str(argv[0]);
372 rsize = strlen(rdriver)+1;
374 DBG(2, fprintf(outfp, "%s too long for root driver\n", rdriver));
377 bzero(root_driver, 75);
378 memcpy(root_driver, rdriver, rsize);
380 mpath = get_str(argv[1]);
381 msize = strlen(mpath)+1;
383 DBG(2, fprintf(outfp, "%s too long for mount path\n", mpath));
387 memcpy(mntpath, mpath, msize);
389 mflags = get_obj(argv[2]);
391 DBG(2, fprintf(outfp, "Invalid flags argument %s\n", argv[2]));
396 DBG(5, fprintf(outfp, "In test_do_init\n"));
398 DBG(3, fprintf(outfp, "initializing\n"));
399 return initilize_sysio();
404 * Returns 1 if the machine is big-endian, 0
407 int get_endian(int argc, char **argv)
411 if ((argc) || (argv)) {
412 DBG(2, fprintf(outfp, "Expected no args for test_do_endian\n"));
416 if(*(char *)&x == 1) {
417 /* little-endian, return 0 */
420 /* big endian, return 1 */
427 int do_setbuf(int argc, char **argv)
429 int val, size, index, offset;
433 DBG(2, fprintf(outfp, "Need val, size, buffer, and offset for setbuf\n"));
436 val = get_obj(argv[0]);
438 DBG(2, fprintf(outfp, "Unable to understand val of %s\n",
443 size = get_obj(argv[1]);
445 DBG(2, fprintf(outfp, "Size of %s is invalid\n", argv[1]));
449 index = get_obj(argv[2]);
451 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
456 buf = buflist[index]->buf;
458 offset = get_obj(argv[3]);
461 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3]));
465 buf = (void *)((char *)buf +offset);
467 memset(buf, val, size);
473 int get_sizeof(int argc, char **argv)
479 DBG(2, fprintf(outfp, "Number of args (%d) invalid for sizeof\n",
486 if (!strcmp(type, "char"))
488 else if (!strcmp(type, "int"))
490 else if (!strcmp(type, "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);
505 DBG(2, fprintf(outfp, "Size is %d\n", size));
512 int test_do_exit(int argc, char **argv)
518 * If argc is given, need to return the value of
519 * the passed in variable
521 val = get_obj(argv[0]);
530 DBG(3, printf("Exiting with %d from %s\n", val, argv[0]));
537 int get_buffer(int argc, char **argv)
542 if (argc == 1) /* Just put size, not alignment */
545 align = get_obj(argv[1]);
547 DBG(2, fprintf(outfp, "Number of args (%d) invalid for alloc\n",
552 size = get_obj(argv[0]);
554 DBG(2, fprintf(outfp, "Invalid size %s\n", argv[0]));
558 DBG(3, fprintf(outfp, "Getting buffer of size %d and aligned at %d\n",
560 buf = (struct buf_t *)malloc(sizeof(struct buf_t));
561 buf->buf = alloc_buff32(size, align);
564 DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n",
565 (void *)buf, buf->buf, next));
569 last_ret_val = next-1;
573 int free_buffer(int argc, char **argv)
576 char *name = argv[0];
579 DBG(2, fprintf(outfp, "Number of args (%d) invalid for free\n",
585 * Assume that there is one arg and it
586 * is a variable name which maps to an
587 * index into the buffer array
589 index = get_obj(name);
591 DBG(2, fprintf(outfp, "Can't find buffer %s\n",
595 DBG(4, fprintf(outfp, "Freeing buffer at index %d\n", index));
596 free(buflist[index]);
602 int cmp_bufs(int argc, char **argv)
604 int res, index1, index2;
608 fprintf(outfp, "Need two buffers to compare\n");
612 index1 = get_obj(argv[0]);
614 fprintf(outfp, "Unable to locate buffer %s\n",
618 buf1 = buflist[index1]->buf;
620 index2 = get_obj(argv[1]);
622 fprintf(outfp, "Unable to locate buffer %s\n",
627 buf2 = buflist[index2]->buf;
628 last_ret_val = strcmp(buf1, buf2);
630 DBG(3, fprintf(outfp, "strcmp returned %d\n", res));
634 int test_do_chdir(int argc, char **argv)
637 DBG(2, fprintf(outfp, "Number of args (%d) invalid for chdir\n",
642 return sysio_chdir(argv[0]);
646 int test_do_chmod(int argc, char **argv)
649 DBG(2, fprintf(outfp, "Number of args (%d) invalid for chmod\n",
654 return sysio_chmod(argv[0], argv[1]);
657 int test_do_chown(int argc, char **argv)
660 DBG(2, fprintf(outfp, "Number of args (%d) invalid for chown\n",
665 return sysio_chown(argv[0], argv[1]);
668 int test_do_open(int argc, char **argv)
670 char *name = argv[0];
674 flags = get_obj(argv[1]);
676 if (name[0] == '$') {
677 int index = get_obj(name);
680 DBG(2, fprintf(outfp, "Unable to find buffer at %s\n",
685 name = buflist[index]->buf;
688 DBG(4, fprintf(outfp, "Opening file %s with flags %d\n", name, flags));
690 return sysio_open(name, flags);
692 return sysio_open3(name, flags, argv[2]);
694 DBG(2, fprintf(outfp, "Invalid number of arguments (%d)\n", argc));
701 int test_do_close(int argc, char **argv)
704 char *name = argv[0];
707 DBG(2, fprintf(outfp, "Number of args (%d) invalid for close\n",
713 * Assume that there is one arg and it
714 * is a variable name which maps to a file
719 DBG(2, fprintf(outfp, "Unable to map var %s to anything\n", name));
727 int test_do_dup(int argc, char **argv)
730 char *var_name = argv[0];
733 DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup\n",
739 fd = get_obj(var_name);
741 DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name));
745 last_ret_val = dup(fd);
752 int test_do_dup2(int argc, char **argv)
755 char *var_name1 = argv[0];
756 char *var_name2 = argv[1];
759 DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup2\n",
764 fd1 = get_obj(var_name1);
766 DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name1));
770 fd2 = get_obj(var_name2);
772 DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name2));
776 last_ret_val = dup2(fd1, fd2);
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 },
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} ,
806 struct cmd_map* get_cmd(char *cmd_name, int argc)
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];
822 int test_do_fcntl(int argc, char **argv)
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
835 cmd = get_cmd(argv[1], argc);
837 DBG(2, fprintf(outfp, "Unable to get command %s\n", argv[1]));
841 fd = get_obj(argv[0]);
843 DBG(2, fprintf(outfp, "Unable to map %s to file descriptor \n", argv[0]));
848 last_ret_val = sysio_fcntl(fd, cmd, argv[2]);
850 last_ret_val = sysio_fcntl(fd, cmd, NULL);
851 DBG(4, fprintf(outfp, "Got return value of %d\n", (int)last_ret_val));
858 int test_do_fstat(int argc, char **argv)
864 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for fstat\n",
869 fd = get_obj(argv[0]);
872 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
877 index = get_obj(argv[1]);
879 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
884 buf = buflist[index]->buf;
886 last_ret_val = sysio_fstat(fd, buf);
893 int test_do_lstat(int argc, char **argv)
895 char *name = argv[0];
900 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for lstat\n",
905 index = get_obj(argv[1]);
907 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
912 buf = buflist[index]->buf;
915 return sysio_lstat(name, buf);
918 int test_do_fsync(int argc, char **argv)
923 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fsync\n", argc));
928 fd = get_obj(argv[0]);
931 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
936 last_ret_val = fsync(fd);
944 int test_do_fdatasync(int argc, char **argv)
949 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fdatasync\n", argc));
954 fd = get_obj(argv[0]);
957 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
962 last_ret_val = fdatasync(fd);
970 int test_do_ftruncate(int argc, char **argv)
976 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ftruncate\n", argc));
981 fd = get_obj(argv[0]);
984 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
989 length = (off_t)get_obj(argv[1]);
991 DBG(3, fprintf(outfp, "Setting file %d to %d\n", fd, (int) length));
993 last_ret_val = ftruncate(fd, length);
1000 int test_do_getcwd(int argc, char **argv)
1006 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getcwd\n", argc));
1007 return INVALID_ARGS;
1010 index = get_obj(argv[0]);
1012 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1017 buf = buflist[index]->buf;
1019 size = get_obj(argv[1]);
1021 DBG(4, fprintf(outfp, "Getting cwd with buffer size of %d\n", size));
1024 if (!getcwd(buf, size)) {
1026 if (errno == ERANGE) {
1027 DBG(2, fprintf(outfp, "Need a bigger buffer!\n"));
1034 DBG(3, fprintf(outfp, "cwd: %s\n", buf));
1040 int test_do_lseek(int argc, char **argv)
1047 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to lseek\n", argc));
1048 return INVALID_ARGS;
1052 fd = get_obj(argv[0]);
1055 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1060 offset = (off_t)get_obj(argv[1]);
1061 whence = get_obj(argv[2]);
1064 DBG(2, fprintf(outfp, "Not familiar with whence of %s\n",
1066 return INVALID_ARGS;
1069 last_ret_val = lseek(fd, offset, whence);
1076 int test_do_getdirentries(int argc, char **argv)
1082 struct var_mapping *base_map;
1085 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getdirentries\n", argc));
1086 return INVALID_ARGS;
1089 fd = get_obj(argv[0]);
1092 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1097 bufindex = get_obj(argv[1]);
1100 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1105 buf = buflist[bufindex]->buf;
1107 nbytes = get_obj(argv[2]);
1110 DBG(2, fprintf(outfp, "I don't understand %s\n",
1112 return INVALID_ARGS;
1115 base_map = get_map(argv[3]);
1117 DBG(3, fprintf(outfp, "Resetting basep\n"));
1119 * Assume that this is the first getdirentries call
1120 * and we need to setup the base pointer
1124 basep = base_map->obj;
1126 DBG(3, fprintf(outfp, "basep is (starting) %d\n", (int) basep));
1127 last_ret_val = sysio_getdirentries(fd, buf, nbytes, &basep);
1129 base_map->obj = basep;
1131 store_result(argv[3]+1, basep);
1132 DBG(3, fprintf(outfp, "basep is (ending) %d\n", (int) basep));
1139 int test_do_mkdir(int argc, char **argv)
1142 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to mkdir\n", argc));
1143 return INVALID_ARGS;
1147 return sysio_mkdir(argv[0], argv[1]);
1150 int test_do_creat(int argc, char **argv)
1153 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to creat\n", argc));
1154 return INVALID_ARGS;
1158 return sysio_creat(argv[0], argv[1]);
1161 int test_do_stat(int argc, char **argv)
1168 fprintf(outfp, "Invalid number of arguments (%d) for stat\n",
1174 index = get_obj(argv[1]);
1176 fprintf(outfp, "Unable to find buffer assocated with %s\n",
1180 buf = buflist[index]->buf;
1183 str = get_str(argv[0]);
1184 return sysio_stat(str, buf);
1187 int test_do_statvfs(int argc, char **argv)
1193 fprintf(outfp, "Invalid number of arguments (%d) for statvfs\n",
1199 index = get_obj(argv[1]);
1201 fprintf(outfp, "Unable to find buffer assocated with %s\n",
1205 buf = buflist[index]->buf;
1208 return sysio_statvfs(argv[0], buf);
1211 int test_do_fstatvfs(int argc, char **argv)
1217 fprintf(outfp, "Invalid number of arguments (%d) for fstatvfs\n",
1223 fd = get_obj(argv[0]);
1226 fprintf(outfp, "Unable to find file assocated with %s\n",
1231 index = get_obj(argv[1]);
1233 fprintf(outfp, "Unable to find buffer assocated with %s\n",
1237 buf = buflist[index]->buf;
1240 return sysio_fstatvfs(fd, buf);
1243 int test_do_truncate(int argc, char **argv)
1248 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to truncate\n", argc));
1249 return INVALID_ARGS;
1252 length = (off_t)get_obj(argv[1]);
1254 DBG(3, fprintf(outfp, "Setting file %s to %d\n", argv[0], (int) length));
1256 last_ret_val = truncate(argv[0], length);
1263 int test_do_rmdir(int argc, char **argv)
1267 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to rmdir\n", argc));
1268 return INVALID_ARGS;
1271 DBG(3, fprintf(outfp, "Removing dir %s\n", argv[0]));
1273 last_ret_val = rmdir(argv[0]);
1280 int test_do_symlink(int argc, char **argv)
1283 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to symlink\n", argc));
1284 return INVALID_ARGS;
1287 DBG(3, fprintf(outfp, "Linking %s to %s\n", argv[0], argv[1]));
1289 last_ret_val = symlink(argv[0], argv[1]);
1293 my_perror("symlink");
1302 struct cmd_map ioctl_cmds[] = {
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},
1323 int get_ioctl_cmd(char *cmd)
1327 while (ioctl_cmds[i].cmd_name != NULL) {
1328 if (strcmp(ioctl_cmds[i].cmd_name, cmd))
1331 return ioctl_cmds[i].cmd;
1337 int test_do_ioctl(int argc, char **argv)
1342 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ioctl\n", argc));
1343 return INVALID_ARGS;
1347 fd = get_obj(argv[0]);
1349 DBG(2, fprintf(outfp, "Unable to find file %s\n", argv[0]));
1353 cmd = get_ioctl_cmd(argv[1]);
1355 DBG(2, fprintf(outfp, "Do not understand command %s\n", argv[1]));
1356 return INVALID_ARGS;
1359 DBG(3, fprintf(outfp, "Executing command %s\n", argv[1]));
1361 last_ret_val = ioctl(fd, cmd, argv[2]);
1370 int test_do_unlink(int argc, char **argv)
1373 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to unlink\n", argc));
1374 return INVALID_ARGS;
1377 DBG(4, fprintf(outfp, "Unlinking %s\n", argv[0]));
1379 last_ret_val = unlink(argv[0]);
1382 my_perror("unlink");
1388 int test_do_umask(int argc, char **argv)
1393 DBG(2, fprintf(outfp, "Incorrect number of args (%d) for umask\n", argc));
1394 return INVALID_ARGS;
1397 last_ret_val = old_mask = sysio_umask(argv[0]);
1399 DBG(3, fprintf(outfp, "Previous umask was %o\n", old_mask));
1405 int test_do_iowait(int argc, char **argv)
1411 DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iowait\n", argc));
1412 return INVALID_ARGS;
1415 err = get_obj(argv[0]);
1417 DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0]));
1423 last_ret_val = iowait(ioid);
1425 if (last_ret_val < 0) {
1426 my_perror("iowait");
1433 int test_do_iodone(int argc, char **argv)
1439 DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iodone\n", argc));
1440 return INVALID_ARGS;
1443 err = get_obj(argv[0]);
1445 DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0]));
1450 last_ret_val = iowait(ioid);
1451 if (last_ret_val < 0) {
1452 my_perror("iodone");
1461 int test_do_ipread(int argc, char **argv)
1463 int fd, index, count, offset;
1467 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipread\n", argc));
1468 return INVALID_ARGS;
1471 fd = get_obj(argv[0]);
1473 DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0]));
1477 index = get_obj(argv[1]);
1479 DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1]));
1483 buf = buflist[index]->buf;
1485 count = get_obj(argv[2]);
1487 DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2]));
1488 return INVALID_ARGS;
1491 offset = get_obj(argv[3]);
1493 DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[3]));
1494 return INVALID_ARGS;
1497 last_ret_val = (long)ipread(fd, buf, count, offset);
1498 if (last_ret_val < 0) {
1499 my_perror("ipread");
1507 int test_do_iread(int argc, char **argv)
1509 int fd, index, count;
1513 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iread\n", argc));
1514 return INVALID_ARGS;
1517 fd = get_obj(argv[0]);
1519 DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0]));
1523 index = get_obj(argv[1]);
1525 DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1]));
1529 buf = buflist[index]->buf;
1531 count = get_obj(argv[2]);
1533 DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2]));
1534 return INVALID_ARGS;
1537 last_ret_val = (long) iread(fd, buf, count);
1538 if (last_ret_val < 0) {
1548 int test_do_ipreadv(int argc, char **argv)
1550 int fd, count, index;
1556 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipreadv\n", argc));
1557 return INVALID_ARGS;
1560 fd = get_obj(argv[0]);
1563 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1567 index = get_obj(argv[1]);
1570 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1574 buf = buflist[index]->buf;
1576 iov = (struct iovec *)buf;
1577 count = get_obj(argv[2]);
1580 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1581 return INVALID_ARGS;
1584 offset = get_obj(argv[3]);
1586 DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3]));
1587 return INVALID_ARGS;
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));
1593 last_ret_val = (long) ipreadv(fd, iov, count, offset);
1594 if (last_ret_val < 0)
1595 my_perror("ipreadv");
1603 int test_do_preadv(int argc, char **argv)
1605 int fd, count, index;
1611 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to preadv\n", argc));
1612 return INVALID_ARGS;
1615 fd = get_obj(argv[0]);
1618 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1622 index = get_obj(argv[1]);
1625 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1629 buf = buflist[index]->buf;
1631 iov = (struct iovec *)buf;
1632 count = get_obj(argv[2]);
1635 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1636 return INVALID_ARGS;
1639 offset = get_obj(argv[3]);
1641 DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3]));
1642 return INVALID_ARGS;
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));
1648 last_ret_val = preadv(fd, iov, count, offset);
1650 if (last_ret_val < 0)
1651 my_perror("preadv");
1658 int test_do_pread(int argc, char **argv)
1660 int fd, count, index, numbytes, offset;
1664 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pread\n", argc));
1665 return INVALID_ARGS;
1669 fd = get_obj(argv[0]);
1672 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1677 index = get_obj(argv[1]);
1680 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1685 buf = buflist[index]->buf;
1687 count = get_obj(argv[2]);
1689 DBG(2, fprintf(outfp, "Unable to understand count of %s\n", argv[1]));
1690 return INVALID_ARGS;
1693 offset = get_obj(argv[3]);
1695 DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[2]));
1696 return INVALID_ARGS;
1700 last_ret_val = numbytes = (int) pread(fd, buf, count, offset);
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));
1711 int test_do_ireadv(int argc, char **argv)
1713 int fd, count, index;
1718 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadv\n", argc));
1719 return INVALID_ARGS;
1722 fd = get_obj(argv[0]);
1725 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1729 index = get_obj(argv[1]);
1732 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1736 buf = buflist[index]->buf;
1738 iov = (struct iovec *)buf;
1739 count = get_obj(argv[2]);
1742 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1743 return INVALID_ARGS;
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));
1749 last_ret_val = (long) ireadv(fd, iov, count);
1750 if (last_ret_val < 0)
1751 my_perror("ireadv");
1758 int test_do_readv(int argc, char **argv)
1760 int fd, count, index;
1765 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readv\n", argc));
1766 return INVALID_ARGS;
1769 fd = get_obj(argv[0]);
1772 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1776 index = get_obj(argv[1]);
1779 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1783 buf = buflist[index]->buf;
1785 iov = (struct iovec *)buf;
1786 count = get_obj(argv[2]);
1789 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
1790 return INVALID_ARGS;
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));
1796 last_ret_val = readv(fd, iov, count);
1797 if (last_ret_val < 0)
1805 int test_do_read(int argc, char **argv)
1807 int fd, count, index, numbytes=0;
1811 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to read\n", argc));
1812 return INVALID_ARGS;
1816 fd = get_obj(argv[0]);
1819 DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n",
1824 index = get_obj(argv[1]);
1828 DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n",
1833 buf = buflist[index]->buf;
1835 count = get_obj(argv[2]);
1837 if ( (argc == 4) && (!strcmp(argv[3], "delay")) ){
1839 /* Wait a little while for input */
1840 for (i=0; i < count; i++) {
1842 numbytes += (int) read(fd, buf, 1);
1843 last_ret_val = numbytes;
1847 last_ret_val = numbytes = (int) read(fd, buf, count);
1851 DBG(3, fprintf(outfp, "Read %d bytes out of %d\n", numbytes, count));
1852 DBG(3, fprintf(outfp, "Got %s\n", buf));
1858 int test_do_ipwritev(int argc, char **argv)
1860 int fd, count, index, offset;
1865 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwritev\n", argc));
1866 return INVALID_ARGS;
1869 fd = get_obj(argv[0]);
1872 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1876 index = get_obj(argv[1]);
1879 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1883 buf = buflist[index]->buf;
1885 iov = (struct iovec *)buf;
1887 count = get_obj(argv[2]);
1889 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1890 return INVALID_ARGS;
1893 offset = get_obj(argv[3]);
1895 DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1896 return INVALID_ARGS;
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));
1903 last_ret_val = (long) ipwritev(fd, iov, count, offset);
1905 if (last_ret_val < 0)
1906 my_perror("ipwritev");
1912 int test_do_ipwrite(int argc, char **argv)
1914 int fd, count, index, offset;
1918 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwrite\n", argc));
1919 return INVALID_ARGS;
1922 fd = get_obj(argv[0]);
1925 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1929 index = get_obj(argv[1]);
1932 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1936 buf = buflist[index]->buf;
1938 count = get_obj(argv[2]);
1940 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1941 return INVALID_ARGS;
1944 offset = get_obj(argv[3]);
1946 DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1947 return INVALID_ARGS;
1950 last_ret_val = (long) ipwrite(fd, buf, count, offset);
1951 if (last_ret_val < 0)
1952 my_perror("ipwrite");
1959 int test_do_pwritev(int argc, char **argv)
1961 int fd, count, index, offset;
1966 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwritev\n", argc));
1967 return INVALID_ARGS;
1970 fd = get_obj(argv[0]);
1973 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
1977 index = get_obj(argv[1]);
1980 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
1984 buf = buflist[index]->buf;
1986 iov = (struct iovec *)buf;
1988 count = get_obj(argv[2]);
1990 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
1991 return INVALID_ARGS;
1994 offset = get_obj(argv[3]);
1996 DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
1997 return INVALID_ARGS;
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));
2005 last_ret_val = (long) pwritev(fd, iov, count, offset);
2006 if (last_ret_val < 0)
2007 my_perror("ipwritev");
2014 int test_do_pwrite(int argc, char **argv)
2016 int fd, count, index, offset;
2020 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwrite\n", argc));
2021 return INVALID_ARGS;
2024 fd = get_obj(argv[0]);
2027 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2031 index = get_obj(argv[1]);
2034 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2038 buf = buflist[index]->buf;
2040 count = get_obj(argv[2]);
2042 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2043 return INVALID_ARGS;
2046 offset = get_obj(argv[3]);
2048 DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3]));
2049 return INVALID_ARGS;
2052 last_ret_val = pwrite(fd, buf, count, offset);
2054 if (last_ret_val < 0)
2055 my_perror("pwrite");
2062 int test_do_iwritev(int argc, char **argv)
2064 int fd, count, index;
2069 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritev\n", argc));
2070 return INVALID_ARGS;
2073 fd = get_obj(argv[0]);
2076 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2080 index = get_obj(argv[1]);
2083 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2087 buf = buflist[index]->buf;
2089 iov = (struct iovec *)buf;
2091 count = get_obj(argv[2]);
2093 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2094 return INVALID_ARGS;
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));
2100 last_ret_val = (long) iwritev(fd, iov, count);
2102 if (last_ret_val < 0)
2103 my_perror("iwritev");
2109 int test_do_iwrite(int argc, char **argv)
2111 int fd, count, index;
2115 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwrite\n", argc));
2116 return INVALID_ARGS;
2119 fd = get_obj(argv[0]);
2122 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2126 index = get_obj(argv[1]);
2129 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2133 buf = buflist[index]->buf;
2135 count = get_obj(argv[2]);
2137 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2138 return INVALID_ARGS;
2141 last_ret_val = (long) iwrite(fd, buf, count);
2143 if (last_ret_val < 0)
2144 my_perror("iwrite");
2151 int test_do_write(int argc, char **argv)
2153 int fd, count, index, err;
2157 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to write\n", argc));
2158 return INVALID_ARGS;
2161 fd = get_obj(argv[0]);
2164 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2168 index = get_obj(argv[1]);
2171 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2175 buf = buflist[index]->buf;
2177 count = get_obj(argv[2]);
2179 DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2]));
2180 return INVALID_ARGS;
2183 DBG(4, fprintf(outfp, "Writing out %d bytes (%s) using fd of %x\n",
2185 err = write(fd, buf, count);
2197 int test_do_writev(int argc, char **argv)
2199 int fd, count, index;
2204 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writev\n", argc));
2205 return INVALID_ARGS;
2208 fd = get_obj(argv[0]);
2211 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2212 return INVALID_ARGS;
2215 index = get_obj(argv[1]);
2218 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2222 buf = buflist[index]->buf;
2224 iov = (struct iovec *)buf;
2225 count = get_obj(argv[2]);
2228 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2229 return INVALID_ARGS;
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));
2235 last_ret_val = writev(fd, iov, count);
2236 if (last_ret_val < 0)
2237 my_perror("writev");
2244 int test_do_mknod(int argc, char **argv)
2249 DBG(2, fprintf(outfp, "Invalid number of args (%d) for mknod\n", argc));
2250 return INVALID_ARGS;
2253 dev = get_obj(argv[2]);
2255 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2256 return INVALID_ARGS;
2261 return sysio_mknod(argv[0], argv[1], (dev_t) dev);
2264 int test_do_umount(int argc, char **argv)
2269 DBG(2, fprintf(outfp, "Invalid number (%d) of args for umount\n", argc));
2270 return INVALID_ARGS;
2273 err = umount(argv[0]);
2275 my_perror("umount");
2284 int test_do_init_iovec(int argc, char **argv)
2286 int iov_index, buf_index;
2287 int offset, len, pos;
2288 struct iovec *iov_ptr;
2292 DBG(2, fprintf(outfp, "Need buffer, offset, len, array pos, and iov pointer\n"));
2293 return INVALID_ARGS;
2296 if ((buf_index = get_obj(argv[0])) < 0) {
2297 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[0]));
2300 base_ptr = buflist[buf_index]->buf;
2302 if ((offset = get_obj(argv[1])) < 0) {
2303 DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[1]));
2307 if ((len = get_obj(argv[2])) < 0) {
2308 DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[2]));
2312 if ((pos = get_obj(argv[3])) < 0) {
2313 DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[3]));
2317 if ((iov_index = get_obj(argv[4])) < 0) {
2318 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[4]));
2321 iov_ptr = (struct iovec *)(buflist[iov_index]->buf);
2323 iov_ptr[pos].iov_len = len;
2324 iov_ptr[pos].iov_base = (void *)(base_ptr + offset);
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));
2335 int test_do_init_xtvec(int argc, char **argv)
2338 int offset, len, pos;
2339 struct xtvec *xtv_ptr;
2342 DBG(2, fprintf(outfp, "Need offset, len, array pos, and xtv pointer\n"));
2343 return INVALID_ARGS;
2346 if ((offset = get_obj(argv[0])) < 0) {
2347 DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[0]));
2351 if ((len = get_obj(argv[1])) < 0) {
2352 DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[1]));
2356 if ((pos = get_obj(argv[2])) < 0) {
2357 DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[2]));
2361 if ((xtv_index = get_obj(argv[3])) < 0) {
2362 DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[3]));
2365 xtv_ptr = (struct xtvec *)(buflist[xtv_index]->buf);
2367 xtv_ptr[pos].xtv_len = len;
2368 xtv_ptr[pos].xtv_off = offset;
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));
2379 int test_do_writex(int argc, char **argv)
2381 int fd, iov_count, xtv_count,index;
2387 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writex\n", argc));
2388 return INVALID_ARGS;
2391 fd = get_obj(argv[0]);
2394 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2395 return INVALID_ARGS;
2398 index = get_obj(argv[1]);
2401 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2405 buf = buflist[index]->buf;
2407 iov = (struct iovec *)buf;
2408 iov_count = get_obj(argv[2]);
2410 if (iov_count < 0) {
2411 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2412 return INVALID_ARGS;
2415 index = get_obj(argv[3]);
2418 DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2422 buf = buflist[index]->buf;
2424 xtv = (struct xtvec *)buf;
2425 xtv_count = get_obj(argv[4]);
2427 if (xtv_count < 0) {
2428 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2429 return INVALID_ARGS;
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));
2435 last_ret_val = writex(fd, iov, iov_count, xtv, xtv_count);
2436 if (last_ret_val < 0)
2437 my_perror("writex");
2445 int test_do_iwritex(int argc, char **argv)
2447 int fd, iov_count, xtv_count,index;
2453 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritex\n", argc));
2454 return INVALID_ARGS;
2457 fd = get_obj(argv[0]);
2460 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2461 return INVALID_ARGS;
2464 index = get_obj(argv[1]);
2467 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2471 buf = buflist[index]->buf;
2473 iov = (struct iovec *)buf;
2474 iov_count = get_obj(argv[2]);
2476 if (iov_count < 0) {
2477 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2478 return INVALID_ARGS;
2481 index = get_obj(argv[3]);
2484 DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2488 buf = buflist[index]->buf;
2490 xtv = (struct xtvec *)buf;
2491 xtv_count = get_obj(argv[4]);
2493 if (xtv_count < 0) {
2494 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2495 return INVALID_ARGS;
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));
2501 last_ret_val = (long) iwritex(fd, iov, iov_count, xtv, xtv_count);
2502 if (last_ret_val < 0)
2503 my_perror("iwritex");
2511 int test_do_readx(int argc, char **argv)
2513 int fd, iov_count, xtv_count,index;
2519 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readx\n", argc));
2520 return INVALID_ARGS;
2523 fd = get_obj(argv[0]);
2526 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2527 return INVALID_ARGS;
2530 index = get_obj(argv[1]);
2533 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2537 buf = buflist[index]->buf;
2539 iov = (struct iovec *)buf;
2540 iov_count = get_obj(argv[2]);
2542 if (iov_count < 0) {
2543 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2544 return INVALID_ARGS;
2547 index = get_obj(argv[3]);
2550 DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2554 buf = buflist[index]->buf;
2556 xtv = (struct xtvec *)buf;
2557 xtv_count = get_obj(argv[4]);
2559 if (xtv_count < 0) {
2560 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2561 return INVALID_ARGS;
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));
2567 last_ret_val = readx(fd, iov, iov_count, xtv, xtv_count);
2568 if (last_ret_val < 0)
2577 int test_do_ireadx(int argc, char **argv)
2579 int fd, iov_count, xtv_count,index;
2585 DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadx\n", argc));
2586 return INVALID_ARGS;
2589 fd = get_obj(argv[0]);
2592 DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0]));
2593 return INVALID_ARGS;
2596 index = get_obj(argv[1]);
2599 DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1]));
2603 buf = buflist[index]->buf;
2605 iov = (struct iovec *)buf;
2606 iov_count = get_obj(argv[2]);
2608 if (iov_count < 0) {
2609 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2610 return INVALID_ARGS;
2613 index = get_obj(argv[3]);
2616 DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3]));
2620 buf = buflist[index]->buf;
2622 xtv = (struct xtvec *)buf;
2623 xtv_count = get_obj(argv[4]);
2625 if (xtv_count < 0) {
2626 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4]));
2627 return INVALID_ARGS;
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));
2633 last_ret_val = (long) ireadx(fd, iov, iov_count, xtv, xtv_count);
2634 if (last_ret_val < 0)
2635 my_perror("ireadx");
2643 int do_checkbuf(int argc, char **argv)
2645 int size, val, index, i, offset;
2649 DBG(2, fprintf(outfp, "Need buffer, val, and offset for checkbuf\n"));
2650 return INVALID_ARGS;
2653 index = get_obj(argv[0]);
2656 DBG(2, fprintf(outfp, "Unable to find buf described by %s\n", argv[0]));
2660 buf = (int *)buflist[index]->buf;
2663 size = get_obj(argv[1]);
2666 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[1]));
2667 return INVALID_ARGS;
2670 val = get_obj(argv[2]);
2673 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
2674 return INVALID_ARGS;
2678 offset = get_obj(argv[3]);
2681 DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3]));
2682 return INVALID_ARGS;
2686 ref_buf = (int *)malloc(size);
2687 memset((void *)ref_buf, val, size);
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);