Changeset 8811 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 14, 2008 1:51:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r8516 r8811 53 53 #include <windows.h> 54 54 #include <winioctl.h> 55 #elif RT_OS_LINUX55 #elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 56 56 #include <errno.h> 57 57 #include <sys/ioctl.h> 58 58 #include <sys/types.h> 59 59 #include <sys/stat.h> 60 #include <fcntl.h> 60 61 #include <unistd.h> 62 #endif 63 #ifdef RT_OS_LINUX 64 #include <sys/utsname.h> 61 65 #include <linux/hdreg.h> 62 66 #include <linux/fs.h> 63 #endif /* !RT_OS_WINDOWS && !RT_OS_LINUX */ 67 #endif /* RT_OS_LINUX */ 68 #ifdef RT_OS_DARWIN 69 #include <sys/disk.h> 70 #endif /* RT_OS_DARWIN */ 64 71 65 72 using namespace com; … … 800 807 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode)) 801 808 { 802 /** @todo add a BLKGETSIZE64 ioctl here, as it eliminates the 2 TByte 803 * limit. But be careful, Linux 2.4.18 is the first revision with 804 * working BLKGETSIZE64, and in 2.5.x it's pretty random. 2.6.0 works. */ 805 long cBlocks; 806 if (!ioctl(RawFile, BLKGETSIZE, &cBlocks)) 807 cbSize = (uint64_t)cBlocks * 512; 809 #ifdef BLKGETSIZE64 810 /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.0 811 * it works without problems. */ 812 struct utsname utsname; 813 if ( uname(&utsname) == 0 814 && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18) 815 || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6))) 816 { 817 uint64_t cbBlk; 818 if (!ioctl(RawFile, BLKGETSIZE64, &cbBlk)) 819 cbSize = cbBlk; 820 } 821 #endif /* BLKGETSIZE64 */ 822 if (!cbSize) 823 { 824 long cBlocks; 825 if (!ioctl(RawFile, BLKGETSIZE, &cBlocks)) 826 cbSize = (uint64_t)cBlocks << 9; 827 else 828 return RTErrConvertFromErrno(errno); 829 } 830 } 831 else 832 { 833 RTPrintf("File '%s' is no disk\n", rawdisk.raw()); 834 return VERR_INVALID_PARAMETER; 835 } 836 #elif defined(RT_OS_DARWIN) 837 struct stat DevStat; 838 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode)) 839 { 840 uint64_t cBlocks; 841 uint32_t cbBlock; 842 if (!ioctl(fd, DKIOCGETBLOCKCOUNT, &cBlocks)) 843 { 844 if (!ioctl(fd, DKIOCGETBLOCKSIZE, &cbBlock)) 845 cbSize = cBlocks * cbBlock; 846 else 847 return RTErrConvertFromErrno(errno); 848 } 808 849 else 809 850 return RTErrConvertFromErrno(errno); … … 814 855 return VERR_INVALID_PARAMETER; 815 856 } 816 #else /* !RT_OS_WINDOWS && !RT_OS_LINUX*/857 #else /* all unrecognized OSes */ 817 858 /* Hopefully this works on all other hosts. If it doesn't, it'll just fail 818 859 * creating the VMDK, so no real harm done. */ … … 823 864 return vrc; 824 865 } 825 #endif /* !RT_OS_WINDOWS && !RT_OS_LINUX */866 #endif 826 867 827 868 PVBOXHDD pDisk = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.