• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1784
  • Last Modified:

C Source code to format a hard drive

I am working on a drive utility and I need a little jumpstart with the formatting routines {having a major brain cramp on the hard drive routines}.  What would be of the greatest help would be some source code in C on how to format a hard drive (by the way I am writting this utility for a Intel DOS/16-bit platform, supporting FAT12/FAT16 and eventually FAT32) .  I am already able to format a floppy drive and would now like to add hard drive capabilities to the program.


1 Solution
FYI(maybe not your case)
HOWTO: Call SHFormatDrive in Windows 95 and Windows NT
mmessuriAuthor Commented:
Thanks for the FYI; However, I am sorry to say that this app will (for now) be running only in a DOS 6.x environment.

-- Michael --
#include <stdlib.h>

system("format c:");

There's no other way in C. If you want to go to a lower level, you'll have to use platform-specific libraries and extensions, as C itself knows nothing of such things as "drives", contenting itself with the knowledge that there's probably some kind of file system.

Formatting a hard drive is, in any case, such a complex business nowadays that you are well advised not to do this. I can think of exactly one use for the program you propose - malice.

Get Certified for a Job in Cybersecurity

Want an exciting career in an emerging field? Earn your MS in Cybersecurity and get certified in ethical hacking or computer forensic investigation. WGU’s MSCSIA degree program was designed to meet the most recent U.S. Department of Homeland Security (DHS) and NSA guidelines.  

How about looking into the Linux mkdosfs sources? There you can find out how to create different FAT filesystems and more.

mmessuriAuthor Commented:

Thanks for the answer.  While it was not exactly what I was looking for, it does provide enough information for me to move on past my brain block.  Besides, the multiple file system information will be helpful as I complete my disk partitioning program (it combines the fdisk program with the format program).

-- Michael --
mmessuriAuthor Commented:
C Dreamer:

Thanks for taking the time to comment; however, I was not able to put to use your suggestion as format.com is not going to be available.


My intentions are not of malice.  The program is a hard disk partitioning application that allows for the creation / deletion and formating of the partition without the use of format.com or fdisk.exe

-- Michael --
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now