VirtualBox

Changeset 35190 in vbox


Ignore:
Timestamp:
Dec 16, 2010 3:24:55 PM (14 years ago)
Author:
vboxsync
Message:

AsyncCompletion: Fixed querying the size of a block device on OS X

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp

    r34612 r35190  
    4141#include <iprt/path.h>
    4242
     43#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     44# include <errno.h>
     45# include <sys/ioctl.h>
     46# include <sys/types.h>
     47# include <sys/stat.h>
     48# include <fcntl.h>
     49# include <unistd.h>
     50#endif
     51
    4352#ifdef RT_OS_WINDOWS
    4453# define _WIN32_WINNT 0x0500
     
    4655# include <winioctl.h>
    4756#endif
     57#ifdef RT_OS_DARWIN
     58# include <sys/disk.h>
     59#endif /* RT_OS_DARWIN */
     60#ifdef RT_OS_SOLARIS
     61# include <stropts.h>
     62# include <sys/dkio.h>
     63# include <sys/vtoc.h>
     64#endif /* RT_OS_SOLARIS */
     65#ifdef RT_OS_FREEBSD
     66# include <sys/disk.h>
     67#endif /* RT_OS_FREEBSD */
    4868
    4969#include "PDMAsyncCompletionFileInternal.h"
     
    614634            rc = RTErrConvertFromWin32(GetLastError());
    615635        }
     636#elif defined(RT_OS_DARWIN)
     637        struct stat DevStat;
     638        if (!fstat(hFile, &DevStat) && S_ISBLK(DevStat.st_mode))
     639        {
     640            uint64_t cBlocks;
     641            uint32_t cbBlock;
     642            if (!ioctl(hFile, DKIOCGETBLOCKCOUNT, &cBlocks))
     643            {
     644                if (!ioctl(hFile, DKIOCGETBLOCKSIZE, &cbBlock))
     645                    cbSize = cBlocks * cbBlock;
     646                else
     647                    rc = RTErrConvertFromErrno(errno);
     648            }
     649            else
     650                rc = RTErrConvertFromErrno(errno);
     651        }
     652        else
     653            rc = VERR_INVALID_PARAMETER;
     654#elif defined(RT_OS_SOLARIS)
     655        struct stat DevStat;
     656        if (!fstat(hFile, &DevStat) && (   S_ISBLK(DevStat.st_mode)
     657                                        || S_ISCHR(DevStat.st_mode)))
     658        {
     659            struct dk_minfo mediainfo;
     660            if (!ioctl(hFile, DKIOCGMEDIAINFO, &mediainfo))
     661                cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize;
     662            else
     663                rc = RTErrConvertFromErrno(errno);
     664        }
     665        else
     666            rc = VERR_INVALID_PARAMETER;
     667#elif defined(RT_OS_FREEBSD)
     668        struct stat DevStat;
     669        if (!fstat(hFile, &DevStat) && S_ISCHR(DevStat.st_mode))
     670        {
     671            off_t cbMedia = 0;
     672            if (!ioctl(hFile, DIOCGMEDIASIZE, &cbMedia))
     673            {
     674                cbSize = cbMedia;
     675            }
     676            else
     677                rc = RTErrConvertFromErrno(errno);
     678        }
     679        else
     680            rc = VERR_INVALID_PARAMETER;
    616681#else
    617682        /* Could be a block device */
    618683        rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &cbSize);
    619 
    620 #endif
     684#endif
     685
    621686        if (RT_SUCCESS(rc) && (cbSize != 0))
    622687            *pcbSize = cbSize;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette