From 4ac6a56d98e38578bc52792e977bf569fb39d556 Mon Sep 17 00:00:00 2001 From: Kenneth Bell Date: Tue, 21 Dec 2010 11:53:04 +0000 Subject: [PATCH] Add block device support to file_getfilesize on Linux FileStream.Length for a block device (such as '/dev/sr0') now returns actual size, rather than Zero on Linux. --- mono/io-layer/io.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mono/io-layer/io.c b/mono/io-layer/io.c index 7f3846d8fa8..e060a7d3724 100644 --- a/mono/io-layer/io.c +++ b/mono/io-layer/io.c @@ -28,6 +28,10 @@ #include #include #include +#ifdef __linux__ +#include +#include +#endif #include #include @@ -798,6 +802,34 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) return(INVALID_FILE_SIZE); } + /* fstat indicates block devices as zero-length, so go a different path */ +#ifdef BLKGETSIZE64 + if (S_ISBLK(statbuf.st_mode)) { + guint64 bigsize; + if (ioctl(fd, BLKGETSIZE64, &bigsize) < 0) { +#ifdef DEBUG + g_message ("%s: handle %p ioctl BLKGETSIZE64 failed: %s", + __func__, handle, strerror(errno)); +#endif + + _wapi_set_last_error_from_errno (); + return(INVALID_FILE_SIZE); + } + + size = bigsize & 0xFFFFFFFF; + if (highsize != NULL) { + *highsize = bigsize>>32; + } + +#ifdef DEBUG + g_message ("%s: Returning block device size %d/%d", + __func__, size, *highsize); +#endif + + return(size); + } +#endif + #ifdef HAVE_LARGE_FILE_SUPPORT size = statbuf.st_size & 0xFFFFFFFF; if (highsize != NULL) { -- 2.25.1