HFSDispatch / PBGetCatInfo

This commit is contained in:
Kelvin Sherlock 2013-05-17 23:49:59 -04:00
parent bc8885c2ab
commit be3c728185
3 changed files with 138 additions and 5 deletions

View File

@ -66,6 +66,7 @@ namespace OS
uint16_t TickCount(uint16_t trap);
uint16_t FSDispatch(uint16_t trap);
uint16_t HFSDispatch(uint16_t trap);
uint16_t HighLevelHFSDispatch(uint16_t trap);

View File

@ -19,6 +19,8 @@
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include <macos/errors.h>
#include "os.h"
#include "os_internal.h"
#include "toolbox.h"
@ -27,10 +29,113 @@
using ToolBox::Log;
using namespace ToolBox::Errors;
using OS::Internal::errno_to_oserr;
namespace OS {
uint16_t PBGetCatInfo(uint32_t paramBlock)
uint16_t PBGetCatInfo(uint32_t parm)
{
uint16_t d0;
// yuck. this is sort of a getdirent/stat call....
//uint32_t ioCompletion = memoryReadLong(parm + 12);
uint32_t ioNamePtr = memoryReadLong(parm + 18);
//uint16_t ioVRefNum = memoryReadWord(parm + 22);
//uint8_t ioFVersNum = memoryReadByte(parm + 26);
int16_t ioFDirIndex = memoryReadWord(parm + 28);
if (ioFDirIndex <= 0)
{
// based name
std::string sname;
if (!ioNamePtr)
{
memoryWriteWord(MacOS::bdNamErr, parm + 16);
return MacOS::bdNamErr;
}
sname = ToolBox::ReadPString(ioNamePtr, true);
Log(" PBGetCatInfo(%s)\n", sname.c_str());
struct stat st;
if (::stat(sname.c_str(), &st) < 0)
{
d0 = errno_to_oserr(errno);
memoryWriteWord(d0, parm + 16);
return d0;
}
if (S_ISDIR(st.st_mode))
{
// bit 4 - is a directory.
memoryWriteByte(1 << 4, parm + 30); // ioFlAttrib
memoryWriteByte(0, parm + 31); //ioACUser
std::memset(memoryPointer(parm + 32), 0, 16); // DInfo
memoryWriteLong(0, parm + 48); // ioDrDirID
memoryWriteWord(0, parm + 52); // ioDrNmFls - # of files in dir
memoryWriteLong(UnixToMac(st.st_birthtime), parm + 60); // create
memoryWriteLong(UnixToMac(st.st_mtime), parm + 64); // modify
memoryWriteLong(UnixToMac(st.st_mtime), parm + 68); // backup
std::memset(memoryPointer(parm + 72), 0, 16); // DXInfo
memoryWriteLong(0, parm + 88); // ioDrParID
}
else
{
memoryWriteByte(0, parm + 30);
memoryWriteByte(0, parm + 31); //ioACUser
Internal::GetFinderInfo(sname, memoryPointer(parm + 32), false); // finder info
memoryWriteLong(0, parm + 48); // ioDrDirID
memoryWriteWord(0, parm + 52); // ioFlStBlk
memoryWriteLong(st.st_size, parm + 54); // ioFlLgLen
memoryWriteLong(st.st_size, parm + 58); // ioFlPyLen
// resource info... below
memoryWriteLong(UnixToMac(st.st_birthtime), parm + 72); // create
memoryWriteLong(UnixToMac(st.st_mtime), parm + 76); // modify
memoryWriteLong(UnixToMac(st.st_mtime), parm + 80); // backup
std::memset(memoryPointer(parm + 84), 0, 16); // FXInfo
memoryWriteWord(0, parm + 100); // ioFlParID
memoryWriteWord(0, parm + 104); // ioFlClpSiz
sname.append(_PATH_RSRCFORKSPEC);
if (::stat(sname.c_str(), &st) >= 0)
{
memoryWriteWord(0, parm + 62);
memoryWriteLong(st.st_size, parm + 64);
memoryWriteLong(st.st_size, parm + 68);
}
else
{
memoryWriteWord(0, parm + 62);
memoryWriteLong(0, parm + 64);
memoryWriteLong(0, parm + 68);
}
}
// no error.
memoryWriteWord(0, parm + 16);
return 0;
}
else
{
fprintf(stderr, "GetFileInfo -- ioFDirIndex not yet supported\n");
exit(1);
}
return 0;
}
@ -42,16 +147,18 @@ namespace OS {
return OS::Open(0xa000);
}
uint16_t HFSDispatch(uint16_t trap)
uint16_t FSDispatch(uint16_t trap)
{
// TODO -- check new hfs bit ( (trap & 0x0200) == 0x0200)
// TODO -- check async bit ((trap & 0x0400) == 0x0400)
uint32_t selector = cpuGetDReg(0);
uint32_t paramBlock = cpuGetAReg(0);
Log("%04x HFSDispatch(%08x, %08x)\n", trap, selector, paramBlock);
Log("%04x FSDispatch(%08x, %08x)\n", trap, selector, paramBlock);
switch (selector)
{
@ -71,6 +178,28 @@ namespace OS {
return 0;
}
uint16_t HFSDispatch(uint16_t trap)
{
uint32_t selector = cpuGetDReg(0);
uint32_t paramBlock = cpuGetAReg(0);
Log("%04x HFSDispatch(%08x, %08x)\n", trap, selector, paramBlock);
switch (selector)
{
case 0x0009:
return PBGetCatInfo(paramBlock);
break;
default:
fprintf(stderr, "HFSDispatch: selector %08x not implemented\n",
selector);
exit(1);
}
return 0;
}
}

View File

@ -85,10 +85,13 @@ namespace ToolBox {
break;
case 0xa060:
// also a260 for async
d0 = OS::HFSDispatch(trap);
d0 = OS::FSDispatch(trap);
break;
case 0xa260:
d0 = OS::HFSDispatch(trap);
break;
case 0xaa52:
d0 = OS::HighLevelHFSDispatch(trap);
break;