2 #include "test_driver.h"
7 fprintf(outfp, "libsysio test harness\n");
8 fprintf(outfp, "To get help on a specific command, use HELP <cmd>\n");
9 fprintf(outfp, "To exit, type exit or quit\n");
11 fprintf(outfp, "\nTo save the result from a function, use \"$res = CALL command\"\n");
12 fprintf(outfp, "To later use that res, do \"comm $res\"\n");
14 fprintf(outfp, "\n\nAvailable commands are (always preceded by CALL):\n\n");
16 /* Get total number of commands */
17 while (cmd_list[count].cmd)
23 for (i=0; i < d; i++) {
25 if ( (i+d) < count ) {
26 if ( (i + 2*d) < count) {
28 fprintf(outfp, "%-15s %-15s %-15s %-15s\n",
29 cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd,
32 fprintf(outfp, "%-15s %-15s %-15s\n",
33 cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd);
35 fprintf(outfp, "%-15s %-15s\n",
36 cmd_list[i].cmd, cmd_list[i+d].cmd);
38 fprintf(outfp, "%-15s\n",
46 fprintf(outfp, "setdebug [level]: Set debugging level to level\n");
51 fprintf(outfp, "setbuf [val] [size] [buf] [off]: fill size bytes of buf with byte val\n");
57 fprintf(outfp, "clear buf: zero out the buffer\n");
60 void usage_printline()
62 fprintf(outfp, "printline [0|1]: Turn off (0) or on (1) the printing of line number\n");
63 fprintf(outfp, " : and file name with debug output\n");
68 fprintf(outfp, "endian: returns 1 for bigendian machines and 0 for little endian machines\n");
74 fprintf(outfp, "sizeof [type]: returns the size of the data type. Currently \n");
75 fprintf(outfp, " : supported types are char, int, long, flock, stat and \n");
76 fprintf(outfp, " : statvfs\n");
80 void usage_get_buffer()
82 fprintf(outfp, "alloc [size] <align>: allocates a buffer of size bytes aligned to align\n");
83 fprintf(outfp, " : align is optional. If not there, buffer will be aligned on\n");
84 fprintf(outfp, " : a one-byte boundary. returns an index into an array that \n");
85 fprintf(outfp, " : holds the buffer\n");
90 void usage_free_buffer()
92 fprintf(outfp, "free [bufidx]: frees buffer at bufidx. Returns 0 on success, -1 on failure\n");
95 void usage_do_fillbuff()
97 fprintf(outfp, "fill [val] [type] [size] [offset] [buf] : Fills the buffer buf with size \n");
98 fprintf(outfp, " : bytes of val starting at buf+offset\n");
99 fprintf(outfp, " : The type of val is specified by type,\n");
100 fprintf(outfp, " : which can be UINT, STR, or PTR\n");
103 void usage_do_printbuf()
105 fprintf(outfp, "printbuf [buf] : print out contents of the buffer stored in buf\n");
106 fprintf(outfp, " : Always returns 0\n");
111 fprintf(outfp, "cmpstr [buf1] [buf2]: Compare the contents of buf1 with buf2 by issuing a \n");
112 fprintf(outfp, " strcmp call. Returns 0 if the buffers match\n");
118 fprintf(outfp, "init <driver> <path> <flags>: Without any arguments, initilizes libsysio\n");
119 fprintf(outfp, " : to default values for root directory and\n");
120 fprintf(outfp, " : current directory. Accepts optional\n");
121 fprintf(outfp, " : arguments for the root driver, the mount\n");
122 fprintf(outfp, " : path, and the mount flags. Must be called\n");
123 fprintf(outfp, " : before any other libsysio calls. Returns\n");
124 fprintf(outfp," : 0 on success, -1 on failure\n");
129 fprintf(outfp, "list <dir>: lists contents of dir. If dir is ommitted, will list contents\n");
130 fprintf(outfp, " : of the current working directory\n");
131 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
136 fprintf(outfp, "chdir [dir]: change the current working directory to dir\n");
137 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
142 fprintf(outfp, "chmod [newmode] [file]: change mode of file to newmode. newmode can be \n");
143 fprintf(outfp, " : specifed symbolically (eg, a+x), numerically \n");
144 fprintf(outfp, " : (eg, 0777), or using system defines \n");
145 fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP)\n");
146 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
152 fprintf(outfp, "chown [newown[:newgrp]] [file]: change the owner of file to newown, the group\n");
153 fprintf(outfp, " : of file to newgrp, or both\n");
154 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
159 fprintf(outfp, "open [file] [flags] <mode>: open file with given flags. The mode is optional\n");
160 fprintf(outfp, " : can use defines for open, (eg, open foo O_RDONLY)\n");
161 fprintf(outfp, " : If flags are 0, file will be opened with O_RDWR\n");
162 fprintf(outfp, " : Returns the file descriptor for the opened file\n");
167 fprintf(outfp, "close [file]: closes the file. Returns 0 on success, -1 on failure\n");
172 fprintf(outfp, "mount [fstype:source] [target]: mount source (which has fstype as its file\n");
173 fprintf(outfp, " : system type) onto target.\n");
174 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
179 fprintf(outfp, "dup [oldfd]: Duplicate oldfd. Returns the duplicated file descriptor\n");
180 fprintf(outfp, " : Returns -1 on failure\n");
185 fprintf(outfp, "dup2 [oldfd] [newfd]: Make newfd be a copy of oldfd. Returns newfd on \n");
186 fprintf(outfp, " : success and -1 on failure\n");
191 fprintf(outfp, "fcntl [fd] [cmd] <args> : execute fcntl cmd on file with file descriptor fd\n");
192 fprintf(outfp, " : using (optional) args. Accepted (but not \n");
193 fprintf(outfp, " : necesarily working) commands are F_DUPFD, \n");
194 fprintf(outfp, " : F_GETFD, F_GETFL, F_GETOWN, F_SETFD, F_SETFL,\n");
195 fprintf(outfp, " : F_SETOWN, F_SETLK, F_SETLKW, and F_GETLK. \n");
200 fprintf(outfp, "fstat [fd] [buf]: Get the stat structure for file descriptor fd and place it\n");
201 fprintf(outfp, " : in buf. Returns 0 on success, -1 on failure\n");
206 fprintf(outfp, "fsync [fd]: ensure all parts of file with file descriptor fd are output to\n");
207 fprintf(outfp, " : stable storage. Returns 0 on success, -1 on failure\n");
210 void usage_fdatasync()
212 fprintf(outfp, "fdatasync [fd]: ensure all parts of file with file descriptor fd except the \n");
213 fprintf(outfp, " : metadata are output to stable storage. Returns 0 on \n");
214 fprintf(outfp, " : success, -1 on failure\n");
217 void usage_ftruncate()
219 fprintf(outfp, "ftruncate [fd] [len]: truncate file with file descriptor fd to have be \n");
220 fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n");
221 fprintf(outfp, " : failure\n");
226 fprintf(outfp, "getcwd [buf] [size]: get the current working directory and store it in buf\n");
227 fprintf(outfp, " : buf is size bytes in length. If buf is too short, an \n");
228 fprintf(outfp, " : error of ERANGE is returned. Returns 0 on success, -1\n");
229 fprintf(outfp, " : on failure\n");
234 fprintf(outfp, "lseek [fd] [offset] [whence]: Sets the offset of the file descriptor fd to\n");
235 fprintf(outfp, " : either offset if whence is SEEK_SET or offset\n");
236 fprintf(outfp, " : plus the current location if whence is SEEK_CUR\n");
237 fprintf(outfp, " : or offset plus the size of the file if whence\n");
238 fprintf(outfp, " : is SEEK_END. Returns 0 on success and -1 on \n");
239 fprintf(outfp, " : failure\n");
244 fprintf(outfp, "lstat [filename] [buf]: Get the stat structure for filename and return it in\n");
245 fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n");
248 void usage_getdirentries()
250 fprintf(outfp, "getdirentries [fd] [buf] [nbytes] [basep]: Read dir entries from directory\n");
251 fprintf(outfp, " : with file descriptor fd into buf\n");
252 fprintf(outfp, " : At most nbytes are read. Reading\n");
253 fprintf(outfp, " : starts at basep, and basep is set\n");
254 fprintf(outfp, " : to new pos. Returns the number of \n");
255 fprintf(outfp, " : bytes read on success or 0 on\n");
256 fprintf(outfp, " : failure\n");
257 fprintf(outfp, "Note that basep does not have to be pre-allocated. Executing cmd: \n");
258 fprintf(outfp, "\"getdirentries $fd $buf 4096 $basep\", where $fd is the result of an open\n");
259 fprintf(outfp, "and $buf is the result of an alloc (but $basep is totally new) will work\n");
260 fprintf(outfp, "After the execution of the command, $basep holds the new offset and can be\n");
261 fprintf(outfp, "used again for any further getdirentries calls\n");
266 fprintf(outfp, "mkdir [newdir] [mode]: make a new directory, newdir, with the permissions \n");
267 fprintf(outfp, " : specified in mode. Permissions can be symbolic \n");
268 fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n");
269 fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n");
270 fprintf(outfp, " : -1 on failure.\n");
276 fprintf(outfp, "creat [newfile] [mode]: create a new file, newfile, with the permissions \n");
277 fprintf(outfp, " : specified in mode. Permissions can be symbolic \n");
278 fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n");
279 fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n");
280 fprintf(outfp, " : -1 on failure.\n");
285 fprintf(outfp, "stat [filename] [buf]: Get the stat structure for filename and return it in\n");
286 fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n");
291 fprintf(outfp, "statvfs [filename] [buf]: Get the statvfs structure for filename and return\n");
292 fprintf(outfp, " : it in buf. Returns 0 on success and -1 on failure\n");
295 void usage_fstatvfs()
297 fprintf(outfp, "fstatvfs [fd] [buf]: Get the stat structure for file with file descriptor fd\n");
298 fprintf(outfp, " : and return it in buf. Returns 0 on success and -1 on\n");
299 fprintf(outfp, " : failure\n");
302 void usage_truncate()
304 fprintf(outfp, "truncate [fname] [len]: truncate file with name fname to be exactly \n");
305 fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n");
306 fprintf(outfp, " : failure\n");
311 fprintf(outfp, "rmdir [dirname]: Remove directory at dirname. Returns 0 on success, -1 on\n");
312 fprintf(outfp, " : failure.\n");
317 fprintf(outfp, "symlink [path1] [path2]: Make a symbolic link from path1 to path2. Returns\n");
318 fprintf(outfp, " : 0 on success, -1 on failure\n");
323 fprintf(outfp, "unlink [path]: Unlink path. If path is the last name to a file, the file is \n");
324 fprintf(outfp, " : is removed. If it was a symbolic link, the link is removed. \n");
325 fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
330 fprintf(outfp, "ioctl [fd] [cmd] <args> : Issue the ioctl command cmd on the file with file\n");
331 fprintf(outfp, " : descriptor fd. Any arguments are placed in args\n");
332 fprintf(outfp, " : At the moment, the only commands understand are the \n");
333 fprintf(outfp, " : ioctl commands found in /usr/include/linux/fs.h\n");
338 fprintf(outfp, "ioctl [mask] : Sets the umask used by open to set initial file permissions on\n");
339 fprintf(outfp, " : a newly created file. Returnds the previous value of the mask\n");
344 fprintf(outfp, "iodone [ioid] : Poll for completion of the asynchronous request identifed by\n");
345 fprintf(outfp, " : ioid. Returns 1 if request finished\n");
350 fprintf(outfp, "iowait [ioid] : Wait for completion of the asynchronous request identifed by\n");
351 fprintf(outfp, " : ioid. Returns result of asynchronous request \n");
356 fprintf(outfp, "ipreadv [fd] [buf] [count] [off]: Reads data asynchrously to file descriptor fd \n");
357 fprintf(outfp, " : starting at offset off. Data comes from \n");
358 fprintf(outfp, " : buffer described by buf, which is a pointer to\n");
359 fprintf(outfp, " : an iovec strucutre. Number of buffers is \n");
360 fprintf(outfp, " : specified by count. Returns an iod_t on \n");
361 fprintf(outfp, " : success and -1 on failure\n");
366 fprintf(outfp, "ipread [fd] [buf] [count] [off]: Read asynchrously up to count bytes from file\n");
367 fprintf(outfp, " : with file descriptor fd starting at offset off\n");
368 fprintf(outfp, " : Read into buffer pointed at by buf. Returns\n");
369 fprintf(outfp, " : an iod_t on success and -1 on failure\n");
374 fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads data from file descriptor fd starting at\n");
375 fprintf(outfp, " : offset off. Data goes into buffer described\n");
376 fprintf(outfp, " : by buf, which is a pointer to an iovec \n");
377 fprintf(outfp, " : structure. Number of buffers is specified by\n");
378 fprintf(outfp, " : count. Returns the number of bytes read\n");
383 fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads count bytes of data from file descriptor\n");
384 fprintf(outfp, " : fd starting at offset off. Data goes into buf.\n");
385 fprintf(outfp, " : Returns number of bytes read or -1 on failure\n");
390 fprintf(outfp, "ireadv [fd] [buf] [count] : Reads data asynchrously to file descriptor fd \n");
391 fprintf(outfp, " : Data comes from buffer described by buf, which is \n");
392 fprintf(outfp, " : an pointer to an iovec structure. Number of\n");
393 fprintf(outfp, " : buffers is specified by count. Returns an iod_t\n");
394 fprintf(outfp, " : on success and -1 on failure\n");
399 fprintf(outfp, "iread [fd] [buf] [count]: Read asynchrously up to count bytes from file with\n");
400 fprintf(outfp, " : file descriptor fd into buffer pointed at by buf\n");
401 fprintf(outfp, " : Returns an iod_t on success and -1 on failure\n");
406 fprintf(outfp, "readv [fd] [buf] [count] : Reads data from file descriptor fd. Data comes from\n");
407 fprintf(outfp, " : the buffer described by buf, which is a pointer to an\n");
408 fprintf(outfp, " : an iovec structure. Number of buffers is specified\n");
409 fprintf(outfp, " : by count. Returns the number of bytes read on \n");
410 fprintf(outfp, " : on success and -1 on failure\n");
415 fprintf(outfp, "read [fd] [buf] [count]: Read up to count bytes from file with file \n");
416 fprintf(outfp, " : descriptor fd into buffer pointed at by buf\n");
417 fprintf(outfp, " : Returns number of bytes read on success or 0 on \n");
418 fprintf(outfp, " : on failure\n");
421 void usage_ipwritev()
423 fprintf(outfp, "ipwritev [fd] [buf] [count] [off]: writes data asynchronously to file with file\n");
424 fprintf(outfp, " : descriptor fd starting at offset off. Data \n");
425 fprintf(outfp, " : comes from buffers described by buf, which\n");
426 fprintf(outfp, " : is a pointer to an iovec structure. Number \n");
427 fprintf(outfp, " : of buffers is specified by count. Returns\n");
428 fprintf(outfp, " : an iod_t on success and -1 on failure\n");
433 fprintf(outfp, "ipwrite [fd] [buf] [count] [off]: writes count bytes of data asynchronously to\n");
434 fprintf(outfp, " : file with file descriptor fd starting at \n");
435 fprintf(outfp, " : offset off. Data comes from buf. Returns an\n");
436 fprintf(outfp, " : iod_t on success and -1 on failure\n");
441 fprintf(outfp, "pwritev [fd] [buf] [count] [off]: writes data to file with file descriptor fd\n");
442 fprintf(outfp, " : starting at offset off. Data comes from \n");
443 fprintf(outfp, " : buffers described by buf, which is a pointer\n");
444 fprintf(outfp, " : to an iovec structure. Number of buffers is\n");
445 fprintf(outfp, " : by count. Returns number of bytes read on \n");
446 fprintf(outfp, " : success and -1 on failure\n");
451 fprintf(outfp, "pwrite [fd] [buf] [count] [off]: writes count bytes of data to file with file \n");
452 fprintf(outfp, " : descriptor fd starting at offset off. Data\n");
453 fprintf(outfp, " : Data comes from buf. Returns number of bytes\n");
454 fprintf(outfp, " : written on success and -1 on failure\n");
459 fprintf(outfp, "iwritev [fd] [buf] [count] : writes data asynchronously to file with file\n");
460 fprintf(outfp, " : descriptor fd. Data comes from buffers described\n");
461 fprintf(outfp, " : by buf, which is a pointer to an iovec structure.\n");
462 fprintf(outfp, " : Number of buffers is specified by count. Returns\n");
463 fprintf(outfp, " : an iod_t on success and -1 on failure\n");
468 fprintf(outfp, "iwrite [fd] [buf] [count] : writes count bytes of data asynchronously to\n");
469 fprintf(outfp, " : file with file descriptor fd. Data comes from buf.\n");
470 fprintf(outfp, " : Returns an iod_t on success and -1 on failure.\n");
475 fprintf(outfp, "writev [fd] [buf] [count]: writes data to file descriptor fd. Data comes from\n");
476 fprintf(outfp, " : buffers described by buf, which is a pointer to a \n");
477 fprintf(outfp, " : iovec strucutre. Number of buffers is specified by \n");
478 fprintf(outfp, " : count \n");
483 fprintf(outfp, "write [fd] [buf] [count] : writes count bytes of data to file with file \n");
484 fprintf(outfp, " : descriptor fd. Data comes from buf. Returns number\n");
485 fprintf(outfp, " : of bytes written on success and -1 on failure.\n");
490 fprintf(outfp, "mknod [path] [mode] [dev] : creates a filesystem node named path with \n");
491 fprintf(outfp, " : specified mode using device special file dev\n");
492 fprintf(outfp, " : Returns 0 on sucess and -1 on failure\n");
498 fprintf(outfp, "umount [path] : Umount file at path. Returns 0 on success and -1 on failure\n");
501 void usage_init_iovec()
503 fprintf(outfp, "init_iovec buf offset len num iov_buf: Init iovector. iov_uf points to an array of\n");
504 fprintf(outfp, " iovecs, num is the number of the iovec, \n");
505 fprintf(outfp, " buf is the buffer to be used, offset \n");
506 fprintf(outfp, " specifies how far into the buffer the iovec\n");
507 fprintf(outfp, " should point and len is the iov length\n");
510 void usage_init_xtvec()
512 fprintf(outfp, "init_xtvec offset len num buf: Init xtvector. Buf points to an array of\n");
513 fprintf(outfp, " xtvecs, num is the number of the xtvec, offset\n");
514 fprintf(outfp, " is xtv_off and len is the iov lenghth\n");
515 fprintf(outfp, " the iov length\n");
520 fprintf(outfp, "writex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n");
521 fprintf(outfp, " xtvcnt xtvecs\n");
526 fprintf(outfp, "iwritex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n");
527 fprintf(outfp, " xtvcnt xtvecs\n");
532 fprintf(outfp, "readx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n");
533 fprintf(outfp, " xtvcnt xtvecs\n");
538 fprintf(outfp, "ireadx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n");
539 fprintf(outfp, " xtvcnt xtvecs\n");
543 void usage_checkbuf()
545 fprintf(outfp, "checkbuf [buf] [size] [val] [off]: Staring at offset off, checks to see\n");
546 fprintf(outfp, " if val is in first size bytes of buf\n");