LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux programming "program to format an external storage device?" (https://www.linuxquestions.org/questions/programming-9/linux-programming-program-to-format-an-external-storage-device-650285/)

Karbon 06-19-2008 06:40 AM

Linux programming "program to format an external storage device?"
 
Hi,

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.

osor 06-19-2008 05:45 PM

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


All times are GMT -5. The time now is 12:29 AM.