4 * Add or delete an NFS export in knfsd.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
14 #include <sys/types.h>
15 #include <asm/types.h>
22 /* if /proc/net/rpc/... exists, then
23 * write to it, as that interface is more stable.
25 * client fsidtype fsid path
26 * to /proc/net/rpc/nfsd.fh/channel
28 * client path expiry flags anonuid anongid fsid
29 * to /proc/net/rpc/nfsd.export/channel
33 exp_unexp(struct nfsctl_export *exp, int export)
44 f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
45 if (f == NULL) return -1;
46 qword_print(f, exp->ex_client);
47 qword_print(f, exp->ex_path);
49 qword_printint(f, 0x7fffffff);
50 qword_printint(f, exp->ex_flags);
51 qword_printint(f, exp->ex_anon_uid);
52 qword_printint(f, exp->ex_anon_gid);
53 qword_printint(f, exp->ex_dev);
60 if (stat(exp->ex_path, &stb) != 0)
62 f = fopen("/proc/net/rpc/nfsd.fh/channel", "w");
63 if (f==NULL) return -1;
64 if (exp->ex_flags & NFSEXP_FSID) {
65 qword_print(f,exp->ex_client);
68 qword_printhex(f, (char*)&fsid, 4);
70 qword_printint(f, 0x7fffffff);
71 qword_print(f, exp->ex_path);
75 err = qword_eol(f) || err;
77 qword_print(f,exp->ex_client);
79 dev = htons(major(stb.st_dev)); memcpy(fsidstr, &dev, 2);
80 dev = htons(minor(stb.st_dev)); memcpy(fsidstr+2, &dev, 2);
81 inode = stb.st_ino; memcpy(fsidstr+4, &inode, 4);
83 qword_printhex(f, fsidstr, 8);
85 qword_printint(f, 0x7fffffff);
86 qword_print(f, exp->ex_path);
89 err = qword_eol(f) || err;
95 nfsexport(struct nfsctl_export *exp)
97 struct nfsctl_arg arg;
99 if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_WRONLY))>= 0) {
101 return exp_unexp(exp, 1);
103 arg.ca_version = NFSCTL_VERSION;
104 memcpy(&arg.ca_export, exp, sizeof(arg.ca_export));
105 return nfsctl(NFSCTL_EXPORT, &arg, NULL);
109 nfsunexport(struct nfsctl_export *exp)
111 struct nfsctl_arg arg;
114 if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_WRONLY))>= 0) {
116 return exp_unexp(exp, 0);
119 arg.ca_version = NFSCTL_VERSION;
120 memcpy(&arg.ca_export, exp, sizeof(arg.ca_export));
121 return nfsctl(NFSCTL_UNEXPORT, &arg, NULL);