Changeset 32976 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Oct 7, 2010 1:35:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r32973 r32976 1031 1031 } 1032 1032 1033 int rtISO9660 ReadFileInternal(VBoxISO9660File *pFile, const char *pszPath,1034 uint32_t cbOffset, size_t cbToRead, size_t *pcbRead)1033 int rtISO9660GetDirectoryRecord(VBoxISO9660File *pFile, const char *pszPath, 1034 VBoxISO9660DirRecord **ppRecord) 1035 1035 { 1036 1036 AssertPtrReturn(pFile, VERR_INVALID_PARAMETER); 1037 1037 AssertPtrReturn(pszPath, VERR_INVALID_PARAMETER); 1038 AssertPtrReturn(ppRecord, VERR_INVALID_PARAMETER); 1038 1039 1039 1040 uint32_t uSector; … … 1041 1042 if (RT_SUCCESS(rc)) 1042 1043 { 1043 /* Seek to directory table. */1044 /* Seek and read the directory record of given file. */ 1044 1045 rc = RTFileSeek(pFile->file, uSector * VBOX_ISO9660_SECTOR_SIZE, 1045 1046 RTFILE_SEEK_BEGIN, NULL); … … 1047 1048 { 1048 1049 size_t cbRead; 1049 VBoxISO9660DirRecord dir_table; 1050 rc = RTFileRead(pFile->file, (VBoxISO9660DirRecord*)&dir_table, sizeof(VBoxISO9660DirRecord), &cbRead); 1050 VBoxISO9660DirRecord *pRecord = (VBoxISO9660DirRecord*)RTMemAlloc(sizeof(VBoxISO9660DirRecord)); 1051 if (pRecord) 1052 { 1053 rc = RTFileRead(pFile->file, (VBoxISO9660DirRecord*)pRecord, sizeof(VBoxISO9660DirRecord), &cbRead); 1054 if (RT_SUCCESS(rc)) 1055 { 1056 Assert(cbRead == sizeof(VBoxISO9660DirRecord)); 1057 *ppRecord = pRecord; 1058 } 1059 if (RT_FAILURE(rc)) 1060 RTMemFree(pRecord); 1061 } 1062 else 1063 rc = VERR_NO_MEMORY; 1064 } 1065 } 1066 return rc; 1067 } 1068 1069 int RTISO9660GetFileInfo(VBoxISO9660File *pFile, const char *pszPath, 1070 uint32_t *pcbOffset, uint32_t *pcbLength) 1071 { 1072 AssertPtrReturn(pFile, VERR_INVALID_PARAMETER); 1073 AssertPtrReturn(pszPath, VERR_INVALID_PARAMETER); 1074 AssertPtrReturn(pcbOffset, VERR_INVALID_PARAMETER); 1075 1076 VBoxISO9660DirRecord *pDirRecord; 1077 int rc = rtISO9660GetDirectoryRecord(pFile, pszPath, &pDirRecord); 1078 if (RT_SUCCESS(rc)) 1079 { 1080 /* Get actual file record. */ 1081 VBoxISO9660DirRecord *pFileRecord; 1082 rc = rtISO9660FindEntry(pFile, 1083 RTPathFilename(pszPath), 1084 pDirRecord->extent_location, 1085 pDirRecord->extent_data_length, 1086 &pFileRecord); 1087 if (RT_SUCCESS(rc)) 1088 { 1089 *pcbOffset = pFileRecord->extent_location * VBOX_ISO9660_SECTOR_SIZE; 1090 *pcbLength = pFileRecord->extent_data_length; 1091 RTMemFree(pFileRecord); 1092 } 1093 RTMemFree(pDirRecord); 1094 } 1095 return rc; 1096 } 1097 1098 int RTISO9660ExtractFile(VBoxISO9660File *pFile, const char *pszSource, 1099 const char *pszDest) 1100 { 1101 uint32_t cbOffset, cbLength; 1102 int rc = RTISO9660GetFileInfo(pFile, pszSource, &cbOffset, &cbLength); 1103 if (RT_SUCCESS(rc)) 1104 { 1105 rc = RTFileSeek(pFile->file, cbOffset, RTFILE_SEEK_BEGIN, NULL); 1106 if (RT_SUCCESS(rc)) 1107 { 1108 RTFILE fileDest; 1109 rc = RTFileOpen(&fileDest, pszDest, RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE); 1051 1110 if (RT_SUCCESS(rc)) 1052 1111 { 1053 Assert(cbRead == sizeof(VBoxISO9660DirRecord)); 1054 VBoxISO9660DirRecord *pRecord = NULL; 1055 rc = rtISO9660FindEntry(pFile, 1056 RTPathFilename(pszPath), 1057 dir_table.extent_location, 1058 dir_table.extent_data_length, 1059 &pRecord); 1060 if ( RT_SUCCESS(rc) 1061 && pRecord) 1062 { 1063 RTMemFree(pRecord); 1064 } 1065 } 1066 else 1067 rc = VERR_INVALID_PARAMETER; 1112 size_t cbToRead, cbRead, cbWritten; 1113 uint8_t byBuffer[_4K]; 1114 while ( cbLength > 0 1115 && RT_SUCCESS(rc)) 1116 { 1117 cbToRead = RT_MIN(cbLength, _4K); 1118 rc = RTFileRead(pFile->file, (uint8_t*)byBuffer, cbToRead, &cbRead); 1119 if (RT_FAILURE(rc)) 1120 break; 1121 rc = RTFileWrite(fileDest, (uint8_t*)byBuffer, cbRead, &cbWritten); 1122 if (RT_FAILURE(rc)) 1123 break; 1124 cbLength -= cbRead; 1125 } 1126 RTFileClose(fileDest); 1127 } 1068 1128 } 1069 1129 } … … 1071 1131 } 1072 1132 1073 int RTISO9660ReadFile(VBoxISO9660File *pFile, const char *pszFileName,1074 uint32_t cbOffset, size_t cbToRead, size_t *pcbRead)1075 {1076 return rtISO9660ReadFileInternal(pFile, pszFileName, cbOffset, cbToRead, pcbRead);1077 }1078 1133 #endif 1079 1134 … … 1084 1139 if (RT_SUCCESS(vrc)) 1085 1140 { 1086 uint32_t uOffset = 0; 1087 size_t cbRead; 1088 while (RT_SUCCESS(vrc)) 1089 { 1090 vrc = RTISO9660ReadFile(&file, "32BIT/OS2/readme.txt", 1091 uOffset, _4K, &cbRead); 1092 uOffset += cbRead; 1093 } 1141 //vrc = RTISO9660ExtractFile(&file, "VBOXWINDOWSADDITIONS_X86.EXE", "C:\\VBOXWINDOWSADDITIONS_X86.EXE"); 1142 vrc = RTISO9660ExtractFile(&file, "32BIT/OS2/README.TXT", "C:\\OS2-Readme.txt"); 1094 1143 RTISO9660Close(&file); 1095 1144 }
Note:
See TracChangeset
for help on using the changeset viewer.