Subject: kern/6225: APM complains of unknown error code 0xce0a during "get power status"
To: None <gnats-bugs@gnats.netbsd.org>
From: David W. Talmage <talmage@jefferson.cmf.nrl.navy.mil>
List: netbsd-bugs
Date: 10/01/1998 17:50:11
>Number:         6225
>Category:       kern
>Synopsis:       APM complains of unknown error code 0xce0a during "get power status"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct  1 15:05:00 1998
>Last-Modified:
>Originator:     David W. Talmage
>Organization:
David W. Talmage
talmage@cmf.nrl.navy.mil
>Release:        Don't know the date
>Environment:
Hardware: Sony VAIO PGC-505G subnotebook, 32MB RAM, NeoMagic <mumble> graphics chips, 2MB video RAM, APM 1.1 (as reported at boot time)

System: NetBSD jefferson 1.3F NetBSD 1.3F (THECHONG) #10: Thu Aug 27 23:30:18 EDT 1998 talmage@jefferson:/usr/src/sys/arch/i386/compile/THECHONG i386


>Description:
The following message appeared in /var/log/messages today:
Oct  1 12:25:56 jefferson /netbsd: APM ioctl get power status: unknown error code (0xce0a)

The only new APM application on my computer is the battery meter
support I just wrote for XOSView 1.6.0 (see pkgsrc/sysutils/xosview).
The new code is:

...
static const char APMFILENAME[] = "/dev/apm";

...
void BtryMeter::getpwrinfo( void ){
  struct apm_power_info buff;
  int error = 0;
  int loadinfo = open(APMFILENAME, O_RDONLY, 0);

  if ( !loadinfo ){
    cerr <<"Can not open file : " <<APMFILENAME <<endl;
    parent_->done(1);
    return;
  }

  error = ioctl(loadinfo, APM_IOC_GETPOWER, &buff);

  if (error != -1) {

    fields_[0] = (float)buff.battery_life;	// percent left
    fields_[1] = 100.0 - fields_[0];		// percent used
    float minutes_left = (float)buff.minutes_left; 

    //    minutes_left = (percent_left/100.0) * max_minutes;
    //    minutes_left / (percent_left/100.0) = max_minutes;
    //    minutes_left * 100.0 / percent_left = max_minutes;
    float max_left = minutes_left * 100.0 / fields_[0];
  
    //
    // Set total_ so that the graphing methods know to set the
    // relative sizes of the percent left and percent used graphs.
    //
    total_ = 100.0;

    //
    // This sets the actual number of minutes left.  If the resource
    // xosview*batteryUsedFormat is "float", then xosview will display
    // that number to the left of the battery graph.  If it's
    // "percent", then you get the percent remaining next to the
    // graph.
    //
    setUsed(minutes_left, max_left);
  }

  close(loadinfo);
}


You can see that it calls the APM_IOC_GETPOWER ioctl.

The struct apm_power_info buff isn't initialized.  I wonder if that is
the cause?

The most recent APM-related message prior to this one was an
announcement of the battery state while the battery was charging.
That message occurred yesterday, about 23 hours before the mystery
message.

>How-To-Repeat:

I haven't been able to repeat the problem yet.  I will continue to run
my battery-meter-enabled version of XOSView.

>Fix:

Don't know.  Could try initializing the struct apm_power_info before calling ioctl().


>Audit-Trail:
>Unformatted: