]> git.ipfire.org Git - thirdparty/cups.git/blame - backend/scsi-irix.c
Change the end copyright for Easy Software Products files to 2003.
[thirdparty/cups.git] / backend / scsi-irix.c
CommitLineData
62810009 1/*
997fbfa7 2 * "$Id: scsi-irix.c,v 1.2 2002/12/17 18:56:33 swdev Exp $"
62810009 3 *
4 * IRIX SCSI printer support for the Common UNIX Printing System (CUPS).
5 *
997fbfa7 6 * Copyright 2003 by Easy Software Products, all rights reserved.
62810009 7 *
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the
10 * following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the
14 * following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the
17 * above copyright notice, this list of conditions and
18 * the following disclaimer in the documentation and/or
19 * other materials provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use
22 * of this software must display the following
23 * acknowledgement:
24 *
25 * This product includes software developed by Easy
26 * Software Products.
27 *
28 * 4. The name of Easy Software Products may not be used to
29 * endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS
33 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
34 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
37 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
45 * DAMAGE.
46 *
47 * Contents:
48 *
49 * list_devices() - List the available SCSI printer devices.
50 * print_device() - Print a file to a SCSI device.
51 */
52
53/*
54 * Include necessary headers.
55 */
56
57#include <bstring.h> /* memcpy() and friends */
58#include <sys/dsreq.h> /* SCSI interface stuff */
59
60
61/*
62 * 'list_devices()' - List the available SCSI printer devices.
63 */
64
65void
66list_devices(void)
67{
68 puts("direct scsi \"Unknown\" \"SCSI Printer\"");
69}
70
71
72/*
73 * 'print_device()' - Print a file to a SCSI device.
74 */
75
76int /* O - Print status */
77print_device(const char *resource, /* I - SCSI device */
78 int fd, /* I - File to print */
79 int copies) /* I - Number of copies to print */
80{
81 int scsi_fd; /* SCSI file descriptor */
82 char buffer[8192]; /* Data buffer */
83 int bytes; /* Number of bytes */
84 int try; /* Current try */
85 dsreq_t scsi_req; /* SCSI request */
86 char scsi_cmd[6], /* SCSI command data */
87 scsi_sense[32]; /* SCSI sense data */
88#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
89 struct sigaction action; /* Actions for POSIX signals */
90#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
91
92
93 /*
94 * Make sure we have a valid resource name...
95 */
96
97 if (strncmp(resource, "/dev/scsi/", 10) != 0)
98 {
99 fprintf(stderr, "ERROR: Bad SCSI device file \"%s\"!\n", resource);
100 return (1);
101 }
102
103 /*
104 * Open the SCSI device file...
105 */
106
107 do
108 {
109 if ((scsi_fd = open(resource, O_RDWR | O_EXCL)) == -1)
110 {
111 if (errno != EAGAIN && errno != EBUSY)
112 {
113 fprintf(stderr, "ERROR: Unable to open SCSI device \"%s\" - %s\n",
114 resource, strerror(errno));
115 return (1);
116 }
117 else
118 {
119 fprintf(stderr, "INFO: SCSI device \"%s\" busy; retrying...\n",
120 resource);
121 sleep(30);
122 }
123 }
124 }
125 while (scsi_fd == -1);
126
127 /*
128 * Now that we are "connected" to the port, ignore SIGTERM so that we
129 * can finish out any page data the driver sends (e.g. to eject the
130 * current page... Only ignore SIGTERM if we are printing data from
131 * stdin (otherwise you can't cancel raw jobs...)
132 */
133
134 if (fd != 0)
135 {
136#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
137 sigset(SIGTERM, SIG_IGN);
138#elif defined(HAVE_SIGACTION)
139 memset(&action, 0, sizeof(action));
140
141 sigemptyset(&action.sa_mask);
142 action.sa_handler = SIG_IGN;
143 sigaction(SIGTERM, &action, NULL);
144#else
145 signal(SIGTERM, SIG_IGN);
146#endif /* HAVE_SIGSET */
147 }
148
149 /*
150 * Copy the print file to the device...
151 */
152
153 while (copies > 0)
154 {
155 if (fd != 0)
156 lseek(fd, 0, SEEK_SET);
157
158 while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
159 {
160 memset(&scsi_req, 0, sizeof(scsi_req));
161
162 scsi_req.ds_flags = DSRQ_WRITE;
163 scsi_req.ds_time = 60 * 1000;
164 scsi_req.ds_cmdbuf = scsi_cmd;
165 scsi_req.ds_cmdlen = 6;
166 scsi_req.ds_databuf = buffer;
167 scsi_req.ds_datalen = bytes;
168
169 scsi_cmd[0] = 0x0a; /* Group 0 print command */
170 scsi_cmd[1] = 0x00;
171 scsi_cmd[2] = bytes / 65536;
172 scsi_cmd[3] = bytes / 256;
173 scsi_cmd[4] = bytes;
174 scsi_cmd[5] = 0x00;
175
176 for (try = 0; try < 10; try ++)
177 if (ioctl(scsi_fd, DS_ENTER, &scsi_req) < 0 ||
178 scsi_req.ds_status != 0)
179 {
180 fprintf(stderr, "WARNING: SCSI command timed out (%d); retrying...\n",
181 scsi_req.ds_status);
182 sleep(try + 1);
183 }
184 else
185 break;
186
187 if (try >= 10)
188 {
189 fprintf(stderr, "ERROR: Unable to send print data (%d)\n",
190 scsi_req.ds_status);
191 close(scsi_fd);
192 return (1);
193 }
194 }
195
196 copies --;
197 }
198
199 /*
200 * Close the device and return...
201 */
202
203 close(fd);
204
205 return (0);
206}
207
208
209/*
997fbfa7 210 * End of "$Id: scsi-irix.c,v 1.2 2002/12/17 18:56:33 swdev Exp $".
62810009 211 */