Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com From: "Rick Rankin" To: "Serguei DACHIAN" , Subject: RE: Again about physical disks. Date: Tue, 23 Mar 1999 20:43:44 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2212 (4.71.2419.0) In-Reply-To: <1.5.4.32.19990323112345.00678700@lola.univ-lemans.fr> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Importance: Normal Here's a short code sample for accessing the physical media id on Win9x from cygwin. The same mechanisms can be used to perform physical I/O. Much of this was taken from the documentation that comes with VC++ 6. It compiles and works fine with gcc. Rick -- Rick Rankin rrankin AT primenet DOT com #include #include #include #include #define VWIN32_DIOC_DOS_IOCTL 1 typedef struct _DEVIOCTL_REGISTERS { DWORD reg_EBX; DWORD reg_EDX; DWORD reg_ECX; DWORD reg_EAX; DWORD reg_EDI; DWORD reg_ESI; DWORD reg_Flags; } DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS; typedef struct _MID { WORD midInfoLevel; DWORD midSerialNum; BYTE midVolLabel[11]; BYTE midFileSysType[8]; } __attribute__ ((packed)) MID, *PMID; BOOL DoIOCTL(PDEVIOCTL_REGISTERS preg) { HANDLE hDevice; BOOL fResult; DWORD cb; preg->reg_Flags = 0x8000; // assume error (carry flag set) hDevice = CreateFile("\\\\.\\vwin32", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); if (hDevice == (HANDLE) INVALID_HANDLE_VALUE) return FALSE; else { fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL, preg, sizeof(*preg), preg, sizeof(*preg), &cb, 0); if (!fResult) return FALSE; } CloseHandle(hDevice); return TRUE; } BOOL GetMediaID(PMID pmid, UINT nDrive) { DEVIOCTL_REGISTERS reg; reg.reg_EAX = 0x440D; // IOCTL for block devices reg.reg_EBX = nDrive; // one-based drive ID reg.reg_ECX = 0x0866; // Get Media ID command reg.reg_EDX = (DWORD) pmid; // receives media ID info if (!DoIOCTL(®)) return FALSE; if (reg.reg_Flags & 0x8000) // error if carry flag set return FALSE; return TRUE; } int main(int argc, char *argv[]) { MID mediaId; UINT driveId = (UINT) (toupper(argv[1][0]) - '@'); memset((void *) &mediaId, 0, sizeof(MID)); if (GetMediaID(&mediaId, driveId)) { printf("infoLevel = %d\n", mediaId.midInfoLevel); printf("serialNum = %x\n", mediaId.midSerialNum); printf("volLabel = '%s'\n", mediaId.midVolLabel); printf("fileSysType = '%s'\n", mediaId.midFileSysType); } return 0; } > -----Original Message----- > From: cygwin-owner AT sourceware DOT cygnus DOT com > [mailto:cygwin-owner AT sourceware DOT cygnus DOT com]On Behalf Of Serguei DACHIAN > Sent: Tuesday, March 23, 1999 4:24 AM > To: cygwin AT sourceware DOT cygnus DOT com > Subject: Again about physical disks. > > > > > I got and installed the DLL, include files (which were with > DLL) and also > > > your version of mount utility. I can't still read my floppy (without > > > speaking about hard drives). Here is my bash session: > > > [...] > > > P.S. Your readme say that some feateres are for NT only. > Does it mean > > > that i will not be able to read /dev/fd0 and/or /dev/hda ??? > > > > Sorry, I haven't noticed, you're on a Win9X system. The used > > methods to access partitions and hard drives are only > > useful on NT. Thanks to M$ :-( > > > So what finally these all means: is there no ANY way to read a physical > sector from a physical disk under CygWin on a Win9x system ??? > > I've also tried to use native Windows API call DeviceIOControl, but > CreateFile (one needs to open disk with this one at first) fails. The > following code: > ------------------------------------------------- > HANDLE myDiskHandle; > if ( (myDiskHandle = CreateFile (disk, > GENERIC_READ, > FILE_SHARE_WRITE, > NULL, > OPEN_EXISTING, > FILE_ATTRIBUTE_NORMAL, > NULL) > ) == INVALID_HANDLE_VALUE ) > { > printf("Error opening disque !!!\n"); > } > ------------------------------------------------ > fails (that is prints "Error opening disque !!!") with any of: > char disk[]="\\\\.\\PHYSICALDRIVE2" ; > char disk[]="\\\\.\\A:" ; > char disk[]="\\\\.\\C:" ; > > I think this is again Win9x problem, because SDK documentation is > not clear > about it. > > So finally I state once more my question. Is there ANY (at least one) > method to read a physical disk from a physical drive using CygWin > on a Win9x > system??? > > Any help whould be greatly appreciated. > > Regards, > Serguei. > __________________________________________________________________ > _________ > Serguei DACHIAN > Laboratoire de Statistique et Processus, > Universite du Maine, Av. Olivier Messiaen > 72085 Le Mans CEDEX 9, FRANCE > Tel. : +33 (0)2 43 83 37 18 > Fax. : +33 (0)2 43 83 35 79 > E-mail : Serguei DOT Dachian AT univ-lemans DOT fr > WWW : > http://www.univ-lemans.fr/sciences/statist/cvs/thesard.html#dachian > > > -- > Want to unsubscribe from this list? > Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com > -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com