plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

mount-BSD.c (1685B)


      1 #include <u.h>
      2 #include <sys/socket.h>
      3 #include <netinet/in.h>
      4 #include <netdb.h>
      5 #include <sys/stat.h>
      6 #include <sys/param.h>
      7 #include <sys/mount.h>
      8 #include <sys/syslog.h>
      9 #include <rpc/rpc.h>
     10 #include <rpc/pmap_clnt.h>
     11 #include <rpc/pmap_prot.h>
     12 #if defined(__FreeBSD_version) && __FreeBSD_version >= 800000
     13 #include <fs/nfs/rpcv2.h>
     14 #include <fs/nfs/nfsproto.h>
     15 # else
     16 #include <nfs/rpcv2.h>
     17 #include <nfs/nfsproto.h>
     18 #endif
     19 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500000
     20 #	include <nfsclient/nfs.h>
     21 #	ifndef MNT_NODEV
     22 #		define MNT_NODEV 0
     23 #	endif
     24 #else
     25 #	include <nfs/nfs.h>
     26 #endif
     27 #ifdef __NetBSD__
     28 #	include <nfs/nfsmount.h>
     29 #endif
     30 #include <libc.h>
     31 #include "mountnfs.h"
     32 #ifndef MNT_NOATIME
     33 #	define MNT_NOATIME 0
     34 #endif
     35 
     36 void
     37 mountnfs(int proto, struct sockaddr_in *sa,
     38 	uchar *handle, int nhandle, char *mtpt)
     39 {
     40 	int mflag;
     41 	struct nfs_args na;
     42 
     43 	memset(&na, 0, sizeof na);
     44 	na.version = NFS_ARGSVERSION;
     45 	na.addr = (struct sockaddr*)sa;
     46 	na.addrlen = sizeof *sa;
     47 	na.sotype = proto;
     48 	na.proto = (proto == SOCK_STREAM) ? IPPROTO_TCP : IPPROTO_UDP;
     49 	na.fh = handle;
     50 	na.fhsize = nhandle;
     51 	na.flags = NFSMNT_RESVPORT|NFSMNT_NFSV3|NFSMNT_INT;
     52 	na.wsize = NFS_WSIZE;
     53 	na.rsize = NFS_RSIZE;
     54 	na.readdirsize = NFS_READDIRSIZE;
     55 	na.timeo = 200;
     56 	na.retrans = NFS_RETRANS;
     57 	na.maxgrouplist = NFS_MAXGRPS;
     58 	na.hostname = "backup";
     59 #if !defined(__NetBSD__) && !defined(__APPLE__)
     60 	na.acregmin = 60;
     61 	na.acregmax = 600;
     62 	na.acdirmin = 60;
     63 	na.acdirmax = 600;
     64 #endif
     65 	mflag = MNT_RDONLY|MNT_NOSUID|MNT_NOATIME|MNT_NODEV;
     66 #ifdef __NetBSD__
     67 	if(mount("nfs", mtpt, mflag, &na, sizeof(na)) < 0)
     68 #else
     69 	if(mount("nfs", mtpt, mflag, &na) < 0)
     70 #endif
     71 		sysfatal("mount: %r");
     72 }