code mount in c language


 
Thread Tools Search this Thread
Top Forums Programming code mount in c language
# 1  
Old 03-15-2006
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 04:22 PM..
# 2  
Old 03-16-2006
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  
Old 03-16-2006
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  
Old 03-16-2006
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 Smilie

#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  
Old 03-16-2006
Did you read Perderabo's comments? What you did won't work....
# 6  
Old 03-17-2006
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  
Old 03-17-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to create a new mount point with 600GB and add 350 GBexisting mount point? IN AIX

How to create a new mount point with 600GB and add 350 GBexisting mount point Best if there step that i can follow or execute before i mount or add diskspace IN AIX Thanks (2 Replies)
Discussion started by: Thilagarajan
2 Replies

2. Shell Programming and Scripting

Script to mount nas-share using generated credentials (mount EC 13,32)

Heyas At home i have 1 nas with 3 shares, of which i used to mount 2 of them using a script with hardcoded password and username in it. EDIT: Turns out, its not the script, but 'how i access' the nas share.. (-o user=XY,password=... VS. -o credentials=...). Figured about credential files,... (0 Replies)
Discussion started by: sea
0 Replies

3. Programming

Mount from C code with --no-mtab?

Hi all, I am writing a mount/umount procedure for CD rom and getting into the problem that /etc/mtab is not in sync with /proc/mounts. Then I am ending up with a bunch of dangling /etc/mtab entries that are not valid anymore. Reading through mount(8) I see a -n switch (--no-mtab) which would... (2 Replies)
Discussion started by: mirni
2 Replies

4. IP Networking

Can't see home folder on one NFS mount but can in another mount on another share

Hello, I have a few Ubuntu 9.10 laptops I'm trying to learn NFS sharing with. I am just experimenting on this right now, so no harsh words about the security of what I'm playing with, please ;) Below are the configs /etc/exports on host /home/woodnt/Homeschool... (2 Replies)
Discussion started by: Narnie
2 Replies

5. UNIX for Advanced & Expert Users

mount -t cifs permission denied by mount -t smbfs works fine

I am having trouble mounting with cifs, but mounting the exact same command with smbfs works fine. The share is on another samba server and is set to full public guest access. # mount -t cifs //servername/sharename /mnt/temp -o password="" mount error 13 = Permission denied Refer to the... (3 Replies)
Discussion started by: humbletech99
3 Replies

6. UNIX for Dummies Questions & Answers

What language is this?

Hi, Just got handed this script set def = HLA_DR.pockets set data = DRB1_1501.dat foreach a ( 'cat $data | args 3 |sort -u' ) cat $def | xC | grep -v $a > $$.def cat $data | grep $a | args 1,2 > $a.dat set pseudo = `cat MHCDR_pseudo.dat | grep HLA | grep $a | args 2`... (8 Replies)
Discussion started by: lost
8 Replies

7. Programming

which language will be the best

Hello, Ive got to amke a script to calculate how many emails are in the servers mailbox, how many times each IP address appears in the mailbox and to search for keywords, tehn produce the results in HTML report. The thing is I dont know where to start and what the best language to use would be. ... (4 Replies)
Discussion started by: clueless
4 Replies

8. UNIX for Dummies Questions & Answers

mount -o llock -F nfs vs mount -F nfs

Hi, We encountered NFS issue (solaris) especially running on Oracle application. Problem such as forms hang when close button is click, concurrent job shows running status all time. Understand we need to use mount -o llock -F nfs instead of mount -F nfs to eliminate? this problem.. Can... (1 Reply)
Discussion started by: KhawHL
1 Replies

9. UNIX for Dummies Questions & Answers

how does unix identify C and other language code!

Hello everyone, this question is probably simple for you ppl but i am jus a beginner and still learing. i was wondering if someone could tell me that how does unix identify different program codes in it's environment. for example, unix recognises this C code in the body of any script. how... (2 Replies)
Discussion started by: a25khan
2 Replies

10. UNIX for Dummies Questions & Answers

how to mount a hotswap scsi drive on a solaris 2.6 netra box using the mount command?

Hi... question is this: How do I mount an LVD hotswap scsi drive in bay #2 on a netra using the mount command? volmgt doesn't seem to mount it and/or I don't know how to view the drives data if it's formatted which it may not be. This drive is not new out of the box so I'm not sure. ... (4 Replies)
Discussion started by: soulshaker
4 Replies
Login or Register to Ask a Question