flat assembler
Message board for the users of flat assembler.
Index
> Windows > [example] Disable APM on HDD |
Author |
|
bzdashek 11 Jul 2012, 06:05
This programme disables APM on HDD (which on some models is cause of clicking and excessive increase of "Load Cycle Count" S.M.A.R.T. parameter).
Structures and disable APM part are ripped off from quietHDD programme. Code: ;http://www.codeproject.com/Articles/19165/Vista-UAC-The-Definitive-Guide format PE GUI 4.0 include 'win32a.inc' BROADCAST_QUERY_DENY = $424D5144 PBT_APMQUERYSUSPEND = $00 WM_POWERBROADCAST = $218 PBT_APMBATTERYLOW = $09 PBT_APMPOWERSTATUSCHANGE = $0A PBT_APMOEMEVENT = $0B PBT_APMQUERYSUSPEND = $00 PBT_APMQUERYSUSPENDFAILED = $02 PBT_APMRESUMECRITICAL = $06 PBT_APMRESUMEAUTOMATIC = $12 PBT_APMQUERYSUSPENDFAILED = $02 IOCTL_IDE_PASS_THROUGH = $04D028 IOCTL_ATA_PASS_THROUGH = $04D02C HDIO_DRIVE_CMD = $03F1 ; Taken from /usr/include/linux/hdreg.h HDIO_SET_ACOUSTIC = $032C HDIO_GET_ACOUSTIC = $030F WIN_SETFEATURES = $EF SETFEATURES_EN_AAM = $42 SETFEATURES_DIS_AAM = $C2 SETFEATURES_EN_APM = $05 SETFEATURES_DIS_APM = $85 ATA_FLAGS_DRDY_REQUIRED = $01 ATA_FLAGS_DATA_IN = $02 ATA_FLAGS_DATA_OUT = $04 ATA_FLAGS_48BIT_COMMAND = $08 struct IDEREGS bFeaturesReg db ? bSectorCountReg db ? bSectorNumberReg db ? bCylLowReg db ? bCylHighReg db ? bDriveHeadReg db ? bCommandReg db ? bReserved db ? ends struct ATA_PASS_THROUGH_EX Length dw ? AtaFlags dw ? PathId db ? TargetId db ? Lun db ? ReservedAsUchar db ? DataTransferLength dd ? TimeOutValue dd ? ReservedAsUlong dd ? DataBufferOffset dd ? PreviousTaskFile IDEREGS CurrentTaskFile IDEREGS ends struct ATA_PASS_THROUGH_EX_WITH_BUFFERS Length dw ? AtaFlags dw ? PathId db ? TargetId db ? Lun db ? ReservedAsUchar db ? DataTransferLength dd ? TimeOutValue dd ? ReservedAsUlong dd ? DataBufferOffset dd ? PreviousTaskFile IDEREGS CurrentTaskFile IDEREGS Filler db ? ucDataBuf db 512 dup (?) ends section '.text' code readable executable ;http://stackoverflow.com/questions/5070987/sending-ata-commands-directly-to-device-in-windows entry $ invoke IsUserAnAdmin or eax,eax jz noadmin invoke CreateFile,_drive,GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ+FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0 cmp eax,-1 je finish mov [hDrive],eax mov [inbuffer.AtaFlags],ATA_FLAGS_DATA_IN mov [inbuffer.DataTransferLength],512 mov [inbuffer.DataBufferOffset],sizeof.ATA_PASS_THROUGH_EX ; mov [inbuffer.CurrentTaskFile.bCommandReg],0ECh ; mov [inbuffer.CurrentTaskFile.bSectorCountReg],1 mov byte[inbuffer.ucDataBuf],$CF mov [inbuffer.TimeOutValue],1 mov [inbuffer.CurrentTaskFile.bCommandReg],WIN_SETFEATURES mov [inbuffer.CurrentTaskFile.bFeaturesReg],SETFEATURES_DIS_APM mov [inbuffer.CurrentTaskFile.bSectorCountReg],0 invoke DeviceIoControl,[hDrive],IOCTL_ATA_PASS_THROUGH,inbuffer,sizeof.ATA_PASS_THROUGH_EX_WITH_BUFFERS,inbuffer,sizeof.ATA_PASS_THROUGH_EX_WITH_BUFFERS,bytes_count,0 ; invoke CreateFile,_output,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0 ; mov [hFile],eax ; invoke WriteFile,eax,inbuffer,sizeof.ATA_PASS_THROUGH_EX_WITH_BUFFERS,bytes_count,0 ; invoke CloseHandle,[hFile] invoke CloseHandle,[hDrive] invoke MessageBox,0,_Ok,0,MB_OK+MB_ICONINFORMATION finish: invoke ExitProcess,0 noadmin: invoke MessageBox,0,_adminReqd,0,MB_OK+MB_ICONHAND jmp finish section '.data' data readable writeable _drive TCHAR '\\.\PhysicalDrive0',0 ;_output TCHAR 'ata.dmp',0 _adminReqd TCHAR 'Administrator rights required to run this programme',0 _Ok TCHAR 'APM Disabled',0 inbuffer ATA_PASS_THROUGH_EX_WITH_BUFFERS sizeof.ATA_PASS_THROUGH_EX hDrive dd ? ; hFile dd ? bytes_count dd ? section '.idata' import data readable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ shell32,'SHELL32.DLL' include 'api/kernel32.inc' import user32,\ MessageBox,'MessageBoxA' import shell32,\ IsUserAnAdmin,'IsUserAnAdmin' section '.rsrc' resource data readable directory RT_MANIFEST,manifest resource manifest,\ 1,LANG_NEUTRAL,man resdata man file 'dipasm.manifest.xml' endres dipasm.manifest.xml: Code: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly> Last edited by bzdashek on 06 Aug 2012, 03:14; edited 1 time in total |
|||
11 Jul 2012, 06:05 |
|
kalambong 12 Jul 2012, 23:54
Any similarity with https://sites.google.com/site/disablehddapm/ ?
|
|||
12 Jul 2012, 23:54 |
|
bzdashek 14 Jul 2012, 21:33
Yes, that's the reason why I thought about writing a small one, since I needed only one parameter.
|
|||
14 Jul 2012, 21:33 |
|
bzdashek 15 Jul 2012, 18:26
Yep, me also. Have to launch it every PC wake up - from hibernation or sleep also. Why don't they patch their firmware, I wonder? Mine is Hitachi HTS545050A7E
|
|||
15 Jul 2012, 18:26 |
|
Goplat 20 Jul 2012, 02:04
It's really a pity that this has become necessary. Disk head parking used to be a good idea, since HDDs would often be idle for very long periods of time. Parking the heads would reduce power usage, so the temperature wouldn't get as high and it would actually extend the life of the drive. But this feature's been ruined by idiot programmers who think it's acceptable for a program to write to disk every 10 seconds for no reason...
|
|||
20 Jul 2012, 02:04 |
|
revolution 20 Jul 2012, 07:44
Goplat wrote: ... idiot programmers who think it's acceptable for a program to write to disk every 10 seconds for no reason... [/sarcasm] |
|||
20 Jul 2012, 07:44 |
|
LocoDelAssembly 20 Jul 2012, 16:35
Mine is WDC WD6400BPVT-55HXZT2.
In the case of my computer, the HDD led turns on every second, and yet it insist in parking the heads moving them very aggressively (in fact I think the click sound is a bit louder than when I turn the computer off). I guess this is probably caused by the HDD internal buffer that doesn't cause R/W head activity soon enough to not timeout the idle timer. At the rate the load/unload cycles occur, in my case it would exceed the manufacturer count limit in less than 3 years (and the warranty is 2 years, so forgive if I think they do this on purpose). |
|||
20 Jul 2012, 16:35 |
|
bzdashek 06 Aug 2012, 03:16
Fixed and updated source - now it works in GUI mode, and utilizes UAC (via manifest). Also, I'm not sure if old version disabled APM, since one parameter ([inbuffer.TimeOutValue]) was 0, but should be 1
|
|||
06 Aug 2012, 03:16 |
|
bzdashek 25 Aug 2012, 20:21
I made it live in tray and keep an eye on Load Cycle Count parameter, and when it increases, it shoots the disabler, so even after a hibernation or sleep, it will be on-guard.
Sources are included
|
||||||||||||||||||||
25 Aug 2012, 20:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.