From sos@FreeBSD.ORG  Mon May 23 13:29:27 2005
Return-Path: <sos@FreeBSD.ORG>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 553D916A41C;
	Mon, 23 May 2005 13:29:27 +0000 (GMT)
	(envelope-from sos@FreeBSD.ORG)
Received: from spider.deepcore.dk (cpe.atm2-0-53484.0x50a6c9a6.abnxx9.customer.tele.dk [80.166.201.166])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 524FF43D1F;
	Mon, 23 May 2005 13:29:26 +0000 (GMT)
	(envelope-from sos@FreeBSD.ORG)
Received: from [194.192.25.136] (mac.deepcore.dk [194.192.25.136])
	by spider.deepcore.dk (8.13.3/8.13.3) with ESMTP id j4NDMuDv043595;
	Mon, 23 May 2005 15:22:56 +0200 (CEST)
	(envelope-from sos@FreeBSD.ORG)
Message-Id: <66D55E9B-EFBF-40D5-8CC9-4B158472F6F4@FreeBSD.ORG>
Date: Mon, 23 May 2005 15:29:17 +0200
From: =?ISO-8859-1?Q?S=F8ren_Schmidt?= <sos@FreeBSD.ORG>
To: Oliver Lehmann <oliver@FreeBSD.ORG>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, martines@rochester.rr.com
In-Reply-To: <200505231320.j4NDKTQS016056@kartoffel.salatschuessel.net>
Subject: Re: smartmontools is malfunctioning on FreeBSD > 600027
References: <200505231320.j4NDKTQS016056@kartoffel.salatschuessel.net>

>Number:         81404
>Category:       ports
>Synopsis:       Re: smartmontools is malfunctioning on FreeBSD > 600027
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 23 13:30:06 GMT 2005
>Closed-Date:    Tue May 24 09:44:38 GMT 2005
>Last-Modified:  Tue May 24 09:44:38 GMT 2005
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 --Apple-Mail-1--1038679942
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=US-ASCII;
 	delsp=yes;
 	format=flowed
 
 
 On 23/05/2005, at 15:20, Oliver Lehmann wrote:
 
 >
 >
 >> Submitter-Id:    current-users
 >> Originator:    Oliver Lehmann
 >> Organization:
 >> Confidential:    no
 >> Synopsis:    smartmontools is malfunctioning on FreeBSD > 600027
 >> Severity:    non-critical
 >> Priority:    low
 >> Category:    ports
 >> Class:        update
 >> Release:    FreeBSD 6.0-CURRENT amd64
 >> Environment:
 >>
 > System: FreeBSD kartoffel.salatschuessel.net 6.0-CURRENT FreeBSD  
 > 6.0-CURRENT #0: Sat May 21 09:29:57 CEST 2005  
 > olivleh1@kartoffel.salatschuessel.net:/usr/obj/usr/src/sys/ 
 > KARTOFFEL amd64
 >
 >
 >
 >> Description:
 >>
 >     http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/ata.h? 
 > f=h#rev1.26
 >     that change causes smartmontools to malfunctioning
 >
 >
 >> How-To-Repeat:
 >> Fix:
 >>
 >
 >
 > --- patch-smartmontools begins here ---
 > Index: Makefile
 > ===================================================================
 > RCS file: /home/pcvs/ports/sysutils/smartmontools/Makefile,v
 > retrieving revision 1.16
 > diff -u -r1.16 Makefile
 > --- Makefile    9 May 2005 10:00:14 -0000    1.16
 > +++ Makefile    23 May 2005 13:17:44 -0000
 > @@ -29,6 +29,13 @@
 >  EXAMPLES=    smartd.conf examplescripts/README examplescripts/ 
 > Example?
 >  RC_SCRIPTS_SUB=    PREFIX=${PREFIX} RC_SUBR=${RC_SUBR}
 >
 > +.include <bsd.port.pre.mk>
 > +
 > +.if ${OSVERSION} > 600027
 > +BROKEN=        The way ioctls are issue to ATA changed which makes  
 > smartmontools malfunctioning
 > +.endif
 > +
 > +
 >  post-build:
 >      ${SED}    ${RC_SCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
 >          ${FILESDIR}/smartd.sh > ${WRKDIR}/smartd.sh
 > @@ -46,8 +53,6 @@
 >      cd ${WRKSRC} && ${INSTALL_DATA} ${DOCS} ${DOCSDIR}
 >  .endif
 >
 > -.include <bsd.port.pre.mk>
 > -
 >  post-install:
 >      ${CAT} ${PKGMESSAGE}
 >
 > --- patch-smartmontools ends here ---
 
 I tried mailing the maintainer but has gotten no reply. the below  
 hack makes it work, feel free to hack and commit, as I dont have the  
 time...
 
 
 --Apple-Mail-1--1038679942
 Content-Transfer-Encoding: 7bit
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="smartmontools-patch"
 Content-Disposition: attachment;
 	filename=smartmontools-patch
 
 --- os_freebsd.c.orig	Sun Sep  5 09:16:07 2004
 +++ os_freebsd.c	Fri May 20 12:42:36 2005
 @@ -18,6 +18,7 @@
  #include <stdio.h>
  #include <sys/types.h>
  #include <dirent.h>
 +#include <fcntl.h>
  #include <err.h>
  #include <camlib.h>
  #include <cam/scsi/scsi_message.h>
 @@ -109,7 +110,7 @@
    }
  
    if (parse_ok == CONTROLLER_ATA) {
 -    if ((fdchan->atacommand = open("/dev/ata",O_RDWR))<0) {
 +    if ((fdchan->atadevice = open(dev,O_RDONLY))<0) {
        int myerror = errno;      //preserve across free call
        free (fdchan);
        errno = myerror;
 @@ -120,7 +121,7 @@
    if (parse_ok == CONTROLLER_3WARE_678K_CHAR) {
      char buf[512];
      sprintf(buf,"/dev/twe%d",fdchan->device);
 -    if ((fdchan->atacommand = open(buf,O_RDWR))<0) {
 +    if ((fdchan->atadevice = open(buf,O_RDWR))<0) {
        int myerror = errno; // preserver across free call
        free(fdchan);
        errno=myerror;
 @@ -167,8 +168,8 @@
      free(fdchan->devname);
    
    // close device, if open
 -  if (fdchan->atacommand)
 -    failed=close(fdchan->atacommand);
 +  if (fdchan->atadevice)
 +    failed=close(fdchan->atadevice);
  
    if (fdchan->scsicontrol)
      failed=close(fdchan->scsicontrol);
 @@ -221,7 +222,7 @@
  }
  
  int ata_command_interface(int fd, smart_command_set command, int select, char *data) {
 -#ifndef ATAREQUEST
 +#ifndef IOCATAREQUEST
    // sorry, but without ATAng, we can't do anything here
    printwarning(BAD_KERNEL,NULL);
    errno = ENOSYS;
 @@ -229,7 +230,7 @@
  #else
    struct freebsd_dev_channel* con;
    int retval, copydata=0;
 -  struct ata_cmd iocmd;
 +  struct ata_ioc_request request;
    unsigned char buff[512];
  
    // check that "file descriptor" is valid
 @@ -238,89 +239,86 @@
  
    bzero(buff,512);
  
 -  bzero(&iocmd,sizeof(struct ata_cmd));
 +  bzero(&request,sizeof(struct ata_ioc_request));
    bzero(buff,512);
 -  iocmd.cmd=ATAREQUEST;
 -  iocmd.channel=con->channel;
 -  iocmd.device=con->device;
  
 -  iocmd.u.request.u.ata.command=ATA_SMART_CMD;
 -  iocmd.u.request.timeout=600;
 +  request.u.ata.command=ATA_SMART_CMD;
 +  request.timeout=600;
    switch (command){
    case READ_VALUES:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_READ_VALUES;
 -    iocmd.u.request.u.ata.lba=0xc24f<<8;
 -    iocmd.u.request.flags=ATA_CMD_READ;
 -    iocmd.u.request.data=buff;
 -    iocmd.u.request.count=512;
 +    request.u.ata.feature=ATA_SMART_READ_VALUES;
 +    request.u.ata.lba=0xc24f<<8;
 +    request.flags=ATA_CMD_READ;
 +    request.data=buff;
 +    request.count=512;
      copydata=1;
      break;
    case READ_THRESHOLDS:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_READ_THRESHOLDS;
 -    iocmd.u.request.u.ata.count=1;
 -    iocmd.u.request.u.ata.lba=1|(0xc24f<<8);
 -    iocmd.u.request.flags=ATA_CMD_READ;
 -    iocmd.u.request.data=buff;
 -    iocmd.u.request.count=512;
 +    request.u.ata.feature=ATA_SMART_READ_THRESHOLDS;
 +    request.u.ata.count=1;
 +    request.u.ata.lba=1|(0xc24f<<8);
 +    request.flags=ATA_CMD_READ;
 +    request.data=buff;
 +    request.count=512;
      copydata=1;
      break;
    case READ_LOG:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_READ_LOG_SECTOR;
 -    iocmd.u.request.u.ata.lba=select|(0xc24f<<8);
 -    iocmd.u.request.u.ata.count=1;
 -    iocmd.u.request.flags=ATA_CMD_READ;
 -    iocmd.u.request.data=buff;
 -    iocmd.u.request.count=512;
 +    request.u.ata.feature=ATA_SMART_READ_LOG_SECTOR;
 +    request.u.ata.lba=select|(0xc24f<<8);
 +    request.u.ata.count=1;
 +    request.flags=ATA_CMD_READ;
 +    request.data=buff;
 +    request.count=512;
      copydata=1;
      break;
    case IDENTIFY:
 -    iocmd.u.request.u.ata.command=ATA_IDENTIFY_DEVICE;
 -    iocmd.u.request.flags=ATA_CMD_READ;
 -    iocmd.u.request.data=buff;
 -    iocmd.u.request.count=512;
 +    request.u.ata.command=ATA_IDENTIFY_DEVICE;
 +    request.flags=ATA_CMD_READ;
 +    request.data=buff;
 +    request.count=512;
      copydata=1;
      break;
    case PIDENTIFY:
 -    iocmd.u.request.u.ata.command=ATA_IDENTIFY_PACKET_DEVICE;
 -    iocmd.u.request.flags=ATA_CMD_READ;
 -    iocmd.u.request.data=buff;
 -    iocmd.u.request.count=512;
 +    request.u.ata.command=ATA_IDENTIFY_PACKET_DEVICE;
 +    request.flags=ATA_CMD_READ;
 +    request.data=buff;
 +    request.count=512;
      copydata=1;
      break;
    case ENABLE:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_ENABLE;
 -    iocmd.u.request.u.ata.lba=0xc24f<<8;
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_ENABLE;
 +    request.u.ata.lba=0xc24f<<8;
 +    request.flags=ATA_CMD_CONTROL;
      break;
    case DISABLE:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_DISABLE;
 -    iocmd.u.request.u.ata.lba=0xc24f<<8;
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_DISABLE;
 +    request.u.ata.lba=0xc24f<<8;
 +    request.flags=ATA_CMD_CONTROL;
      break;
    case AUTO_OFFLINE:
      // NOTE: According to ATAPI 4 and UP, this command is obsolete
 -    iocmd.u.request.u.ata.feature=ATA_SMART_AUTO_OFFLINE;
 -    iocmd.u.request.u.ata.lba=select|(0xc24f<<8);
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_AUTO_OFFLINE;
 +    request.u.ata.lba=select|(0xc24f<<8);
 +    request.flags=ATA_CMD_CONTROL;
      break;
    case AUTOSAVE:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_AUTOSAVE;
 -    iocmd.u.request.u.ata.count=0xf1;  // to enable autosave
 -    iocmd.u.request.u.ata.lba=0xc24f<<8;
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_AUTOSAVE;
 +    request.u.ata.count=0xf1;  // to enable autosave
 +    request.u.ata.lba=0xc24f<<8;
 +    request.flags=ATA_CMD_CONTROL;
      break;
    case IMMEDIATE_OFFLINE:
 -    iocmd.u.request.u.ata.feature=ATA_SMART_IMMEDIATE_OFFLINE;
 -    iocmd.u.request.u.ata.lba = select|(0xc24f<<8); // put test in sector
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_IMMEDIATE_OFFLINE;
 +    request.u.ata.lba = select|(0xc24f<<8); // put test in sector
 +    request.flags=ATA_CMD_CONTROL;
      break;
    case STATUS_CHECK: // same command, no HDIO in FreeBSD
    case STATUS:
      // this command only says if SMART is working.  It could be
      // replaced with STATUS_CHECK below.
 -    iocmd.u.request.u.ata.feature=ATA_SMART_STATUS;
 -    iocmd.u.request.u.ata.lba=0xc24f<<8;
 -    iocmd.u.request.flags=ATA_CMD_CONTROL;
 +    request.u.ata.feature=ATA_SMART_STATUS;
 +    request.u.ata.lba=0xc24f<<8;
 +    request.flags=ATA_CMD_CONTROL;
      break;
    default:
      pout("Unrecognized command %d in ata_command_interface()\n"
 @@ -334,15 +332,15 @@
      unsigned const char failed_lo=0xf4, failed_hi=0x2c;
      unsigned char low,high;
      
 -    if ((retval=ioctl(con->atacommand, IOCATA, &iocmd)))
 +    if ((retval=ioctl(con->atadevice, IOCATAREQUEST, &request)))
        return -1;
  
  #if __FreeBSD_version < 502000
      printwarning(NO_RETURN,NULL);
  #endif
  
 -    high = (iocmd.u.request.u.ata.lba >> 16) & 0xff;
 -    low = (iocmd.u.request.u.ata.lba >> 8) & 0xff;
 +    high = (request.u.ata.lba >> 16) & 0xff;
 +    low = (request.u.ata.lba >> 8) & 0xff;
      
      // Cyl low and Cyl high unchanged means "Good SMART status"
      if (low==normal_lo && high==normal_hi)
 @@ -355,18 +353,18 @@
      // We haven't gotten output that makes sense; print out some debugging info
      char buf[512];
      sprintf(buf,"CMD=0x%02x\nFR =0x%02x\nNS =0x%02x\nSC =0x%02x\nCL =0x%02x\nCH =0x%02x\nRETURN =0x%04x\n",
 -            (int)iocmd.u.request.u.ata.command,
 -            (int)iocmd.u.request.u.ata.feature,
 -            (int)iocmd.u.request.u.ata.count,
 -            (int)((iocmd.u.request.u.ata.lba) & 0xff),
 -            (int)((iocmd.u.request.u.ata.lba>>8) & 0xff),
 -            (int)((iocmd.u.request.u.ata.lba>>16) & 0xff),
 -            (int)iocmd.u.request.error);
 +            (int)request.u.ata.command,
 +            (int)request.u.ata.feature,
 +            (int)request.u.ata.count,
 +            (int)((request.u.ata.lba) & 0xff),
 +            (int)((request.u.ata.lba>>8) & 0xff),
 +            (int)((request.u.ata.lba>>16) & 0xff),
 +            (int)request.error);
      printwarning(BAD_SMART,buf);
      return 0;   
    }
  
 -  if ((retval=ioctl(con->atacommand, IOCATA, &iocmd))) {
 +  if ((retval=ioctl(con->atadevice, IOCATAREQUEST, &request))) {
      perror("Failed command: ");
      return -1;
    }
 @@ -637,7 +635,7 @@
    }
  
    // Now send the command down through an ioctl()
 -  ioctlreturn=ioctl(con->atacommand,TWEIO_COMMAND,cmd);
 +  ioctlreturn=ioctl(con->atadevice,TWEIO_COMMAND,cmd);
    
    // Deal with the different error cases
    if (ioctlreturn) {
 @@ -709,55 +707,6 @@
    return 0;
  }
  
 -static int get_ata_channel_unit ( const char* name, int* unit, int* dev) {
 -#ifndef ATAREQUEST
 -  *dev=0;
 -  *unit=0;
 -return 0;
 -#else
 -  // there is no direct correlation between name 'ad0, ad1, ...' and
 -  // channel/unit number.  So we need to iterate through the possible
 -  // channels and check each unit to see if we match names
 -  struct ata_cmd iocmd;
 -  int fd,maxunit;
 -  
 -  bzero(&iocmd, sizeof(struct ata_cmd));
 -
 -  if ((fd = open("/dev/ata", O_RDWR)) < 0)
 -    return -errno;
 -  
 -  iocmd.cmd = ATAGMAXCHANNEL;
 -  if (ioctl(fd, IOCATA, &iocmd) < 0) {
 -    return -errno;
 -    close(fd);
 -  }
 -  maxunit = iocmd.u.maxchan;
 -  for (*unit = 0; *unit < maxunit; (*unit)++) {
 -    iocmd.channel = *unit;
 -    iocmd.device = -1;
 -    iocmd.cmd = ATAGPARM;
 -    if (ioctl(fd, IOCATA, &iocmd) < 0) {
 -      close(fd);
 -      return -errno;
 -    }
 -    if (iocmd.u.param.type[0] && !strcmp(name,iocmd.u.param.name[0])) {
 -      *dev = 0;
 -      break;
 -    }
 -    if (iocmd.u.param.type[1] && !strcmp(name,iocmd.u.param.name[1])) {
 -      *dev = 1;
 -      break;
 -    }
 -  }
 -  close(fd);
 -  if (*unit == maxunit)
 -    return -1;
 -  else
 -    return 0;
 -#endif
 -}
 -
 -
  // Guess device type (ata or scsi) based on device name (FreeBSD
  // specific) SCSI device name in FreeBSD can be sd, sr, scd, st, nst,
  // osst, nosst and sg.
 @@ -788,11 +737,6 @@
    // form /dev/ad* or ad*
    if (!strncmp(fbsd_dev_ata_disk_prefix, dev_name,
                 strlen(fbsd_dev_ata_disk_prefix))) {
 -    if (chan != NULL) {
 -      if (get_ata_channel_unit(dev_name,&(chan->channel),&(chan->device))<0) {
 -        return CONTROLLER_UNKNOWN;
 -      }
 -    }
      return CONTROLLER_ATA;
    }
    
 
 --Apple-Mail-1--1038679942
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain;
 	charset=ISO-8859-1;
 	format=flowed
 
 
 - S=F8ren
 
 
 
 
 --Apple-Mail-1--1038679942--
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Tue May 24 09:44:12 GMT 2005 
State-Changed-Why:  
Misfiled followup to ports/81403; content migrated. 


Responsible-Changed-From-To: gnats-admin->freebsd-ports-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue May 24 09:44:12 GMT 2005 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=81404 
>Unformatted:
