From 5f2bea6836c576802883c70959dcb34deafb3d71 Mon Sep 17 00:00:00 2001 From: Wouter Verhelst Date: Mon, 8 Jun 2009 23:02:29 +0200 Subject: [PATCH] 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. --- nbd-server.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 */ -- 1.7.10.4