From the device on and off by explaining, we need two parameters (file pathname, and device access mode) to open a Linux device.
According to the front of the original code, the first argument should be the/dev/hda, second O_RDONLY | O_NONBLOCK. The modified code is as follows: HANDLEdevHandle = open ("/dev/hda", O_RDONLY | O_NONBLOCK);. Corresponding to CloseHandle (devHandle); changes to close (devHandle);. The main part of the transplantations is how to use ioctl to access specific devices and obtain the required information. The original Windows code as shown in Listing 6: inventory of the source code on the DeviceIoControl 6.Windows typedefstruct_Bufer {UCHARreq [8];//DetailedcommandinformationothertancontrolcodeULONGDataBufferSize;//SizeofDataBuffer, hereis512UCHARDataBuffer [512];//DataBufer} Bufer; BufferregBufer; memcpy (regBuffer.req, cmdBuff, 7);//req [7] isreservedforfutureuse.Mustbezero.regBuffer.DataBufferSize = 512; unsignedintsize = 512 + 12;//SizeofregBufer//8forreq, 4forDataBufferSize, 512fordataDWORDbytesRet = 0;//Numberofbytesreturnedintretval;//Returnedvalueretval = DeviceIoControl (devHandle, IOCTL_IDE_PASS_THROUGH,//ControlcoderegBuffer,//InputBuffer, includingdetailedcommandsize, regBuffer,//OutputBuffer, usethesamebuffereresize, & bytesRet, NULL); if (! retval) cout <"deviceiocontrolfailed.">"deviceiocontrolfailed.">Linxu Security , the latest breaking news and information on security, linux, open source, firewalls
Monday, February 14, 2011
Migration from Windows to Linux device control applications
Labels:
[:]
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment