4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2003-6 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 2003-6 Doug Gilbert <dougg@torque.net>
9 * Parts of this file are derived from code that was
11 * Written By: Adam Radford <linux@3ware.com>
12 * Modifications By: Joel Jacobson <linux@3ware.com>
13 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
14 * Brad Strand <linux@3ware.com>
16 * Copyright (C) 1999-2003 3ware Inc.
18 * Kernel compatablity By: Andre Hedrick <andre@suse.com>
19 * Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
21 * Other ars of this file are derived from code that was
23 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
24 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2, or (at your option)
31 * You should have received a copy of the GNU General Public License
32 * (for example COPYING); if not, write to the Free
33 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 * This code was originally developed as a Senior Thesis by Michael Cornwell
36 * at the Concurrent Systems Laboratory (now part of the Storage Systems
37 * Research Center), Jack Baskin School of Engineering, University of
38 * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
42 // This file contains the linux-specific IOCTL parts of
43 // smartmontools. It includes one interface routine for ATA devices,
44 // one for SCSI devices, and one for ATA devices behind escalade
51 #ifdef HAVE_LINUX_COMPILER_H
52 #include <linux/compiler.h>
55 #include <scsi/scsi_ioctl.h>
59 #include <sys/ioctl.h>
62 #ifndef makedev // old versions of types.h do not include sysmacros.h
63 #include <sys/sysmacros.h>
70 extern smartmonctrl
* con
;
76 #include <linux/cciss_ioctl.h>
80 #define ENOTSUP ENOSYS
82 typedef unsigned long long u8
;
85 #define ARGUSED(x) ((void)(x))
87 static const char *filenameandversion
="$Id: os_linux.cpp,v 1.88 2006/10/25 17:01:42 ballen4705 Exp $";
89 const char *os_XXXX_c_cvsid
="$Id: os_linux.cpp,v 1.88 2006/10/25 17:01:42 ballen4705 Exp $" \
90 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_LINUX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID
;
92 // to hold onto exit code for atexit routine
93 extern int exitstatus
;
95 // global variable holding byte count of allocated memory
96 extern long long bytes
;
98 /* for passing global control variables */
99 extern smartmonctrl
*con
;
101 static int cciss_io_interface(int device
, int target
,
102 struct scsi_cmnd_io
* iop
, int report
);
104 typedef struct _ReportLUNdata_struct
106 BYTE LUNListLength
[4];
108 BYTE LUN
[CISS_MAX_LUN
][8];
109 } ReportLunData_struct
;
111 /* Structure/defines of Report Physical LUNS of drive */
112 #define CISS_MAX_LUN 16
113 #define CISS_MAX_PHYS_LUN 1024
114 #define CISS_REPORT_PHYS 0xc3
117 /* This function will setup and fix device nodes for a 3ware controller. */
118 #define MAJOR_STRING_LENGTH 3
119 #define DEVICE_STRING_LENGTH 32
120 #define NODE_STRING_LENGTH 16
121 int setup_3ware_nodes(char *nodename
, char *driver_name
) {
124 char majorstring
[MAJOR_STRING_LENGTH
+1];
125 char device_name
[DEVICE_STRING_LENGTH
+1];
126 char nodestring
[NODE_STRING_LENGTH
];
127 struct stat stat_buf
;
130 /* First try to open up /proc/devices */
131 if (!(file
= fopen("/proc/devices", "r"))) {
132 pout("Error opening /proc/devices to check/create 3ware device nodes\n");
134 return 0; // don't fail here: user might not have /proc !
137 /* Attempt to get device major number */
138 while (EOF
!= fscanf(file
, "%3s %32s", majorstring
, device_name
)) {
139 majorstring
[MAJOR_STRING_LENGTH
]='\0';
140 device_name
[DEVICE_STRING_LENGTH
]='\0';
141 if (!strncmp(device_name
, nodename
, DEVICE_STRING_LENGTH
)) {
142 tw_major
= atoi(majorstring
);
148 /* See if we found a major device number */
150 pout("No major number for /dev/%s listed in /proc/devices. Is the %s driver loaded?\n", nodename
, driver_name
);
154 /* Now check if nodes are correct */
155 for (index
=0; index
<16; index
++) {
156 sprintf(nodestring
, "/dev/%s%d", nodename
, index
);
158 /* Try to stat the node */
159 if ((stat(nodestring
, &stat_buf
))) {
160 /* Create a new node if it doesn't exist */
161 if (mknod(nodestring
, S_IFCHR
|0600, makedev(tw_major
, index
))) {
162 pout("problem creating 3ware device nodes %s", nodestring
);
168 /* See if nodes major and minor numbers are correct */
169 if ((tw_major
!= (int)(major(stat_buf
.st_rdev
))) ||
170 (index
!= (int)(minor(stat_buf
.st_rdev
))) ||
171 (!S_ISCHR(stat_buf
.st_mode
))) {
173 /* Delete the old node */
174 if (unlink(nodestring
)) {
175 pout("problem unlinking stale 3ware device node %s", nodestring
);
180 /* Make a new node */
181 if (mknod(nodestring
, S_IFCHR
|0600, makedev(tw_major
, index
))) {
182 pout("problem creating 3ware device nodes %s", nodestring
);
191 // equivalent to open(path, flags)
192 int deviceopen(const char *pathname
, char *type
){
193 if (!strcmp(type
,"SCSI")) {
194 int fd
= open(pathname
, O_RDWR
| O_NONBLOCK
);
195 if (fd
< 0 && errno
== EROFS
)
196 fd
= open(pathname
, O_RDONLY
| O_NONBLOCK
);
199 else if (!strcmp(type
,"ATA"))
200 return open(pathname
, O_RDONLY
| O_NONBLOCK
);
201 else if (!strcmp(type
,"ATA_3WARE_9000")) {
202 // the device nodes for this controller are dynamically assigned,
203 // so we need to check that they exist with the correct major
204 // numbers and if not, create them
205 if (setup_3ware_nodes("twa", "3w-9xxx")) {
210 return open(pathname
, O_RDONLY
| O_NONBLOCK
);
212 else if (!strcmp(type
,"ATA_3WARE_678K")) {
213 // the device nodes for this controller are dynamically assigned,
214 // so we need to check that they exist with the correct major
215 // numbers and if not, create them
216 if (setup_3ware_nodes("twe", "3w-xxxx")) {
221 return open(pathname
, O_RDONLY
| O_NONBLOCK
);
223 else if(!strcmp(type
, "CCISS")) {
224 // the device is a cciss smart array device.
225 return open(pathname
, O_RDWR
| O_NONBLOCK
);
232 // equivalent to close(file descriptor)
233 int deviceclose(int fd
){
237 // print examples for smartctl
238 void print_smartctl_examples(){
239 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
240 #ifdef HAVE_GETOPT_LONG
242 " smartctl --all /dev/hda (Prints all SMART information)\n\n"
243 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
244 " (Enables SMART on first disk)\n\n"
245 " smartctl --test=long /dev/hda (Executes extended disk self-test)\n\n"
246 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
247 " (Prints Self-Test & Attribute errors)\n"
248 " smartctl --all --device=3ware,2 /dev/sda\n"
249 " smartctl --all --device=3ware,2 /dev/twe0\n"
250 " smartctl --all --device=3ware,2 /dev/twa0\n"
251 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
252 " smartctl --all --device=hpt,1/1/3 /dev/sda\n"
253 " (Prints all SMART info for the SATA disk attached to the 3rd PMPort\n"
254 " of the 1st channel on the 1st HighPoint RAID controller)\n"
258 " smartctl -a /dev/hda (Prints all SMART information)\n"
259 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
260 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
261 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
262 " (Prints Self-Test & Attribute errors)\n"
263 " smartctl -a -d 3ware,2 /dev/sda\n"
264 " smartctl -a -d 3ware,2 /dev/twa0\n"
265 " smartctl -a -d 3ware,2 /dev/twe0\n"
266 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
267 " smartctl -a -d hpt,1/1/3 /dev/sda\n"
268 " (Prints all SMART info for the SATA disk attached to the 3rd PMPort\n"
269 " of the 1st channel on the 1st HighPoint RAID controller)\n"
276 // we are going to take advantage of the fact that Linux's devfs will only
277 // have device entries for devices that exist. So if we get the equivalent of
278 // ls /dev/hd[a-t], we have all the ATA devices on the system
280 // If any errors occur, leave errno set as it was returned by the
281 // system call, and return <0.
282 int get_dev_names(char*** names
, const char* pattern
, const char* name
, int max
) {
283 int n
= 0, retglob
, i
, lim
;
287 memset(&globbuf
, 0, sizeof(globbuf
));
289 // in case of non-clean exit
292 // Use glob to look for any directory entries matching the pattern
293 if ((retglob
=glob(pattern
, GLOB_ERR
, NULL
, &globbuf
))) {
295 // glob failed: free memory and return
298 if (retglob
==GLOB_NOMATCH
){
299 pout("glob(3) found no matches for pattern %s\n", pattern
);
303 if (retglob
==GLOB_NOSPACE
)
304 pout("glob(3) ran out of memory matching pattern %s\n", pattern
);
305 #ifdef GLOB_ABORTED // missing in old versions of glob.h
306 else if (retglob
==GLOB_ABORTED
)
307 pout("glob(3) aborted matching pattern %s\n", pattern
);
310 pout("Unexplained error in glob(3) of pattern %s\n", pattern
);
315 // did we find too many paths?
316 lim
= ((int)globbuf
.gl_pathc
< max
) ? (int)globbuf
.gl_pathc
: max
;
317 if (lim
< (int)globbuf
.gl_pathc
)
318 pout("glob(3) found %d > MAX=%d devices matching pattern %s: ignoring %d paths\n",
319 (int)globbuf
.gl_pathc
, max
, pattern
, (int)(globbuf
.gl_pathc
-max
));
321 // allocate space for up to lim number of ATA devices
322 if (!(mp
= (char **)calloc(lim
, sizeof(char*)))){
323 pout("Out of memory constructing scan device list\n");
327 // now step through the list returned by glob. If not a link, copy
328 // to list. If it is a link, evaluate it and see if the path ends
330 for (i
=0; i
<lim
; i
++){
333 // prepare a buffer for storing the link
336 // see if path is a link
337 retlink
=readlink(globbuf
.gl_pathv
[i
], linkbuf
, 1023);
339 // if not a link (or a strange link), keep it
340 if (retlink
<=0 || retlink
>1023)
341 mp
[n
++] = CustomStrDup(globbuf
.gl_pathv
[i
], 1, __LINE__
, filenameandversion
);
343 // or if it's a link that points to a disc, follow it
345 linkbuf
[retlink
]='\0';
346 if ((p
=strrchr(linkbuf
,'/')) && !strcmp(p
+1, "disc"))
347 // This is the branch of the code that gets followed if we are
348 // using devfs WITH traditional compatibility links. In this
349 // case, we add the traditional device name to the list that
351 mp
[n
++] = CustomStrDup(globbuf
.gl_pathv
[i
], 1, __LINE__
, filenameandversion
);
353 // This is the branch of the code that gets followed if we are
354 // using devfs WITHOUT traditional compatibility links. In
355 // this case, we check that the link to the directory is of
356 // the correct type, and then append "disc" to it.
357 char tmpname
[1024]={0};
358 const char * type
= (strcmp(name
,"ATA") ? "scsi" : "ide");
359 if (strstr(linkbuf
, type
)){
360 snprintf(tmpname
, 1024, "%s/disc", globbuf
.gl_pathv
[i
]);
361 mp
[n
++] = CustomStrDup(tmpname
, 1, __LINE__
, filenameandversion
);
367 // free memory, track memory usage
369 mp
= static_cast<char **>(realloc(mp
,n
*(sizeof(char*))));
370 bytes
+= n
*(sizeof(char*));
372 // and set up return values
377 // makes a list of device names to scan, for either ATA or SCSI
378 // devices. Return -1 if no memory remaining, else the number of
379 // devices on the list, which can be >=0.
380 int make_device_names (char*** devlist
, const char* name
) {
384 // for testing case where no device names are found
388 if (!strcmp(name
,"SCSI"))
389 retval
=get_dev_names(devlist
,"/dev/sd[a-z]", name
, maxdev
=26);
390 else if (!strcmp(name
,"ATA"))
391 retval
=get_dev_names(devlist
,"/dev/hd[a-t]", name
, maxdev
=20);
393 // don't recognize disk type!
396 // if we found traditional links, we are done
400 // else look for devfs entries without traditional links
401 return get_dev_names(devlist
,"/dev/discs/disc*", name
, maxdev
);
406 // This is an interface routine meant to isolate the OS dependent
407 // parts of the code, and to provide a debugging interface. Each
408 // different port and OS needs to provide it's own interface. This
410 // DETAILED DESCRIPTION OF ARGUMENTS
411 // device: is the file descriptor provided by open()
412 // command: defines the different operations.
413 // select: additional input data if needed (which log, which type of
415 // data: location to write output data, if needed (512 bytes).
416 // Note: not all commands use all arguments.
418 // -1 if the command failed
419 // 0 if the command succeeded,
420 // STATUS_CHECK routine:
421 // -1 if the command failed
422 // 0 if the command succeeded and disk SMART status is "OK"
423 // 1 if the command succeeded and disk SMART status is "FAILING"
426 // huge value of buffer size needed because HDIO_DRIVE_CMD assumes
427 // that buff[3] is the data size. Since the ATA_SMART_AUTOSAVE and
428 // ATA_SMART_AUTO_OFFLINE use values of 0xf1 and 0xf8 we need the space.
429 // Otherwise a 4+512 byte buffer would be enough.
430 #define STRANGE_BUFFER_LENGTH (4+512*0xf8)
432 int ata_command_interface(int device
, smart_command_set command
, int select
, char *data
){
433 unsigned char buff
[STRANGE_BUFFER_LENGTH
];
434 // positive: bytes to write to caller. negative: bytes to READ from
435 // caller. zero: non-data command
438 const int HDIO_DRIVE_CMD_OFFSET
= 4;
440 // See struct hd_drive_cmd_hdr in hdreg.h. Before calling ioctl()
441 // buff[0]: ATA COMMAND CODE REGISTER
442 // buff[1]: ATA SECTOR NUMBER REGISTER == LBA LOW REGISTER
443 // buff[2]: ATA FEATURES REGISTER
444 // buff[3]: ATA SECTOR COUNT REGISTER
446 // Note that on return:
447 // buff[2] contains the ATA SECTOR COUNT REGISTER
449 // clear out buff. Large enough for HDIO_DRIVE_CMD (4+512 bytes)
450 memset(buff
, 0, STRANGE_BUFFER_LENGTH
);
452 buff
[0]=ATA_SMART_CMD
;
454 case CHECK_POWER_MODE
:
455 buff
[0]=ATA_CHECK_POWER_MODE
;
459 buff
[2]=ATA_SMART_READ_VALUES
;
463 case READ_THRESHOLDS
:
464 buff
[2]=ATA_SMART_READ_THRESHOLDS
;
469 buff
[2]=ATA_SMART_READ_LOG_SECTOR
;
477 buff
[0]=ATA_IDENTIFY_DEVICE
;
482 buff
[0]=ATA_IDENTIFY_PACKET_DEVICE
;
487 buff
[2]=ATA_SMART_ENABLE
;
491 buff
[2]=ATA_SMART_DISABLE
;
495 // this command only says if SMART is working. It could be
496 // replaced with STATUS_CHECK below.
497 buff
[2]=ATA_SMART_STATUS
;
500 buff
[2]=ATA_SMART_AUTO_OFFLINE
;
501 buff
[3]=select
; // YET NOTE - THIS IS A NON-DATA COMMAND!!
504 buff
[2]=ATA_SMART_AUTOSAVE
;
505 buff
[3]=select
; // YET NOTE - THIS IS A NON-DATA COMMAND!!
507 case IMMEDIATE_OFFLINE
:
508 buff
[2]=ATA_SMART_IMMEDIATE_OFFLINE
;
512 // This command uses HDIO_DRIVE_TASK and has different syntax than
513 // the other commands.
514 buff
[1]=ATA_SMART_STATUS
;
517 pout("Unrecognized command %d in linux_ata_command_interface()\n"
518 "Please contact " PACKAGE_BUGREPORT
"\n", command
);
523 // This command uses the HDIO_DRIVE_TASKFILE ioctl(). This is the
524 // only ioctl() that can be used to WRITE data to the disk.
525 if (command
==WRITE_LOG
) {
526 unsigned char task
[sizeof(ide_task_request_t
)+512];
527 ide_task_request_t
*reqtask
=(ide_task_request_t
*) task
;
528 task_struct_t
*taskfile
=(task_struct_t
*) reqtask
->io_ports
;
531 memset(task
, 0, sizeof(task
));
534 taskfile
->feature
= ATA_SMART_WRITE_LOG_SECTOR
;
535 taskfile
->sector_count
= 1;
536 taskfile
->sector_number
= select
;
537 taskfile
->low_cylinder
= 0x4f;
538 taskfile
->high_cylinder
= 0xc2;
539 taskfile
->device_head
= 0;
540 taskfile
->command
= ATA_SMART_CMD
;
542 reqtask
->data_phase
= TASKFILE_OUT
;
543 reqtask
->req_cmd
= IDE_DRIVE_TASK_OUT
;
544 reqtask
->out_size
= 512;
545 reqtask
->in_size
= 0;
547 // copy user data into the task request structure
548 memcpy(task
+sizeof(ide_task_request_t
), data
, 512);
550 if ((retval
=ioctl(device
, HDIO_DRIVE_TASKFILE
, task
))) {
552 pout("Kernel lacks HDIO_DRIVE_TASKFILE support; compile kernel with CONFIG_IDE_TASKFILE_IO set\n");
558 // There are two different types of ioctls(). The HDIO_DRIVE_TASK
560 if (command
==STATUS_CHECK
){
563 // NOT DOCUMENTED in /usr/src/linux/include/linux/hdreg.h. You
564 // have to read the IDE driver source code. Sigh.
565 // buff[0]: ATA COMMAND CODE REGISTER
566 // buff[1]: ATA FEATURES REGISTER
567 // buff[2]: ATA SECTOR_COUNT
568 // buff[3]: ATA SECTOR NUMBER
569 // buff[4]: ATA CYL LO REGISTER
570 // buff[5]: ATA CYL HI REGISTER
571 // buff[6]: ATA DEVICE HEAD
573 unsigned const char normal_lo
=0x4f, normal_hi
=0xc2;
574 unsigned const char failed_lo
=0xf4, failed_hi
=0x2c;
578 if ((retval
=ioctl(device
, HDIO_DRIVE_TASK
, buff
))) {
579 if (retval
==-EINVAL
) {
580 pout("Error SMART Status command via HDIO_DRIVE_TASK failed");
581 pout("Rebuild older linux 2.2 kernels with HDIO_DRIVE_TASK support added\n");
584 syserror("Error SMART Status command failed");
588 // Cyl low and Cyl high unchanged means "Good SMART status"
589 if (buff
[4]==normal_lo
&& buff
[5]==normal_hi
)
592 // These values mean "Bad SMART status"
593 if (buff
[4]==failed_lo
&& buff
[5]==failed_hi
)
596 // We haven't gotten output that makes sense; print out some debugging info
597 syserror("Error SMART Status command failed");
598 pout("Please get assistance from " PACKAGE_HOMEPAGE
"\n");
599 pout("Register values returned from SMART Status command are:\n");
600 pout("CMD=0x%02x\n",(int)buff
[0]);
601 pout("FR =0x%02x\n",(int)buff
[1]);
602 pout("NS =0x%02x\n",(int)buff
[2]);
603 pout("SC =0x%02x\n",(int)buff
[3]);
604 pout("CL =0x%02x\n",(int)buff
[4]);
605 pout("CH =0x%02x\n",(int)buff
[5]);
606 pout("SEL=0x%02x\n",(int)buff
[6]);
611 // Note to people doing ports to other OSes -- don't worry about
612 // this block -- you can safely ignore it. I have put it here
613 // because under linux when you do IDENTIFY DEVICE to a packet
614 // device, it generates an ugly kernel syslog error message. This
615 // is harmless but frightens users. So this block detects packet
616 // devices and make IDENTIFY DEVICE fail "nicely" without a syslog
619 // If you read only the ATA specs, it appears as if a packet device
620 // *might* respond to the IDENTIFY DEVICE command. This is
621 // misleading - it's because around the time that SFF-8020 was
622 // incorporated into the ATA-3/4 standard, the ATA authors were
623 // sloppy. See SFF-8020 and you will see that ATAPI devices have
624 // *always* had IDENTIFY PACKET DEVICE as a mandatory part of their
625 // command set, and return 'Command Aborted' to IDENTIFY DEVICE.
626 if (command
==IDENTIFY
|| command
==PIDENTIFY
){
627 unsigned short deviceid
[256];
628 // check the device identity, as seen when the system was booted
629 // or the device was FIRST registered. This will not be current
630 // if the user has subsequently changed some of the parameters. If
631 // device is a packet device, swap the command interpretations.
632 if (!ioctl(device
, HDIO_GET_IDENTITY
, deviceid
) && (deviceid
[0] & 0x8000))
633 buff
[0]=(command
==IDENTIFY
)?ATA_IDENTIFY_PACKET_DEVICE
:ATA_IDENTIFY_DEVICE
;
637 // We are now doing the HDIO_DRIVE_CMD type ioctl.
638 if ((ioctl(device
, HDIO_DRIVE_CMD
, buff
)))
641 // CHECK POWER MODE command returns information in the Sector Count
642 // register (buff[3]). Copy to return data buffer.
643 if (command
==CHECK_POWER_MODE
)
644 buff
[HDIO_DRIVE_CMD_OFFSET
]=buff
[2];
646 // if the command returns data then copy it back
648 memcpy(data
, buff
+HDIO_DRIVE_CMD_OFFSET
, copydata
);
653 // CCISS Smart Array Controller
654 static int cciss_sendpassthru(unsigned int cmdtype
, unsigned char *CDB
,
655 unsigned int CDBlen
, char *buff
,
656 unsigned int size
, unsigned int LunID
,
657 unsigned char *scsi3addr
, int fd
)
660 IOCTL_Command_struct iocommand
;
662 memset(&iocommand
, 0, sizeof(iocommand
));
666 // To controller; nothing to do
668 else if (cmdtype
== 1)
670 iocommand
.LUN_info
.LogDev
.VolId
= LunID
;
671 iocommand
.LUN_info
.LogDev
.Mode
= 1;
673 else if (cmdtype
== 2)
675 memcpy(&iocommand
.LUN_info
.LunAddrBytes
,scsi3addr
,8);
676 iocommand
.LUN_info
.LogDev
.Mode
= 0;
680 fprintf(stderr
, "cciss_sendpassthru: bad cmdtype\n");
684 memcpy(&iocommand
.Request
.CDB
[0], CDB
, CDBlen
);
685 iocommand
.Request
.CDBLen
= CDBlen
;
686 iocommand
.Request
.Type
.Type
= TYPE_CMD
;
687 iocommand
.Request
.Type
.Attribute
= ATTR_SIMPLE
;
688 iocommand
.Request
.Type
.Direction
= XFER_READ
;
689 iocommand
.Request
.Timeout
= 0;
691 iocommand
.buf_size
= size
;
692 iocommand
.buf
= (unsigned char *)buff
;
694 if ((err
= ioctl(fd
, CCISS_PASSTHRU
, &iocommand
)))
696 fprintf(stderr
, "CCISS ioctl error %d\n", err
);
701 static int cciss_getlun(int device
, int target
, unsigned char *physlun
)
703 unsigned char CDB
[16]= {0};
704 ReportLunData_struct
*luns
;
705 int reportlunsize
= sizeof(*luns
) + CISS_MAX_PHYS_LUN
* 8;
709 luns
= (ReportLunData_struct
*)malloc(reportlunsize
);
711 memset(luns
, 0, reportlunsize
);
713 /* Get Physical LUN Info (for physical device) */
714 CDB
[0] = CISS_REPORT_PHYS
;
715 CDB
[6] = (reportlunsize
>> 24) & 0xFF; /* MSB */
716 CDB
[7] = (reportlunsize
>> 16) & 0xFF;
717 CDB
[8] = (reportlunsize
>> 8) & 0xFF;
718 CDB
[9] = reportlunsize
& 0xFF;
720 if ((ret
= cciss_sendpassthru(0, CDB
, 12, (char *)luns
, reportlunsize
, 0, NULL
, device
)))
726 for (i
=0; i
<CISS_MAX_LUN
+1; i
++)
728 if (luns
->LUN
[i
][6] == target
)
730 memcpy(physlun
, luns
->LUN
[i
], 8);
739 // end CCISS Smart Array Controller
741 // >>>>>> Start of general SCSI specific linux code
743 /* Linux specific code.
744 * Historically smartmontools (and smartsuite before it) used the
745 * SCSI_IOCTL_SEND_COMMAND ioctl which is available to all linux device
746 * nodes that use the SCSI subsystem. A better interface has been available
747 * via the SCSI generic (sg) driver but this involves the extra step of
748 * mapping disk devices (e.g. /dev/sda) to the corresponding sg device
749 * (e.g. /dev/sg2). In the linux kernel 2.6 series most of the facilities of
750 * the sg driver have become available via the SG_IO ioctl which is available
751 * on all SCSI devices (on SCSI tape devices from lk 2.6.6).
752 * So the strategy below is to find out if the SG_IO ioctl is available and
753 * if so use it; failing that use the older SCSI_IOCTL_SEND_COMMAND ioctl.
754 * Should work in 2.0, 2.2, 2.4 and 2.6 series linux kernels. */
756 #define MAX_DXFER_LEN 1024 /* can be increased if necessary */
757 #define SEND_IOCTL_RESP_SENSE_LEN 16 /* ioctl limitation */
758 #define SG_IO_RESP_SENSE_LEN 64 /* large enough see buffer */
759 #define LSCSI_DRIVER_MASK 0xf /* mask out "suggestions" */
760 #define LSCSI_DRIVER_SENSE 0x8 /* alternate CHECK CONDITION indication */
761 #define LSCSI_DRIVER_TIMEOUT 0x6
762 #define LSCSI_DID_TIME_OUT 0x3
763 #define LSCSI_DID_BUS_BUSY 0x2
764 #define LSCSI_DID_NO_CONNECT 0x1
766 #ifndef SCSI_IOCTL_SEND_COMMAND
767 #define SCSI_IOCTL_SEND_COMMAND 1
770 #define SG_IO_PRESENT_UNKNOWN 0
771 #define SG_IO_PRESENT_YES 1
772 #define SG_IO_PRESENT_NO 2
774 static int sg_io_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
, int report
,
776 static int sisc_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
, int report
);
778 static int sg_io_state
= SG_IO_PRESENT_UNKNOWN
;
780 /* Preferred implementation for issuing SCSI commands in linux. This
781 * function uses the SG_IO ioctl. Return 0 if command issued successfully
782 * (various status values should still be checked). If the SCSI command
783 * cannot be issued then a negative errno value is returned. */
784 static int sg_io_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
, int report
,
788 ARGUSED(dev_fd
); ARGUSED(iop
); ARGUSED(report
);
791 struct sg_io_hdr io_hdr
;
795 const unsigned char * ucp
= iop
->cmnd
;
798 const int sz
= (int)sizeof(buff
);
800 np
= scsi_get_opcode_name(ucp
[0]);
801 j
= snprintf(buff
, sz
, " [%s: ", np
? np
: "<unknown opcode>");
802 for (k
= 0; k
< (int)iop
->cmnd_len
; ++k
)
803 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "%02x ", ucp
[k
]);
805 (DXFER_TO_DEVICE
== iop
->dxfer_dir
) && (iop
->dxferp
)) {
806 int trunc
= (iop
->dxfer_len
> 256) ? 1 : 0;
808 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "]\n Outgoing "
809 "data, len=%d%s:\n", (int)iop
->dxfer_len
,
810 (trunc
? " [only first 256 bytes shown]" : ""));
811 dStrHex((const char *)iop
->dxferp
,
812 (trunc
? 256 : iop
->dxfer_len
) , 1);
815 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "]\n");
818 memset(&io_hdr
, 0, sizeof(struct sg_io_hdr
));
819 io_hdr
.interface_id
= 'S';
820 io_hdr
.cmd_len
= iop
->cmnd_len
;
821 io_hdr
.mx_sb_len
= iop
->max_sense_len
;
822 io_hdr
.dxfer_len
= iop
->dxfer_len
;
823 io_hdr
.dxferp
= iop
->dxferp
;
824 io_hdr
.cmdp
= iop
->cmnd
;
825 io_hdr
.sbp
= iop
->sensep
;
826 /* sg_io_hdr interface timeout has millisecond units. Timeout of 0
827 defaults to 60 seconds. */
828 io_hdr
.timeout
= ((0 == iop
->timeout
) ? 60 : iop
->timeout
) * 1000;
829 switch (iop
->dxfer_dir
) {
831 io_hdr
.dxfer_direction
= SG_DXFER_NONE
;
833 case DXFER_FROM_DEVICE
:
834 io_hdr
.dxfer_direction
= SG_DXFER_FROM_DEV
;
836 case DXFER_TO_DEVICE
:
837 io_hdr
.dxfer_direction
= SG_DXFER_TO_DEV
;
840 pout("do_scsi_cmnd_io: bad dxfer_dir\n");
843 iop
->resp_sense_len
= 0;
844 iop
->scsi_status
= 0;
846 if (ioctl(dev_fd
, SG_IO
, &io_hdr
) < 0) {
847 if (report
&& (! unknown
))
848 pout(" SG_IO ioctl failed, errno=%d [%s]\n", errno
,
853 pout(" scsi_status=0x%x, host_status=0x%x, driver_status=0x%x\n"
854 " info=0x%x duration=%d milliseconds\n", io_hdr
.status
,
855 io_hdr
.host_status
, io_hdr
.driver_status
, io_hdr
.info
,
858 if (DXFER_FROM_DEVICE
== iop
->dxfer_dir
) {
859 int trunc
= (iop
->dxfer_len
> 256) ? 1 : 0;
861 pout(" Incoming data, len=%d%s:\n", (int)iop
->dxfer_len
,
862 (trunc
? " [only first 256 bytes shown]" : ""));
863 dStrHex((const char*)iop
->dxferp
,
864 (trunc
? 256 : iop
->dxfer_len
) , 1);
868 iop
->resid
= io_hdr
.resid
;
869 iop
->scsi_status
= io_hdr
.status
;
871 if (io_hdr
.info
| SG_INFO_CHECK
) { /* error or warning */
872 int masked_driver_status
= (LSCSI_DRIVER_MASK
& io_hdr
.driver_status
);
874 if (0 != io_hdr
.host_status
) {
875 if ((LSCSI_DID_NO_CONNECT
== io_hdr
.host_status
) ||
876 (LSCSI_DID_BUS_BUSY
== io_hdr
.host_status
) ||
877 (LSCSI_DID_TIME_OUT
== io_hdr
.host_status
))
880 return -EIO
; /* catch all */
882 if (0 != masked_driver_status
) {
883 if (LSCSI_DRIVER_TIMEOUT
== masked_driver_status
)
885 else if (LSCSI_DRIVER_SENSE
!= masked_driver_status
)
888 if (LSCSI_DRIVER_SENSE
== masked_driver_status
)
889 iop
->scsi_status
= SCSI_STATUS_CHECK_CONDITION
;
890 iop
->resp_sense_len
= io_hdr
.sb_len_wr
;
891 if ((SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) &&
892 iop
->sensep
&& (iop
->resp_sense_len
> 0)) {
894 pout(" >>> Sense buffer, len=%d:\n",
895 (int)iop
->resp_sense_len
);
896 dStrHex((const char *)iop
->sensep
, iop
->resp_sense_len
, 1);
900 if (SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) {
901 if ((iop
->sensep
[0] & 0x7f) > 0x71)
902 pout(" status=%x: [desc] sense_key=%x asc=%x ascq=%x\n",
903 iop
->scsi_status
, iop
->sensep
[1] & 0xf,
904 iop
->sensep
[2], iop
->sensep
[3]);
906 pout(" status=%x: sense_key=%x asc=%x ascq=%x\n",
907 iop
->scsi_status
, iop
->sensep
[2] & 0xf,
908 iop
->sensep
[12], iop
->sensep
[13]);
911 pout(" status=0x%x\n", iop
->scsi_status
);
918 struct linux_ioctl_send_command
922 UINT8 buff
[MAX_DXFER_LEN
+ 16];
925 /* The Linux SCSI_IOCTL_SEND_COMMAND ioctl is primitive and it doesn't
926 * support: CDB length (guesses it from opcode), resid and timeout.
927 * Patches in Linux 2.4.21 and 2.5.70 to extend SEND DIAGNOSTIC timeout
928 * to 2 hours in order to allow long foreground extended self tests. */
929 static int sisc_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
, int report
)
931 struct linux_ioctl_send_command wrk
;
932 int status
, buff_offset
;
935 memcpy(wrk
.buff
, iop
->cmnd
, iop
->cmnd_len
);
936 buff_offset
= iop
->cmnd_len
;
939 const unsigned char * ucp
= iop
->cmnd
;
942 const int sz
= (int)sizeof(buff
);
944 np
= scsi_get_opcode_name(ucp
[0]);
945 j
= snprintf(buff
, sz
, " [%s: ", np
? np
: "<unknown opcode>");
946 for (k
= 0; k
< (int)iop
->cmnd_len
; ++k
)
947 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "%02x ", ucp
[k
]);
949 (DXFER_TO_DEVICE
== iop
->dxfer_dir
) && (iop
->dxferp
)) {
950 int trunc
= (iop
->dxfer_len
> 256) ? 1 : 0;
952 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "]\n Outgoing "
953 "data, len=%d%s:\n", (int)iop
->dxfer_len
,
954 (trunc
? " [only first 256 bytes shown]" : ""));
955 dStrHex((const char *)iop
->dxferp
,
956 (trunc
? 256 : iop
->dxfer_len
) , 1);
959 j
+= snprintf(&buff
[j
], (sz
> j
? (sz
- j
) : 0), "]\n");
962 switch (iop
->dxfer_dir
) {
967 case DXFER_FROM_DEVICE
:
969 if (iop
->dxfer_len
> MAX_DXFER_LEN
)
971 wrk
.outbufsize
= iop
->dxfer_len
;
973 case DXFER_TO_DEVICE
:
974 if (iop
->dxfer_len
> MAX_DXFER_LEN
)
976 memcpy(wrk
.buff
+ buff_offset
, iop
->dxferp
, iop
->dxfer_len
);
977 wrk
.inbufsize
= iop
->dxfer_len
;
981 pout("do_scsi_cmnd_io: bad dxfer_dir\n");
984 iop
->resp_sense_len
= 0;
985 iop
->scsi_status
= 0;
987 status
= ioctl(dev_fd
, SCSI_IOCTL_SEND_COMMAND
, &wrk
);
990 pout(" SCSI_IOCTL_SEND_COMMAND ioctl failed, errno=%d [%s]\n",
991 errno
, strerror(errno
));
997 if (DXFER_FROM_DEVICE
== iop
->dxfer_dir
) {
998 memcpy(iop
->dxferp
, wrk
.buff
, iop
->dxfer_len
);
1000 int trunc
= (iop
->dxfer_len
> 256) ? 1 : 0;
1002 pout(" Incoming data, len=%d%s:\n", (int)iop
->dxfer_len
,
1003 (trunc
? " [only first 256 bytes shown]" : ""));
1004 dStrHex((const char*)iop
->dxferp
,
1005 (trunc
? 256 : iop
->dxfer_len
) , 1);
1010 iop
->scsi_status
= status
& 0x7e; /* bits 0 and 7 used to be for vendors */
1011 if (LSCSI_DRIVER_SENSE
== ((status
>> 24) & 0xf))
1012 iop
->scsi_status
= SCSI_STATUS_CHECK_CONDITION
;
1013 len
= (SEND_IOCTL_RESP_SENSE_LEN
< iop
->max_sense_len
) ?
1014 SEND_IOCTL_RESP_SENSE_LEN
: iop
->max_sense_len
;
1015 if ((SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) &&
1016 iop
->sensep
&& (len
> 0)) {
1017 memcpy(iop
->sensep
, wrk
.buff
, len
);
1018 iop
->resp_sense_len
= len
;
1020 pout(" >>> Sense buffer, len=%d:\n", (int)len
);
1021 dStrHex((const char *)wrk
.buff
, len
, 1);
1025 if (SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) {
1026 pout(" status=%x: sense_key=%x asc=%x ascq=%x\n", status
& 0xff,
1027 wrk
.buff
[2] & 0xf, wrk
.buff
[12], wrk
.buff
[13]);
1030 pout(" status=0x%x\n", status
);
1032 if (iop
->scsi_status
> 0)
1036 pout(" ioctl status=0x%x but scsi status=0, fail with EIO\n",
1038 return -EIO
; /* give up, assume no device there */
1042 /* SCSI command transmission interface function, linux version.
1043 * Returns 0 if SCSI command successfully launched and response
1044 * received. Even when 0 is returned the caller should check
1045 * scsi_cmnd_io::scsi_status for SCSI defined errors and warnings
1046 * (e.g. CHECK CONDITION). If the SCSI command could not be issued
1047 * (e.g. device not present or timeout) or some other problem
1048 * (e.g. timeout) then returns a negative errno value */
1049 static int do_normal_scsi_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
,
1054 /* implementation relies on static sg_io_state variable. If not
1055 * previously set tries the SG_IO ioctl. If that succeeds assume
1056 * that SG_IO ioctl functional. If it fails with an errno value
1057 * other than ENODEV (no device) or permission then assume
1058 * SCSI_IOCTL_SEND_COMMAND is the only option. */
1059 switch (sg_io_state
) {
1060 case SG_IO_PRESENT_UNKNOWN
:
1061 /* ignore report argument */
1062 if (0 == (res
= sg_io_cmnd_io(dev_fd
, iop
, report
, 1))) {
1063 sg_io_state
= SG_IO_PRESENT_YES
;
1065 } else if ((-ENODEV
== res
) || (-EACCES
== res
) || (-EPERM
== res
))
1066 return res
; /* wait until we see a device */
1067 sg_io_state
= SG_IO_PRESENT_NO
;
1068 /* drop through by design */
1069 case SG_IO_PRESENT_NO
:
1070 return sisc_cmnd_io(dev_fd
, iop
, report
);
1071 case SG_IO_PRESENT_YES
:
1072 return sg_io_cmnd_io(dev_fd
, iop
, report
, 0);
1074 pout(">>>> do_scsi_cmnd_io: bad sg_io_state=%d\n", sg_io_state
);
1075 sg_io_state
= SG_IO_PRESENT_UNKNOWN
;
1076 return -EIO
; /* report error and reset state */
1080 /* Check and call the right interface. Maybe when the do_generic_scsi_cmd_io interface is better
1081 we can take off this crude way of calling the right interface */
1082 int do_scsi_cmnd_io(int dev_fd
, struct scsi_cmnd_io
* iop
, int report
)
1084 switch(con
->controller_type
)
1086 case CONTROLLER_CCISS
:
1087 return cciss_io_interface(dev_fd
, con
->controller_port
-1, iop
, report
);
1091 return do_normal_scsi_cmnd_io(dev_fd
, iop
, report
);
1097 // >>>>>> End of general SCSI specific linux code
1099 /* cciss >> CCSISS I/O passthrough
1100 This is an interface that uses the cciss passthrough to talk to the SMART controller on
1101 the HP system. The cciss driver provides a way to send SCSI cmds through the CCISS passthrough
1102 essentially the methods above and below pertain to SCSI, except for the SG driver which is not
1103 involved. The CCISS driver does not engage the scsi subsystem. */
1104 static int cciss_io_interface(int device
, int target
, struct scsi_cmnd_io
* iop
, int report
)
1106 unsigned char pBuf
[512] = {0};
1107 unsigned char phylun
[1024] = {0};
1110 int len
= 0; // used later in the code.
1113 cciss_getlun(device
, target
, phylun
);
1114 status
= cciss_sendpassthru( 2, iop
->cmnd
, iop
->cmnd_len
, (char*) pBuf
, iBufLen
, 1, phylun
, device
);
1119 printf(" status=0\n");
1120 if (DXFER_FROM_DEVICE
== iop
->dxfer_dir
)
1122 memcpy(iop
->dxferp
, pBuf
, iop
->dxfer_len
);
1125 int trunc
= (iop
->dxfer_len
> 256) ? 1 : 0;
1126 printf(" Incoming data, len=%d%s:\n", (int)iop
->dxfer_len
,
1127 (trunc
? " [only first 256 bytes shown]" : ""));
1128 dStrHex((const char*)iop
->dxferp
, (trunc
? 256 : iop
->dxfer_len
) , 1);
1133 iop
->scsi_status
= status
& 0x7e; /* bits 0 and 7 used to be for vendors */
1134 if (LSCSI_DRIVER_SENSE
== ((status
>> 24) & 0xf))
1135 iop
->scsi_status
= SCSI_STATUS_CHECK_CONDITION
;
1136 len
= (SEND_IOCTL_RESP_SENSE_LEN
< iop
->max_sense_len
) ?
1137 SEND_IOCTL_RESP_SENSE_LEN
: iop
->max_sense_len
;
1138 if ((SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) &&
1139 iop
->sensep
&& (len
> 0))
1141 memcpy(iop
->sensep
, pBuf
, len
);
1142 iop
->resp_sense_len
= iBufLen
;
1145 printf(" >>> Sense buffer, len=%d:\n", (int)len
);
1146 dStrHex((const char *)pBuf
, len
, 1);
1151 if (SCSI_STATUS_CHECK_CONDITION
== iop
->scsi_status
) {
1152 printf(" status=%x: sense_key=%x asc=%x ascq=%x\n", status
& 0xff,
1153 pBuf
[2] & 0xf, pBuf
[12], pBuf
[13]);
1156 printf(" status=0x%x\n", status
);
1158 if (iop
->scsi_status
> 0)
1163 printf(" ioctl status=0x%x but scsi status=0, fail with EIO\n", status
);
1164 return -EIO
; /* give up, assume no device there */
1170 void printwarning(smart_command_set command
);
1173 // This is an interface routine meant to isolate the OS dependent
1174 // parts of the code, and to provide a debugging interface. Each
1175 // different port and OS needs to provide it's own interface. This
1176 // is the linux interface to the 3ware 3w-xxxx driver. It allows ATA
1177 // commands to be passed through the SCSI driver.
1178 // DETAILED DESCRIPTION OF ARGUMENTS
1179 // fd: is the file descriptor provided by open()
1180 // disknum is the disk number (0 to 15) in the RAID array
1181 // escalade_type indicates the type of controller type, and if scsi or char interface is used
1182 // command: defines the different operations.
1183 // select: additional input data if needed (which log, which type of
1185 // data: location to write output data, if needed (512 bytes).
1186 // Note: not all commands use all arguments.
1188 // -1 if the command failed
1189 // 0 if the command succeeded,
1190 // STATUS_CHECK routine:
1191 // -1 if the command failed
1192 // 0 if the command succeeded and disk SMART status is "OK"
1193 // 1 if the command succeeded and disk SMART status is "FAILING"
1196 /* 512 is the max payload size: increase if needed */
1197 #define BUFFER_LEN_678K ( sizeof(TW_Ioctl) ) // 1044 unpacked, 1041 packed
1198 #define BUFFER_LEN_678K_CHAR ( sizeof(TW_New_Ioctl)+512-1 ) // 1539 unpacked, 1536 packed
1199 #define BUFFER_LEN_9000 ( sizeof(TW_Ioctl_Buf_Apache)+512-1 ) // 2051 unpacked, 2048 packed
1200 #define TW_IOCTL_BUFFER_SIZE ( MAX(MAX(BUFFER_LEN_678K, BUFFER_LEN_9000), BUFFER_LEN_678K_CHAR) )
1202 int escalade_command_interface(int fd
, int disknum
, int escalade_type
, smart_command_set command
, int select
, char *data
){
1204 // return value and buffer for ioctl()
1205 int ioctlreturn
, readdata
=0;
1207 // Used by both the SCSI and char interfaces
1208 TW_Passthru
*passthru
=NULL
;
1209 char ioctl_buffer
[TW_IOCTL_BUFFER_SIZE
];
1211 // only used for SCSI device interface
1212 TW_Ioctl
*tw_ioctl
=NULL
;
1213 TW_Output
*tw_output
=NULL
;
1215 // only used for 6000/7000/8000 char device interface
1216 TW_New_Ioctl
*tw_ioctl_char
=NULL
;
1218 // only used for 9000 character device interface
1219 TW_Ioctl_Buf_Apache
*tw_ioctl_apache
=NULL
;
1221 memset(ioctl_buffer
, 0, TW_IOCTL_BUFFER_SIZE
);
1223 if (escalade_type
==CONTROLLER_3WARE_9000_CHAR
) {
1224 tw_ioctl_apache
= (TW_Ioctl_Buf_Apache
*)ioctl_buffer
;
1225 tw_ioctl_apache
->driver_command
.control_code
= TW_IOCTL_FIRMWARE_PASS_THROUGH
;
1226 tw_ioctl_apache
->driver_command
.buffer_length
= 512; /* payload size */
1227 passthru
= (TW_Passthru
*)&(tw_ioctl_apache
->firmware_command
.command
.oldcommand
);
1229 else if (escalade_type
==CONTROLLER_3WARE_678K_CHAR
) {
1230 tw_ioctl_char
= (TW_New_Ioctl
*)ioctl_buffer
;
1231 tw_ioctl_char
->data_buffer_length
= 512;
1232 passthru
= (TW_Passthru
*)&(tw_ioctl_char
->firmware_command
);
1234 else if (escalade_type
==CONTROLLER_3WARE_678K
) {
1235 tw_ioctl
= (TW_Ioctl
*)ioctl_buffer
;
1236 tw_ioctl
->cdb
[0] = TW_IOCTL
;
1237 tw_ioctl
->opcode
= TW_ATA_PASSTHRU
;
1238 tw_ioctl
->input_length
= 512; // correct even for non-data commands
1239 tw_ioctl
->output_length
= 512; // correct even for non-data commands
1240 tw_output
= (TW_Output
*)tw_ioctl
;
1241 passthru
= (TW_Passthru
*)&(tw_ioctl
->input_data
);
1244 pout("Unrecognized escalade_type %d in linux_3ware_command_interface(disk %d)\n"
1245 "Please contact " PACKAGE_BUGREPORT
"\n", escalade_type
, disknum
);
1250 // Same for (almost) all commands - but some reset below
1251 passthru
->byte0
.opcode
= TW_OP_ATA_PASSTHRU
;
1252 passthru
->request_id
= 0xFF;
1253 passthru
->byte3
.aport
= disknum
;
1254 passthru
->byte3
.host_id
= 0;
1255 passthru
->status
= 0;
1256 passthru
->flags
= 0x1;
1257 passthru
->drive_head
= 0x0;
1258 passthru
->sector_num
= 0;
1260 // All SMART commands use this CL/CH signature. These are magic
1261 // values from the ATA specifications.
1262 passthru
->cylinder_lo
= 0x4F;
1263 passthru
->cylinder_hi
= 0xC2;
1265 // SMART ATA COMMAND REGISTER value
1266 passthru
->command
= ATA_SMART_CMD
;
1268 // Is this a command that reads or returns 512 bytes?
1269 // passthru->param values are:
1270 // 0x0 - non data command without TFR write check,
1271 // 0x8 - non data command with TFR write check,
1272 // 0xD - data command that returns data to host from device
1273 // 0xF - data command that writes data from host to device
1274 // passthru->size values are 0x5 for non-data and 0x07 for data
1275 if (command
== READ_VALUES
||
1276 command
== READ_THRESHOLDS
||
1277 command
== READ_LOG
||
1278 command
== IDENTIFY
||
1279 command
== WRITE_LOG
) {
1281 passthru
->byte0
.sgloff
= 0x5;
1282 passthru
->size
= 0x7;
1283 passthru
->param
= 0xD;
1284 passthru
->sector_count
= 0x1;
1285 // For 64-bit to work correctly, up the size of the command packet
1286 // in dwords by 1 to account for the 64-bit single sgl 'address'
1287 // field. Note that this doesn't agree with the typedefs but it's
1288 // right (agree with kernel driver behavior/typedefs).
1289 if (escalade_type
==CONTROLLER_3WARE_9000_CHAR
&& sizeof(long)==8)
1293 // Non data command -- but doesn't use large sector
1294 // count register values.
1295 passthru
->byte0
.sgloff
= 0x0;
1296 passthru
->size
= 0x5;
1297 passthru
->param
= 0x8;
1298 passthru
->sector_count
= 0x0;
1301 // Now set ATA registers depending upon command
1303 case CHECK_POWER_MODE
:
1304 passthru
->command
= ATA_CHECK_POWER_MODE
;
1305 passthru
->features
= 0;
1306 passthru
->cylinder_lo
= 0;
1307 passthru
->cylinder_hi
= 0;
1310 passthru
->features
= ATA_SMART_READ_VALUES
;
1312 case READ_THRESHOLDS
:
1313 passthru
->features
= ATA_SMART_READ_THRESHOLDS
;
1316 passthru
->features
= ATA_SMART_READ_LOG_SECTOR
;
1317 // log number to return
1318 passthru
->sector_num
= select
;
1321 if (escalade_type
== CONTROLLER_3WARE_9000_CHAR
)
1322 memcpy((unsigned char *)tw_ioctl_apache
->data_buffer
, data
, 512);
1323 else if (escalade_type
== CONTROLLER_3WARE_678K_CHAR
)
1324 memcpy((unsigned char *)tw_ioctl_char
->data_buffer
, data
, 512);
1326 // COMMAND NOT SUPPORTED VIA SCSI IOCTL INTERFACE
1327 // memcpy(tw_output->output_data, data, 512);
1328 printwarning(command
);
1333 passthru
->features
= ATA_SMART_WRITE_LOG_SECTOR
;
1334 passthru
->sector_count
= 1;
1335 passthru
->sector_num
= select
;
1336 passthru
->param
= 0xF; // PIO data write
1339 // ATA IDENTIFY DEVICE
1340 passthru
->command
= ATA_IDENTIFY_DEVICE
;
1341 passthru
->features
= 0;
1342 passthru
->cylinder_lo
= 0;
1343 passthru
->cylinder_hi
= 0;
1346 // 3WARE controller can NOT have packet device internally
1347 pout("WARNING - NO DEVICE FOUND ON 3WARE CONTROLLER (disk %d)\n", disknum
);
1348 pout("Note: /dev/sdX many need to be replaced with /dev/tweN or /dev/twaN\n");
1352 passthru
->features
= ATA_SMART_ENABLE
;
1355 passthru
->features
= ATA_SMART_DISABLE
;
1358 passthru
->features
= ATA_SMART_AUTO_OFFLINE
;
1359 // Enable or disable?
1360 passthru
->sector_count
= select
;
1363 passthru
->features
= ATA_SMART_AUTOSAVE
;
1364 // Enable or disable?
1365 passthru
->sector_count
= select
;
1367 case IMMEDIATE_OFFLINE
:
1368 passthru
->features
= ATA_SMART_IMMEDIATE_OFFLINE
;
1369 // What test type to run?
1370 passthru
->sector_num
= select
;
1373 passthru
->features
= ATA_SMART_STATUS
;
1376 // This is JUST to see if SMART is enabled, by giving SMART status
1377 // command. But it doesn't say if status was good, or failing.
1378 // See below for the difference.
1379 passthru
->features
= ATA_SMART_STATUS
;
1382 pout("Unrecognized command %d in linux_3ware_command_interface(disk %d)\n"
1383 "Please contact " PACKAGE_BUGREPORT
"\n", command
, disknum
);
1388 // Now send the command down through an ioctl()
1389 if (escalade_type
==CONTROLLER_3WARE_9000_CHAR
)
1390 ioctlreturn
=ioctl(fd
, TW_IOCTL_FIRMWARE_PASS_THROUGH
, tw_ioctl_apache
);
1391 else if (escalade_type
==CONTROLLER_3WARE_678K_CHAR
)
1392 ioctlreturn
=ioctl(fd
, TW_CMD_PACKET_WITH_DATA
, tw_ioctl_char
);
1394 ioctlreturn
=ioctl(fd
, SCSI_IOCTL_SEND_COMMAND
, tw_ioctl
);
1396 // Deal with the different error cases
1398 if (CONTROLLER_3WARE_678K
==escalade_type
&& ((command
==AUTO_OFFLINE
|| command
==AUTOSAVE
) && select
)){
1399 // error here is probably a kernel driver whose version is too old
1400 printwarning(command
);
1408 // The passthru structure is valid after return from an ioctl if:
1409 // - we are using the character interface OR
1410 // - we are using the SCSI interface and this is a NON-READ-DATA command
1411 // For SCSI interface, note that we set passthru to a different
1412 // value after ioctl().
1413 if (CONTROLLER_3WARE_678K
==escalade_type
) {
1417 passthru
=(TW_Passthru
*)&(tw_output
->output_data
);
1420 // See if the ATA command failed. Now that we have returned from
1421 // the ioctl() call, if passthru is valid, then:
1422 // - passthru->status contains the 3ware controller STATUS
1423 // - passthru->command contains the ATA STATUS register
1424 // - passthru->features contains the ATA ERROR register
1426 // Check bits 0 (error bit) and 5 (device fault) of the ATA STATUS
1427 // If bit 0 (error bit) is set, then ATA ERROR register is valid.
1428 // While we *might* decode the ATA ERROR register, at the moment it
1429 // doesn't make much sense: we don't care in detail why the error
1432 if (passthru
&& (passthru
->status
|| (passthru
->command
& 0x21))) {
1437 // If this is a read data command, copy data to output buffer
1439 if (escalade_type
==CONTROLLER_3WARE_9000_CHAR
)
1440 memcpy(data
, (unsigned char *)tw_ioctl_apache
->data_buffer
, 512);
1441 else if (escalade_type
==CONTROLLER_3WARE_678K_CHAR
)
1442 memcpy(data
, (unsigned char *)tw_ioctl_char
->data_buffer
, 512);
1444 memcpy(data
, tw_output
->output_data
, 512);
1447 // For STATUS_CHECK, we need to check register values
1448 if (command
==STATUS_CHECK
) {
1450 // To find out if the SMART RETURN STATUS is good or failing, we
1451 // need to examine the values of the Cylinder Low and Cylinder
1454 unsigned short cyl_lo
=passthru
->cylinder_lo
;
1455 unsigned short cyl_hi
=passthru
->cylinder_hi
;
1457 // If values in Cyl-LO and Cyl-HI are unchanged, SMART status is good.
1458 if (cyl_lo
==0x4F && cyl_hi
==0xC2)
1461 // If values in Cyl-LO and Cyl-HI are as follows, SMART status is FAIL
1462 if (cyl_lo
==0xF4 && cyl_hi
==0x2C)
1465 // Any other values mean that something has gone wrong with the command
1466 if (CONTROLLER_3WARE_678K
==escalade_type
) {
1467 printwarning(command
);
1477 // copy sector count register (one byte!) to return data
1478 if (command
==CHECK_POWER_MODE
)
1479 *data
=*(char *)&(passthru
->sector_count
);
1481 // look for nonexistent devices/ports
1482 if (command
==IDENTIFY
&& !nonempty((unsigned char *)data
, 512)) {
1492 int marvell_command_interface(int device
,
1493 smart_command_set command
,
1503 mvsata_scsi_cmd smart_command
;
1504 unsigned char *buff
= (unsigned char *)&smart_command
.cmd
[6];
1505 // See struct hd_drive_cmd_hdr in hdreg.h
1506 // buff[0]: ATA COMMAND CODE REGISTER
1507 // buff[1]: ATA SECTOR NUMBER REGISTER
1508 // buff[2]: ATA FEATURES REGISTER
1509 // buff[3]: ATA SECTOR COUNT REGISTER
1511 // clear out buff. Large enough for HDIO_DRIVE_CMD (4+512 bytes)
1512 memset(&smart_command
, 0, sizeof(smart_command
));
1513 smart_command
.inlen
= 540;
1514 smart_command
.outlen
= 540;
1515 smart_command
.cmd
[0] = 0xC; //Vendor-specific code
1516 smart_command
.cmd
[4] = 6; //command length
1518 buff
[0] = ATA_SMART_CMD
;
1520 case CHECK_POWER_MODE
:
1521 buff
[0]=ATA_CHECK_POWER_MODE
;
1524 buff
[2]=ATA_SMART_READ_VALUES
;
1527 case READ_THRESHOLDS
:
1528 buff
[2]=ATA_SMART_READ_THRESHOLDS
;
1529 copydata
=buff
[1]=buff
[3]=1;
1532 buff
[2]=ATA_SMART_READ_LOG_SECTOR
;
1537 buff
[0]=ATA_IDENTIFY_DEVICE
;
1541 buff
[0]=ATA_IDENTIFY_PACKET_DEVICE
;
1545 buff
[2]=ATA_SMART_ENABLE
;
1549 buff
[2]=ATA_SMART_DISABLE
;
1554 // this command only says if SMART is working. It could be
1555 // replaced with STATUS_CHECK below.
1556 buff
[2] = ATA_SMART_STATUS
;
1559 buff
[2]=ATA_SMART_AUTO_OFFLINE
;
1560 buff
[3]=select
; // YET NOTE - THIS IS A NON-DATA COMMAND!!
1563 buff
[2]=ATA_SMART_AUTOSAVE
;
1564 buff
[3]=select
; // YET NOTE - THIS IS A NON-DATA COMMAND!!
1566 case IMMEDIATE_OFFLINE
:
1567 buff
[2]=ATA_SMART_IMMEDIATE_OFFLINE
;
1571 pout("Unrecognized command %d in mvsata_os_specific_handler()\n", command
);
1575 // There are two different types of ioctls(). The HDIO_DRIVE_TASK
1577 // We are now doing the HDIO_DRIVE_CMD type ioctl.
1578 if (ioctl(device
, SCSI_IOCTL_SEND_COMMAND
, (void *)&smart_command
))
1581 if (command
==CHECK_POWER_MODE
) {
1582 // LEON -- CHECK THIS PLEASE. THIS SHOULD BE THE SECTOR COUNT
1583 // REGISTER, AND IT MIGHT BE buff[2] NOT buff[3]. Bruce
1588 // Always succeed on a SMART status, as a disk that failed returned
1589 // buff[4]=0xF4, buff[5]=0x2C, i.e. "Bad SMART status" (see below).
1590 if (command
== STATUS
)
1592 //Data returned is starting from 0 offset
1593 if (command
== STATUS_CHECK
)
1595 // Cyl low and Cyl high unchanged means "Good SMART status"
1596 if (buff
[4] == 0x4F && buff
[5] == 0xC2)
1598 // These values mean "Bad SMART status"
1599 if (buff
[4] == 0xF4 && buff
[5] == 0x2C)
1601 // We haven't gotten output that makes sense; print out some debugging info
1602 syserror("Error SMART Status command failed");
1603 pout("Please get assistance from %s\n",PACKAGE_BUGREPORT
);
1604 pout("Register values returned from SMART Status command are:\n");
1605 pout("CMD =0x%02x\n",(int)buff
[0]);
1606 pout("FR =0x%02x\n",(int)buff
[1]);
1607 pout("NS =0x%02x\n",(int)buff
[2]);
1608 pout("SC =0x%02x\n",(int)buff
[3]);
1609 pout("CL =0x%02x\n",(int)buff
[4]);
1610 pout("CH =0x%02x\n",(int)buff
[5]);
1611 pout("SEL=0x%02x\n",(int)buff
[6]);
1616 memcpy(data
, buff
, 512);
1620 // this implementation is derived from ata_command_interface with a header
1621 // packing for highpoint linux driver ioctl interface
1623 // ioctl(fd,HPTIO_CTL,buff)
1626 // structure of hpt_buff
1627 // +----+----+----+----+--------------------.....---------------------+
1628 // | 1 | 2 | 3 | 4 | 5 |
1629 // +----+----+----+----+--------------------.....---------------------+
1631 // 1: The target controller [ int ( 4 Bytes ) ]
1632 // 2: The channel of the target controllee [ int ( 4 Bytes ) ]
1633 // 3: HDIO_ ioctl call [ int ( 4 Bytes ) ]
1634 // available from ${LINUX_KERNEL_SOURCE}/Documentation/ioctl/hdio
1635 // 4: the pmport that disk attached, [ int ( 4 Bytes ) ]
1636 // if no pmport device, set to 1 or leave blank
1637 // 5: data [ void * ( var leangth ) ]
1639 int highpoint_command_interface(int device
, smart_command_set command
,
1640 int select
, char *data
)
1642 unsigned char hpt_buff
[4*sizeof(int) + STRANGE_BUFFER_LENGTH
];
1643 unsigned int *hpt
= (unsigned int *)hpt_buff
;
1644 unsigned char *buff
= &hpt_buff
[4*sizeof(int)];
1646 const int HDIO_DRIVE_CMD_OFFSET
= 4;
1648 memset(hpt_buff
, 0, 4*sizeof(int) + STRANGE_BUFFER_LENGTH
);
1649 hpt
[0] = con
->hpt_data
[0]; // controller id
1650 hpt
[1] = con
->hpt_data
[1]; // channel number
1651 hpt
[3] = con
->hpt_data
[2]; // pmport number
1653 buff
[0]=ATA_SMART_CMD
;
1655 case CHECK_POWER_MODE
:
1656 buff
[0]=ATA_CHECK_POWER_MODE
;
1660 buff
[2]=ATA_SMART_READ_VALUES
;
1664 case READ_THRESHOLDS
:
1665 buff
[2]=ATA_SMART_READ_THRESHOLDS
;
1670 buff
[2]=ATA_SMART_READ_LOG_SECTOR
;
1678 buff
[0]=ATA_IDENTIFY_DEVICE
;
1683 buff
[0]=ATA_IDENTIFY_PACKET_DEVICE
;
1688 buff
[2]=ATA_SMART_ENABLE
;
1692 buff
[2]=ATA_SMART_DISABLE
;
1696 buff
[2]=ATA_SMART_STATUS
;
1699 buff
[2]=ATA_SMART_AUTO_OFFLINE
;
1703 buff
[2]=ATA_SMART_AUTOSAVE
;
1706 case IMMEDIATE_OFFLINE
:
1707 buff
[2]=ATA_SMART_IMMEDIATE_OFFLINE
;
1711 buff
[1]=ATA_SMART_STATUS
;
1714 pout("Unrecognized command %d in linux_highpoint_command_interface()\n"
1715 "Please contact " PACKAGE_BUGREPORT
"\n", command
);
1720 if (command
==WRITE_LOG
) {
1721 unsigned char task
[4*sizeof(int)+sizeof(ide_task_request_t
)+512];
1722 unsigned int *hpt
= (unsigned int *)task
;
1723 ide_task_request_t
*reqtask
= (ide_task_request_t
*)(&task
[4*sizeof(int)]);
1724 task_struct_t
*taskfile
= (task_struct_t
*)reqtask
->io_ports
;
1727 memset(task
, 0, sizeof(task
));
1729 hpt
[0] = con
->hpt_data
[0]; // controller id
1730 hpt
[1] = con
->hpt_data
[1]; // channel number
1731 hpt
[3] = con
->hpt_data
[2]; // pmport number
1732 hpt
[2] = HDIO_DRIVE_TASKFILE
; // real hd ioctl
1735 taskfile
->feature
= ATA_SMART_WRITE_LOG_SECTOR
;
1736 taskfile
->sector_count
= 1;
1737 taskfile
->sector_number
= select
;
1738 taskfile
->low_cylinder
= 0x4f;
1739 taskfile
->high_cylinder
= 0xc2;
1740 taskfile
->device_head
= 0;
1741 taskfile
->command
= ATA_SMART_CMD
;
1743 reqtask
->data_phase
= TASKFILE_OUT
;
1744 reqtask
->req_cmd
= IDE_DRIVE_TASK_OUT
;
1745 reqtask
->out_size
= 512;
1746 reqtask
->in_size
= 0;
1748 memcpy(task
+sizeof(ide_task_request_t
)+4*sizeof(int), data
, 512);
1750 if ((retval
=ioctl(device
, HPTIO_CTL
, task
))) {
1751 if (retval
==-EINVAL
)
1752 pout("Kernel lacks HDIO_DRIVE_TASKFILE support; compile kernel with CONFIG_IDE_TASKFILE_IO set\n");
1758 if (command
==STATUS_CHECK
){
1760 unsigned const char normal_lo
=0x4f, normal_hi
=0xc2;
1761 unsigned const char failed_lo
=0xf4, failed_hi
=0x2c;
1765 hpt
[2] = HDIO_DRIVE_TASK
;
1767 if ((retval
=ioctl(device
, HPTIO_CTL
, hpt_buff
))) {
1768 if (retval
==-EINVAL
) {
1769 pout("Error SMART Status command via HDIO_DRIVE_TASK failed");
1770 pout("Rebuild older linux 2.2 kernels with HDIO_DRIVE_TASK support added\n");
1773 syserror("Error SMART Status command failed");
1777 if (buff
[4]==normal_lo
&& buff
[5]==normal_hi
)
1780 if (buff
[4]==failed_lo
&& buff
[5]==failed_hi
)
1783 syserror("Error SMART Status command failed");
1784 pout("Please get assistance from " PACKAGE_HOMEPAGE
"\n");
1785 pout("Register values returned from SMART Status command are:\n");
1786 pout("CMD=0x%02x\n",(int)buff
[0]);
1787 pout("FR =0x%02x\n",(int)buff
[1]);
1788 pout("NS =0x%02x\n",(int)buff
[2]);
1789 pout("SC =0x%02x\n",(int)buff
[3]);
1790 pout("CL =0x%02x\n",(int)buff
[4]);
1791 pout("CH =0x%02x\n",(int)buff
[5]);
1792 pout("SEL=0x%02x\n",(int)buff
[6]);
1797 if (command
==IDENTIFY
|| command
==PIDENTIFY
) {
1798 unsigned char deviceid
[4*sizeof(int)+512*sizeof(char)];
1799 unsigned int *hpt
= (unsigned int *)deviceid
;
1801 hpt
[0] = con
->hpt_data
[0]; // controller id
1802 hpt
[1] = con
->hpt_data
[1]; // channel number
1803 hpt
[3] = con
->hpt_data
[2]; // pmport number
1805 hpt
[2] = HDIO_GET_IDENTITY
;
1806 if (!ioctl(device
, HPTIO_CTL
, deviceid
) && (deviceid
[4*sizeof(int)] & 0x8000))
1807 buff
[0]=(command
==IDENTIFY
)?ATA_IDENTIFY_PACKET_DEVICE
:ATA_IDENTIFY_DEVICE
;
1811 hpt
[2] = HDIO_DRIVE_CMD
;
1812 if ((ioctl(device
, HPTIO_CTL
, hpt_buff
)))
1815 if (command
==CHECK_POWER_MODE
)
1816 buff
[HDIO_DRIVE_CMD_OFFSET
]=buff
[2];
1819 memcpy(data
, buff
+HDIO_DRIVE_CMD_OFFSET
, copydata
);
1825 // Utility function for printing warnings
1826 void printwarning(smart_command_set command
){
1827 static int printed
[4]={0,0,0,0};
1828 const char* message
=
1829 "can not be passed through the 3ware 3w-xxxx driver. This can be fixed by\n"
1830 "applying a simple 3w-xxxx driver patch that can be found here:\n"
1831 PACKAGE_HOMEPAGE
"\n"
1832 "Alternatively, upgrade your 3w-xxxx driver to version 1.02.00.037 or greater.\n\n";
1834 if (command
==AUTO_OFFLINE
&& !printed
[0]) {
1836 pout("The SMART AUTO-OFFLINE ENABLE command (smartmontools -o on option/Directive)\n%s", message
);
1838 else if (command
==AUTOSAVE
&& !printed
[1]) {
1840 pout("The SMART AUTOSAVE ENABLE command (smartmontools -S on option/Directive)\n%s", message
);
1842 else if (command
==STATUS_CHECK
&& !printed
[2]) {
1844 pout("The SMART RETURN STATUS return value (smartmontools -H option/Directive)\n%s", message
);
1846 else if (command
==WRITE_LOG
&& !printed
[3]) {
1848 pout("The SMART WRITE LOG command (smartmontools -t selective) only supported via char /dev/tw[ae] interface\n");
1854 // Guess device type (ata or scsi) based on device name (Linux
1855 // specific) SCSI device name in linux can be sd, sr, scd, st, nst,
1856 // osst, nosst and sg.
1857 static const char * lin_dev_prefix
= "/dev/";
1858 static const char * lin_dev_ata_disk_plus
= "h";
1859 static const char * lin_dev_ata_devfs_disk_plus
= "ide/";
1860 static const char * lin_dev_scsi_devfs_disk_plus
= "scsi/";
1861 static const char * lin_dev_scsi_disk_plus
= "s";
1862 static const char * lin_dev_scsi_tape1
= "ns";
1863 static const char * lin_dev_scsi_tape2
= "os";
1864 static const char * lin_dev_scsi_tape3
= "nos";
1865 static const char * lin_dev_3ware_9000_char
= "twa";
1866 static const char * lin_dev_3ware_678k_char
= "twe";
1867 static const char * lin_dev_cciss_dir
= "cciss/";
1869 int guess_device_type(const char * dev_name
) {
1871 int dev_prefix_len
= strlen(lin_dev_prefix
);
1873 // if dev_name null, or string length zero
1874 if (!dev_name
|| !(len
= strlen(dev_name
)))
1875 return CONTROLLER_UNKNOWN
;
1877 // Remove the leading /dev/... if it's there
1878 if (!strncmp(lin_dev_prefix
, dev_name
, dev_prefix_len
)) {
1879 if (len
<= dev_prefix_len
)
1880 // if nothing else in the string, unrecognized
1881 return CONTROLLER_UNKNOWN
;
1882 // else advance pointer to following characters
1883 dev_name
+= dev_prefix_len
;
1886 // form /dev/h* or h*
1887 if (!strncmp(lin_dev_ata_disk_plus
, dev_name
,
1888 strlen(lin_dev_ata_disk_plus
)))
1889 return CONTROLLER_ATA
;
1891 // form /dev/ide/* or ide/*
1892 if (!strncmp(lin_dev_ata_devfs_disk_plus
, dev_name
,
1893 strlen(lin_dev_ata_devfs_disk_plus
)))
1894 return CONTROLLER_ATA
;
1896 // form /dev/s* or s*
1897 if (!strncmp(lin_dev_scsi_disk_plus
, dev_name
,
1898 strlen(lin_dev_scsi_disk_plus
)))
1899 return CONTROLLER_SCSI
;
1901 // form /dev/scsi/* or scsi/*
1902 if (!strncmp(lin_dev_scsi_devfs_disk_plus
, dev_name
,
1903 strlen(lin_dev_scsi_devfs_disk_plus
)))
1904 return CONTROLLER_SCSI
;
1906 // form /dev/ns* or ns*
1907 if (!strncmp(lin_dev_scsi_tape1
, dev_name
,
1908 strlen(lin_dev_scsi_tape1
)))
1909 return CONTROLLER_SCSI
;
1911 // form /dev/os* or os*
1912 if (!strncmp(lin_dev_scsi_tape2
, dev_name
,
1913 strlen(lin_dev_scsi_tape2
)))
1914 return CONTROLLER_SCSI
;
1916 // form /dev/nos* or nos*
1917 if (!strncmp(lin_dev_scsi_tape3
, dev_name
,
1918 strlen(lin_dev_scsi_tape3
)))
1919 return CONTROLLER_SCSI
;
1922 if (!strncmp(lin_dev_3ware_9000_char
, dev_name
,
1923 strlen(lin_dev_3ware_9000_char
)))
1924 return CONTROLLER_3WARE_9000_CHAR
;
1927 if (!strncmp(lin_dev_3ware_678k_char
, dev_name
,
1928 strlen(lin_dev_3ware_678k_char
)))
1929 return CONTROLLER_3WARE_678K_CHAR
;
1931 if (!strncmp(lin_dev_cciss_dir
, dev_name
,
1932 strlen(lin_dev_cciss_dir
)))
1933 return CONTROLLER_CCISS
;
1935 // we failed to recognize any of the forms
1936 return CONTROLLER_UNKNOWN
;
1942 [ed@firestorm ed
]$ ls
-l
/dev
/discs
1944 lr
-xr
-xr
-x
1 root root
30 Dec
31 1969 disc0
-> ../ide
/host2
/bus0
/target0
/lun0
/
1945 lr
-xr
-xr
-x
1 root root
30 Dec
31 1969 disc1
-> ../ide
/host2
/bus1
/target0
/lun0
/
1946 [ed@firestorm ed
]$ ls
-l dev
/ide
/host*/bus*/target*/lun*/disc
1947 ls
: dev
/ide
/host*/bus*/target*/lun*/disc
: No such file
or directory
1948 [ed@firestorm ed
]$ ls
-l
/dev
/ide
/host*/bus*/target*/lun*/disc
1949 brw
------- 1 root root
33, 0 Dec
31 1969 /dev
/ide
/host2
/bus0
/target0
/lun0
/disc
1950 brw
------- 1 root root
34, 0 Dec
31 1969 /dev
/ide
/host2
/bus1
/target0
/lun0
/disc
1951 [ed@firestorm ed
]$ ls
-l
/dev
/ide
/c
*b
*t
*u
*
1952 ls
: /dev
/ide
/c
*b
*t
*u
*: No such file
or directory
1954 Script done on Fri Nov
7 13:46:28 2003