]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/scsi-irix.c
2 * "$Id: scsi-irix.c 4703 2005-09-26 19:33:58Z mike $"
4 * IRIX SCSI printer support for the Common UNIX Printing System (CUPS).
6 * Copyright 2003-2005 by Easy Software Products, all rights reserved.
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the
10 * following conditions are met:
12 * 1. Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the
14 * following disclaimer.
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.
21 * 3. All advertising materials mentioning features or use
22 * of this software must display the following
25 * This product includes software developed by Easy
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.
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
49 * list_devices() - List the available SCSI printer devices.
50 * print_device() - Print a file to a SCSI device.
54 * Include necessary headers.
57 #include <bstring.h> /* memcpy() and friends */
58 #include <sys/dsreq.h> /* SCSI interface stuff */
62 * 'list_devices()' - List the available SCSI printer devices.
68 puts("direct scsi \"Unknown\" \"SCSI Printer\"");
73 * 'print_device()' - Print a file to a SCSI device.
76 int /* O - Print status */
77 print_device(const char *resource
, /* I - SCSI device */
78 int fd
, /* I - File to print */
79 int copies
) /* I - Number of copies to print */
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 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
88 struct sigaction action
; /* Actions for POSIX signals */
89 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
93 * Make sure we have a valid resource name...
96 if (strncmp(resource
, "/dev/scsi/", 10) != 0)
98 fprintf(stderr
, "ERROR: Bad SCSI device file \"%s\"!\n", resource
);
99 return (CUPS_BACKEND_STOP
);
103 * Open the SCSI device file...
108 if ((scsi_fd
= open(resource
, O_RDWR
| O_EXCL
)) == -1)
110 if (getenv("CLASS") != NULL
)
113 * If the CLASS environment variable is set, the job was submitted
114 * to a class and not to a specific queue. In this case, we want
115 * to abort immediately so that the job can be requeued on the next
116 * available printer in the class.
119 fputs("INFO: Unable to open SCSI device, queuing on next printer in class...\n",
123 * Sleep 5 seconds to keep the job from requeuing too rapidly...
131 if (errno
!= EAGAIN
&& errno
!= EBUSY
)
133 fprintf(stderr
, "ERROR: Unable to open SCSI device \"%s\" - %s\n",
134 resource
, strerror(errno
));
135 return (CUPS_BACKEND_FAILED
);
139 fprintf(stderr
, "INFO: SCSI device \"%s\" busy; retrying...\n",
145 while (scsi_fd
== -1);
148 * Now that we are "connected" to the port, ignore SIGTERM so that we
149 * can finish out any page data the driver sends (e.g. to eject the
150 * current page... Only ignore SIGTERM if we are printing data from
151 * stdin (otherwise you can't cancel raw jobs...)
156 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
157 sigset(SIGTERM
, SIG_IGN
);
158 #elif defined(HAVE_SIGACTION)
159 memset(&action
, 0, sizeof(action
));
161 sigemptyset(&action
.sa_mask
);
162 action
.sa_handler
= SIG_IGN
;
163 sigaction(SIGTERM
, &action
, NULL
);
165 signal(SIGTERM
, SIG_IGN
);
166 #endif /* HAVE_SIGSET */
170 * Copy the print file to the device...
176 lseek(fd
, 0, SEEK_SET
);
178 while ((bytes
= read(fd
, buffer
, sizeof(buffer
))) > 0)
180 memset(&scsi_req
, 0, sizeof(scsi_req
));
182 scsi_req
.ds_flags
= DSRQ_WRITE
;
183 scsi_req
.ds_time
= 60 * 1000;
184 scsi_req
.ds_cmdbuf
= scsi_cmd
;
185 scsi_req
.ds_cmdlen
= 6;
186 scsi_req
.ds_databuf
= buffer
;
187 scsi_req
.ds_datalen
= bytes
;
189 scsi_cmd
[0] = 0x0a; /* Group 0 print command */
191 scsi_cmd
[2] = bytes
/ 65536;
192 scsi_cmd
[3] = bytes
/ 256;
196 for (try = 0; try < 10; try ++)
197 if (ioctl(scsi_fd
, DS_ENTER
, &scsi_req
) < 0 ||
198 scsi_req
.ds_status
!= 0)
200 fprintf(stderr
, "WARNING: SCSI command timed out (%d); retrying...\n",
209 fprintf(stderr
, "ERROR: Unable to send print data (%d)\n",
212 return (CUPS_BACKEND_FAILED
);
220 * Close the device and return...
225 return (CUPS_BACKEND_OK
);
230 * End of "$Id: scsi-irix.c 4703 2005-09-26 19:33:58Z mike $".