C Source code to format a hard drive

Posted on 2000-03-24
Last Modified: 2008-03-03
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.


Question by:mmessuri

Expert Comment

ID: 2655828
FYI(maybe not your case)
HOWTO: Call SHFormatDrive in Windows 95 and Windows NT 

Author Comment

ID: 2656009
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 --

Expert Comment

ID: 2656175
#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.

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.


Accepted Solution

feenix earned 995 total points
ID: 2656576
How about looking into the Linux mkdosfs sources? There you can find out how to create different FAT filesystems and more.

Author Comment

ID: 2656871

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 --

Author Comment

ID: 2656881
C Dreamer:

Thanks for taking the time to comment; however, I was not able to put to use your suggestion as 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 or fdisk.exe

-- Michael --

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is my core dump file in Ubuntu? 12 443
How to organize data in excel ? 2 112
C simple state machine for client server handshake 4 269
How to creat good software interface ? 1 60
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now