Update to use the new ioctl interface.

Add the list command.
This commit is contained in:
Søren Schmidt 2001-05-17 10:30:07 +00:00
parent 2c68839222
commit d1eb1df37a
2 changed files with 71 additions and 73 deletions

View File

@ -52,6 +52,8 @@
.Nm .Nm
.Ic info .Ic info
.Ar channel .Ar channel
.Nm
.Ic list
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
is a control program that provides the user access and control to the is a control program that provides the user access and control to the
@ -103,10 +105,12 @@ as argument (i.e.\&
.Dq Li XXX ) , .Dq Li XXX ) ,
and the mode will remain unchanged. and the mode will remain unchanged.
.It Ic info .It Ic info
Show info on the device on the Show info about the attached devices on the
.Ar channel , .Ar channel ,
currently only the device currently only the device
name and manufacture/version strings are shown. name and manufacture/version strings are shown.
.It Ic list
Show info about all attached devices on all active controllers.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr ata 4 .Xr ata 4

View File

@ -32,6 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <err.h> #include <err.h>
#include <sys/ata.h> #include <sys/ata.h>
@ -88,10 +89,10 @@ version(int version)
int bit; int bit;
if (version == 0xffff) if (version == 0xffff)
return 0; return 0;
for (bit = 15; bit >= 0; bit--) for (bit = 15; bit >= 0; bit--)
if (version & (1<<bit)) if (version & (1<<bit))
return bit; return bit;
return 0; return 0;
} }
@ -102,99 +103,92 @@ param_print(struct ata_params *parm)
parm->model, parm->revision, version(parm->versmajor)); parm->model, parm->revision, version(parm->versmajor));
} }
void int
info_print(int fd, int channel) info_print(int fd, int channel, int prchan)
{ {
struct ata_param param; struct ata_cmd iocmd;
bzero(&param, sizeof(struct ata_param)); bzero(&iocmd, sizeof(struct ata_cmd));
param.channel = channel; iocmd.channel = channel;
if (ioctl(fd, ATAGPARM, &param) < 0) iocmd.cmd = ATAGPARM;
err(1, "ioctl(ATAGPARM)"); if (ioctl(fd, IOCATA, &iocmd) < 0)
printf("Master slot: "); return errno;
if (param.type[0]) { if (prchan)
printf("%4.4s: ", param.name[0]); printf("ATA channel %d:\n", channel);
param_print(&param.params[0]); printf("%sMaster: ", prchan ? " " : "");
if (iocmd.u.param.type[0]) {
printf("%4.4s ", iocmd.u.param.name[0]);
param_print(&iocmd.u.param.params[0]);
} }
else else
printf(" no device present\n"); printf(" no device present\n");
printf("Slave slot: "); printf("%sSlave: ", prchan ? " " : "");
if (param.type[1]) { if (iocmd.u.param.type[1]) {
printf("%4.4s: ", param.name[1]); printf("%4.4s ", iocmd.u.param.name[1]);
param_print(&param.params[1]); param_print(&iocmd.u.param.params[1]);
} }
else else
printf(" no device present\n"); printf(" no device present\n");
return 0;
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int unit; struct ata_cmd iocmd;
int fd = open("/dev/ata", O_RDWR); int fd;
if (fd < 0) if ((fd = open("/dev/ata", O_RDWR)) < 0)
err(1, "control device not found\n"); err(1, "control device not found");
if (argc < 3) if (argc < 2)
usage(); usage();
if (!strcmp(argv[1], "detach")) { bzero(&iocmd, sizeof(struct ata_cmd));
if (argc != 3) if (argc > 2)
usage(); iocmd.channel = atoi(argv[2]);
unit = atoi(argv[2]);
if (ioctl(fd, ATADETACH, &unit) < 0) if (!strcmp(argv[1], "list") && argc == 2) {
int unit = 0;
while (info_print(fd, unit++, 1) != ENXIO);
}
else if (!strcmp(argv[1], "info") && argc == 3) {
info_print(fd, iocmd.channel, 0);
}
else if (!strcmp(argv[1], "detach") && argc == 3) {
iocmd.cmd = ATADETACH;
if (ioctl(fd, IOCATA, &iocmd) < 0)
err(1, "ioctl(ATADETACH)"); err(1, "ioctl(ATADETACH)");
} }
else if (!strcmp(argv[1], "attach")) { else if (!strcmp(argv[1], "attach") && argc == 3) {
if (argc != 3) iocmd.cmd = ATAATTACH;
usage(); if (ioctl(fd, IOCATA, &iocmd) < 0)
unit = atoi(argv[2]);
if (ioctl(fd, ATAATTACH, &unit) < 0)
err(1, "ioctl(ATAATTACH)"); err(1, "ioctl(ATAATTACH)");
info_print(fd, unit); info_print(fd, iocmd.channel, 0);
} }
else if (!strcmp(argv[1], "reinit")) { else if (!strcmp(argv[1], "reinit") && argc == 3) {
if (argc != 3) iocmd.cmd = ATAATTACH;
usage(); if (ioctl(fd, IOCATA, &iocmd) < 0)
unit = atoi(argv[2]);
if (ioctl(fd, ATAREINIT, &unit) < 0 )
warn("ioctl(ATAREINIT)"); warn("ioctl(ATAREINIT)");
info_print(fd, unit); info_print(fd, iocmd.channel, 0);
} }
else if (!strcmp(argv[1], "mode")) { else if (!strcmp(argv[1], "mode") && (argc == 3 || argc == 5)) {
struct ata_modes modes; if (argc == 5) {
iocmd.cmd = ATASMODE;
bzero(&modes, sizeof(struct ata_modes)); iocmd.u.mode.mode[0] = str2mode(argv[3]);
if (argc == 3) { iocmd.u.mode.mode[1] = str2mode(argv[4]);
modes.channel = atoi(argv[2]); if (ioctl(fd, IOCATA, &iocmd) < 0)
if (ioctl(fd, ATAGMODE, &modes) < 0) warn("ioctl(ATASMODE)");
}
if (argc == 3 || argc == 5) {
iocmd.cmd = ATAGMODE;
if (ioctl(fd, IOCATA, &iocmd) < 0)
err(1, "ioctl(ATAGMODE)"); err(1, "ioctl(ATAGMODE)");
printf("Master = %s \nSlave = %s\n", printf("Master = %s \nSlave = %s\n",
mode2str(modes.mode[0]), mode2str(iocmd.u.mode.mode[0]),
mode2str(modes.mode[1])); mode2str(iocmd.u.mode.mode[1]));
} }
else if (argc == 5) {
modes.channel = atoi(argv[2]);
modes.mode[0] = str2mode(argv[3]);
modes.mode[1] = str2mode(argv[4]);
if (ioctl(fd, ATASMODE, &modes) < 0) {
warn("ioctl(ATASMODE)");
modes.channel = atoi(argv[2]);
if (ioctl(fd, ATAGMODE, &modes) < 0)
err(1, "ioctl(ATAGMODE)");
}
printf("Master = %s \nSlave = %s\n",
mode2str(modes.mode[0]),
mode2str(modes.mode[1]));
}
else
usage();
}
else if (!strcmp(argv[1], "info")) {
if (argc != 3)
usage();
info_print(fd, atoi(argv[2]));
} }
else else
usage(); usage();