HGetVol, ResolveFileAlias (SC Support)

This commit is contained in:
Kelvin Sherlock 2013-05-17 20:14:30 -04:00
parent caa0b8b74f
commit bc8885c2ab
5 changed files with 145 additions and 0 deletions

View File

@ -12,6 +12,7 @@ set(TOOLBOX_SRC
os_internal.cpp
os_hfs_dispatch.cpp
os_highlevel.cpp
os_alias.cpp
qd.cpp
sane.cpp
utility.cpp

View File

@ -49,6 +49,7 @@ namespace OS
uint16_t SetFPos(uint16_t trap);
uint16_t GetVol(uint16_t trap);
uint16_t HGetVol(uint16_t trap);
uint16_t Open(uint16_t trap);
uint16_t Read(uint16_t trap);
@ -72,6 +73,12 @@ namespace OS
uint16_t GetToolTrapAddress(uint16_t trap);
uint16_t GetOSTrapAddress(uint16_t trap);
#pragma mark - Alias Manager
uint16_t ResolveAliasFile();
uint16_t AliasDispatch(uint16_t trap);
}
#endif

59
toolbox/os_alias.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <cerrno>
#include <cctype>
#include <ctime>
#include <algorithm>
#include <chrono>
#include <deque>
#include <string>
#include <sys/xattr.h>
#include <sys/stat.h>
#include <sys/paths.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include "os.h"
#include "os_internal.h"
#include "toolbox.h"
#include "stackframe.h"
using ToolBox::Log;
using namespace ToolBox::Errors;
namespace OS {
uint16_t AliasDispatch(uint16_t trap)
{
uint16_t selector = cpuGetDReg(0);
Log("%04x AliasDispatch($%04x)\n", trap, selector);
switch (selector)
{
case 0x000c:
return ResolveAliasFile();
break;
default:
fprintf(stderr, "AliasDispatch: selector $%04x not implemented\n",
selector);
exit(1);
}
return 0;
}
}

View File

@ -244,6 +244,44 @@ namespace OS {
}
uint16_t ResolveAliasFile()
{
uint32_t spec;
uint16_t resolveAliasChains;
uint32_t targetIsFolder;
uint32_t wasAliased;
StackFrame<14>(spec, resolveAliasChains, targetIsFolder, wasAliased);
int parentID = memoryReadLong(spec + 2);
std::string leaf = ToolBox::ReadPString(spec + 6, false);
std::string path = FSSpecManager::pathForID(parentID);
path += leaf;
Log(" ResolveAliasFile(%s)\n", path.c_str());
struct stat st;
int rv;
rv = ::stat(path.c_str(), &st);
if (rv < 0) return errno_to_oserr(errno);
if (targetIsFolder)
{
memoryWriteWord(S_ISDIR(st.st_mode) ? 1 : 0, targetIsFolder);
}
// don't bother pretending a soft link is an alias.
if (wasAliased) memoryWriteWord(0, wasAliased);
return 0;
}
uint16_t HighLevelHFSDispatch(uint16_t trap)
{
@ -274,6 +312,38 @@ namespace OS {
}
uint16_t HGetVol(uint16_t trap)
{
uint32_t parm = cpuGetAReg(0);
Log("%04x HGetVol(%08x)\n", trap, parm);
//uint32_t ioCompletion = memoryReadLong(parm + 12);
uint32_t namePtr = memoryReadLong(parm + 18);
// ioResult
memoryWriteWord(0, parm + 16);
// ioVRefNum
memoryWriteWord(0, parm + 22);
// ioWDProcID
memoryWriteLong(0, parm + 28);
// ioWDVRefNum
memoryWriteWord(0, parm + 32);
// todo -- this should create an FSSpec entry for
// the current wd and return the id.
// (FSMakeSpec handles 0 as a dir, so ok for now)
// ioWDDirID
memoryWriteLong(0, parm + 48);
std::string tmp = "MacOS";
ToolBox::WritePString(namePtr, tmp);
return 0;
}

View File

@ -76,6 +76,10 @@ namespace ToolBox {
d0 = OS::GetVol(trap);
break;
case 0xa214:
d0 = OS::HGetVol(trap);
break;
case 0xa044:
d0 = OS::SetFPos(trap);
break;
@ -98,6 +102,10 @@ namespace ToolBox {
d0 = OS::GetOSTrapAddress(trap);
break;
case 0xA823:
d0 = OS::AliasDispatch(trap);
break;
// SetPtrSize (p: Ptr; newSize: Size);
case 0xa020: