Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,677
    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!

  3. #3
    Just 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

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    "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.

  6. #5
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    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.

  7. #6
    Just 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.

  8. #7
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •