aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vbackup/mount-BSD.c
blob: 63841b5c8b07d61005db3b979764b284d499e766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <u.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/syslog.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000
#include <fs/nfs/rpcv2.h>
#include <fs/nfs/nfsproto.h>
# else
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
#endif
#if defined(__FreeBSD_version) && __FreeBSD_version >= 500000
#	include <nfsclient/nfs.h>
#	ifndef MNT_NODEV
#		define MNT_NODEV 0
#	endif
#else
#	include <nfs/nfs.h>
#endif
#ifdef __NetBSD__
#	include <nfs/nfsmount.h>
#endif
#include <libc.h>
#include "mountnfs.h"
#ifndef MNT_NOATIME
#	define MNT_NOATIME 0
#endif

void
mountnfs(int proto, struct sockaddr_in *sa,
	uchar *handle, int nhandle, char *mtpt)
{
	int mflag;
	struct nfs_args na;

	memset(&na, 0, sizeof na);
	na.version = NFS_ARGSVERSION;
	na.addr = (struct sockaddr*)sa;
	na.addrlen = sizeof *sa;
	na.sotype = proto;
	na.proto = (proto == SOCK_STREAM) ? IPPROTO_TCP : IPPROTO_UDP;
	na.fh = handle;
	na.fhsize = nhandle;
	na.flags = NFSMNT_RESVPORT|NFSMNT_NFSV3|NFSMNT_INT;
	na.wsize = NFS_WSIZE;
	na.rsize = NFS_RSIZE;
	na.readdirsize = NFS_READDIRSIZE;
	na.timeo = 200;
	na.retrans = NFS_RETRANS;
	na.maxgrouplist = NFS_MAXGRPS;
	na.hostname = "backup";
#if !defined(__NetBSD__) && !defined(__APPLE__)
	na.acregmin = 60;
	na.acregmax = 600;
	na.acdirmin = 60;
	na.acdirmax = 600;
#endif
	mflag = MNT_RDONLY|MNT_NOSUID|MNT_NOATIME|MNT_NODEV;
#ifdef __NetBSD__
	if(mount("nfs", mtpt, mflag, &na, sizeof(na)) < 0)
#else
	if(mount("nfs", mtpt, mflag, &na) < 0)
#endif
		sysfatal("mount: %r");
}