1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

start implementing command line parsing to scsi_io to make it take

parameters that control what operations to perform

(This used to be ctdb commit 6350b353bc436a2b5a1e4c1b0bc332e83932148d)
This commit is contained in:
Ronnie Sahlberg 2007-07-02 17:52:57 +10:00
parent 27ce064abd
commit c3884e1b29

View File

@ -26,6 +26,7 @@
#include <errno.h>
#include <sys/ioctl.h>
#include <scsi/sg.h>
#include "popt.h"
#define SCSI_TIMEOUT 5000 /* ms */
@ -123,11 +124,6 @@ printf("\n");
return 0;
}
void usage(void)
{
printf("Usage: scsi <device>\n");
}
typedef struct _value_string_t {
int value;
const char *string;
@ -877,28 +873,95 @@ int open_scsi_device(const char *dev)
return fd;
}
int main(int argc, char *argv[])
{
int fd;
typedef int (*scsi_func_t)(int fd);
typedef struct _cmds_t {
const char *cmd;
scsi_func_t func;
const char *comment;
} cmds_t;
cmds_t cmds[] = {
{"inq", scsi_inquiry, "Standard INQUIRY output"},
{"vpd", scsi_inquiry_supported_vpd_pages, "Supported VPD Pages"},
{"usn", scsi_inquiry_unit_serial_number, "Unit serial number"},
{"readkeys", scsi_persistent_reserve_in_read_keys, "Read SCSI Reservation Keys"},
{"readrsvr", scsi_persistent_reserve_in_read_reservation, "Read SCSI Reservation Data"},
{"reportcap", scsi_persistent_reserve_in_report_capabilities, "Report reservation Capabilities"},
};
if(argc!=2){
void usage(void)
{
int i;
printf("Usage: scsi_io --command <command> --device <device>\n");
printf("Commands:\n");
for (i=0;i<sizeof(cmds)/sizeof(cmds[0]);i++){
printf(" %s %s\n", cmds[i].cmd, cmds[i].comment);
}
}
int main(int argc, const char *argv[])
{
int i, fd;
int opt;
char *command = NULL;
char *device = NULL;
scsi_func_t func=NULL;
struct poptOption popt_options[] = {
POPT_AUTOHELP
// { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, "timelimit", "integer" },
{ "command", 'n', POPT_ARG_STRING, &command, 0, "command", "command" },
{ "device", 'n', POPT_ARG_STRING, &device, 0, "device", "device" },
// { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL },
POPT_TABLEEND
};
poptContext pc;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
default:
fprintf(stderr, "Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
_exit(1);
}
}
if (!command) {
printf("Must specify the command\n");
usage();
_exit(10);
}
fd=open_scsi_device(argv[1]);
if(fd<0){
printf("Could not open SCSI device %s\n",argv[1]);
if (!device) {
printf("Must specify the device\n");
usage();
_exit(10);
}
scsi_inquiry(fd);
scsi_inquiry_supported_vpd_pages(fd);
scsi_inquiry_unit_serial_number(fd);
scsi_persistent_reserve_in_read_keys(fd);
scsi_persistent_reserve_in_read_reservation(fd);
scsi_persistent_reserve_in_report_capabilities(fd);
scsi_persistent_reserve_in_read_full_status(fd);
fd=open_scsi_device(device);
if(fd<0){
printf("Could not open SCSI device %s\n",device);
usage();
_exit(10);
}
for (i=0;i<sizeof(cmds)/sizeof(cmds[0]);i++){
if(!strcmp(cmds[i].cmd, command)) {
func = cmds[i].func;
break;
}
}
if (!func) {
printf("Unrecognized command : %s\n", command);
usage();
_exit(10);
}
func(fd);
#if 0
scsi_persistent_reserve_in_read_full_status(fd);
scsi_persistent_reserve_out_register_and_ignore_existing_key(fd);
scsi_persistent_reserve_in_read_keys(fd);