Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

IOCTL support for disk format

Posted on 2003-03-05
2
Medium Priority
?
1,001 Views
Last Modified: 2008-02-01
Hi,

I'm trying to write my own formating utility for various removable media in Visual C++. i have found out that I can use IOCTL device control codes. But I have problem with using them. Does anybody know what is the order of IOCTL codes to do a low level format and set up a apropriete partition and file system?
I found here an example for floppy disk, but most of the removable media are close to disk (or most of them apear to use the disk.sys driver)
Or does anybody know how can I get the list of supported IOCTL control codes directly from device drivers if I don't have a source code from these .sys drivers?
Is there any chance to do a media recovery?

Thanks

dp7
0
Comment
Question by:dp7
2 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 8073141
Unless you know something I don't I would assume it is the same codes as for floppy.

Be aware that formatting a hard disk is a very serious business and you must warn the user that all data on that disk is deleted when you do that.

Also be aware that in a multi tasking environment such as Win2000 or WinXP you can't just format the disk. The disk might be used by other tasks, so you first have to reserve the disk before you can format it.

Also, be aware that the disk which the system boot on (usually C:) cannot be reserved, since the system is using it. Disks that cannot be reserved cannot be formatted while the system is running. A drive such as C: would typically be formatted when you install a new OS on it and the formatting will be done before the system is up and running on it - i.e. in a controlled environment where there are no other tasks that might want to use the disk.

Other disks that cannot be reserved can under windows still be formatted but you place the command to do so in a special queue. When the system boots windows will check that queue and call any command stored in that queue. If that command is a format command the disk will be formatted before the system boot is completed. Once again, the format will be done in a controlled environment.

If the disk can be reserved, it means that no other application can access that disk and so you can just go ahead and format it.

Be sure you display proper warnings and so on to the user so that if he inadvertedly typed "format c:" he will get proper warnings and chance to cancel the operation before you attempt to do it or place the command into the boot queue I mentioned earlier.

If the boot is done in a non-windows environment such as unix it might be completely different though, generally 'formatting' in unix speak isn't the same as 'formatting' in windows speak. Formatting in unix speak (and most other OS except windows) means the low level formatting of a hard disk or other medium where the system divide the disk into blocks and places markers where each block begin and end and check that each block is ok to read and write from if any block give errors they are properly marked so that the disk won't attempt to access those block any more (so called bad blocks).

What windows refer to as 'formatting' is in all other OSes that I know of called 'creating a file system' and means that you attempt to create some form of file system on that medium.

Another term that is related to the two above is also 'partioning' where you divide a medium such as a hard disk into several partitions. Partitions is in reality a very simple file system which only has room for 1-4 or so files and each file must be contiguous. The files do not have names but are instead referred to as partitions. Each OS has their way of naming or numbering partitions. Each file is referred to as a 'partition' and is a portion of the disk that is available for a system which can view this partition as a medium by itself and therefore can create a filesystem or some other structure on that partition.

Note that partitions have a type - a one byte indicating what kind of partition it is and there is some (weak) attempt at using unique byte values for each partition type. Microsoft is infamous for stepping on other system's toes and using undocumented byte values and some times byte values which was really used by other systems for their own internal purpose. This can cause pain and much sorrow for a poor person who try to mix windows and some other OS that uses those bytes.

To my knowledge, windows isn't using the values used by Linux. Linux uses to my knowledge only two values. One for a regular file system and another for swap partition. Windows uses a bunch of different values in that type byte, one for FAT or FAT32, another for NTFS, and yet a bunch of others for internal and to some extent undocumented purposes.

It is really odd that they can't have separate values for each OS. One would think that since a byte can hold 256 different values there should be enough for everyone if each weren't so greedy. After all, the minimum would be for each system to use one type byte saying 'my system'. Then further info could be in the information in the initial sector of the partition. That would theoretically hold room for 256 different OSes and should be more than enough - there aren't that many different OSes that run on a PC. Anyway, if you ever get misinterpretations of partition table the reason is often that some system uses values also used by other vendors and they step on each other toes.

Alf
0
 

Accepted Solution

by:
la_chose earned 225 total points
ID: 8075365

The best help you can get is from sysinternals:
http://www.sysinternals.com/ntw2k/source/fmifs.shtml
It's a format utility with source code.

If you really want to do media recovery AND If you are advanced enough, try sniffing a existing software like (the example here is the first one I got w/ a search):
http://www.lc-tech.com/download.htm
with the tools Irp Tracker and DeviceTree from OSR.
Softice will help too.
http://www.osr.com/resources_downloads.shtml
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

581 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