linux mount函数nfs挂载

1、使用linux的mout函数挂载

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

void test_mount()
{
    /*
        char* src = ":/home/record/";
        char* opt = "addr=192.168.1.250,nolock,hard,bg,tcp,rsize=4096,vers=4,clientaddr=192.168.1.241";
    */

    char* src = "172.16.41.252:/home/record/";
    char* dst = "/mnt/cloud_nfs";
    /* 需要加上本地ip及远程主机ip,否则报错:Invalid argument */
    char* opt = "addr=172.16.41.252,nolock,hard,bg,tcp,rsize=4096,vers=4,clientaddr=172.16.41.208";
    int ret = mount(src, dst, "nfs", MS_SYNCHRONOUS, (void*)opt);
    if(ret < 0)
    {
        printf("mount error: %s\n", strerror(errno));
    }
}

int main()
{
    test_mount();
    return 0;
}

执行程序之后,使用mount命令看不到挂载信息
linux mount函数nfs挂载_第1张图片
需要使用cat /proc/mounts查看
linux mount函数nfs挂载_第2张图片

你可能感兴趣的:(linux编程)