Hi,

What's the windows API to perform formatting or quick formatting of a floppy, a partition, or a volume?

Please advice, thanks!
-CL

Re: Format and quick format by David

David
Mon Jul 12 07:56:20 CDT 2004

>What's the windows API to perform formatting or quick formatting of a floppy, a partition, or a volume?

Paul,

Have a look at the SHFormatDrive documentation.

Dave

Re: Format and quick format by Igor

Igor
Mon Jul 12 12:32:34 CDT 2004

"Paul" <Paul@discussions.microsoft.com> wrote in message
news:D7A159E0-F29E-4A25-82A1-2D0E988A7312@microsoft.com
> What's the windows API to perform formatting or quick formatting of a
> floppy, a partition, or a volume?

DeviceIoControl(IOCTL_DISK_FORMAT_TRACKS[_EX])
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: Format and quick format by William

William
Mon Jul 12 12:39:22 CDT 2004

"Paul" <Paul@discussions.microsoft.com> wrote in message
news:D7A159E0-F29E-4A25-82A1-2D0E988A7312@microsoft.com...
> What's the windows API to perform formatting or
> quick formatting of a floppy, a partition, or a volume?

I see that Dave has already pointed out the easiest way.

If you find that UI unacceptable then I think you are in for a lot of work.

On NT/2K/XP/2K+3 you can pass the name of a floppy drive, e.g. \\.\A: (or in
source code where backslashes must be doubled up "\\\\.\\A:") to
CreateFile(). Then to write to sector number n you write to the device
handle at an offset given by the product of the sector number n and the size
of one sector. Note this caveat from the docs:

<quote>
Note that all I/O buffers should be sector aligned (aligned on addresses in
memory that are integer multiples of the volume's sector size), even if the
disk device is opened without the FILE_FLAG_NO_BUFFERING flag. Depending the
disk, this requirement may not be enforced.
</quote>

To do this, you'll need to be aware of the layout of the MBR, the FAT table,
the root directory etc. It's a trip down memory lane. :-)

On 95/98/Me I think what you have to do is to get yourself a DOS reference
such as Ralf Brown's interrupt list and use DeviceIOControl() to issue DOS
interrupt functions (int 21h) to the virtual device driver in question. The
technique is sketched here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/calling_deviceiocontrol_on_windows_95_98_me.asp

As above, you'll need to know the layout of the disk.

You may want to post again in the kernel group to find out if there is an
easier alternative.

Regards,
Will



Re: Format and quick format by Paul

Paul
Tue Jul 13 01:20:02 CDT 2004

I was looking at this too but according to MSDN IOCTL_DISK_FORMAT_TRACKS[_EX] is to format a specified, contiguous set of tracks on a floppy disk.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/ioctl_disk_format_tracks.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/ioctl_disk_format_tracks_ex.asp

-P


"Igor Tandetnik" wrote:

> "Paul" <Paul@discussions.microsoft.com> wrote in message
> news:D7A159E0-F29E-4A25-82A1-2D0E988A7312@microsoft.com
> > What's the windows API to perform formatting or quick formatting of a
> > floppy, a partition, or a volume?
>
> DeviceIoControl(IOCTL_DISK_FORMAT_TRACKS[_EX])
> --
> With best wishes,
> Igor Tandetnik
>
> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken
>
>
>

Re: Format and quick format by Paul

Paul
Tue Jul 13 01:29:02 CDT 2004

Hmmm... pretty complicated, huh? Igor replied something about IOCTL_DISK_FORMAT_TRACKS[_EX], but according to MSDN it's only for formatting a floppy. I need something that also works for a partition or a mounted volume.

Thanks anyway for your reply!
-P


"William DePalo [MVP VC++]" wrote:

> "Paul" <Paul@discussions.microsoft.com> wrote in message
> news:D7A159E0-F29E-4A25-82A1-2D0E988A7312@microsoft.com...
> > What's the windows API to perform formatting or
> > quick formatting of a floppy, a partition, or a volume?
>
> I see that Dave has already pointed out the easiest way.
>
> If you find that UI unacceptable then I think you are in for a lot of work.
>
> On NT/2K/XP/2K+3 you can pass the name of a floppy drive, e.g. \\.\A: (or in
> source code where backslashes must be doubled up "\\\\.\\A:") to
> CreateFile(). Then to write to sector number n you write to the device
> handle at an offset given by the product of the sector number n and the size
> of one sector. Note this caveat from the docs:
>
> <quote>
> Note that all I/O buffers should be sector aligned (aligned on addresses in
> memory that are integer multiples of the volume's sector size), even if the
> disk device is opened without the FILE_FLAG_NO_BUFFERING flag. Depending the
> disk, this requirement may not be enforced.
> </quote>
>
> To do this, you'll need to be aware of the layout of the MBR, the FAT table,
> the root directory etc. It's a trip down memory lane. :-)
>
> On 95/98/Me I think what you have to do is to get yourself a DOS reference
> such as Ralf Brown's interrupt list and use DeviceIOControl() to issue DOS
> interrupt functions (int 21h) to the virtual device driver in question. The
> technique is sketched here:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/calling_deviceiocontrol_on_windows_95_98_me.asp
>
> As above, you'll need to know the layout of the disk.
>
> You may want to post again in the kernel group to find out if there is an
> easier alternative.
>
> Regards,
> Will
>
>
>

Re: Format and quick format by William

William
Tue Jul 13 01:44:36 CDT 2004

"Paul" <Paul@discussions.microsoft.com> wrote in message
news:DD52E440-8830-41AD-A69C-507268365FF5@microsoft.com...
> Hmmm... pretty complicated, huh? Igor replied something
> about IOCTL_DISK_FORMAT_TRACKS[_EX], but according
> to MSDN it's only for formatting a floppy. I need something
> that also works for a partition or a mounted volume.

It's not like I am brave enough to try the technique I described on a
mounted disk here, but with sufficient privileges, it should work. I haven't
had to do anything similar in quite a number of years, but IIRC, I had to do
lots of other stuff apart from formatting the tracks and filling the unused
clusters with 0xF6 bytes all over the place. I vaguely recall having to
worry about the master boot record, the FAT tables and the root directory as
well.

As to whether DeviceIOControl() does all of that or if it works with hard
disks too, I'm sorry to tell you that I don't know for sure and feeling more
cautious then curious. :-) You might want to post again in

microsoft.public.programmer.win32.kernel

> Thanks anyway for your reply!

You are welcome.

Regards,
Will



Re: Format and quick format by Paul

Paul
Tue Jul 13 04:11:01 CDT 2004

Will,

THIS IS IT! Someone in kernel newsgroup replied. =)

http://www.sysinternals.com/ntw2k/source/fmifs.shtml

Very cool!
-P


"William DePalo [MVP VC++]" wrote:

> "Paul" <Paul@discussions.microsoft.com> wrote in message
> news:DD52E440-8830-41AD-A69C-507268365FF5@microsoft.com...
> > Hmmm... pretty complicated, huh? Igor replied something
> > about IOCTL_DISK_FORMAT_TRACKS[_EX], but according
> > to MSDN it's only for formatting a floppy. I need something
> > that also works for a partition or a mounted volume.
>
> It's not like I am brave enough to try the technique I described on a
> mounted disk here, but with sufficient privileges, it should work. I haven't
> had to do anything similar in quite a number of years, but IIRC, I had to do
> lots of other stuff apart from formatting the tracks and filling the unused
> clusters with 0xF6 bytes all over the place. I vaguely recall having to
> worry about the master boot record, the FAT tables and the root directory as
> well.
>
> As to whether DeviceIOControl() does all of that or if it works with hard
> disks too, I'm sorry to tell you that I don't know for sure and feeling more
> cautious then curious. :-) You might want to post again in
>
> microsoft.public.programmer.win32.kernel
>
> > Thanks anyway for your reply!
>
> You are welcome.
>
> Regards,
> Will
>
>
>