From 9d46424968eec051fc986fec5844258865830a35 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 26 Dec 2014 14:36:57 -0500 Subject: [PATCH] fix Open/PBOpen (no iodir/fs spec stuff) --- toolbox/os.cpp | 79 ++++++++----------------------------- toolbox/os.h | 2 + toolbox/os_hfs_dispatch.cpp | 9 ++--- toolbox/os_highlevel.cpp | 38 +----------------- 4 files changed, 24 insertions(+), 104 deletions(-) diff --git a/toolbox/os.cpp b/toolbox/os.cpp index 5454b25..b42a48d 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -337,7 +337,7 @@ namespace OS } - uint16_t Open(uint16_t trap) + uint16_t OpenCommon(uint32_t parm, bool fsspec, bool resource) { enum { @@ -368,22 +368,18 @@ namespace OS int fd; - uint32_t parm = cpuGetAReg(0); - - - Log("%04x Open(%08x)\n", trap, parm); - - uint32_t namePtr = memoryReadLong(parm + _ioNamePtr); - uint32_t ioDirID = memoryReadLong(parm + _ioDirID); - uint8_t ioPermission = memoryReadByte(parm + _ioPermssn); + uint32_t namePtr = memoryReadLong(parm + _ioNamePtr); std::string sname = ToolBox::ReadPString(namePtr, true); - sname = FSSpecManager::ExpandPath(sname, ioDirID); + if (fsspec) + { + uint32_t ioDirID = memoryReadLong(parm + _ioDirID); + sname = FSSpecManager::ExpandPath(sname, ioDirID); + } - - fd = Internal::FDEntry::open(sname, ioPermission, false); + fd = Internal::FDEntry::open(sname, ioPermission, resource); d0 = fd < 0 ? fd : 0; if (fd >= 0) { @@ -394,59 +390,18 @@ namespace OS return d0; } + uint16_t Open(uint16_t trap) + { + uint32_t parm = cpuGetAReg(0); + Log("%04x Open(%08x)\n", trap, parm); + return OpenCommon(parm, false, false); + } + uint16_t OpenRF(uint16_t trap) { - - enum { - /* IOParam */ - _qLink = 0, - _qType = 4, - _ioTrap = 6, - _ioCmdAddr = 8, - _ioCompletion = 12, - _ioResult = 16, - _ioNamePtr = 18, - _ioVRefNum = 22, - _ioRefNum = 24, - _ioVersNum = 26, - _ioPermssn = 27, - _ioMisc = 28, - _ioBuffer = 32, - _ioReqCount = 36, - _ioActCount = 40, - _ioPosMode = 44, - _ioPosOffset = 46, - - _ioDirID = 48, - - }; - - uint32_t d0; - - int fd; - uint32_t parm = cpuGetAReg(0); - - - Log("%04x OpenRF(%08x)\n", trap, parm); - - uint32_t namePtr = memoryReadLong(parm + _ioNamePtr); - uint32_t ioDirID = memoryReadLong(parm + _ioDirID); - - uint8_t ioPermission = memoryReadByte(parm + _ioPermssn); - - std::string sname = ToolBox::ReadPString(namePtr, true); - sname = FSSpecManager::ExpandPath(sname, ioDirID); - - fd = Internal::FDEntry::open(sname, ioPermission, true); - d0 = fd < 0 ? fd : 0; - if (fd >= 0) - { - memoryWriteWord(fd, parm + _ioRefNum); - } - - memoryWriteWord(d0, parm + _ioResult); - return d0; + Log("%04x Open(%08x)\n", trap, parm); + return OpenCommon(parm, false, true); } diff --git a/toolbox/os.h b/toolbox/os.h index 55b6c2a..c49f67a 100644 --- a/toolbox/os.h +++ b/toolbox/os.h @@ -35,6 +35,8 @@ namespace OS time_t UnixToMac(time_t); time_t MacToUnix(time_t); + uint16_t OpenCommon(uint32_t parm, bool fsspec, bool resource); + #pragma mark FS Utilities uint16_t Close(uint16_t trap); diff --git a/toolbox/os_hfs_dispatch.cpp b/toolbox/os_hfs_dispatch.cpp index 3b2d4da..7c60617 100644 --- a/toolbox/os_hfs_dispatch.cpp +++ b/toolbox/os_hfs_dispatch.cpp @@ -381,7 +381,7 @@ namespace OS { { Log(" PBOpenDF\n"); // same as Open but slightly different handling of . files. - return OS::Open(0xa000); + return OS::OpenCommon(paramBlock, false, false); } @@ -391,8 +391,7 @@ namespace OS { // that it accepts a directory ID in ioDirID. Log(" PBHOpenDF\n"); - // same as Open but slightly different handling of . files. - return OS::Open(0xa000); + return OS::OpenCommon(paramBlock, true, false); } @@ -402,13 +401,13 @@ namespace OS { // up with the permission byte considering it's big-endian. Log(" PBHOpenDeny\n"); - return OS::Open(0xa000); + return OS::OpenCommon(paramBlock, true, false); } uint16_t PBHOpenRFDeny(uint32_t paramBlock) { Log(" PBHOpenRFDeny\n"); - return OS::OpenRF(0xa000); + return OS::OpenCommon(paramBlock, true, true); } uint16_t FSDispatch(uint16_t trap) diff --git a/toolbox/os_highlevel.cpp b/toolbox/os_highlevel.cpp index 4245d96..c80e5fd 100644 --- a/toolbox/os_highlevel.cpp +++ b/toolbox/os_highlevel.cpp @@ -448,45 +448,9 @@ namespace OS { uint16_t HOpen(uint16_t trap) { - - int fd; - int d0; - - uint32_t parm = cpuGetAReg(0); - Log("%04x HOpen(%08x)\n", trap, parm); - - uint32_t ioNamePtr = memoryReadLong(parm + 18); - uint8_t ioPermission = memoryReadByte(parm + 27); - uint32_t ioDirID = memoryReadLong(parm + 48); - - std::string sname = ToolBox::ReadPString(ioNamePtr, true); - bool absolute = sname.length() ? sname[0] == '/' : 0; - - if (ioDirID && !absolute) - { - std::string dir = FSSpecManager::PathForID(ioDirID); - if (dir.empty()) - { - d0 = MacOS::dirNFErr; - memoryWriteWord(d0, parm + 16); - - return d0; - } - sname = dir + sname; - } - - fd = Internal::FDEntry::open(sname, ioPermission, false); - - d0 = fd < 0 ? fd : 0; - if (fd >= 0) - { - memoryWriteWord(fd, parm + 24); - } - - memoryWriteWord(d0, parm + 16); - return d0; + return OpenCommon(parm, true, false); }