Renamed symbols, mainly Native to Host

VolumeLetter into DriveLetter (the official term)
XboxFullPath into XboxDevicePath
NativePath into HostPath / HostDevicePath
NativeRootHandle into HostRootHandle
Also, small improvements to _CxbxConvertFilePath
Added drive A, S and V
This commit is contained in:
PatrickvL 2016-12-23 16:21:43 +01:00
parent 591fe83b40
commit 8af250f042
6 changed files with 156 additions and 131 deletions

View File

@ -467,7 +467,7 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
strcat(szBuffer, "\\Cxbx-Reloaded\\");
std::string basePath(szBuffer);
CxbxBasePath = basePath + "\\EmuDisk\\";
CxbxBasePath = basePath + "EmuDisk\\";
// Determine XBE Path
memset(szBuffer, 0, MAX_PATH);
@ -485,19 +485,19 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
std::string titleId(szBuffer);
// Games may assume they are running from CdRom :
CxbxRegisterDeviceNativePath(DeviceCdrom0, xbeDirectory);
CxbxDefaultXbeDriveIndex = CxbxRegisterDeviceHostPath(DeviceCdrom0, xbeDirectory);
// Partition 0 contains configuration data, and is accessed as a native file, instead as a folder :
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition0, CxbxBasePath + "Partition0", /*IsFile=*/true);
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition0, CxbxBasePath + "Partition0", /*IsFile=*/true);
// The first two partitions are for Data and Shell files, respectively :
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition1, CxbxBasePath + "Partition1");
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition2, CxbxBasePath + "Partition2");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition1, CxbxBasePath + "Partition1");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition2, CxbxBasePath + "Partition2");
// The following partitions are for caching purposes - for now we allocate up to 7 (as xbmp needs that many) :
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition3, CxbxBasePath + "Partition3");
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition4, CxbxBasePath + "Partition4");
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition5, CxbxBasePath + "Partition5");
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition6, CxbxBasePath + "Partition6");
CxbxRegisterDeviceNativePath(DeviceHarddisk0Partition7, CxbxBasePath + "Partition7");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition3, CxbxBasePath + "Partition3");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition4, CxbxBasePath + "Partition4");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition5, CxbxBasePath + "Partition5");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition6, CxbxBasePath + "Partition6");
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition7, CxbxBasePath + "Partition7");
DbgPrintf("EmuMain : Creating default symbolic links.\n");
@ -506,7 +506,7 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
{
// Arrange that the Xbe path can reside outside the partitions, and put it to g_hCurDir :
CxbxCreateSymbolicLink(DriveC, xbeDirectory);
EmuNtSymbolicLinkObject* xbePathSymbolicLinkObject = FindNtSymbolicLinkObjectByVolumeLetter(CxbxDefaultXbeVolumeLetter);
EmuNtSymbolicLinkObject* xbePathSymbolicLinkObject = FindNtSymbolicLinkObjectByDriveLetter(CxbxDefaultXbeDriveLetter);
g_hCurDir = xbePathSymbolicLinkObject->RootDirectoryHandle;
// Determine Xbox path to XBE and place it in XeImageFileName
@ -522,16 +522,20 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
xboxkrnl::XeImageFileName.MaximumLength = MAX_PATH;
xboxkrnl::XeImageFileName.Buffer = (PCHAR)malloc(MAX_PATH);
sprintf(xboxkrnl::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeVolumeLetter, fileName.c_str());
sprintf(xboxkrnl::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeDriveLetter, fileName.c_str());
xboxkrnl::XeImageFileName.Length = (USHORT)strlen(xboxkrnl::XeImageFileName.Buffer);
DbgPrintf("EmuMain : XeImageFileName = %s\n", xboxkrnl::XeImageFileName.Buffer);
CxbxCreateSymbolicLink(DriveA, DeviceCdrom0); // CdRom could be read from A:
CxbxCreateSymbolicLink(DriveD, DeviceCdrom0); // CdRom goes to D:
CxbxCreateSymbolicLink(DriveE, DeviceHarddisk0Partition1); // Partition1 goes to E: (Data files, savegames, etc.)
//CxbxCreateSymbolicLink(DriveE, DeviceHarddisk0Partition1 + "\\DevKit"); // Partition1 goes to E: (Devkit)
CxbxCreateSymbolicLink(DriveF, DeviceHarddisk0Partition2); // Partition2 goes to F: (Shell files, dashboard, etc.)
CxbxCreateSymbolicLink(DriveT, DeviceHarddisk0Partition1 + "\\TDATA\\" + titleId + "\\"); // Partition1\Title data goes to T:
CxbxCreateSymbolicLink(DriveU, DeviceHarddisk0Partition1 + "\\UDATA\\" + titleId + "\\"); // Partition1\User data goes to U:
CxbxCreateSymbolicLink(DriveS, DeviceHarddisk0Partition1 + "\\TDATA"); // Partition1\TDATA data goes to S:
CxbxCreateSymbolicLink(DriveT, DeviceHarddisk0Partition1 + "\\TDATA\\" + titleId); // Partition1 Title data goes to T:
CxbxCreateSymbolicLink(DriveU, DeviceHarddisk0Partition1 + "\\UDATA\\" + titleId); // Partition1 User data goes to U:
CxbxCreateSymbolicLink(DriveV, DeviceHarddisk0Partition1 + "\\UDATA"); // Partition1\UDATA data goes to V:
CxbxCreateSymbolicLink(DriveX, DeviceHarddisk0Partition3); // Partition3 goes to X:
CxbxCreateSymbolicLink(DriveY, DeviceHarddisk0Partition4); // Partition4 goes to Y:

View File

@ -54,10 +54,12 @@ const std::string DriveCdRom0 = DrivePrefix + "CdRom0:"; // CD-ROM device
const std::string DriveMbfs = DrivePrefix + "mbfs:"; // media board's file system area device
const std::string DriveMbcom = DrivePrefix + "mbcom:"; // media board's communication area device
const std::string DriveMbrom = DrivePrefix + "mbrom:"; // media board's boot ROM device
const std::string DriveA = DrivePrefix + "A:"; // A: could be CDROM
const std::string DriveC = DrivePrefix + "C:"; // C: is HDD0
const std::string DriveD = DrivePrefix + "D:"; // D: is DVD Player
const std::string DriveE = DrivePrefix + "E:";
const std::string DriveF = DrivePrefix + "F:";
const std::string DriveS = DrivePrefix + "S:";
const std::string DriveT = DrivePrefix + "T:"; // T: is Title persistent data region
const std::string DriveU = DrivePrefix + "U:"; // U: is User persistent data region
const std::string DriveV = DrivePrefix + "V:";
@ -90,13 +92,15 @@ const std::string DeviceHarddisk0Partition17 = DeviceHarddisk0PartitionPrefix +
const std::string DeviceHarddisk0Partition18 = DeviceHarddisk0PartitionPrefix + "18";
const std::string DeviceHarddisk0Partition19 = DeviceHarddisk0PartitionPrefix + "19";
const std::string DeviceHarddisk0Partition20 = DeviceHarddisk0PartitionPrefix + "20"; // 20 = Largest possible partition number
const char CxbxDefaultXbeVolumeLetter = 'C';
const char CxbxDefaultXbeDriveLetter = 'C';
int CxbxDefaultXbeDriveIndex = -1;
EmuNtSymbolicLinkObject* NtSymbolicLinkObjects[26];
struct XboxDevice {
std::string XboxFullPath;
std::string NativePath;
HANDLE NativeRootHandle;
std::string XboxDevicePath;
std::string HostDevicePath;
HANDLE HostRootHandle;
};
std::vector<XboxDevice> Devices;
@ -188,12 +192,16 @@ void copy_string_to_PSTRING_to(std::string const & src, const xboxkrnl::PSTRING
memcpy(dest->Buffer, src.c_str(), dest->Length);
}
NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &RelativeNativePath, NtDll::HANDLE *RootDirectory, std::string aFileAPIName)
NTSTATUS _CxbxConvertFilePath(
std::string RelativeXboxPath,
OUT std::wstring &RelativeHostPath,
OUT NtDll::HANDLE *RootDirectory,
std::string aFileAPIName)
{
std::string OriginalPath = RelativeXboxPath;
std::string RelativePath = RelativeXboxPath;
std::string XboxFullPath;
std::string NativePath;
std::string HostPath;
EmuNtSymbolicLinkObject* NtSymbolicLinkObject = NULL;
// Always trim '\??\' off :
@ -207,14 +215,14 @@ NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &Relati
if ((RelativePath.length() >= 2) && (RelativePath[1] == ':'))
{
// Look up the symbolic link information using the drive letter :
NtSymbolicLinkObject = FindNtSymbolicLinkObjectByVolumeLetter(RelativePath[0]);
NtSymbolicLinkObject = FindNtSymbolicLinkObjectByDriveLetter(RelativePath[0]);
RelativePath.erase(0, 2); // Remove 'C:'
// If the remaining path starts with a ':', remove it (to prevent errors) :
if ((RelativePath.length() > 0) && (RelativePath[0] == ':'))
RelativePath.erase(0, 1); // xbmp needs this, as it accesses 'e::\'
}
else if (RelativePath.compare(0, 1, "$") == 0)
else if (RelativePath[0] == '$')
{
if (RelativePath.compare(0, 5, "$HOME") == 0) // "xbmp" needs this
{
@ -225,35 +233,39 @@ NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &Relati
CxbxKrnlCleanup(("Unsupported path macro : " + OriginalPath).c_str());
}
// Check if the path starts with a relative path indicator :
else if (RelativePath.compare(0, 1, ".") == 0) // "4x4 Evo 2" needs this
else if (RelativePath[0] == '.') // "4x4 Evo 2" needs this
{
NtSymbolicLinkObject = FindNtSymbolicLinkObjectByRootHandle(g_hCurDir);
RelativePath.erase(0, 1); // Remove the '.'
}
else
{
// TODO : How should we handle accesses to the serial: (?semi-)volume?
if (RelativePath.compare(0, 7, "serial:") == 0)
return STATUS_UNRECOGNIZED_VOLUME;
// The path seems to be a device path, look it up :
NtSymbolicLinkObject = FindNtSymbolicLinkObjectByDevice(RelativePath);
// Fixup RelativePath path here
if ((NtSymbolicLinkObject != NULL))
RelativePath.erase(0, NtSymbolicLinkObject->XboxFullPath.length()); // Remove '\Device\Harddisk0\Partition2'
if (NtSymbolicLinkObject != NULL)
RelativePath.erase(0, NtSymbolicLinkObject->XboxSymbolicLinkPath.length()); // Remove '\Device\Harddisk0\Partition2'
// else TODO : Turok requests 'gamedata.dat' without a preceding path, we probably need 'CurrentDir'-functionality
}
if ((NtSymbolicLinkObject != NULL))
if (NtSymbolicLinkObject != NULL)
{
NativePath = NtSymbolicLinkObject->NativePath;
HostPath = NtSymbolicLinkObject->HostSymbolicLinkPath;
// If the remaining path starts with a '\', remove it (to prevent working in a native root) :
if ((RelativePath.length() > 0) && (RelativePath[0] == '\\'))
{
RelativePath.erase(0, 1);
// And if needed, add it to the Native path instead :
if (NativePath.back() != '\\')
NativePath.append(1, '\\');
// And if needed, add it to the host path instead :
if (HostPath.back() != '\\')
HostPath.append(1, '\\');
}
XboxFullPath = NtSymbolicLinkObject->XboxFullPath;
XboxFullPath = NtSymbolicLinkObject->XboxSymbolicLinkPath;
*RootDirectory = NtSymbolicLinkObject->RootDirectoryHandle;
}
else
@ -270,7 +282,7 @@ NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &Relati
RelativePath.erase(0, DeviceHarddisk0.length() + 1);
// And set Root to the folder containing the partition-folders :
*RootDirectory = CxbxBasePathHandle;
NativePath = CxbxBasePath;
HostPath = CxbxBasePath;
}
// Check for special case : Partition0
@ -285,9 +297,9 @@ NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &Relati
DbgPrintf("EmuKrnl : %s Corrected path...\n", aFileAPIName.c_str());
DbgPrintf(" Org:\"%s\"\n", OriginalPath.c_str());
if (_strnicmp(NativePath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0)
if (_strnicmp(HostPath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0)
{
DbgPrintf(" New:\"$CxbxPath\\EmuDisk\\%s\\%s\"\n", (NativePath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str());
DbgPrintf(" New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str());
}
else
DbgPrintf(" New:\"$XbePath\\%s\"\n", RelativePath.c_str());
@ -301,19 +313,19 @@ NTSTATUS _CxbxConvertFilePath(std::string RelativeXboxPath, std::wstring &Relati
}
// Convert the relative path to unicode
RelativeNativePath = string_to_wstring(RelativePath);
RelativeHostPath = string_to_wstring(RelativePath);
return STATUS_SUCCESS;
}
NTSTATUS CxbxObjectAttributesToNT(
xboxkrnl::POBJECT_ATTRIBUTES ObjectAttributes,
NativeObjectAttributes& nativeObjectAttributes,
OUT NativeObjectAttributes& nativeObjectAttributes,
const std::string aFileAPIName)
{
NTSTATUS result = STATUS_SUCCESS;
std::string RelativeXboxPath;
std::wstring RelativeNativePath;
std::wstring RelativeHostPath;
NtDll::HANDLE RootDirectory;
if (ObjectAttributes == NULL)
@ -327,46 +339,47 @@ NTSTATUS CxbxObjectAttributesToNT(
nativeObjectAttributes.NtObjAttrPtr = &nativeObjectAttributes.NtObjAttr;
RelativeXboxPath = PSTRING_to_string(ObjectAttributes->ObjectName);
result = _CxbxConvertFilePath(RelativeXboxPath, RelativeNativePath, &RootDirectory, aFileAPIName);
result = _CxbxConvertFilePath(RelativeXboxPath, /*OUT*/RelativeHostPath, /*OUT*/&RootDirectory, aFileAPIName);
if (!FAILED(result))
{
// Copy relative path string to the unicode string
wcscpy_s(nativeObjectAttributes.wszObjectName, RelativeHostPath.c_str());
NtDll::RtlInitUnicodeString(&nativeObjectAttributes.NtUnicodeString, nativeObjectAttributes.wszObjectName);
// Copy relative path string to the unicode string
wcscpy_s(nativeObjectAttributes.wszObjectName, RelativeNativePath.c_str());
NtDll::RtlInitUnicodeString(&nativeObjectAttributes.NtUnicodeString, nativeObjectAttributes.wszObjectName);
// Initialize the NT ObjectAttributes
InitializeObjectAttributes(&nativeObjectAttributes.NtObjAttr, &nativeObjectAttributes.NtUnicodeString, ObjectAttributes->Attributes, RootDirectory, NULL);
// Initialize the NT ObjectAttributes
InitializeObjectAttributes(&nativeObjectAttributes.NtObjAttr, &nativeObjectAttributes.NtUnicodeString, ObjectAttributes->Attributes, RootDirectory, NULL);
}
return result;
}
bool CxbxRegisterDeviceNativePath(std::string XboxFullPath, std::string NativePath, bool IsFile)
int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile)
{
bool result;
int result = -1;
if (IsFile) {
if (!PathFileExists(NativePath.c_str())) {
HANDLE hf = CreateFile(NativePath.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if (!PathFileExists(HostDevicePath.c_str())) {
HANDLE hf = CreateFile(HostDevicePath.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
SetFilePointer(hf, 512 * 1024, 0, FILE_BEGIN);
SetEndOfFile(hf);
CloseHandle(hf);
}
return true; // Actually, this is the Config sectors partition (partition0) registered as a file
// Actually, this is the Config sectors partition (partition0) registered as a file
}
else
{
int status = SHCreateDirectoryEx(NULL, NativePath.c_str(), NULL);
result = status == STATUS_SUCCESS || ERROR_ALREADY_EXISTS;
}
int status = SHCreateDirectoryEx(NULL, HostDevicePath.c_str(), NULL);
if (status == STATUS_SUCCESS || status == ERROR_ALREADY_EXISTS)
{
XboxDevice newDevice;
if (result)
{
XboxDevice newDevice;
newDevice.XboxFullPath = XboxFullPath;
newDevice.NativePath = NativePath;
Devices.push_back(newDevice);
newDevice.XboxDevicePath = XboxDevicePath;
newDevice.HostDevicePath = HostDevicePath;
Devices.push_back(newDevice);
result = Devices.size() - 1;
}
}
return result;
@ -378,10 +391,9 @@ NTSTATUS CxbxCreateSymbolicLink(std::string SymbolicLinkName, std::string FullPa
NTSTATUS result = 0;
EmuNtSymbolicLinkObject* SymbolicLinkObject = FindNtSymbolicLinkObjectByName(SymbolicLinkName);
if ((SymbolicLinkObject != NULL)) {
// In that case, close it :
if (SymbolicLinkObject != NULL)
// In that case, close it (will also delete if reference count drops to zero)
SymbolicLinkObject->NtClose();
}
// Now (re)create a symbolic link object, and initialize it with the new definition :
SymbolicLinkObject = new EmuNtSymbolicLinkObject();
@ -397,29 +409,27 @@ NTSTATUS CxbxCreateSymbolicLink(std::string SymbolicLinkName, std::string FullPa
NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::string aFullPath)
{
NTSTATUS result = STATUS_OBJECT_NAME_INVALID;
bool IsNativePath = false;
int i = 0;
std::string ExtraPath;
int DeviceIndex = 0;
DriveLetter = SymbolicLinkToDriveLetter(aSymbolicLinkName);
if (DriveLetter >= 'A' && DriveLetter <= 'Z')
{
result = STATUS_OBJECT_NAME_COLLISION;
if (FindNtSymbolicLinkObjectByVolumeLetter(DriveLetter) == NULL)
if (FindNtSymbolicLinkObjectByDriveLetter(DriveLetter) == NULL)
{
// Look up the partition in the list of pre-registered devices :
result = STATUS_DEVICE_DOES_NOT_EXIST; // TODO : Is this the correct error?
// Make a distinction between Xbox paths (starting with '\Device'...) and Native paths :
IsNativePath = _strnicmp(aFullPath.c_str(), DevicePrefix.c_str(), DevicePrefix.length()) != 0;
if (IsNativePath)
DeviceIndex = 0;
// Make a distinction between Xbox paths (starting with '\Device'...) and host paths :
IsHostBasedPath = _strnicmp(aFullPath.c_str(), DevicePrefix.c_str(), DevicePrefix.length()) != 0;
if (IsHostBasedPath)
DeviceIndex = CxbxDefaultXbeDriveIndex;
else
{
DeviceIndex = -1;
for (size_t i = 0; i < Devices.size(); i++) {
if (_strnicmp(aFullPath.c_str(), Devices[i].XboxFullPath.c_str(), Devices[i].XboxFullPath.length()) == 0)
if (_strnicmp(aFullPath.c_str(), Devices[i].XboxDevicePath.c_str(), Devices[i].XboxDevicePath.length()) == 0)
{
DeviceIndex = i;
break;
@ -431,33 +441,33 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin
{
result = STATUS_SUCCESS;
SymbolicLinkName = aSymbolicLinkName;
XboxFullPath = aFullPath; // TODO : What path do we remember in IsNativePath mode?
if (IsNativePath)
if (IsHostBasedPath)
{
NativePath = "";
ExtraPath = aFullPath;
XboxSymbolicLinkPath = "";
HostSymbolicLinkPath = aFullPath;
}
else
{
NativePath = Devices[DeviceIndex].NativePath;
XboxSymbolicLinkPath = aFullPath;
HostSymbolicLinkPath = Devices[DeviceIndex].HostDevicePath;
// Handle the case where a sub folder of the partition is mounted (instead of it's root) :
ExtraPath = aFullPath.substr(Devices[DeviceIndex].XboxFullPath.length(), std::string::npos);
std::string ExtraPath = aFullPath.substr(Devices[DeviceIndex].XboxDevicePath.length(), std::string::npos);
if (!ExtraPath.empty())
HostSymbolicLinkPath = HostSymbolicLinkPath + ExtraPath;
}
if (!ExtraPath.empty())
NativePath = NativePath + ExtraPath;
SHCreateDirectoryEx(NULL, NativePath.c_str(), NULL);
RootDirectoryHandle = CreateFile(NativePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
SHCreateDirectoryEx(NULL, HostSymbolicLinkPath.c_str(), NULL);
RootDirectoryHandle = CreateFile(HostSymbolicLinkPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (RootDirectoryHandle == INVALID_HANDLE_VALUE)
{
result = STATUS_DEVICE_DOES_NOT_EXIST; // TODO : Is this the correct error?
CxbxKrnlCleanup((std::string("Could not map ") + NativePath).c_str());
CxbxKrnlCleanup((std::string("Could not map ") + HostSymbolicLinkPath).c_str());
}
else
{
NtSymbolicLinkObjects[DriveLetter - 'A'] = this;
DbgPrintf("EmuMain : Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), NativePath.c_str());
DbgPrintf("EmuMain : Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str());
}
}
}
@ -505,29 +515,29 @@ char SymbolicLinkToDriveLetter(std::string SymbolicLinkName)
return NULL;
}
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByVolumeLetter(const char VolumeLetter)
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDriveLetter(const char DriveLetter)
{
if (VolumeLetter >= 'A' && VolumeLetter <= 'Z')
return NtSymbolicLinkObjects[VolumeLetter - 'A'];
if (DriveLetter >= 'A' && DriveLetter <= 'Z')
return NtSymbolicLinkObjects[DriveLetter - 'A'];
if (VolumeLetter >= 'a' && VolumeLetter <= 'z')
return NtSymbolicLinkObjects[VolumeLetter - 'a'];
if (DriveLetter >= 'a' && DriveLetter <= 'z')
return NtSymbolicLinkObjects[DriveLetter - 'a'];
return NULL;
}
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByName(std::string SymbolicLinkName)
{
return FindNtSymbolicLinkObjectByVolumeLetter(SymbolicLinkToDriveLetter(SymbolicLinkName));
return FindNtSymbolicLinkObjectByDriveLetter(SymbolicLinkToDriveLetter(SymbolicLinkName));
}
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDevice(std::string DeviceName)
{
for (char VolumeLetter = 'A'; VolumeLetter <= 'Z'; VolumeLetter++)
for (char DriveLetter = 'A'; DriveLetter <= 'Z'; DriveLetter++)
{
EmuNtSymbolicLinkObject* result = NtSymbolicLinkObjects[VolumeLetter - 'A'];
if ((result != NULL) && _strnicmp(DeviceName.c_str(), result->XboxFullPath.c_str(), result->XboxFullPath.length()) == 0)
EmuNtSymbolicLinkObject* result = NtSymbolicLinkObjects[DriveLetter - 'A'];
if ((result != NULL) && _strnicmp(DeviceName.c_str(), result->XboxSymbolicLinkPath.c_str(), result->XboxSymbolicLinkPath.length()) == 0)
return result;
}
@ -537,9 +547,9 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDevice(std::string DeviceName
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(const HANDLE Handle)
{
for (char VolumeLetter = 'A'; VolumeLetter <= 'Z'; VolumeLetter++)
for (char DriveLetter = 'A'; DriveLetter <= 'Z'; DriveLetter++)
{
EmuNtSymbolicLinkObject* result = NtSymbolicLinkObjects[VolumeLetter - 'A'];
EmuNtSymbolicLinkObject* result = NtSymbolicLinkObjects[DriveLetter - 'A'];
if ((result != NULL) && (Handle == result->RootDirectoryHandle))
return result;
}
@ -564,7 +574,8 @@ NtDll::FILE_LINK_INFORMATION * _XboxToNTLinkInfo(xboxkrnl::FILE_LINK_INFORMATION
std::string originalFileName(xboxLinkInfo->FileName, xboxLinkInfo->FileNameLength);
std::wstring convertedFileName;
NtDll::HANDLE RootDirectory;
_CxbxConvertFilePath(originalFileName, convertedFileName, &RootDirectory, "NtSetInformationFile");
NTSTATUS res = _CxbxConvertFilePath(originalFileName, /*OUT*/convertedFileName, /*OUT*/&RootDirectory, "NtSetInformationFile");
// TODO : handle if(FAILED(res))
// Build the native FILE_LINK_INFORMATION struct
*Length = sizeof(NtDll::FILE_LINK_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);
@ -584,7 +595,8 @@ NtDll::FILE_RENAME_INFORMATION * _XboxToNTRenameInfo(xboxkrnl::FILE_RENAME_INFOR
std::string originalFileName(xboxRenameInfo->FileName.Buffer, xboxRenameInfo->FileName.Length);
std::wstring convertedFileName;
NtDll::HANDLE RootDirectory;
_CxbxConvertFilePath(originalFileName, convertedFileName, &RootDirectory, "NtSetInformationFile");
NTSTATUS res = _CxbxConvertFilePath(originalFileName, /*OUT*/convertedFileName, /*OUT*/&RootDirectory, "NtSetInformationFile");
// TODO : handle if(FAILED(res))
// Build the native FILE_RENAME_INFORMATION struct
*Length = sizeof(NtDll::FILE_RENAME_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);

View File

@ -1,4 +1,3 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
@ -65,10 +64,12 @@ extern const std::string DriveCdRom0;
extern const std::string DriveMbfs;
extern const std::string DriveMbcom;
extern const std::string DriveMbrom;
extern const std::string DriveA;
extern const std::string DriveC;
extern const std::string DriveD;
extern const std::string DriveE;
extern const std::string DriveF;
extern const std::string DriveS;
extern const std::string DriveT;
extern const std::string DriveU;
extern const std::string DriveV;
@ -101,7 +102,8 @@ extern const std::string DeviceHarddisk0Partition17;
extern const std::string DeviceHarddisk0Partition18;
extern const std::string DeviceHarddisk0Partition19;
extern const std::string DeviceHarddisk0Partition20;
extern const char CxbxDefaultXbeVolumeLetter;
extern const char CxbxDefaultXbeDriveLetter;
extern int CxbxDefaultXbeDriveIndex;
extern std::string CxbxBasePath;
extern HANDLE CxbxBasePathHandle;
@ -200,8 +202,9 @@ class EmuNtSymbolicLinkObject : public EmuNtObject {
public:
char DriveLetter;
std::string SymbolicLinkName;
std::string XboxFullPath;
std::string NativePath;
bool IsHostBasedPath;
std::string XboxSymbolicLinkPath;
std::string HostSymbolicLinkPath;
HANDLE RootDirectoryHandle;
NTSTATUS Init(std::string aSymbolicLinkName, std::string aFullPath);
~EmuNtSymbolicLinkObject();
@ -217,12 +220,12 @@ HANDLE EmuHandleToHandle(EmuHandle* emuHandle);
CHAR* NtStatusToString(IN NTSTATUS Status);
char SymbolicLinkToDriveLetter(std::string aSymbolicLinkName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByVolumeLetter(const char VolumeLetter);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDriveLetter(const char DriveLetter);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByName(std::string SymbolicLinkName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDevice(std::string DeviceName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(HANDLE Handle);
void CleanupSymbolicLinks();
bool CxbxRegisterDeviceNativePath(std::string XboxFullPath, std::string NativePath, bool IsFile = false);
int CxbxRegisterDeviceHostPath(std::string XboxFullPath, std::string HostDevicePath, bool IsFile = false);
HANDLE CxbxGetDeviceNativeRootHandle(std::string XboxFullPath);
NTSTATUS CxbxCreateSymbolicLink(std::string SymbolicLinkName, std::string FullPath);
bool CxbxMountUtilityDrive(bool formatClean);

View File

@ -122,21 +122,22 @@ XBSYSAPI EXPORTNUM(66) xboxkrnl::NTSTATUS NTAPI xboxkrnl::IoCreateFile
NativeObjectAttributes nativeObjectAttributes;
NTSTATUS ret = CxbxObjectAttributesToNT(ObjectAttributes, nativeObjectAttributes, "IoCreateFile"); /*var*/
NTSTATUS ret = CxbxObjectAttributesToNT(ObjectAttributes, /*OUT*/nativeObjectAttributes, "IoCreateFile");
// redirect to NtCreateFile
ret = NtDll::NtCreateFile(
FileHandle,
DesiredAccess | GENERIC_READ,
nativeObjectAttributes.NtObjAttrPtr,
NtDll::PIO_STATUS_BLOCK(IoStatusBlock),
NtDll::PLARGE_INTEGER(AllocationSize),
FileAttributes,
ShareAccess,
Disposition,
CreateOptions,
NULL,
0);
if (!FAILED(ret))
// redirect to NtCreateFile
ret = NtDll::NtCreateFile(
FileHandle,
DesiredAccess | GENERIC_READ,
nativeObjectAttributes.NtObjAttrPtr,
NtDll::PIO_STATUS_BLOCK(IoStatusBlock),
NtDll::PLARGE_INTEGER(AllocationSize),
FileAttributes,
ShareAccess,
Disposition,
CreateOptions,
NULL,
0);
if (FAILED(ret))
{

View File

@ -1000,22 +1000,27 @@ XBSYSAPI EXPORTNUM(215) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQuerySymbolicLinkOb
// Retrieve the NtSymbolicLinkObject and populate the output arguments :
ret = STATUS_SUCCESS;
symbolicLinkObject = (EmuNtSymbolicLinkObject*)iEmuHandle->NtObject;
if (LinkTarget != NULL)
{
if (LinkTarget->Length > LinkTarget->MaximumLength)
if (symbolicLinkObject->IsHostBasedPath) {
// TODO : What should we do with symbolic links
ret = STATUS_UNRECOGNIZED_VOLUME;
} else {
if (LinkTarget != NULL)
{
ret = STATUS_BUFFER_TOO_SMALL;
LinkTarget->Length = LinkTarget->MaximumLength;
if (LinkTarget->Length > LinkTarget->MaximumLength)
{
ret = STATUS_BUFFER_TOO_SMALL;
LinkTarget->Length = LinkTarget->MaximumLength;
}
copy_string_to_PSTRING_to(symbolicLinkObject->XboxSymbolicLinkPath, LinkTarget);
}
copy_string_to_PSTRING_to(symbolicLinkObject->XboxFullPath, LinkTarget);
if (ReturnedLength != NULL)
{
*ReturnedLength = symbolicLinkObject->XboxSymbolicLinkPath.length(); // Return full length (even if buffer was too small)
}
}
if (ReturnedLength != NULL)
{
*ReturnedLength = symbolicLinkObject->XboxFullPath.length(); // Return full length (even if buffer was too small)
}
if (ret != STATUS_SUCCESS)
EmuWarning("NtQuerySymbolicLinkObject failed! (%s)", NtStatusToString(ret));

View File

@ -970,7 +970,7 @@ DWORD WINAPI XTL::EmuXLaunchNewImage
if (!lpTitlePath) {
char szDashboardPath[MAX_PATH];
EmuNtSymbolicLinkObject* symbolicLinkObject = FindNtSymbolicLinkObjectByDevice(DeviceHarddisk0Partition2);
sprintf(szDashboardPath, "%s\\xboxdash.xbe", symbolicLinkObject->NativePath.c_str());
sprintf(szDashboardPath, "%s\\xboxdash.xbe", symbolicLinkObject->HostSymbolicLinkPath.c_str());
if (PathFileExists(szDashboardPath)) {
MessageBox(CxbxKrnl_hEmuParent, "The title is rebooting to dashboard", "Cxbx-Reloaded", 0);
@ -988,8 +988,8 @@ DWORD WINAPI XTL::EmuXLaunchNewImage
// Convert Xbox XBE Path to Windows Path
char szXbePath[MAX_PATH];
EmuNtSymbolicLinkObject* symbolicLink = FindNtSymbolicLinkObjectByVolumeLetter(lpTitlePath[0]);
snprintf(szXbePath, MAX_PATH, "%s%s", symbolicLink->NativePath.c_str(), &lpTitlePath[2]);
EmuNtSymbolicLinkObject* symbolicLink = FindNtSymbolicLinkObjectByDriveLetter(lpTitlePath[0]);
snprintf(szXbePath, MAX_PATH, "%s%s", symbolicLink->HostSymbolicLinkPath.c_str(), &lpTitlePath[2]);
// Determine Working Directory
char szWorkingDirectoy[MAX_PATH];