Fix autodetection
authorWouter Verhelst <w@uter.be>
Mon, 8 Jun 2009 21:02:29 +0000 (23:02 +0200)
committerWouter Verhelst <w@uter.be>
Mon, 8 Jun 2009 21:02:29 +0000 (23:02 +0200)
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

index 4ac6d1f..4426345 100644 (file)
@@ -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, &sectors) && 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 */