From 0be93e7b89131cb15c6983ec3176e448f6aa11d4 Mon Sep 17 00:00:00 2001 From: nretro Date: Sat, 25 May 2019 20:02:49 +0200 Subject: [PATCH] get size of special file by calling ioctl --- file_io.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index 5dddd5e..85dd53e 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -320,14 +322,26 @@ int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute) FileClose(file); return 0; } - - file->size = st.st_size; + if ((st.st_rdev != 0) && (st.st_size == 0)) //for special files we need an ioctl call to get the correct size + { + unsigned long long blksize; + int ret = ioctl(fd, BLKGETSIZE64, &blksize); + if (ret < 0 ) + { + if (!mute) printf("FileOpenEx(ioctl) File:%s, error: %d.\n", full_path, ret); + FileClose(file); + return 0; + } + file->size = blksize; + } + else + file->size = st.st_size; file->offset = 0; file->mode = mode; } } - //printf("opened %s, size %lu\n", full_path, file->size); + //printf("opened %s, size %llu\n", full_path, file->size); return 1; }