From 91416bd2afebd84ccd289c0d54a8282496348bf3 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Mon, 16 Jan 2012 13:50:43 +0100 Subject: [PATCH] atacontrol - Few fixes. Merge following revisions: 103250 103387 112494 An endless loop in list command is fixed by only checking up to maximum unit number. Obtained-from: FreeBSD --- sbin/atacontrol/atacontrol.c | 26 +++++++++++++++----------- sys/dev/disk/ata/ata-all.c | 5 +++++ sys/sys/ata.h | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sbin/atacontrol/atacontrol.c b/sbin/atacontrol/atacontrol.c index a5a925a..74034a5 100644 --- a/sbin/atacontrol/atacontrol.c +++ b/sbin/atacontrol/atacontrol.c @@ -26,16 +26,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sbin/atacontrol/atacontrol.c,v 1.11.2.5 2002/08/21 13:18:17 sos Exp $ - * $DragonFly: src/sbin/atacontrol/atacontrol.c,v 1.4 2005/01/09 04:43:33 cpressey Exp $ */ +#include +#include + +#include +#include +#include #include #include #include -#include -#include -#include -#include static const char *mode2str(int); static int str2mode(char *); @@ -168,8 +169,8 @@ cap_print(struct ata_params *parm) parm->enabled.microcode ? "yes" : "no"); printf("security %s %s\n", - parm->support.smart ? "yes" : "no", - parm->enabled.smart ? "yes" : "no"); + parm->support.security ? "yes" : "no", + parm->enabled.security ? "yes" : "no"); printf("power management %s %s\n", parm->support.power_mngt ? "yes" : "no", @@ -246,7 +247,7 @@ int main(int argc, char **argv) { struct ata_cmd iocmd; - int fd; + int fd, maxunit, unit; if ((fd = open("/dev/ata", O_RDWR)) < 0) err(1, "control device not found"); @@ -275,9 +276,12 @@ main(int argc, char **argv) } if (!strcmp(argv[1], "list") && argc == 2) { - int unit = 0; - - while (info_print(fd, unit++, 1) != ENXIO); + iocmd.cmd = ATAGMAXCHANNEL; + if (ioctl(fd, IOCATA, &iocmd) < 0) + err(1, "ioctl(ATAGMAXCHANNEL)"); + maxunit = iocmd.u.maxchan; + for (unit = 0; unit < maxunit; unit++) + info_print(fd, unit, 1); } else if (!strcmp(argv[1], "info") && argc == 3) { info_print(fd, iocmd.channel, 0); diff --git a/sys/dev/disk/ata/ata-all.c b/sys/dev/disk/ata/ata-all.c index b48c223..18e0106 100644 --- a/sys/dev/disk/ata/ata-all.c +++ b/sys/dev/disk/ata/ata-all.c @@ -337,6 +337,11 @@ ataioctl(struct dev_ioctl_args *ap) if (ap->a_cmd != IOCATA) return ENOTTY; + if (iocmd->cmd == ATAGMAXCHANNEL) { + iocmd->u.maxchan = devclass_get_maxunit(ata_devclass); + return 0; + } + if (iocmd->channel < -1 || iocmd->device < -1 || iocmd->device > SLAVE) return ENXIO; diff --git a/sys/sys/ata.h b/sys/sys/ata.h index 52e5d56..be2ffd1 100644 --- a/sys/sys/ata.h +++ b/sys/sys/ata.h @@ -244,6 +244,7 @@ struct ata_cmd { #define ATARAIDDELETE 10 #define ATARAIDSTATUS 11 #define ATAENCSTAT 12 +#define ATAGMAXCHANNEL 13 union { struct { @@ -296,6 +297,7 @@ struct ata_cmd { int error; char sense_data[18]; } atapi; + int maxchan; } u; }; -- 1.7.6.3