r54: - Unbreak compilation
authoryoe <yoe>
Wed, 21 Apr 2004 22:21:51 +0000 (22:21 +0000)
committeryoe <yoe>
Wed, 21 Apr 2004 22:21:51 +0000 (22:21 +0000)
- portability: The Hurd doesn't have <sys/mount.h> or ioctls. They're
  not essential to us, so #ifdef out the code that uses them if they
  are not available.

cliserv.h
nbd-client.c
nbd-server.c

index 87051f1..5d6dc48 100644 (file)
--- a/cliserv.h
+++ b/cliserv.h
@@ -9,7 +9,6 @@
    Send 128 bytes of zeros (reserved for future use)
  */
 
-#include "config.h"
 #include <errno.h>
 #include <string.h>
 #include <netdb.h>
index 379a3bd..72e7f60 100644 (file)
@@ -13,6 +13,8 @@
  *     open the exported file.
  */
 
+#include "config.h"
+
 #include <asm/page.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
index bc4b101..212ed9f 100644 (file)
  *     <wouter@debian.org>
  */
 
-/* used in cliserv.h, so must come first */
-#define MY_NAME "nbd_server"
 /* Includes LFS defines, which defines behaviours of some of the following
  * headers, so must come before those */
-#include "cliserv.h"
+#include "config.h"
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/wait.h>          /* wait */
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/param.h>
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>         /* For BLKGETSIZE */
+#endif
 #include <signal.h>            /* sigaction */
 #include <netinet/tcp.h>
 #include <netinet/in.h>                /* sockaddr_in, htons, in_addr */
 #include <strings.h>
 #include <dirent.h>
 
+/* used in cliserv.h, so must come first */
+#define MY_NAME "nbd_server"
+#include "cliserv.h"
+
 /** how much space for child PIDs we have by default. Dynamically
    allocated, and will be realloc()ed if out of space, so this should
    probably be fair for most situations. */
@@ -401,13 +407,15 @@ off_t size_autodetect(int export)
        struct stat stat_buf;
        int error;
 
-       DEBUG("looking for export size with lseek SEEK_END\n");
-       es = lseek(export, (off_t)0, SEEK_END);
-       if (es > ((off_t)0)) {
+#ifdef HAVE_SYS_MOUNT_H
+#ifdef HAVE_SYS_IOCTL_H
+       DEBUG("looking for export size with ioctl BLKGETSIZE\n");
+       if (!ioctl(export, BLKGETSIZE, &es32) && es32) {
+               es = (off_t)es32 * (off_t)512;
                return es;
-        } else {
-                DEBUG2("lseek failed: %d", errno==EBADF?1:(errno==ESPIPE?2:(errno==EINVAL?3:4)));
-        }
+       }
+#endif
+#endif
 
        DEBUG("looking for export size with fstat\n");
        stat_buf.st_size = 0;
@@ -417,14 +425,15 @@ off_t size_autodetect(int export)
         } else {
                 err("fstat failed: %m");
         }
-       
-#ifdef BLKGETSIZE
-       DEBUG("looking for export size with ioctl BLKGETSIZE\n");
-       if (!ioctl(export, BLKGETSIZE, &es32) && es32) {
-               es = (off_t)es32 * (off_t)512;
+
+       DEBUG("looking for export size with lseek SEEK_END\n");
+       es = lseek(export, (off_t)0, SEEK_END);
+       if (es > ((off_t)0)) {
                return es;
-       }
-#endif
+        } else {
+                DEBUG2("lseek failed: %d", errno==EBADF?1:(errno==ESPIPE?2:(errno==EINVAL?3:4)));
+        }
+
        err("Could not find size of exported block device: %m");
        return OFFT_MAX;
 }