Results 1 to 7 of 7
Hi,
I'd like to know if it's possible in my program (C/C++) to create a filesystem on a partition, maybe with advanced options too. I don't want to call the ...
- 04-05-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Filesystem formatting in C
Hi,
I'd like to know if it's possible in my program (C/C++) to create a filesystem on a partition, maybe with advanced options too. I don't want to call the shell and execute the usual commands to do that, so I wonder if there are some native Linux syscalls or external libraries to do that.
Thanks in advance,
Lisa
- 04-05-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
And you want to reinvent the wheel why?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-05-2011 #3Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Why I'm reinventing the wheel?
However, I don't like executing shell commands from my programs, if there's an alternative. Maybe those commands (like mke2fs for example) are using some syscalls or libraries I can have access too from my program; I couldn't find anything on Google about it, but you never know your luck ^^
Lisa
- 04-05-2011 #4
"Reinventing the wheel" refers to doing work that someone else has already done.
There is pretty much no reason to avoid using external programs, since they implement a lot of functionality. There is no system call to format a filesystem; this is what those external programs are for.
If your real problem is going through the shell, you can certainly use fork/exec to execute the program directly. However, you should be using mke2fs to accomplish this.DISTRO=Arch
Registered Linux User #388732
- 04-06-2011 #5
For debian derivates this should get you the sources:
$ apt-get source util-linux
However, I agree my pre-posters unless you're doing this to learn how things work. Otherwise doing things on your own most probably would cause just problems.
- 04-06-2011 #6Just Joined!
- Join Date
- Sep 2010
- Location
- Montgomery, AL
- Posts
- 27
I am certain you can download the gparted source: sourceforge.net/projects/gparted/files/gparted/
Download it and see how they do it. While I agree with the previous commenters,-- after all this is unix programming and one of the central principles is to never write a piece of code that has already been written well-- sometimes you need to tweek their functionality to do something completely different.
P.S. I am sure you know this, but such an application will need to be run as root.
- 04-06-2011 #7Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Thanks to everyone for the advices. I'll see how to use existent filesystem management programs in an efficient way

Lisa


Reply With Quote