/*
- * "$Id: usb-unix.c 5726 2006-07-12 20:00:11Z mike $"
+ * "$Id: usb-unix.c 6032 2006-10-12 19:19:47Z mike $"
*
* USB port backend for the Common UNIX Printing System (CUPS).
*
do
{
/*
- * Disable backchannel data when printing to Canon USB printers - apparently
- * Canon printers will return the IEEE-1284 device ID over and over and over
- * when they get a read request...
+ * Disable backchannel data when printing to Canon or Minolta USB
+ * printers - apparently these printers will return the IEEE-1284
+ * device ID over and over and over when they get a read request...
*/
- use_bc = strcasecmp(hostname, "Canon") != 0;
+ use_bc = strcasecmp(hostname, "Canon") != 0 ||
+ strstr(hostname, "Minolta") != NULL;
if ((device_fd = open_device(uri, &use_bc)) == -1)
{
list_devices(void)
{
#ifdef __linux
- int i; /* Looping var */
- int fd; /* File descriptor */
- char format[255], /* Format for device filename */
- device[255], /* Device filename */
- device_id[1024], /* Device ID string */
- device_uri[1024], /* Device URI string */
- make_model[1024]; /* Make and model */
-
-
- /*
- * First figure out which USB printer filename to use...
- */
-
- if (!access("/dev/usblp0", 0))
- strcpy(format, "/dev/usblp%d");
- else if (!access("/dev/usb/usblp0", 0))
- strcpy(format, "/dev/usb/usblp%d");
- else
- strcpy(format, "/dev/usb/lp%d");
+ int i; /* Looping var */
+ int fd; /* File descriptor */
+ char device[255], /* Device filename */
+ device_id[1024], /* Device ID string */
+ device_uri[1024], /* Device URI string */
+ make_model[1024]; /* Make and model */
/*
- * Then open each USB device...
+ * Try to open each USB device...
*/
for (i = 0; i < 16; i ++)
{
- sprintf(device, format, i);
+ /*
+ * Linux has a long history of changing the standard filenames used
+ * for USB printer devices. We get the honor of trying them all...
+ */
- if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
+ sprintf(device, "/dev/usblp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
{
- if (!backendGetDeviceID(fd, device_id, sizeof(device_id),
- make_model, sizeof(make_model),
- "usb", device_uri, sizeof(device_uri)))
- printf("direct %s \"%s\" \"%s USB #%d\" \"%s\"\n", device_uri,
- make_model, make_model, i + 1, device_id);
+ if (errno != ENOENT)
+ continue;
- close(fd);
+ sprintf(device, "/dev/usb/lp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
+ {
+ if (errno != ENOENT)
+ continue;
+
+ sprintf(device, "/dev/usb/usblp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
+ continue;
+ }
}
+
+ if (!backendGetDeviceID(fd, device_id, sizeof(device_id),
+ make_model, sizeof(make_model),
+ "usb", device_uri, sizeof(device_uri)))
+ printf("direct %s \"%s\" \"%s USB #%d\" \"%s\"\n", device_uri,
+ make_model, make_model, i + 1, device_id);
+
+ close(fd);
}
#elif defined(__sgi)
#elif defined(__sun) && defined(ECPPIOC_GETDEVID)
int i; /* Looping var */
int busy; /* Are any ports busy? */
- char format[255], /* Format for device filename */
- device[255], /* Device filename */
+ char device[255], /* Device filename */
device_id[1024], /* Device ID string */
make_model[1024], /* Make and model */
device_uri[1024]; /* Device URI string */
/*
- * First figure out which USB printer filename to use...
- */
-
- if (!access("/dev/usblp0", 0))
- strcpy(format, "/dev/usblp%d");
- else if (!access("/dev/usb/usblp0", 0))
- strcpy(format, "/dev/usb/usblp%d");
- else
- strcpy(format, "/dev/usb/lp%d");
-
- /*
- * Then find the correct USB device...
+ * Find the correct USB device...
*/
do
{
for (busy = 0, i = 0; i < 16; i ++)
{
- sprintf(device, format, i);
+ /*
+ * Linux has a long history of changing the standard filenames used
+ * for USB printer devices. We get the honor of trying them all...
+ */
+
+ sprintf(device, "/dev/usblp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
+ {
+ sprintf(device, "/dev/usb/lp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
+ {
+ sprintf(device, "/dev/usb/usblp%d", i);
+
+ if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
+ continue;
+ }
+ }
- if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
+ if (fd >= 0)
{
backendGetDeviceID(fd, device_id, sizeof(device_id),
make_model, sizeof(make_model),
/*
- * End of "$Id: usb-unix.c 5726 2006-07-12 20:00:11Z mike $".
+ * End of "$Id: usb-unix.c 6032 2006-10-12 19:19:47Z mike $".
*/