]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/nfssvc.c
Add support for suppressing different NFS versions.
[nfs-utils.git] / support / nfs / nfssvc.c
index dae16f7f7adc59a540b565e210e8861f71cacd37..c51ace18ea078c223aa597afb4637b9fbd1663a1 100644 (file)
@@ -6,20 +6,55 @@
  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  */
 
  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <unistd.h>
 #include <fcntl.h>
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
+#include <syslog.h>
 
 #include "nfslib.h"
 
 
 #include "nfslib.h"
 
+static void
+nfssvc_versbits(unsigned int ctlbits)
+{
+       int fd, n, off;
+       char buf[BUFSIZ], *ptr;
+
+       ptr = buf;
+       off = 0;
+       fd = open("/proc/fs/nfsd/versions", O_WRONLY);
+       if (fd < 0)
+               return;
+
+       for (n = NFSD_MINVERS; n <= NFSD_MAXVERS; n++) {
+               if (NFSCTL_VERISSET(ctlbits, n))
+                   off += snprintf(ptr+off, BUFSIZ - off, "+%d ", n);
+               else
+                   off += snprintf(ptr+off, BUFSIZ - off, "-%d ", n);
+       }
+       snprintf(ptr+off, BUFSIZ - off, "\n");
+       if (write(fd, buf, strlen(buf)) != strlen(buf)) {
+               syslog(LOG_ERR, "nfssvc: Setting version failed: errno %d (%s)", 
+                       errno, strerror(errno));
+       }
+       close(fd);
+
+       return;
+}
 int
 int
-nfssvc(int port, int nrservs)
+nfssvc(int port, int nrservs, unsigned int versbits)
 {
        struct nfsctl_arg       arg;
        int fd;
 
 {
        struct nfsctl_arg       arg;
        int fd;
 
-       fd = open("/proc/fs/nfs/threads", O_WRONLY);
+       nfssvc_versbits(versbits);
+
+       fd = open("/proc/fs/nfsd/threads", O_WRONLY);
+       if (fd < 0)
+               fd = open("/proc/fs/nfs/threads", O_WRONLY);
        if (fd >= 0) {
                /* 2.5+ kernel with nfsd filesystem mounted.
                 * Just write the number in.
        if (fd >= 0) {
                /* 2.5+ kernel with nfsd filesystem mounted.
                 * Just write the number in.