URI:
       tmount-Linux.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tmount-Linux.c (1295B)
       ---
            1 #include <u.h>
            2 #include <sys/socket.h>
            3 #include <sys/mount.h>
            4 #include <linux/version.h>
            5 #if LINUX_VERSION_CODE < 0x020600
            6 #        define __KERNEL__
            7 #        include <linux/nfs.h>
            8 #        undef __KERNEL__
            9 #else
           10 #        include <linux/nfs.h>
           11 #endif
           12 #include <linux/nfs2.h>
           13 #include <linux/nfs_mount.h>
           14 #include <libc.h>
           15 #include "mountnfs.h"
           16 
           17 void
           18 mountnfs(int proto, struct sockaddr_in *sa, uchar *handle, int nhandle, char *mtpt)
           19 {
           20         int mflag, fd;
           21         struct nfs_mount_data nfs;
           22 
           23         fd = socket(AF_INET, proto, proto==SOCK_STREAM ? IPPROTO_TCP : IPPROTO_UDP);
           24         if(fd < 0)
           25                 sysfatal("socket: %r");
           26 
           27         memset(&nfs, 0, sizeof nfs);
           28         nfs.version = NFS_MOUNT_VERSION;
           29         nfs.fd = fd;
           30         nfs.flags =
           31                 NFS_MOUNT_SOFT|
           32                 NFS_MOUNT_INTR|
           33                 NFS_MOUNT_NOAC|
           34                 NFS_MOUNT_NOCTO|
           35                 NFS_MOUNT_VER3|
           36                 NFS_MOUNT_NONLM;
           37         if(proto==SOCK_STREAM)
           38                 nfs.flags |= NFS_MOUNT_TCP;
           39         nfs.rsize = 8192;
           40         nfs.wsize = 8192;
           41         nfs.timeo = 120;
           42         nfs.retrans = 2;
           43         nfs.acregmin = 60;
           44         nfs.acregmax = 600;
           45         nfs.acdirmin = 60;
           46         nfs.acdirmax = 600;
           47         nfs.addr = *sa;
           48         strcpy(nfs.hostname, "backup");
           49         nfs.namlen = 1024;
           50         nfs.bsize = 8192;
           51         memcpy(nfs.root.data, handle, nhandle);
           52         nfs.root.size = nhandle;
           53         mflag = MS_NOATIME|MS_NODEV|MS_NODIRATIME|
           54                 MS_NOEXEC|MS_NOSUID|MS_RDONLY;
           55 
           56         if(mount("backup:/", mtpt, "nfs", mflag, &nfs) < 0)
           57                 sysfatal("mount: %r");
           58 }