else powerp->battery_state = APM_BATT_UNKNOWN;
apmioctl(dev, cmd, data, flag, p)	dev_t dev;	u_long cmd;	caddr_t data;	int flag;	struct proc *p;{	struct apm_softc *sc;	struct apm_power_info *powerp;	struct apm_event_info *evp;	struct apmregs regs;	register int i;	struct apm_ctl *actl;	/* apm0 only */	if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || !(sc = apm_cd.cd_devs[APMUNIT(dev)]))		return ENXIO;		switch (cmd) {		/* some ioctl names from linux */	case APM_IOC_STANDBY:		if ((flag & FWRITE) == 0)			return EBADF;		apm_userstandbys++;		return 0;	case APM_IOC_SUSPEND:		if ((flag & FWRITE) == 0)			return EBADF;		apm_suspends++;		return 0;	case APM_IOC_PRN_CTL:		if ((flag & FWRITE) == 0)			return EBADF;		{			int flag = *(int*)data;			DPRINTF(( "APM_IOC_PRN_CTL: %d\n", flag ));			switch (flag) {			case APM_PRINT_ON:	/* enable printing */				sc->sc_flags &= ~SCFLAG_PRINT;				return 0;			case APM_PRINT_OFF: /* disable printing */				sc->sc_flags &= ~SCFLAG_PRINT;				sc->sc_flags |= SCFLAG_NOPRINT;				return 0;			case APM_PRINT_PCT: /* disable some printing */				sc->sc_flags &= ~SCFLAG_PRINT;				sc->sc_flags |= SCFLAG_PCTPRINT;				return 0;			default:				break;			}		}		return EINVAL;	case APM_IOC_DEV_CTL:		actl = (struct apm_ctl *)data;		if ((flag & FWRITE) == 0)			return EBADF;		{			struct apmregs regs;						bzero(&regs, sizeof(regs));			if (!apmcall(APM_GET_POWER_STATE, actl->dev, &regs))				printf("%s: dev %04x state %04x\n",				       sc->sc_dev.dv_xname, dev, regs.cx);		}		return apm_set_powstate(actl->dev, actl->mode);	case APM_IOC_NEXTEVENT:		if (sc->event_count) {			evp = (struct apm_event_info *)data;			i = sc->event_ptr + APM_NEVENTS - sc->event_count;			i %= APM_NEVENTS;			*evp = sc->event_list[i];			sc->event_count--;			return 0;		} else			return EAGAIN;	case APM_IOC_GETPOWER:		powerp = (struct apm_power_info *)data;		if (apm_get_powstat(regs) == 0) {			bzero(powerp, sizeof(*powerp));			if (BATT_LIFE(&regs) != APM_BATT_LIFE_UNKNOWN)				powerp->battery_life = BATT_LIFE(&regs);			powerp->ac_state = AC_STATE(&regs);			switch (apm_minver) {			case 0:				powerp->battery_state = BATT_STATE(&regs);				break;			case 1:			default:				powerp->battery_state = APM_BATT_UNKNOWN;				if (BATT_FLAGS(&regs) & APM_BATT_FLAG_HIGH)					powerp->battery_state = APM_BATT_HIGH;				else if (BATT_FLAGS(&regs) & APM_BATT_FLAG_LOW)					powerp->battery_state = APM_BATT_LOW;				else if (BATT_FLAGS(&regs) & APM_BATT_FLAG_CRITICAL)					powerp->battery_state = APM_BATT_CRITICAL;				else if (BATT_FLAGS(&regs) & APM_BATT_FLAG_CHARGING)					powerp->battery_state = APM_BATT_CHARGING;				else if (BATT_FLAGS(&regs) & APM_BATT_FLAG_NOBATTERY)					powerp->battery_state = APM_BATTERY_ABSENT;				if (BATT_REM_VALID(&regs))					powerp->minutes_left = BATT_REMAINING(&regs);			}		} else {			apm_perror("ioctl get power status", &regs);			return (EIO);		}		break;			default:		return (ENOTTY);	}	return 0;}