Skip to content

Commit

Permalink
Merge pull request #5149 from maxpat78/master
Browse files Browse the repository at this point in the history
Fix some Linux issues in VHD code
  • Loading branch information
joncampbell123 authored Aug 3, 2024
2 parents 78b7bb5 + 7956f0b commit 5af9c01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 3 additions & 11 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8311,15 +8311,8 @@ void VHDMAKE::Run()
safe_strcpy(basename, temp_line.c_str());
cmd->FindCommand(2, temp_line);
safe_strcpy(filename, temp_line.c_str());
#ifdef WIN32
if(basename[1] == ':')
WriteOut(MSG_Get("PROGRAM_VHDMAKE_ABSPATH_WIN"));
#else
if(basename[0] == '/') {
WriteOut(MSG_Get("PROGRAM_VHDMAKE_ABSPATH_UX"));
return;
}
#endif
if(basename[1] == ':' || basename[0] == '/')
WriteOut(MSG_Get("PROGRAM_VHDMAKE_ABSPATH"));
if(! bOverwrite && _access(filename, 0) == 0) {
WriteOut(MSG_Get("PROGRAM_VHDMAKE_FNEEDED"));
return;
Expand Down Expand Up @@ -9879,8 +9872,7 @@ void DOS_SetupPrograms(void) {
MSG_Add("PROGRAM_VHDMAKE_MERGEOKDELETE", "Snapshot VHD merged and deleted.\n");
MSG_Add("PROGRAM_VHDMAKE_MERGEFAILED", "Failure while merging, aborted!\n");
MSG_Add("PROGRAM_VHDMAKE_MERGEWARNCORRUPTION", " Parent \"%s\" contents could be corrupted!\n");
MSG_Add("PROGRAM_VHDMAKE_ABSPATH_WIN", "Warning: an absolute path to parent limits portability to Windows.\nPlease prefer a path relative to differencing image file!\n");
MSG_Add("PROGRAM_VHDMAKE_ABSPATH_UX", "ERROR: an absolute path to parent inhibits portability.\nUse a path relative to differencing image file!\n");
MSG_Add("PROGRAM_VHDMAKE_ABSPATH", "Warning: an absolute path to parent prevents portability.\nPlease prefer a path relative to the differencing image file!\n");
MSG_Add("PROGRAM_VHDMAKE_HELP",
"Creates Dynamic or Differencing VHD images, converts raw images into Fixed VHD,\n"
"shows information about VHD images and merges them.\n"
Expand Down
14 changes: 11 additions & 3 deletions src/ints/bios_vhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,15 @@ uint32_t imageDiskVHD::CreateDifferencing(const char* filename, const char* base
uint32_t table_size = (4 * header.maxTableEntries + 511) / 512 * 512;

//Locators - Windows 11 wants at least the relative W2ru locator, or won't mount!
uint32_t l_basename = strlen(basename);
// we store the absolute pathname to prevent complex depth calculations
#if defined (WIN32)
char absBasePathName[MAX_PATH];
_fullpath(absBasePathName, basename, MAX_PATH);
#else
char absBasePathName[PATH_MAX];
realpath(basename, absBasePathName);
#endif
uint32_t l_basename = strlen(absBasePathName);
uint32_t platsize = (2 * l_basename + 511) / 512 * 512;
header.parentLocatorEntry[0].platformCode = 0x57326B75; //W2ku
header.parentLocatorEntry[0].platformDataLength = 2 * l_basename;
Expand Down Expand Up @@ -760,11 +768,11 @@ uint32_t imageDiskVHD::CreateDifferencing(const char* filename, const char* base
table_size -= 512;
}
//write Parent Locator sectors
wchar_t* w_basename = (wchar_t*)malloc(platsize);
uint16_t* w_basename = (uint16_t*)malloc(platsize);
memset(w_basename, 0, platsize);
for(uint32_t i = 0; i < l_basename; i++)
//dirty hack to quickly convert ASCII -> UTF-16 *LE* and fix slashes
w_basename[i] = SDL_SwapLE16(basename[i]=='/'? (uint16_t)'\\' : (uint16_t)basename[i]);
w_basename[i] = SDL_SwapLE16(absBasePathName[i]=='/'? (uint16_t)'\\' : (uint16_t)absBasePathName[i]);
if (fwrite(w_basename, 1, platsize, vhd) != platsize) STATUS = ERROR_WRITING;
if (fwrite(w_basename, 1, platsize, vhd) != platsize) STATUS = ERROR_WRITING;

Expand Down

0 comments on commit 5af9c01

Please sign in to comment.