Skip to content

Commit ab3dfd9

Browse files
authored
Merge pull request #18591 from mlevogiannis/fix-ps2-internal-hdd
PS2: Fix booting from internal HDD
2 parents 0f62d73 + 8f3147f commit ab3dfd9

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

frontend/drivers/platform_ps2.c

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@
5252

5353
static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE;
5454
static char cwd[FILENAME_MAX] = {0};
55-
static char mountString[10] = {0};
56-
static char mountPoint[50] = {0};
55+
static char mountPoint[10] = {0};
56+
static char partition[50] = {0};
5757
static enum HDD_MOUNT_STATUS hddMountStatus = HDD_MOUNT_INIT_STATUS_NOT_READY;
5858
static enum HDD_INIT_STATUS hddStatus = HDD_INIT_STATUS_UNKNOWN;
5959

6060
static void create_path_names(void)
6161
{
6262
char user_path[FILENAME_MAX];
6363
size_t _len = strlcpy(user_path, cwd, sizeof(user_path));
64-
strlcpy(user_path + _len, "/retroarch", sizeof(user_path) - _len);
64+
if (!PATH_CHAR_IS_SLASH(user_path[_len - 1])) {
65+
_len += strlcpy(user_path + _len, PATH_DEFAULT_SLASH(), sizeof(user_path) - _len);
66+
}
67+
strlcpy(user_path + _len, "retroarch", sizeof(user_path) - _len);
6568
fill_pathname_basedir(g_defaults.dirs[DEFAULT_DIR_PORT], cwd, sizeof(g_defaults.dirs[DEFAULT_DIR_PORT]));
6669

6770
/* Content in the same folder */
@@ -127,23 +130,23 @@ static void reset_IOP()
127130
}
128131

129132
/* This method returns true if it can extract needed info from path, otherwise false.
130-
* In case of true, it also updates mountString, mountPoint and newCWD parameters
133+
* In case of true, it also updates mountPoint, partition and newCWD parameters
131134
* It splits path by ":", and requires a minimum of 3 elements
132135
* Example: if path = hdd0:__common:pfs:/retroarch/ then
133-
* mountString = "pfs:"
134-
* mountPoint = "hdd0:__common"
136+
* mountPoint = "pfs:"
137+
* partition = "hdd0:__common"
135138
* newCWD = pfs:/retroarch/
136139
* return true
137140
*/
138-
bool getMountInfo(char *path, char *mountString, char *mountPoint, char *newCWD)
141+
bool getMountInfo(char *path, char *mountPoint, char *partition, char *newCWD)
139142
{
140143
struct string_list *str_list = string_split(path, ":");
141144
if (str_list->size < 3)
142145
return false;
143146

144-
sprintf(mountPoint, "%s:%s", str_list->elems[0].data, str_list->elems[1].data);
145-
sprintf(mountString, "%s:", str_list->elems[2].data);
146-
sprintf(newCWD, "%s%s", mountString, str_list->size == 4 ? str_list->elems[3].data : "");
147+
sprintf(partition, "%s:%s", str_list->elems[0].data, str_list->elems[1].data);
148+
sprintf(mountPoint, "%s:", str_list->elems[2].data);
149+
sprintf(newCWD, "%s%s", mountPoint, str_list->size == 4 ? str_list->elems[3].data : "");
147150

148151
return true;
149152
}
@@ -201,31 +204,31 @@ static void mount_partition(void)
201204
if (!should_mount)
202205
return;
203206

204-
if (getMountInfo(mount_path, mountString, mountPoint, new_cwd) != 1)
207+
if (getMountInfo(mount_path, mountPoint, partition, new_cwd) != 1)
205208
{
206209
RARCH_WARN("Partition info not read\n");
207210
return;
208211
}
209212

210-
hddMountStatus = mount_hdd_partition(mountString, mountPoint);
213+
hddMountStatus = mount_hdd_partition(mountPoint, partition);
211214
if (hddMountStatus != HDD_MOUNT_STATUS_OK)
212215
{
213-
RARCH_WARN("Error mount mounting partition %s, %s\n", mountString, mountPoint);
216+
RARCH_WARN("Error mount mounting partition %s, %s\n", mountPoint, partition);
214217
return;
215218
}
216219

217220
/* If we're booting from HDD, we must update the cwd variable
218-
* and add : to the mount point */
221+
* and add : to the partition */
219222
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0)
220223
{
221-
size_t _len = strlcpy(cwd, new_cwd, sizeof(cwd));
222-
strlcpy(mountPoint + _len, ":", sizeof(mountPoint) - _len);
224+
strlcpy(cwd, new_cwd, sizeof(cwd));
225+
strlcat(partition, ":", sizeof(partition));
223226
}
224227
else
225228
{
226-
/* We MUST put mountPoint as empty to avoid wrong results
229+
/* We MUST put partition as empty to avoid wrong results
227230
with LoadELFFromFileWithPartition */
228-
strlcpy(mountPoint, "", sizeof(mountPoint));
231+
strlcpy(partition, "", sizeof(partition));
229232
}
230233
}
231234

@@ -238,10 +241,10 @@ static void deinit_drivers(bool deinit_filesystem, bool deinit_powerOff)
238241

239242
if (deinit_filesystem)
240243
{
241-
umount_hdd_partition(mountString);
244+
umount_hdd_partition(mountPoint);
242245

243-
deinit_dev9_driver();
244246
deinit_hdd_driver(false);
247+
deinit_dev9_driver();
245248
deinit_cdfs_driver();
246249
deinit_mx4sio_driver(true);
247250
deinit_usb_driver(true);
@@ -307,6 +310,16 @@ static void common_init_drivers(bool extra_drivers)
307310
poweroffSetCallback(&poweroffHandler, NULL);
308311

309312
getcwd(cwd, sizeof(cwd));
313+
314+
// Workaround for PS2SDK issue: https://github.com/ps2dev/ps2sdk/issues/805
315+
// PS2SDK's initialization routine does not properly set the CWD for HDD
316+
// paths, leading to all slashes being converted to backslashes. Manually
317+
// convert them back to slashes to work around the issue until it is
318+
// properly fixed in PS2SDK.
319+
int bootDeviceID = getBootDeviceID(cwd);
320+
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0)
321+
pathname_conform_slashes_to_os(cwd);
322+
310323
#if !defined(IS_SALAMANDER) && !defined(DEBUG)
311324
/* If it is not Salamander, we need to go one level
312325
* up for setting the CWD. */
@@ -342,7 +355,7 @@ static void frontend_ps2_exec(const char *path, bool should_load_game)
342355
{
343356
int args = 0;
344357
char *argv[1];
345-
RARCH_LOG("Attempt to load executable: [%s], partition [%s].\n", path, mountPoint);
358+
RARCH_LOG("Attempt to load executable: [%s], partition [%s].\n", path, partition);
346359

347360
/* Reload IOP drivers for saving IOP ram */
348361
deinit_drivers(true, true);
@@ -358,10 +371,10 @@ static void frontend_ps2_exec(const char *path, bool should_load_game)
358371
const char *content = path_get(RARCH_PATH_CONTENT);
359372
strlcpy(game_path, content, sizeof(game_path));
360373
argv[0] = game_path;
361-
RARCH_LOG("Attempt to load executable: [%s], partition [%s] with game [%s]\n", path, mountPoint, game_path);
374+
RARCH_LOG("Attempt to load executable: [%s], partition [%s] with game [%s]\n", path, partition, game_path);
362375
}
363376
#endif
364-
LoadELFFromFileWithPartition(path, mountPoint, args, argv);
377+
LoadELFFromFileWithPartition(path, partition, args, argv);
365378
}
366379

367380
#ifndef IS_SALAMANDER
@@ -491,7 +504,7 @@ static int frontend_ps2_parse_drive_list(void *data, bool load_content)
491504

492505
if (hddMountStatus == HDD_MOUNT_STATUS_OK)
493506
{
494-
size_t _len = strlcpy(hdd, mountString, sizeof(hdd));
507+
size_t _len = strlcpy(hdd, mountPoint, sizeof(hdd));
495508
hdd[ _len] = '/';
496509
hdd[ ++_len] = '\0';
497510
menu_entries_append(list,

0 commit comments

Comments
 (0)