ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have the need to be able to programatically format a thumb drive having a single Linux partition on it using C/C++. What function call(s) do I need to make in order to get this done ?
I want to format the partition using a default partition type of my choosing if the partition has not yet been formatted. Otherwise I want to reformat the partition with the same partition type it already has. I know how to programatically mount or unmount the thumb drive to a path. What I do not know are the details of the functionality for formatting or reformatting the partition of the thumb drive.
Any help in this area would be welcome. I am an experienced C++ programmer, but have not dealt with this functionality on Linux before.
fdisk -o Device,Id,Type -l /dev/sda 2>/dev/null | grep '^/'
/dev/sda1 7 HPFS/NTFS/exFAT
/dev/sda2 7 HPFS/NTFS/exFAT
/dev/sda3 5 Extended
/dev/sda4 12 Compaq diagnostics
/dev/sda5 82 Linux swap / Solaris
/dev/sda6 83 Linux
/dev/sda7 83 Linux
What does piping the results of an fdisk call get me ? I already know the device designation I need to format. Do you mean to say that reading the output from fdisk is the standard way of determing what filesystem is on a partition rather than calling some Linux API function which gives me that information ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.