#include <unistd.h>
#include <syslog.h>
#include <scsi/sg.h>
-#ifdef __KLIBC__
-/*
- * Assume built under udev with KLIBC
- */
-#include <libsysfs.h>
-#else
#include <sysfs/libsysfs.h>
-#endif
#include "scsi_id.h"
#include "scsi.h"
static const char hex_str[]="0123456789abcdef";
-/*
- * XXX maybe move all these to an sg_io.c file.
- *
- * From here ...
- */
-
/*
* Values returned in the result/status, only the ones used by the code
* are used here.
hp->sbp, hp->sb_len_wr);
}
-static int scsi_dump_sense(struct sysfs_class_device *scsi_dev,
- struct sg_io_hdr *io)
+static int scsi_dump_sense(struct sysfs_device *scsi_dev, struct sg_io_hdr *io)
{
unsigned char *sense_buffer;
int s;
scsi_dev->name, sense_buffer[0],
sense_buffer[2]);
log_message(LOG_WARNING,
- "%s: non-extended sense class %d code 0x%0x ",
+ "%s: non-extended sense class %d code 0x%0x\n",
scsi_dev->name, sense_class, code);
}
return -1;
}
-static int scsi_dump(struct sysfs_class_device *scsi_dev, struct sg_io_hdr *io)
+static int scsi_dump(struct sysfs_device *scsi_dev, struct sg_io_hdr *io)
{
if (!io->status && !io->host_status && !io->msg_status &&
!io->driver_status) {
return -1;
}
-static int scsi_inquiry(struct sysfs_class_device *scsi_dev, int fd,
- unsigned char evpd, unsigned char page, unsigned
- char *buf, unsigned int buflen)
+static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd, unsigned
+ char evpd, unsigned char page, unsigned char *buf,
+ unsigned int buflen)
{
unsigned char inq_cmd[INQUIRY_CMDLEN] =
{ INQUIRY_CMD, evpd, page, 0, buflen, 0 };
io_hdr.timeout = DEF_TIMEOUT;
if (ioctl(fd, SG_IO, &io_hdr) < 0) {
- log_message(LOG_WARNING, "%s ioctl failed: %s\n",
+ log_message(LOG_WARNING, "%s: ioctl failed: %s\n",
scsi_dev->name, strerror(errno));
return -1;
}
retval = scsi_dump(scsi_dev, &io_hdr);
}
- /*
- * XXX where is the length checked? That is, was our request
- * buffer long enough?
- */
-
if (!retval) {
retval = buflen;
memcpy(buf, buffer, retval);
return retval;
}
-/*
- * XXX maybe move all these to an sg_io.c file.
- *
- * Ending here.
- */
-
-static int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
+static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
char *buffer, int len)
{
int retval;
- char *vendor;
+ char vendor[MAX_ATTR_LEN];
memset(buffer, 0, len);
retval = scsi_inquiry(scsi_dev, fd, 1, 0x0, buffer, len);
return 1;
}
if (buffer[3] > len) {
- log_message(LOG_WARNING, "%s: page 0 buffer too long %d",
+ log_message(LOG_WARNING, "%s: page 0 buffer too long %d\n",
scsi_dev->name, buffer[3]);
return 1;
}
* If the vendor id appears in the page assume the page is
* invalid.
*/
- vendor = sysfs_get_attr(scsi_dev, "vendor");
- if (!vendor) {
- log_message(LOG_WARNING, "%s: no vendor attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "vendor", vendor,
+ MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING,
+ "%s: cannot get model attribute\n",
scsi_dev->name);
return 1;
}
if (!strncmp(&buffer[VENDOR_LENGTH], vendor, VENDOR_LENGTH)) {
- log_message(LOG_WARNING, "%s invalid page0 data\n",
+ log_message(LOG_WARNING, "%s: invalid page0 data\n",
scsi_dev->name);
return 1;
}
* The caller checks that serial is long enough to include the vendor +
* model.
*/
-static int prepend_vendor_model(struct sysfs_class_device *scsi_dev,
- char *serial)
+static int prepend_vendor_model(struct sysfs_device *scsi_dev, char *serial)
{
- char *attr;
+ char attr[MAX_ATTR_LEN];
int ind;
- attr = sysfs_get_attr(scsi_dev, "vendor");
- if (!attr) {
- log_message(LOG_WARNING, "%s: no vendor attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "vendor", attr, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
scsi_dev->name);
return 1;
}
if (serial[ind] == '\n')
serial[ind] = '\0';
- attr = sysfs_get_attr(scsi_dev, "model");
- if (!attr) {
- log_message(LOG_WARNING, "%s: no model attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "model", attr, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get model attribute\n",
scsi_dev->name);
return 1;
}
* check_fill_0x83_id - check the page 0x83 id, if OK allocate and fill
* serial number.
**/
-static int check_fill_0x83_id(struct sysfs_class_device *scsi_dev,
- char *page_83,
- const struct scsi_id_search_values *id_search,
- char *serial, int max_len)
+static int check_fill_0x83_id(struct sysfs_device *scsi_dev, char
+ *page_83, const struct scsi_id_search_values
+ *id_search, char *serial, int max_len)
{
int i, j, len;
return 0;
}
-static int do_scsi_page83_inquiry(struct sysfs_class_device *scsi_dev, int fd,
+static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
char *serial, int len)
{
int retval;
return 1;
}
-static int do_scsi_page80_inquiry(struct sysfs_class_device *scsi_dev, int fd,
+static int do_scsi_page80_inquiry(struct sysfs_device *scsi_dev, int fd,
char *serial, int max_len)
{
int retval;
return 0;
}
-int scsi_get_serial (struct sysfs_class_device *scsi_dev, const char *devname,
+int scsi_get_serial (struct sysfs_device *scsi_dev, const char *devname,
int page_code, char *serial, int len)
{
unsigned char page0[256];
}
memset(serial, 0, len);
dprintf("opening %s\n", devname);
- fd = open(devname, O_RDONLY);
+ fd = open(devname, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- log_message(LOG_WARNING, "%s cannot open %s: %s\n",
+ log_message(LOG_WARNING, "%s: cannot open %s: %s\n",
scsi_dev->name, devname, strerror(errno));
return 1;
}
goto completed;
}
} else if (page_code != 0x00) {
- log_message(LOG_WARNING, "%s unsupported page code 0x%d\n",
+ log_message(LOG_WARNING, "%s: unsupported page code 0x%d\n",
scsi_dev->name, page_code);
return 1;
}
retval = 1;
completed:
if (close(fd) < 0)
- log_message(LOG_WARNING, "close failed: %s", strerror(errno));
+ log_message(LOG_WARNING, "%s: close failed: %s\n",
+ scsi_dev->name, strerror(errno));
return retval;
}