The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mount -o llock -F nfs vs mount -F nfs KhawHL UNIX for Dummies Questions & Answers 1 01-15-2008 08:48 PM
how i prepare a c++ code(c code) for implementing my own protocol format amitpansuria High Level Programming 1 09-06-2007 08:09 PM
SSH key code versus server key code Texan Security 1 04-12-2006 08:57 AM
how does unix identify C and other language code! a25khan UNIX for Dummies Questions & Answers 2 01-21-2004 06:44 AM
how to mount a hotswap scsi drive on a solaris 2.6 netra box using the mount command? soulshaker UNIX for Dummies Questions & Answers 4 07-18-2001 10:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-15-2006
Registered User
 

Join Date: Jul 2005
Posts: 11
code mount in c language

HI All:
Where I can find out the mount lib or function to view
because I think about using c to mount a file system
without shell command.

Thanks

Last edited by jeter; 03-15-2006 at 12:22 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-16-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
You can mount a filesystem through your C program. Check the man page of mount(2). Just remember, the mount command th atactually mounts a filesystem can only be run by root.
Reply With Quote
  #3 (permalink)  
Old 03-16-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,453
I am always very disappointed when I see code like:
system("cat /some/file.txt");
in a C program. But sometimes building a command line and passing it to system() is the more sensible approach. I have to argue that mounting a file system is an example of that. At first it was the mount() system call. Then it was vfs_mount(). Now it is mount() again. At least, that was the progression on HP-UX. Posix does not attempt to control mounting system calls or commands so your OS may differ. A C program that invokes the mount command via system() would have been largely insulated from this evolution. Besides the chaos at the system call level, mounting a filesystem rivals thread operations when it comes to splitting the work between user mode and kernel mode. But the system call only performs the actual kernel mode operations. The additional work required varies from system to system. It may include stuff like error checking, adding an entry to /etc/mnttab, initializing quotas, and auditing. And it could include other stuff that I don't remember. But you will need to figure it out and get it right in your program. You also need to maintain it as it varies from release to release. This is why I think that mounting a filesystem is too daunting for a user program.
Reply With Quote
  #4 (permalink)  
Old 03-16-2006
Registered User
 

Join Date: Jul 2005
Posts: 11
Hi All:
I am coming here again ,i have viewed doucment and write a code as following. but the program con not runs, I have tryed login super user.
thanks

#include <sys/param.h>
#include <sys/mount.h>
#include <errno.h>
#include <string.h>
int main()
{

const char path[]="data/test/my";
const char Workstationpath[]="/export/home/data/testpgm/"; // a location computer

int flag;

if ((flag = mount(Workstationpath,path,"MNT_RDONLY")))
printf("message %s",strerror(errno));

return 0;
}
Reply With Quote
  #5 (permalink)  
Old 03-16-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,861
Did you read Perderabo's comments? What you did won't work....
Reply With Quote
  #6 (permalink)  
Old 03-17-2006
Registered User
 

Join Date: Jul 2005
Posts: 11
I modify the code as following
produce a message : "Invalid argument "


#include <sys/param.h>
#include <sys/mount.h>
#include <errno.h>
#include <string.h>
int main()
{

const char javapath[]="data/test/my";//need to be mounted

const char workstationpath[]="/export/home/testpgm/";
int flag;

if ((flag = mount("MNT_RDONLY",workstationpath,javapath)))
printf("PLEASE LOGIN SUPER SUER %s",strerror(errno));

return 0;
}

Thanks
Reply With Quote
  #7 (permalink)  
Old 03-17-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,861
I'll try this one last time. You C code needs:
Code:
system("/usr/sbin/mount <put your options & arguments here>");
which will work from a privileged account.

Calling mount() will probably not do what you want, if I understand what you are doing.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0