From 5dfbb9438e2bc205b159d67b97e2d7504de99c80 Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Tue, 24 Feb 2009 07:30:10 +0000 Subject: Attempt at raw drive access for linux / osx, test please :) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2410 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/FileUtil.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/Src/FileUtil.cpp') diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index e371ab78e5..07ffc9d1f3 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include #endif #include @@ -72,11 +75,33 @@ bool Exists(const char *filename) bool IsDisk(const char *filename) { #ifdef _WIN32 - std::string copy = filename; - if (copy.size() < 4 && copy.c_str()[1] == ':') + if (GetDriveType(filename) == DRIVE_CDROM) // CD_ROM also applies to DVD. Noone has a plain CDROM without DVD anymore so we should be fine. return true; #else - // TODO: add linux \ osx + struct stat statInfo; + if((stat(filename, &statInfo) > -1) && (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))) + { + int fileHandle; + // try to open the device + fileHandle = open(filename, O_RDONLY | O_NONBLOCK, 0); + if (fileHandle >= 0) + { + cdrom_subchnl cdChannelInfo; + cdChannelInfo.cdsc_format = CDROM_MSF; + + if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) || + (errno == EIO) || (errno == ENOENT) || + (errno == EINVAL) + #ifdef __GNUC__ + || (errno == ENOMEDIUM) + #endif + ) + { + return true; + } + close(fileHandle); + } + } #endif return false; } -- cgit v1.2.3