From bf86338efbb3cf24fa5ef0a5b76aa874ba8c6997 Mon Sep 17 00:00:00 2001 From: yoe Date: Wed, 21 Apr 2004 22:21:51 +0000 Subject: [PATCH] r54: - Unbreak compilation - portability: The Hurd doesn't have or ioctls. They're not essential to us, so #ifdef out the code that uses them if they are not available. --- cliserv.h | 1 - nbd-client.c | 2 ++ nbd-server.c | 41 +++++++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/cliserv.h b/cliserv.h index 87051f1..5d6dc48 100644 --- a/cliserv.h +++ b/cliserv.h @@ -9,7 +9,6 @@ Send 128 bytes of zeros (reserved for future use) */ -#include "config.h" #include #include #include diff --git a/nbd-client.c b/nbd-client.c index 379a3bd..72e7f60 100644 --- a/nbd-client.c +++ b/nbd-client.c @@ -13,6 +13,8 @@ * open the exported file. */ +#include "config.h" + #include #include #include diff --git a/nbd-server.c b/nbd-server.c index bc4b101..212ed9f 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -51,19 +51,21 @@ * */ -/* 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 #include #include #include /* wait */ +#ifdef HAVE_SYS_IOCTL_H #include +#endif #include +#ifdef HAVE_SYS_MOUNT_H #include /* For BLKGETSIZE */ +#endif #include /* sigaction */ #include #include /* sockaddr_in, htons, in_addr */ @@ -78,6 +80,10 @@ #include #include +/* 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; } -- 1.7.10.4