2 * Copyright (c) 1992,1997 Sun Microsystems, Inc. All Rights Reserved.
3 * Sun considers its source code as an unpublished, proprietary
4 * trade secret, and it is available only under strict license
5 * provisions. This copyright notice is placed here only to protect
6 * Sun in the event the source is deemed a published work.
7 * Disassembly, decompilation, or other means of reducing the
8 * object code to human readable form is prohibited by the license
9 * agreement under which this code is provided to the user or
10 * company in possession of this copy.
12 * RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
13 * Government is subject to restrictions as set forth in
14 * subparagraph (c)(1)(ii) of the Rights in Technical Data and
15 * Computer Software clause at DFARS 52.227-7013 and in similar
16 * clauses in the FAR and NASA FAR Supplement.
18 * These examples are provided with no warranties of any kind,
19 * including without limitation accuracy and usefulness, and Sun
20 * expressly disclaims all implied warranties of merchantability,
21 * fitness for a particular purpose and non-infringement. In no
22 * event shall Sun be liable for any damages, including without
23 * limitation, direct, special, indirect, or consequential damages
24 * arising out of, or relating to, use of these examples by customer
25 * or any third party. Sun is under no obligation to provide support
26 * to customer for this software.
29 * A simple tst program for the sample SCSI target driver.
30 * To compile: cc (or acc) sstest.c -o sstest
31 * Note: the full ANSI conformance flag, -Xt, fails because of the
32 * system header files.
35 * sstest [device] [command] [arg]
36 * Device is the /devices entry
38 * open - just open and close the device
39 * read [arg] - read a block. If arg is specifed, printf the result
40 * write [arg] - write a block. With arg, write "arg"
41 * rew - send the SCSI Rewind command (tests the USCSICMD ioctl)
42 * tur - send the SCSI Test Unit Ready command (SSTIOC_READY ioctl)
43 * errlev [lev] - set the error reporting level to <lev> (see sst_def.h)
46 #pragma ident "@(#)sstest.c 1.4 97/04/07 SMI"
51 #include <sys/scsi/impl/uscsi.h>
52 #include <sys/scsi/generic/commands.h>
57 static void usage(char *name);
59 main(int argc, char *argv[])
61 int fd, nbytes, level, arg;
62 char buf[BUFSZ], *progname, *devname, *command, *value;
63 struct uscsi_cmd scmd;
65 if ((argc != 3) && (argc != 4)) {
70 progname = argv[0]; /* name of this program */
71 devname = argv[1]; /* full path of device name */
72 command = argv[2]; /* command to do */
73 value = argv[3]; /* command's argument if present */
74 arg = (argc == 4); /* command has arg */
78 (void) sprintf(buf, "%s", devname);
79 if ((fd = open(buf, O_RDWR)) == -1) {
85 (void) memset((void *)buf, 0, BUFSZ);
87 if (strcmp(command, "open") == 0) {
88 fprintf(stdout, "Device opened\n");
89 } else if (strcmp(command, "read") == 0) {
90 if ((nbytes = read(fd, buf, BUFSZ)) != BUFSZ) {
97 fprintf(stdout, "Read \"%s\"\n", buf);
99 fprintf(stdout, "Read %d bytes\n", nbytes);
102 } else if (strcmp(command, "write") == 0) {
106 if ((nbytes = write(fd, buf, BUFSZ)) != BUFSZ) {
112 fprintf(stdout, "Wrote %d bytes\n", nbytes);
114 } else if (strcmp(command, "rew") == 0) {
115 (void) memset((void *) &scmd, 0, sizeof (scmd));
116 scmd.uscsi_flags = 0;
117 scmd.uscsi_timeout = 30;
118 buf[0] = SCMD_REWIND;
119 scmd.uscsi_cdb = buf;
120 scmd.uscsi_bufaddr = NULL;
121 scmd.uscsi_buflen = 0;
122 scmd.uscsi_cdblen = CDB_GROUP0;
124 if (ioctl(fd, USCSICMD, &scmd) == -1) {
125 perror("rewind ioctl");
130 fprintf(stdout, "Device rewound, status = 0x%x\n",
132 } else if (strcmp(command, "errlev") == 0) {
136 } else if ((level = atoi(value)) == 0) {
137 fprintf(stderr, "Bad error level %s\n", value);
141 if (ioctl(fd, SSTIOC_ERRLEV, &level) == -1) {
142 perror("Set error level ioctl");
147 } else if (strcmp(command, "tur") == 0) {
148 if (ioctl(fd, SSTIOC_READY, NULL) == -1) {
149 perror("Ready ioctl");
154 fprintf(stdout, "Device is ready\n");
156 fprintf(stderr, "Unknown command: %s\n", command);
168 (void) fprintf(stderr, "Usage: %s: [device] [command]\n", name);
169 (void) fprintf(stderr, "Device is the full path name of device\n");
170 (void) fprintf(stderr, "Command is one of:\n");
171 (void) fprintf(stderr, "\topen - just open & close\n");
172 (void) fprintf(stderr, "\tread - read a block\n");
173 (void) fprintf(stderr, "\twrite - write a block\n");
174 (void) fprintf(stderr, "\trew - send the SCSI 'rewind' command\n");
175 (void) fprintf(stderr, "\terrlev [lev] - Set the error "
176 "reporting level\n");
177 (void) fprintf(stderr, "\ttur - send the SCSI 'test unit ready'"