Skip to main content

 none
DeviceIoControl Returning Error Code 7a RRS feed

  • Question

  • Hi Guys,

    I am using Windows XP SP3 and I am executing the following C program. The DeviceIoControl function fails with error code 7a (ERROR_INSUFFICIENT_BUFFER). I think the buffer I am taking in this program should be appropriate. Please suggest if any modifications can be made to the code to make this program work....

     

    // Program to Read the MBR Information from the Mass Storage Device

    #include<stdio.h>

    #include<Windows.h>

    int main(void)

    {

           HANDLE devicehndl = INVALID_HANDLE_VALUE;

           PARTITION_INFORMATION_EX pinfo;

           BOOL devioctlsuccess = FALSE; 

           DWORD junk = 0;  // discard results

           devicehndl = CreateFile("\\\\.\\PhysicalDrive0",0,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);

           if (devicehndl == INVALID_HANDLE_VALUE)

           {

                  printf("Unable to Open Handle to the Device\n");

                  return 0;

           }

           else

           {

                  printf("Device Handle Opened Successfully\n");

           }

           devioctlsuccess = DeviceIoControl(devicehndl,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,NULL,0,&pinfo,sizeof(pinfo),&junk,NULL);

           if (devioctlsuccess == 0)

           {

                  fprintf(stderr, "Device Error : %x\n", GetLastError());

           }

           else

           {

                  printf("Device information is as follows:\n\n");

                  printf("Device : PhysicalDrive0\n");

                  printf("Partition Style : %i", pinfo.PartitionLength);

           }

          

           CloseHandle(devicehndl);

                 

    }


    • Edited by vineet1981 Wednesday, October 31, 2012 9:34 PM
    Wednesday, October 31, 2012 8:40 PM

Answers

  • Hi Mike,

    Your earlier suggestion work I have changed the following line in code :

    PARTITION_INFORMATION_EX pinfo;   

    changed to:

    DRIVE_LAYOUT_INFORMATION_EX pinfo[20];

    The above line made my program work.

    Thanks.
    Vineet

    • Marked as answer by vineet1981 Thursday, November 1, 2012 9:40 PM
    Thursday, November 1, 2012 9:40 PM

All replies

  • And if you want use the partition info, you will need this control code: 
    IOCTL_DISK_GET_PARTITION_INFO_EX
    Thursday, November 1, 2012 5:34 AM
    Moderator
  • Hi Mike,

    Your earlier suggestion work I have changed the following line in code :

    PARTITION_INFORMATION_EX pinfo;   

    changed to:

    DRIVE_LAYOUT_INFORMATION_EX pinfo[20];

    The above line made my program work.

    Thanks.
    Vineet

    • Marked as answer by vineet1981 Thursday, November 1, 2012 9:40 PM
    Thursday, November 1, 2012 9:40 PM