驱动中区分 win8 的 fast startup 与普通的 cold startup

    win8在电源管理中有一个选项,default会是enable的。他就是 “turn on fast startup”。

    我们要如何找到这个选项并进行设置呢,可以参考:http://www.eightforums.com/tutorials/6320-fast-startup-turn-off-windows-8-a.html

    Locates: control panel -> power options -> choose what the power buttons do -> change settings that are currently unavailable -> shutup settings

    具体位置:控制面板 -> 电源选项 -> 选择电源按钮的功能 -> 更改当前无法显示的设定 -> 关机设定   中会显示。

    

    但是我们如何区分fast startup与通常的 tranditional cold startup 呢?

    相信调试过driver的一定可以获得这两者的区别,笔者在调试中发现,fast startup,在power off阶段,系统会下发 IRP_MN_SET_POWER Irp,这其中包括两个,一个是用于通知SystemPowerState,另一个用于通知DevicePowerState。而差别正在与 SystemPowerState。

fast startup时,SystemPowerState对应的state是 PowerSystemHibernate

tranditional cold startup时,SystemPowerState对应的state是 PowerSystemShutdown

由此可以看出他们的区别。按照MS的解释,上述的区别是正常的。

MS关于fast startup的解释可以参考:http://msdn.microsoft.com/en-us/library/windows/hardware/jj835779(v=vs.85).aspx

因此,如果需要区别上述两种startup,可以考虑采用此处IRP_MN_SET_POWER Irp中的区别。

    而我们的driver需要一些特别设定来区别 hibernate 和 cold boot。因此在boot时需要区分它们的不同。这可以透过MS提供的方法:

To distinguish a fast startup from a wake-from-hibernation, a driver can inspect the information in the system set-power (IRP_MN_SET_POWER) IRP that informs the driver that the computer has entered the S0 (working) state. The driver's I/O stack location in this IRP contains a Power member, which is a structure that contains power-related information. Starting with Windows Vista, the Power member structure contains a SystemPowerStateContext member, which is aSYSTEM_POWER_STATE_CONTEXT structure that contains information about the previous system power states. This information is encoded in bit fields in the SYSTEM_POWER_STATE_CONTEXT structure.

Most of the bit fields in the SYSTEM_POWER_STATE_CONTEXT structure are reserved for system use and are opaque to drivers. However, this structure contains two bit fields, TargetSystemState and EffectiveSystemState, that can be read by drivers to determine whether a fast startup or a wake-from-hibernation occurred.

The TargetSystemState and EffectiveSystemState bit fields are set to SYSTEM_POWER_STATE enumeration values. IfTargetSystemState = PowerSystemHibernate and EffectiveSystemState = PowerSystemHibernate, a wake-from-hibernation occurred. However, if TargetSystemState = PowerSystemHibernate and EffectiveSystemState =PowerSystemShutdown, a fast startup occurred.


你可能感兴趣的:(驱动中区分 win8 的 fast startup 与普通的 cold startup)