1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

udev/scsi_id: drop unused udev struct

This commit is contained in:
Yu Watanabe 2018-08-24 12:30:12 +09:00
parent f1ff9e8dd9
commit efc2774c25
3 changed files with 71 additions and 122 deletions

View File

@ -17,8 +17,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include "libudev.h"
#include "alloc-util.h"
#include "fd-util.h"
#include "libudev-private.h"
@ -148,10 +146,8 @@ static int argc_count(char *opts)
*
* vendor and model can end in '\n'.
*/
static int get_file_options(struct udev *udev,
const char *vendor, const char *model,
int *argc, char ***newargv)
{
static int get_file_options(const char *vendor, const char *model,
int *argc, char ***newargv) {
_cleanup_free_ char *buffer = NULL;
_cleanup_fclose_ FILE *f;
char *buf;
@ -311,10 +307,8 @@ static void help(void) {
}
static int set_options(struct udev *udev,
int argc, char **argv,
char *maj_min_dev)
{
static int set_options(int argc, char **argv,
char *maj_min_dev) {
int option;
/*
@ -400,9 +394,7 @@ static int set_options(struct udev *udev,
return 0;
}
static int per_dev_options(struct udev *udev,
struct scsi_id_device *dev_scsi, int *good_bad, int *page_code)
{
static int per_dev_options(struct scsi_id_device *dev_scsi, int *good_bad, int *page_code) {
int retval;
int newargc;
char **newargv = NULL;
@ -411,7 +403,7 @@ static int per_dev_options(struct udev *udev,
*good_bad = all_good;
*page_code = default_page_code;
retval = get_file_options(udev, vendor_str, model_str, &newargc, &newargv);
retval = get_file_options(vendor_str, model_str, &newargc, &newargv);
optind = 1; /* reset this global extern */
while (retval == 0) {
@ -455,13 +447,12 @@ static int per_dev_options(struct udev *udev,
return retval;
}
static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, const char *path)
{
static int set_inq_values(struct scsi_id_device *dev_scsi, const char *path) {
int retval;
dev_scsi->use_sg = sg_version;
retval = scsi_std_inquiry(udev, dev_scsi, path);
retval = scsi_std_inquiry(dev_scsi, path);
if (retval)
return retval;
@ -482,27 +473,26 @@ static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, co
* scsi_id: try to get an id, if one is found, printf it to stdout.
* returns a value passed to exit() - 0 if printed an id, else 1.
*/
static int scsi_id(struct udev *udev, char *maj_min_dev)
{
static int scsi_id(char *maj_min_dev) {
struct scsi_id_device dev_scsi = {};
int good_dev;
int page_code;
int retval = 0;
if (set_inq_values(udev, &dev_scsi, maj_min_dev) < 0) {
if (set_inq_values(&dev_scsi, maj_min_dev) < 0) {
retval = 1;
goto out;
}
/* get per device (vendor + model) options from the config file */
per_dev_options(udev, &dev_scsi, &good_dev, &page_code);
per_dev_options(&dev_scsi, &good_dev, &page_code);
if (!good_dev) {
retval = 1;
goto out;
}
/* read serial number from mode pages (no values for optical drives) */
scsi_get_serial(udev, &dev_scsi, maj_min_dev, page_code, MAX_SERIAL_LEN);
scsi_get_serial(&dev_scsi, maj_min_dev, page_code, MAX_SERIAL_LEN);
if (export) {
char serial_str[MAX_SERIAL_LEN];
@ -557,7 +547,6 @@ out:
}
int main(int argc, char **argv) {
_cleanup_(udev_unrefp) struct udev *udev;
int retval = 0;
char maj_min_dev[MAX_PATH_LEN];
int newargc;
@ -568,14 +557,10 @@ int main(int argc, char **argv) {
log_parse_environment();
log_open();
udev = udev_new();
if (udev == NULL)
goto exit;
/*
* Get config file options.
*/
retval = get_file_options(udev, NULL, NULL, &newargc, &newargv);
retval = get_file_options(NULL, NULL, &newargc, &newargv);
if (retval < 0) {
retval = 1;
goto exit;
@ -583,7 +568,7 @@ int main(int argc, char **argv) {
if (retval == 0) {
assert(newargv);
if (set_options(udev, newargc, newargv, maj_min_dev) < 0) {
if (set_options(newargc, newargv, maj_min_dev) < 0) {
retval = 2;
goto exit;
}
@ -592,7 +577,7 @@ int main(int argc, char **argv) {
/*
* Get command line options (overriding any config file settings).
*/
if (set_options(udev, argc, argv, maj_min_dev) < 0)
if (set_options(argc, argv, maj_min_dev) < 0)
exit(EXIT_FAILURE);
if (!dev_specified) {
@ -601,7 +586,7 @@ int main(int argc, char **argv) {
goto exit;
}
retval = scsi_id(udev, maj_min_dev);
retval = scsi_id(maj_min_dev);
exit:
if (newargv) {

View File

@ -48,8 +48,8 @@ struct scsi_id_device {
char tgpt_group[8];
};
int scsi_std_inquiry(struct udev *udev, struct scsi_id_device *dev_scsi, const char *devname);
int scsi_get_serial(struct udev *udev, struct scsi_id_device *dev_scsi, const char *devname,
int scsi_std_inquiry(struct scsi_id_device *dev_scsi, const char *devname);
int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname,
int page_code, int len);
/*

View File

@ -21,13 +21,11 @@
#include <time.h>
#include <unistd.h>
#include "libudev.h"
#include "libudev-private.h"
#include "random-util.h"
#include "scsi.h"
#include "scsi_id.h"
#include "string-util.h"
#include "util.h"
/*
* A priority based list of id, naa, and binary/ascii for the identifier
@ -85,15 +83,12 @@ static const char hex_str[]="0123456789abcdef";
#define SG_ERR_CAT_SENSE 98 /* Something else in the sense buffer */
#define SG_ERR_CAT_OTHER 99 /* Some other error/warning */
static int do_scsi_page80_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int max_len);
static int sg_err_category_new(struct udev *udev,
int scsi_status, int msg_status, int
static int sg_err_category_new(int scsi_status, int msg_status, int
host_status, int driver_status, const
unsigned char *sense_buffer, int sb_len)
{
unsigned char *sense_buffer, int sb_len) {
scsi_status &= 0x7e;
/*
@ -140,26 +135,21 @@ static int sg_err_category_new(struct udev *udev,
return SG_ERR_CAT_OTHER;
}
static int sg_err_category3(struct udev *udev, struct sg_io_hdr *hp)
{
return sg_err_category_new(udev,
hp->status, hp->msg_status,
static int sg_err_category3(struct sg_io_hdr *hp) {
return sg_err_category_new(hp->status, hp->msg_status,
hp->host_status, hp->driver_status,
hp->sbp, hp->sb_len_wr);
}
static int sg_err_category4(struct udev *udev, struct sg_io_v4 *hp)
{
return sg_err_category_new(udev, hp->device_status, 0,
static int sg_err_category4(struct sg_io_v4 *hp) {
return sg_err_category_new(hp->device_status, 0,
hp->transport_status, hp->driver_status,
(unsigned char *)(uintptr_t)hp->response,
hp->response_len);
}
static int scsi_dump_sense(struct udev *udev,
struct scsi_id_device *dev_scsi,
unsigned char *sense_buffer, int sb_len)
{
static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
unsigned char *sense_buffer, int sb_len) {
int s;
int code;
int sense_class;
@ -254,9 +244,7 @@ static int scsi_dump_sense(struct udev *udev,
return -1;
}
static int scsi_dump(struct udev *udev,
struct scsi_id_device *dev_scsi, struct sg_io_hdr *io)
{
static int scsi_dump(struct scsi_id_device *dev_scsi, struct sg_io_hdr *io) {
if (!io->status && !io->host_status && !io->msg_status &&
!io->driver_status) {
/*
@ -269,14 +257,12 @@ static int scsi_dump(struct udev *udev,
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x",
dev_scsi->kernel, io->driver_status, io->host_status, io->msg_status, io->status);
if (io->status == SCSI_CHECK_CONDITION)
return scsi_dump_sense(udev, dev_scsi, io->sbp, io->sb_len_wr);
return scsi_dump_sense(dev_scsi, io->sbp, io->sb_len_wr);
else
return -1;
}
static int scsi_dump_v4(struct udev *udev,
struct scsi_id_device *dev_scsi, struct sg_io_v4 *io)
{
static int scsi_dump_v4(struct scsi_id_device *dev_scsi, struct sg_io_v4 *io) {
if (!io->device_status && !io->transport_status &&
!io->driver_status) {
/*
@ -289,17 +275,15 @@ static int scsi_dump_v4(struct udev *udev,
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x",
dev_scsi->kernel, io->driver_status, io->transport_status, io->device_status);
if (io->device_status == SCSI_CHECK_CONDITION)
return scsi_dump_sense(udev, dev_scsi, (unsigned char *)(uintptr_t)io->response,
return scsi_dump_sense(dev_scsi, (unsigned char *)(uintptr_t)io->response,
io->response_len);
else
return -1;
}
static int scsi_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
static int scsi_inquiry(struct scsi_id_device *dev_scsi, int fd,
unsigned char evpd, unsigned char page,
unsigned char *buf, unsigned int buflen)
{
unsigned char *buf, unsigned int buflen) {
unsigned char inq_cmd[INQUIRY_CMDLEN] =
{ INQUIRY_CMD, evpd, page, 0, buflen, 0 };
unsigned char sense[SENSE_BUFF_LEN];
@ -352,9 +336,9 @@ resend:
}
if (dev_scsi->use_sg == 4)
retval = sg_err_category4(udev, io_buf);
retval = sg_err_category4(io_buf);
else
retval = sg_err_category3(udev, io_buf);
retval = sg_err_category3(io_buf);
switch (retval) {
case SG_ERR_CAT_NOTSUPPORTED:
@ -367,9 +351,9 @@ resend:
default:
if (dev_scsi->use_sg == 4)
retval = scsi_dump_v4(udev, dev_scsi, io_buf);
retval = scsi_dump_v4(dev_scsi, io_buf);
else
retval = scsi_dump(udev, dev_scsi, io_buf);
retval = scsi_dump(dev_scsi, io_buf);
}
if (!retval) {
@ -389,14 +373,12 @@ error:
}
/* Get list of supported EVPD pages */
static int do_scsi_page0_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
unsigned char *buffer, unsigned int len)
{
static int do_scsi_page0_inquiry(struct scsi_id_device *dev_scsi, int fd,
unsigned char *buffer, unsigned int len) {
int retval;
memzero(buffer, len);
retval = scsi_inquiry(udev, dev_scsi, fd, 1, 0x0, buffer, len);
retval = scsi_inquiry(dev_scsi, fd, 1, 0x0, buffer, len);
if (retval < 0)
return 1;
@ -433,9 +415,7 @@ static int do_scsi_page0_inquiry(struct udev *udev,
* The caller checks that serial is long enough to include the vendor +
* model.
*/
static int prepend_vendor_model(struct udev *udev,
struct scsi_id_device *dev_scsi, char *serial)
{
static int prepend_vendor_model(struct scsi_id_device *dev_scsi, char *serial) {
int ind;
strncpy(serial, dev_scsi->vendor, VENDOR_LENGTH);
@ -458,14 +438,12 @@ static int prepend_vendor_model(struct udev *udev,
* check_fill_0x83_id - check the page 0x83 id, if OK allocate and fill
* serial number.
*/
static int check_fill_0x83_id(struct udev *udev,
struct scsi_id_device *dev_scsi,
static int check_fill_0x83_id(struct scsi_id_device *dev_scsi,
unsigned char *page_83,
const struct scsi_id_search_values
*id_search, char *serial, char *serial_short,
int max_len, char *wwn,
char *wwn_vendor_extension, char *tgpt_group)
{
char *wwn_vendor_extension, char *tgpt_group) {
int i, j, s, len;
/*
@ -534,7 +512,7 @@ static int check_fill_0x83_id(struct udev *udev,
* included in the identifier.
*/
if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0)
if (prepend_vendor_model(dev_scsi, &serial[1]) < 0)
return 1;
i = 4; /* offset to the start of the identifier */
@ -569,12 +547,10 @@ static int check_fill_0x83_id(struct udev *udev,
}
/* Extract the raw binary from VPD 0x83 pre-SPC devices */
static int check_fill_0x83_prespc3(struct udev *udev,
struct scsi_id_device *dev_scsi,
static int check_fill_0x83_prespc3(struct scsi_id_device *dev_scsi,
unsigned char *page_83,
const struct scsi_id_search_values
*id_search, char *serial, char *serial_short, int max_len)
{
*id_search, char *serial, char *serial_short, int max_len) {
int i, j;
serial[0] = hex_str[SCSI_ID_NAA];
@ -591,21 +567,19 @@ static int check_fill_0x83_prespc3(struct udev *udev,
}
/* Get device identification VPD page */
static int do_scsi_page83_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
static int do_scsi_page83_inquiry(struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int len,
char *unit_serial_number, char *wwn,
char *wwn_vendor_extension, char *tgpt_group)
{
char *wwn_vendor_extension, char *tgpt_group) {
int retval;
unsigned int id_ind, j;
unsigned char page_83[SCSI_INQ_BUFF_LEN];
/* also pick up the page 80 serial number */
do_scsi_page80_inquiry(udev, dev_scsi, fd, NULL, unit_serial_number, MAX_SERIAL_LEN);
do_scsi_page80_inquiry(dev_scsi, fd, NULL, unit_serial_number, MAX_SERIAL_LEN);
memzero(page_83, SCSI_INQ_BUFF_LEN);
retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_83, page_83,
retval = scsi_inquiry(dev_scsi, fd, 1, PAGE_83, page_83,
SCSI_INQ_BUFF_LEN);
if (retval < 0)
return 1;
@ -645,8 +619,7 @@ static int do_scsi_page83_inquiry(struct udev *udev,
*/
if (page_83[6] != 0)
return check_fill_0x83_prespc3(udev,
dev_scsi, page_83, id_search_list,
return check_fill_0x83_prespc3(dev_scsi, page_83, id_search_list,
serial, serial_short, len);
/*
@ -661,8 +634,7 @@ static int do_scsi_page83_inquiry(struct udev *udev,
* one or a small number of descriptors.
*/
for (j = 4; j <= (unsigned int)page_83[3] + 3; j += page_83[j + 3] + 4) {
retval = check_fill_0x83_id(udev,
dev_scsi, &page_83[j],
retval = check_fill_0x83_id(dev_scsi, &page_83[j],
&id_search_list[id_ind],
serial, serial_short, len,
wwn, wwn_vendor_extension,
@ -683,16 +655,14 @@ static int do_scsi_page83_inquiry(struct udev *udev,
* Return the hard coded error code value 2 if the page 83 reply is not
* conformant to the SCSI-2 format.
*/
static int do_scsi_page83_prespc3_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int len)
{
static int do_scsi_page83_prespc3_inquiry(struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int len) {
int retval;
int i, j;
unsigned char page_83[SCSI_INQ_BUFF_LEN];
memzero(page_83, SCSI_INQ_BUFF_LEN);
retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_83, page_83, SCSI_INQ_BUFF_LEN);
retval = scsi_inquiry(dev_scsi, fd, 1, PAGE_83, page_83, SCSI_INQ_BUFF_LEN);
if (retval < 0)
return 1;
@ -745,10 +715,8 @@ static int do_scsi_page83_prespc3_inquiry(struct udev *udev,
}
/* Get unit serial number VPD page */
static int do_scsi_page80_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int max_len)
{
static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
char *serial, char *serial_short, int max_len) {
int retval;
int ser_ind;
int i;
@ -756,7 +724,7 @@ static int do_scsi_page80_inquiry(struct udev *udev,
unsigned char buf[SCSI_INQ_BUFF_LEN];
memzero(buf, SCSI_INQ_BUFF_LEN);
retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_80, buf, SCSI_INQ_BUFF_LEN);
retval = scsi_inquiry(dev_scsi, fd, 1, PAGE_80, buf, SCSI_INQ_BUFF_LEN);
if (retval < 0)
return retval;
@ -778,7 +746,7 @@ static int do_scsi_page80_inquiry(struct udev *udev,
len = buf[3];
if (serial != NULL) {
serial[0] = 'S';
ser_ind = prepend_vendor_model(udev, dev_scsi, &serial[1]);
ser_ind = prepend_vendor_model(dev_scsi, &serial[1]);
if (ser_ind < 0)
return 1;
ser_ind++; /* for the leading 'S' */
@ -792,9 +760,7 @@ static int do_scsi_page80_inquiry(struct udev *udev,
return 0;
}
int scsi_std_inquiry(struct udev *udev,
struct scsi_id_device *dev_scsi, const char *devname)
{
int scsi_std_inquiry(struct scsi_id_device *dev_scsi, const char *devname) {
int fd;
unsigned char buf[SCSI_INQ_BUFF_LEN];
struct stat statbuf;
@ -815,7 +781,7 @@ int scsi_std_inquiry(struct udev *udev,
minor(statbuf.st_rdev));
memzero(buf, SCSI_INQ_BUFF_LEN);
err = scsi_inquiry(udev, dev_scsi, fd, 0, 0, buf, SCSI_INQ_BUFF_LEN);
err = scsi_inquiry(dev_scsi, fd, 0, 0, buf, SCSI_INQ_BUFF_LEN);
if (err < 0)
goto out;
@ -833,10 +799,8 @@ out:
return err;
}
int scsi_get_serial(struct udev *udev,
struct scsi_id_device *dev_scsi, const char *devname,
int page_code, int len)
{
int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname,
int page_code, int len) {
unsigned char page0[SCSI_INQ_BUFF_LEN];
int fd = -1;
int cnt;
@ -859,7 +823,7 @@ int scsi_get_serial(struct udev *udev,
return 1;
if (page_code == PAGE_80) {
if (do_scsi_page80_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len)) {
if (do_scsi_page80_inquiry(dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len)) {
retval = 1;
goto completed;
} else {
@ -867,7 +831,7 @@ int scsi_get_serial(struct udev *udev,
goto completed;
}
} else if (page_code == PAGE_83) {
if (do_scsi_page83_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
if (do_scsi_page83_inquiry(dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
retval = 1;
goto completed;
} else {
@ -875,7 +839,7 @@ int scsi_get_serial(struct udev *udev,
goto completed;
}
} else if (page_code == PAGE_83_PRE_SPC3) {
retval = do_scsi_page83_prespc3_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len);
retval = do_scsi_page83_prespc3_inquiry(dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len);
if (retval) {
/*
* Fallback to servicing a SPC-2/3 compliant page 83
@ -883,7 +847,7 @@ int scsi_get_serial(struct udev *udev,
* conform to pre-SPC3 expectations.
*/
if (retval == 2) {
if (do_scsi_page83_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
if (do_scsi_page83_inquiry(dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
retval = 1;
goto completed;
} else {
@ -909,7 +873,7 @@ int scsi_get_serial(struct udev *udev,
* Get page 0, the page of the pages. By default, try from best to
* worst of supported pages: 0x83 then 0x80.
*/
if (do_scsi_page0_inquiry(udev, dev_scsi, fd, page0, SCSI_INQ_BUFF_LEN)) {
if (do_scsi_page0_inquiry(dev_scsi, fd, page0, SCSI_INQ_BUFF_LEN)) {
/*
* Don't try anything else. Black list if a specific page
* should be used for this vendor+model, or maybe have an
@ -921,7 +885,7 @@ int scsi_get_serial(struct udev *udev,
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_83)
if (!do_scsi_page83_inquiry(udev, dev_scsi, fd,
if (!do_scsi_page83_inquiry(dev_scsi, fd,
dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
/*
* Success
@ -932,7 +896,7 @@ int scsi_get_serial(struct udev *udev,
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_80)
if (!do_scsi_page80_inquiry(udev, dev_scsi, fd,
if (!do_scsi_page80_inquiry(dev_scsi, fd,
dev_scsi->serial, dev_scsi->serial_short, len)) {
/*
* Success