Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-19-2008, 07:40 AM   #1
LQ Newbie
Registered: Jun 2008
Posts: 5

Rep: Reputation: 0
Question Linux programming "program to format an external storage device?"


I am a newbie to programming on linux.

I wanted to write a program to detect and format an external Usb storage device connected to linux.

I need info from a programming point of view:

1. how does linux tell me if a new mass storage usb device is plugged into the system?

2. How do i format the device connected ? I checked man pages and found reference to "mkfs". The only way to make it work through code is by using the system() API. I do not want to use system() API. Is there any other way of doing this ?

Thanks in advance,

- Karbon.
Old 06-19-2008, 06:45 PM   #2
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
  1. A few ways (e.g., udev or hal) are available. If you want to monitor from your own program, you can interface with hal using the dbus interface or libhal.
  2. Well there are obviously many different types of “format” for a filesystem. If you want to create your own, you are welcome to perform simple write()s on the block device representing the volume. Otherwise, you can use one of the programs specifically designed to format partitions (e.g., mkfs.ext3 or mkfs.vfat). If you don’t want to launch an external program, you might find libraries which give you the ability to do this (e.g., libext2fs).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
External HD "Not a valid block device" Slackware 10.0 ZiggyJustice Linux - Hardware 2 03-02-2005 04:18 PM
Getting error: "ALSA device "default" is already in use by another program." brynjarh Debian 7 02-04-2005 12:45 PM
Linux "broke" USB-mass storage device? - no longer workable in Windows XP lrt2003 Linux - Hardware 3 06-13-2004 11:56 PM
USB storage device works in 2.4 not 2.6 "no device error" critch Linux - Hardware 4 05-18-2004 12:13 PM
USB-Storage "6 in 1" device alfiejohn Linux - Hardware 2 09-06-2003 08:52 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:16 PM.

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