![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 09: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 07: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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 01:22 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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; } |
|
#5
|
|||
|
|||
|
Did you read Perderabo's comments? What you did won't work....
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
I'll try this one last time. You C code needs:
Code:
system("/usr/sbin/mount <put your options & arguments here>");
Calling mount() will probably not do what you want, if I understand what you are doing. |
|||
| Google The UNIX and Linux Forums |