?
Solved

Physical/Logical partition info - how to get?

Posted on 1998-01-24
8
Medium Priority
?
787 Views
Last Modified: 2013-12-03
I have a computer with one hard disk. the disk is splited into two logical drives (C:, D:). I need to write a procedure that retrive this data (one hard disk with two logical drives).
The real task is to know how many hard disks the computer have( IDE or SCSI ) and which logical drive reside in which hard disk.
I know how to do this by reading from the registry in win95, but the NT registry is different from the win95 one, so I can't use this.
I also tried use the DeviceIOCtrl, but failed to make it work right.
There is also an int 21 service that deals with the subject but I couldn't make it work properly.
I already post this question in the delphi section but they helped none. Please answer this only if you REALLY know the answer.
0
Comment
Question by:TheSwine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1410297
Use the DevIoControl IOCTL_DISK_GET_DRIVE_LAYOUT operation.  This gets you a DRIVE_LAYOUT_INFORMATION structure which points to a series of PARTITION_INFORMATION structutes for each partition.
0
 
LVL 1

Author Comment

by:TheSwine
ID: 1410298
As I wrote before, I failed make this work using DeviceIOControl. I am familiar with everything you wrote, please add some full sample code, Thanks.
0
 
LVL 1

Author Comment

by:TheSwine
ID: 1410299
Adjusted points to 305
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 4

Expert Comment

by:jeurk
ID: 1410300
Hi,
You might recognize me, cause I already tried to answer your question
in the delphi section.
You see, I am also interessed in solving that problem.
I'm writing here now to keep the question alive ;)
Would you agree to help me solve your problem ?
May you send me the code you already tryed out ?
I will only have time to answer that question next week,
cause for now I still have exams at school :(
Unfortunately I had done a part of the answer yesterday,
but since I'm very new to using NT, I made some changes that
crashed the NT partition, so I lost the code source I wrote in temp ;).
I wrote C++ in parallel with pascal, and I did not get the same
result in pascal. this might be because I had to write the
structures by myself. How do you translate following in pascal ?

partLayout test[1];

partLayout is the type. The msdn says this is a variable array.
How do you make such a thing in pascal?

I'm waiting your suggestions ?

Jeurk
0
 
LVL 5

Expert Comment

by:inter
ID: 1410301
Dear Jeurk,

The partLayout test[1]; code is a generic code that indicates the test variable may contain several partLayout structures attached end to end in the memory: The direct translation is

  test : array[0..0] of partLayout;

but I should see the actual API help fragment to correcly interpret. If need help please give the keyword for WIN32 help

Igor
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1410302
Hi Igor,
Your help is welcome, i'm at school for now.
I'll come back tomorrow and post the structures I need
to be translated.

CU, Jeurk
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 600 total points
ID: 1410303
Here's some sample code:

void CDrvLayView::AddLine(const CString& msg)
{
      CRichEditCtrl& ctrl = GetRichEditCtrl();

      long l = ctrl.GetTextLength();
      ctrl.SetSel(l, l);
      ctrl.ReplaceSel(msg);
}

struct _PTMAP
{
      int   m_PT;
      char* m_Info;
} g_PTMap[] =
{
      { PARTITION_ENTRY_UNUSED, "Entry unused" },
      { PARTITION_FAT_12, "Specifies a partition with 12-bit FAT entries" },
      { PARTITION_XENIX_1, "Specifies a Xenix type 1 partition" },
      { PARTITION_XENIX_2, "Specifies a Xenix type 2 partition" },
      { PARTITION_FAT_16, "Specifies a partition with 16-bit FAT entries" },
      { PARTITION_EXTENDED, "Specifies an extended partition entry" },
      { PARTITION_HUGE, "Specifies an MS-DOS V4 huge partition" },
      { PARTITION_IFS, "Specifies an IFS partition" },
      { PARTITION_PREP, "Specifies a PowerPC Reference Platform partition" },
      { PARTITION_UNIX, "Specifies a UNIX partition" },
      { VALID_NTFT, "Specifies an NTFT partition" },
      { PARTITION_XINT13, "Specifies a Windows 95 partition that uses extended int13 services" },
      { PARTITION_XINT13_EXTENDED, "Same as PARTITION_EXTENDED, but uses extended int13 services" },
};

CString ConvertBool(BOOL b)
{
      return b ? "True" : "False";
}


void CDrvLayView::OnDrivesSelChange()
{
      CString driveLetter =  g_DriveTB->GetCurrentDrive();

      CString msg;
      msg.Format("Changing to %s.\r\n", driveLetter);
      AddLine(msg);

      CString drive = "\\\\.\\" + driveLetter;

      HANDLE h = CreateFile(drive, GENERIC_READ, FILE_SHARE_WRITE, NULL,
            OPEN_EXISTING, 0, NULL);

      if (h == INVALID_HANDLE_VALUE)
      {
            msg.Format("Failed to open %s. GetLastError() returned %d\r\n",
                  driveLetter, GetLastError());
            AddLine(msg);
      }
      else
      {
            PARTITION_INFORMATION pi;
            DWORD bytesReturned = 0;

            if (!DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
                  &pi, sizeof(pi), &bytesReturned, NULL))
            {
                  msg.Format("Failed to obtain partition info for %s. GetLastError() returned %d\r\n",
                        driveLetter, GetLastError());
                  AddLine(msg);
            }
            else
            {
                  msg.Format("Offset at 0x%08X:0x%08X\r\n", pi.StartingOffset.HighPart,
                        pi.StartingOffset.LowPart);
                  AddLine(msg);

                  msg.Format("Length at 0x%08X:0x%08X\r\n", pi.PartitionLength.HighPart,
                        pi.PartitionLength.LowPart);
                  AddLine(msg);

                  msg.Format("Number of hidden sectors: %d\r\n", pi.HiddenSectors);
                  AddLine(msg);

                  msg.Format("Number of partitions: %d\r\n", pi.PartitionNumber);
                  AddLine(msg);

                  CString partitionType = "Unknown";

                  for (int i = 0; i < sizeof(g_PTMap) / sizeof(g_PTMap[0]); i++)
                  {
                        if (pi.PartitionType == g_PTMap[i].m_PT)
                        {
                              partitionType = g_PTMap[i].m_Info;
                              break;
                        }
                  }

                  msg.Format("Type of partitions: %s\r\n", partitionType);
                  AddLine(msg);

                  msg.Format("Bootable? %s\r\n", ConvertBool(pi.BootIndicator));
                  AddLine(msg);

                  msg.Format("Recognized? %s\r\n", ConvertBool(pi.RecognizedPartition));
                  AddLine(msg);

//                  msg.Format("Rewritable? %s\r\n", ConvertBool(pi.RewritePartition));
//                  AddLine(msg);
            }

            CloseHandle(h);
      }
}


0
 
LVL 1

Author Comment

by:TheSwine
ID: 1410304
Thanks tui.
It will take me about a week to check it up cause I'm very busy right now. I'll get back to you in few day's
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question