LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2011, 01:09 AM   #1
raj010
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Rep: Reputation: 0
Red face System Call (not bash command) to format Linux partition


I'm working on Linux OS (Suse/redhat) and trying to format a linux partition from a c program.
Is there a way to do this without using :
'system ("mkfs.ext4 /dev/sdxy")'
 
Old 02-18-2011, 01:27 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Certainly not a system call - the kernel couldn't care less. Supporting every new filesystem that comes along ?. Not likely - that's userspace functionality.
Precisely the reason fuse was merged.
 
Old 04-18-2011, 09:09 AM   #3
16pide
Member
 
Registered: Jan 2010
Posts: 418

Rep: Reputation: 83
raj010, why would using system() not possible in your case?
 
Old 04-19-2011, 01:40 AM   #4
raj010
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by 16pide View Post
raj010, why would using system() not possible in your case?
system command will be executed in bash.....i don't want to use bash shell
 
Old 06-17-2011, 08:26 PM   #5
brasshopper
LQ Newbie
 
Registered: Apr 2004
Location: Boca Raton, Florida
Distribution: Fedora/Redhat
Posts: 8

Rep: Reputation: 3
Quote:
Originally Posted by raj010 View Post
system command will be executed in bash.....i don't want to use bash shell
OK, then exec the program you want directly (actually fork()/exec() the program you want) without calling the shell. Yes, for many purposes, using bash is a bad idea, certainly not using it is way more secure..you don't want to run their profile with your root authority for example.. In order to be sure, you clear the environment (after the fork, in the child) and exec the program you want using the complete path name.

Remember that in Unix, you have to do all substitution that the shell would otherwise do. So you would want (pseudocode, use your own man pages)..

pid_t child;

if((child=fork())== 0) { // in child
// in a loop close everything but fd 0,1,2. http://www.linuxquestions.org/questi...iptors-571188/
execle("/path/mke2fs", "mke2fs","/dev/partition",NULL, NULL); // Second null is environment
perror("whoops, exec of mke2fs failed");
exit(1);
}
if(child == -1) {
perror("fork failed");
exit(1);
}
waitpid(child,.......);

And so forth. That allows you to call another program without using bash, more or less, for security reasons. Of course, you should be sure that you are calling from the system library. You might consider checking the ownership of the program you want to exec to increase the chance it is not a trojan.
 
  


Reply



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
hey i want to know which command in linux uses the system call kill() vineetnair Linux - Newbie 1 10-02-2007 05:26 AM
i wud like to know which command in linux uses the system call kill() vineetnair Linux - General 1 10-02-2007 04:31 AM
list file system linux supports "please give the command or system call" varun_shrivastava Linux - General 4 01-09-2007 07:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:59 AM.

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