LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2006, 08:19 AM   #1
sharathksin
LQ Newbie
 
Registered: Feb 2006
Posts: 12

Rep: Reputation: 0
how to format hard disk partition using it's superblock using C program


Hi here is my problem,
I want to format the hard disk partition using filesystem independent method which will look into superblock of the partition and format the contents of the disk and also edit the superblock making all the erased blocks as the free blocks in bitmap.I want to do all these using C program is there any example code showing how to achieve this.
Thanks in advance.
 
Old 04-25-2006, 11:43 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Last time I checked, formatting a drive _was_ file system dependent. There is no such thing as a generic formatter. Although the different filesystems use the same concepts of superblocks, inodes, their implementation varies thus a generic program would not be adivsed.

Do you want something that will just delete from the disk in an file system independent way? One already exists, it's called dd. No matter what you do, dd, or any other wipe utility, you'll be forced to use a 'filesystem' formatter before you can use the disk again, unless you have a program that will access raw partitions.

Last edited by crabboy; 04-25-2006 at 11:58 AM.
 
Old 04-28-2006, 07:08 AM   #3
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 55
It might be worth looking at the source for ext2/3 and Reiserfs.
 
Old 04-28-2006, 08:37 AM   #4
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
You don't need to "format" a hard drive, they are formatted at the factory.

If you want to create a filesystem, then that is obviously filesystem dependant!!!!

If you want to wipe the drive, then use dd as crabboy said.
 
Old 04-28-2006, 11:36 PM   #5
sharathksin
LQ Newbie
 
Registered: Feb 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the suggestions I'll follow the filesystem dependent format commands in linux.
one more query can I format the NTFS partition from linux?R there any commands like mkfs.ntfs? please help.
Thanks once again for the suggestions.
 
Old 04-29-2006, 01:41 PM   #6
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 55
There is no robust r/w support for NTFS in linux (yet) and certainly no formatting support. If you write it, you'll be a hero, unless you toast peoples' filesystems. In that case, you will be the opposite of a hero
 
Old 04-29-2006, 01:45 PM   #7
sajjadc
Member
 
Registered: May 2005
Location: kerala,india
Distribution: UBUNTU
Posts: 94

Rep: Reputation: 15
u can easily easily use shell options in
system call like
"
#include<stdio.h>
....................
system(" fdisk .....");
 
Old 04-29-2006, 02:33 PM   #8
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
EVIL EVIL I SAY.

actually i would like to see fsck.ntfs more then anything.

Please make one linux gods
 
Old 04-30-2006, 02:46 AM   #9
sharathksin
LQ Newbie
 
Registered: Feb 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for reply regarding NTFS support for linux I just wanted to confirm it.
Regarding using system(command); in C I know how to use it but how to catch errors when I execute a command using system it just returns whether the command was able to execute or not isn't it? if I want to catch errors occured during execution of that command then how to do that?
Thanks for NTFS clarifications.
 
Old 04-30-2006, 04:22 AM   #10
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Quote:
if I want to catch errors occured during execution of that command then how to do that?
Use fork & exec and then a wait/waitpid to check the exit status.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition and format unpartitioned hard disk which lies on an external usb case odysseus.lost Linux - General 1 08-09-2005 06:03 PM
Format Hard Disk Don Cherry Linux - Hardware 1 02-21-2005 12:56 PM
Format hard disk! yenonn Linux - Newbie 9 10-04-2003 06:56 PM
How do I format a hard disk under console? lectraplayer Linux - Newbie 21 04-05-2003 11:43 PM
hard disk format mariomason Linux - Software 1 01-08-2001 10:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration