From: Wouter Verhelst Date: Mon, 8 Jun 2009 21:02:29 +0000 (+0200) Subject: Fix autodetection X-Git-Url: http://git.alex.org.uk Fix autodetection Everything else in nbd-server was already 64bit-clean, but this part, where the size of a block device is autodected, wasn't. Replace the ioctl() to BLKGETSIZE with its 64bit version, so that trying to detect the size of a multi-terabyte block device does not fail. --- diff --git a/nbd-server.c b/nbd-server.c index 4ac6d1f..4426345 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -770,19 +770,18 @@ void sigterm_handler(int s) { **/ off_t size_autodetect(int fhandle) { off_t es; - unsigned long sectors; + u64 bytes; struct stat stat_buf; int error; #ifdef HAVE_SYS_MOUNT_H #ifdef HAVE_SYS_IOCTL_H -#ifdef BLKGETSIZE - DEBUG("looking for export size with ioctl BLKGETSIZE\n"); - if (!ioctl(fhandle, BLKGETSIZE, §ors) && sectors) { - es = (off_t)sectors * (off_t)512; - return es; +#ifdef BLKGETSIZE64 + DEBUG("looking for export size with ioctl BLKGETSIZE64\n"); + if (!ioctl(fhandle, BLKGETSIZE64, bytes) && bytes) { + return (off_t)bytes; } -#endif /* BLKGETSIZE */ +#endif /* BLKGETSIZE64 */ #endif /* HAVE_SYS_IOCTL_H */ #endif /* HAVE_SYS_MOUNT_H */