[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Initialize/Partition/Format

Posted on 2006-06-07
10
Medium Priority
?
1,791 Views
Last Modified: 2012-06-27
I am writing a Windows front-end to a new storage array product. One of the software requirements is to provide a "Setup" Wizard that will initialize, partition, and format the array.

Unfortunately, I can't find a way to implement this. I've dug around a bit and the DDK routines IOCTL_DISK_CREATE_DISK looks promising but I can't seem to get it to work. The return code indicates success but examining the drive within the Disk Management snap-in after the call shows no visible change. Does anyone have an example of IOCTL_DISK_CREATE_DISK? Are there other alternatives? What am I missing?

Help me Obi-Wan-Experts Exchange, you're my only hope... =)
0
Comment
Question by:Ezchdahal
  • 4
  • 3
  • 2
9 Comments
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16861081
The IOCTL_DISK_CREATE_DISK control code initializes the specified disk and disk partition table using the information in the CREATE_DISK structure.
To perform this operation, call the DeviceIoControl function with the following parameters.
Read more at
http://msdn.net/library/default.asp?url=/library/en-us/fileio/fs/ioctl_disk_create_disk.asp

Look at the sample calling the API DeviceIOControl
http://msdn.net/library/default.asp?url=/library/en-us/devio/base/calling_deviceiocontrol.asp
0
 

Author Comment

by:Ezchdahal
ID: 16865869
Yep. I found those two links before posting. The sample code works but does not involve IOCTL_DISK_CREATE_DISK. I've written some code based on the sample but, while returning a positive return code, nothing else appears to happen. Here's my code.

HANDLE hDevice;              
BOOL bResult;                
DWORD junk;                  

hDevice = CreateFile("\\\\.\\PhysicalDrive2",  
      FILE_ALL_ACCESS,        
      FILE_SHARE_READ |
      FILE_SHARE_WRITE,
      NULL,            
      OPEN_EXISTING,  
      0,                
      NULL);          

if (hDevice != INVALID_HANDLE_VALUE)
{
  CREATE_DISK cd;  
  cd.PartitionStyle = PARTITION_STYLE_MBR;
  cd.Mbr.Signature = 0x28;

  bResult = DeviceIoControl(hDevice,  
      IOCTL_DISK_CREATE_DISK,  
      &cd, sizeof(cd),    
      NULL, 0,                  
      &junk,                
      (LPOVERLAPPED) NULL);  

  CloseHandle(hDevice);
}

Perhaps the signature field has something to do with the problem. It wasn't
clear what I should set it to. I tried 0 and 0x28.
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16872467
You said you get a positive return code. Did you mean DeviceIoControl returned non zero value?

I am not sure what the signature value should be. You can try to do this way.

CREATE_DISK cd;  
CREATE_DISK_MBR cdMBR;

cdMbr.Signature = 0x28;

cd.PartitionStyle = PARTITION_STYLE_MBR;
cd.Mbr = cdMBR;
 
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Ezchdahal
ID: 16872856
Yes. DeviceIoControl returns 1.

I went ahead and tried your suggestion for completeness, the union semantics should be equivalent. The same response was generated.

My assumptions must be wrong somewhere along the line. I wonder what the Disk Management Snap-In actually does when you select "Initialize Disk"?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1000 total points
ID: 16874497
I don't know the answer to this, but there are some clues to what the Disk Manager does...

First it displays "Connecting to the Logical Disk Manager Service"
So I presume it communicates with a Service

Next, you should be able to Check Dependancies of the snap-in executable and see what APIs it accesses.

Finally there are utilities at for instance http://www.apimonitor.com/ that let you see what system calls are excercised.  That would be a pain to do, but it might bw worth it if you can't otherwise find out.

This SysInternals utility might help to provide a clue...
   http://www.sysinternals.com/utilities/ldmdump.html

You can always run diskpart.exe using CreateProcess.
This is probably not what you want but it is good alternative if you want to get your job done very quickly.

   http://support.microsoft.com/default.aspx?kbid=300415

and this source code shoudl be right on point since FormatX
    http://www.sysinternals.com/SourceCode/fmifs.html

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
You will surely want to take a look at...

    SHFormatDrive Function
    http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shformatdrive.asp
It is interactive (displaying a dialgo box) and perhaps that is the best way to go, considering how dangerous formatting operations are.  But if you must have  purely programatic execution, you might be able to automate the dialog by sending message to it.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 16874535
0
 

Author Comment

by:Ezchdahal
ID: 16875209
Thanks Dan,

To keep the post simple I didn't go into all the detail regarding solutions I had already explored but you have mentioned many of them. Specifically, diskpart, FormatX, and SHFormatDrive. Diskpart scripting is too scary as a production solution. That tool is dangerous. SHFormatDrive brings up UI, which I'd like to avoid. (Not because I want to write a virus, because I want the wizard to be as simple, tailored and foolproof as possible.) FormatX was my current favorite if I couldn't find a DDK solution for formatting. BTW. There's a couple useful Experts Exchange questions on FormatX for anyone researching the subject

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21861608.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10500798.html

The initializing and partitioning comes first though. I noticed just a couple minutes ago that after disconnecting and reconnecting my test array, it showed up as initialized in Disk Management. This is promising. Perhaps, there is another call I need to make to flush the drive information and reload it. That will be an investigation for Monday...

Oh and thanks for the APIMonitor suggestion. I was thinking StraceNT but APIMonitor might be a better way to go.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 16875939
The Formatx source code is in easy-to-understand C code.
After formatting, it calls
   GetVolumeInformationW(...)
   GetDiskFreeSpaceExW()
which might be what makes up the Explorer to the new drive (for obvious reasons, I am not testing any of these suggestions :-).

THis looks promising.  Maybe you need to mount the frive:

   Mounting a Volume at a Mount Point
   http://msdn.microsoft.com/library/en-us/fileio/fs/mounting_a_volume_at_a_mount_point.asp
0
 

Author Comment

by:Ezchdahal
ID: 17031658
Sure, I'll give Dan the points. The puzzle still remains unfinished (mainly because I've been working on other topics) but hopefully we've gathered most of the pieces to solve it.

Thanks for the help Lakshmanan and Dan,

John
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

872 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