A question about the system call mount in a C program
Dear all,
Currently I'm working on a C program (OS = ubuntu 9.0.4)in which a USB key will
be mounted and umounted for several times. I read the man page
of the mount system call.
I use the following test code
Whether the USB key has already been mounted or not, when I run this program as root I get
the following error message:
I don't really understand what is invalid argument in my code, because here is the line that I put
in /etc/fstab:
And also here is what I see in /etc/mtab when I connect the USB to my PC
Therefore the file system is 'fuseblk' and options are rw,nosuid,nodev,allow_other,blksize=4096
So what's the problem? Where did I make a mistake in the code that generates this error
message?
It probably doesn't like the options. The options string for the kernel mount() call are not the same as given to the commandline utility, or put in /etc/fstab. Most of those options belong to the mountflags bitfield, whereas data is entirely filesystem-specific flags. If you prefer those style options, it might be better to stick with the utilities as you have them than use hardcoded kernel calls.
It probably doesn't like the options.
...
If you prefer those style options, it might be better to stick with the utilities as you have them than use hardcoded kernel calls.
Actually, the only reason that I wrote those options in my code was due to
what I read in 'man 2 mount'
Well, I looked mount(8) but I found nothing for the file system 'fuseblk'
so I didn't really know what to put as argument for the last parameter
of the mount system call (that is, const void *data). Therefore I thought
maybe it is the same as /etc/mtab, which seems that it is not the case.
I really need to do this mount and umount within the C code. If it was a
script (bash, KornShell, etc.) it would have been much easier, but
what I want to do is part of a C application and therefore I need to use
a system call. I wonder whether there is other system calls allowing
to mount/umount devices. Because I looked the POSIX specification
and it seems that mount is linux specific (there is no mount.h), because I
couldn't find the system call among the list of POSIX system calls. Do you
know any other system call?
I didn't really know what to put as argument for the last parameter
of the mount system call (that is, const void *data). Therefore I thought
maybe it is the same as /etc/mtab, which seems that it is not the case.
If you have no specific arguments for it try ""
Quote:
I really need to do this mount and umount within the C code. If it was a
script (bash, KornShell, etc.) it would have been much easier, but
what I want to do is part of a C application and therefore I need to use
a system call.
No, you don't. You can use system() or fork() and exec() or even popen() to do it, arguably better if you don't want to rewrite half of the commandline utilities from scratch anyway. But the system call should work if you don't feed generic options into the filesystem-specific flags.
By the way, are you typing up your replies in notepad then copy-pasting them into your browser? You don't need to do that, and shouldn't do so, since it adds dozens of pointless line breaks.
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
"Your a7.c program should use printf to print a nice message. (You can decide what to say.) Then the process... (9 Replies)
Hi all
I wonder if its possible to mount on a hp-ux server a file system that was previously mounted on a solaris 10 server. The LUN is on NetApp stoarge.
The problem on hp-ux I cannot do pvcreate on the lun (disk) because contains data.
Any help will be appreciated
FR (2 Replies)
Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Hello everyone!
I'm quite new here, but this forum helped me a lot before without registering :-)
I'll go directly to my problem, I have been searching a bit about this issue but I was not successful.
I need to write a program in C code to notificate me (to my email) when some action is done... (7 Replies)
hi guys
i have only basic knowledge of c so guys plz help me .....
i want 2 call c executable which requires file name as argument and i need to modify file contents before calling that executable now my question is how can i call this c executable inside another c program with arguments ??
i... (9 Replies)
Hi,
I would like to know how to call a program "cmp_size" ... where to put in progam to run it
ex: program checkdisk is below, and it will call a nother problem "cmp_size"
Do I just put the cmp_size program at the end of this program.
Thank you very much,
# check all directory for size... (3 Replies)
Hi Friends,
Could you pleas help me out..
I have an awk program which works fine while running it in the command prompt.
The awk program is
===============
awk 'BEGIN {
format="head -%d M2_Sales_N01.txt |tail -%d >M2_Sales_N01_%02d.txt\n"
n=0
m=0
}
{
if (n==0)
{
tmp=$1
n=1
}... (5 Replies)
Hi,
Ho do I differentiate system call from library call?
for example if I am using chmod , how do I find out if it is a system call or library call?
Thanks
Muru (2 Replies)