开发者

mount failed, errno is 20?

I'm newbie in linux program. why following code failed? its output is "failed 20". but in terminal the command: sudo mount /dev/sd开发者_如何学编程b /home/abc/work/tmp works.

void main()
{
    int rtn;

    rtn=mount("/dev/sdb","/home/abc/work/tmp","vfat",MS_BIND,"");  
    if (rtn==-1)
        printf("failed %d.\n",errno);
    else
        printf("OK!\n");
}


You can't bind-mount a device, only a directory. Try providing a useful value for mountflags.


Error 20 is ENOTDIR (http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html).

I think with MS_BIND, you would need the first argument to be an actual directory somewhere, not a device. See also the man page for mount

What you are trying to do would be equivalent to sudo mount --bind /dev/sdb /home/abc/work/temp which will give you an error too.


You should print out not just the errno value, but also the corresponding error message:

printf("failed %d: %s\n", errno, strerror(errno));

This should reveal the reason for the problem. ("Not a directory", so /home/abc/work/tmp does not seem to be a directory.)

(There are various other problems with your code, such as missing #include statements, and writing error messages to stdout and not stderr, but those are irrelevant to your problem at hand. You can fix them later.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜