LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2009, 09:56 AM   #1
dariyoosh
LQ Newbie
 
Registered: Mar 2009
Location: Iran (Tehran)
Posts: 12

Rep: Reputation: 0
Question 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

Code:
#include <sys/mount.h>

int main(int argc, char *argv[])
{
    if (mount("/dev/sdg1", "/media/flashCorsaire/", "fuseblk",
               MS_MGC_VAL,"rw,nosuid,nodev,allow_other,blksize=4096") != 0)
    {
        fprintf(stderr, "Error: The program doesn't seem to be able ");
        fprintf(stderr, "to control the USB device\n");
        fprintf(stderr, "%s\n", strerror(errno));
        return 1;
    }

    return 0;
}
Whether the USB key has already been mounted or not, when I run this program as root I get
the following error message:

Code:
Error: The program doesn't seem to be able to control the USB device
Invalid argument
I don't really understand what is invalid argument in my code, because here is the line that I put
in /etc/fstab:
Code:
/dev/sdg1    /media/flashCorsaire    auto    defaults    0    0

And also here is what I see in /etc/mtab when I connect the USB to my PC
Code:
/dev/sdg1 /media/flashCorsaire fuseblk rw,nosuid,nodev,allow_other,blksize=4096 0 0
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?


Thanks in advance,
Kind Regards,
Dariyoosh
 
Old 08-16-2009, 10:11 AM   #2
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
Did you try it yet without the trailing slash in "/media/flashCorsaire/" in the parameters to the 'mount' function ?

That's at least a little difference I can notice there, compared to your mtab entry.
 
Old 08-16-2009, 05:41 PM   #3
dariyoosh
LQ Newbie
 
Registered: Mar 2009
Location: Iran (Tehran)
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by fantas View Post
Did you try it yet without the trailing slash in "/media/flashCorsaire/" in the parameters to the 'mount' function ?

That's at least a little difference I can notice there, compared to your mtab entry.
I removed the '/' but it didn't change anything.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
issue system call from running fortran program msander Linux - Newbie 1 04-24-2009 07:49 AM
HELP:Error running program which includes system call stefio Programming 2 07-27-2008 10:37 AM
How to issue system call from running fortran program swerdna Programming 3 12-27-2006 07:44 AM
c question: system call blackzone Programming 1 07-19-2006 05:55 PM
Is Mount a system call or shell command? comeon Linux - Software 8 02-20-2005 11:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:08 PM.

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