LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A question about the system call mount in a C program (https://www.linuxquestions.org/questions/programming-9/a-question-about-the-system-call-mount-in-a-c-program-747921/)

dariyoosh 08-16-2009 09:56 AM

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

fantas 08-16-2009 10:11 AM

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.

dariyoosh 08-16-2009 05:41 PM

Quote:

Originally Posted by fantas (Post 3645358)
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.


All times are GMT -5. The time now is 10:26 PM.