2013-07-30 05:06:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Kelvin W Sherlock
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2015-02-18 14:32:01 +00:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2013-07-30 05:06:19 +00:00
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
2015-02-18 14:32:01 +00:00
|
|
|
* list of conditions and the following disclaimer.
|
2013-07-30 05:06:19 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
2015-02-18 14:32:01 +00:00
|
|
|
* and/or other materials provided with the distribution.
|
2013-07-30 05:06:19 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-05-23 00:37:57 +00:00
|
|
|
#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 <macos/sysequ.h>
|
|
|
|
#include <macos/errors.h>
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
#include "os_internal.h"
|
|
|
|
#include "toolbox.h"
|
|
|
|
#include "stackframe.h"
|
2015-01-05 00:12:35 +00:00
|
|
|
#include "fs_spec.h"
|
2013-05-23 00:37:57 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
#include <native/native.h>
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
using ToolBox::Log;
|
|
|
|
|
2014-12-21 00:32:54 +00:00
|
|
|
using MacOS::macos_error_from_errno;
|
2013-05-23 00:37:57 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
|
2015-02-17 00:23:12 +00:00
|
|
|
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
|
|
|
|
#define st_birthtime st_mtime
|
|
|
|
#endif
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
namespace OS {
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
static uint16_t FileInfoByName(const std::string &sname, uint32_t parm) {
|
2013-05-23 00:37:57 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
enum { // FileParam
|
|
|
|
_qLink = 0,
|
|
|
|
_qType = 4,
|
|
|
|
_ioTrap = 6,
|
|
|
|
_ioCmdAddr = 8,
|
|
|
|
_ioCompletion = 12,
|
|
|
|
_ioResult = 16,
|
|
|
|
_ioNamePtr = 18,
|
|
|
|
_ioVRefNum = 22,
|
|
|
|
_ioFRefNum = 24,
|
|
|
|
_ioFVersNum = 26,
|
|
|
|
_filler1 = 27,
|
|
|
|
_ioFDirIndex = 28,
|
|
|
|
_ioFlAttrib = 30,
|
|
|
|
_ioFlVersNum = 31,
|
|
|
|
_ioFlFndrInfo = 32,
|
|
|
|
_ioFlNum = 48, // ioDirID in other
|
|
|
|
_ioFlStBlk = 52,
|
|
|
|
_ioFlLgLen = 54,
|
|
|
|
_ioFlPyLen = 58,
|
|
|
|
_ioFlRStBlk = 62,
|
|
|
|
_ioFlRLgLen = 64,
|
|
|
|
_ioFlRPyLen = 68,
|
|
|
|
_ioFlCrDat = 72,
|
|
|
|
_ioFlMdDat = 76,
|
|
|
|
|
|
|
|
_ioDirID = 48,
|
|
|
|
};
|
2013-05-23 00:37:57 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
using namespace native;
|
2013-05-23 00:37:57 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
file_info fi;
|
|
|
|
auto err = native::get_file_info(sname, fi);
|
|
|
|
if (err) return err;
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
// if this is not a file, error out?
|
|
|
|
|
|
|
|
std::memcpy(memoryPointer(parm + _ioFlFndrInfo), fi.finder_info, 16);
|
|
|
|
|
|
|
|
|
|
|
|
// file reference number
|
|
|
|
memoryWriteWord(0, parm + _ioFRefNum);
|
|
|
|
// file attributes
|
|
|
|
memoryWriteByte(0, parm + _ioFlAttrib);
|
|
|
|
// version (unused)
|
|
|
|
memoryWriteByte(0, parm + _ioFlVersNum);
|
|
|
|
|
|
|
|
// file id
|
|
|
|
memoryWriteLong(0, parm + _ioFlNum);
|
|
|
|
|
2015-02-18 14:32:01 +00:00
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
// file size
|
|
|
|
memoryWriteWord(0, parm + _ioFlStBlk);
|
|
|
|
memoryWriteLong(fi.data_logical_size, parm + _ioFlLgLen);
|
|
|
|
memoryWriteLong(fi.data_physical_size, parm + _ioFlPyLen);
|
|
|
|
|
|
|
|
// create date.
|
|
|
|
memoryWriteLong(fi.create_date, parm + _ioFlCrDat);
|
|
|
|
memoryWriteLong(fi.modify_date, parm + _ioFlMdDat);
|
|
|
|
|
|
|
|
// res fork...
|
|
|
|
memoryWriteWord(0, parm + _ioFlRStBlk);
|
|
|
|
memoryWriteLong(fi.resource_logical_size, parm + _ioFlRLgLen);
|
|
|
|
memoryWriteLong(fi.resource_physical_size, parm + _ioFlRPyLen);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
uint16_t GetFileInfo(uint16_t trap)
|
|
|
|
{
|
|
|
|
|
|
|
|
enum { // FileParam
|
|
|
|
_qLink = 0,
|
|
|
|
_qType = 4,
|
|
|
|
_ioTrap = 6,
|
|
|
|
_ioCmdAddr = 8,
|
|
|
|
_ioCompletion = 12,
|
|
|
|
_ioResult = 16,
|
|
|
|
_ioNamePtr = 18,
|
|
|
|
_ioVRefNum = 22,
|
|
|
|
_ioFRefNum = 24,
|
|
|
|
_ioFVersNum = 26,
|
|
|
|
_filler1 = 27,
|
|
|
|
_ioFDirIndex = 28,
|
|
|
|
_ioFlAttrib = 30,
|
|
|
|
_ioFlVersNum = 31,
|
|
|
|
_ioFlFndrInfo = 32,
|
|
|
|
_ioFlNum = 48, // ioDirID in other
|
|
|
|
_ioFlStBlk = 52,
|
|
|
|
_ioFlLgLen = 54,
|
|
|
|
_ioFlPyLen = 58,
|
|
|
|
_ioFlRStBlk = 62,
|
|
|
|
_ioFlRLgLen = 64,
|
|
|
|
_ioFlRPyLen = 68,
|
|
|
|
_ioFlCrDat = 72,
|
|
|
|
_ioFlMdDat = 76,
|
2015-01-05 00:12:35 +00:00
|
|
|
|
|
|
|
_ioDirID = 48,
|
2013-05-23 00:37:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t d0;
|
|
|
|
|
|
|
|
uint32_t parm = cpuGetAReg(0);
|
|
|
|
|
|
|
|
Log("%04x GetFileInfo($%08x)\n", trap, parm);
|
|
|
|
|
|
|
|
//uint32_t ioCompletion = memoryReadLong(parm + _ioCompletion);
|
|
|
|
uint32_t ioNamePtr = memoryReadLong(parm + _ioNamePtr);
|
|
|
|
//uint16_t ioVRefNum = memoryReadWord(parm + _ioVRefNum);
|
|
|
|
//uint8_t ioFVersNum = memoryReadByte(parm + _ioFVersNum);
|
|
|
|
int16_t ioFDirIndex = memoryReadWord(parm + _ioFDirIndex);
|
|
|
|
|
|
|
|
if (ioFDirIndex <= 0)
|
|
|
|
{
|
|
|
|
// based name
|
|
|
|
std::string sname;
|
|
|
|
|
|
|
|
if (!ioNamePtr)
|
|
|
|
{
|
|
|
|
d0 = MacOS::bdNamErr;
|
|
|
|
memoryWriteWord(d0, parm + _ioResult);
|
|
|
|
return d0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sname = ToolBox::ReadPString(ioNamePtr, true);
|
2015-01-05 00:12:35 +00:00
|
|
|
// a20c HGetFileInfo uses a the dir id
|
|
|
|
if (trap == 0xa20c)
|
|
|
|
{
|
|
|
|
uint32_t ioDirID = memoryReadLong(parm + _ioDirID);
|
|
|
|
sname = FSSpecManager::ExpandPath(sname, ioDirID);
|
|
|
|
}
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
Log(" GetFileInfo(%s)\n", sname.c_str());
|
|
|
|
|
2016-07-31 17:36:29 +00:00
|
|
|
d0 = FileInfoByName(sname, parm);
|
|
|
|
memoryWriteWord(d0, parm + _ioResult);
|
|
|
|
return d0;
|
2013-05-23 00:37:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "GetFileInfo -- ioFDirIndex not yet supported\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if iocompletion handler && asyn call....
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t SetFileInfo(uint16_t trap)
|
|
|
|
{
|
|
|
|
|
|
|
|
enum { // FileParam
|
|
|
|
_qLink = 0,
|
|
|
|
_qType = 4,
|
|
|
|
_ioTrap = 6,
|
|
|
|
_ioCmdAddr = 8,
|
|
|
|
_ioCompletion = 12,
|
|
|
|
_ioResult = 16,
|
|
|
|
_ioNamePtr = 18,
|
|
|
|
_ioVRefNum = 22,
|
|
|
|
_ioFRefNum = 24,
|
|
|
|
_ioFVersNum = 26,
|
|
|
|
_filler1 = 27,
|
|
|
|
_ioFDirIndex = 28,
|
|
|
|
_ioFlAttrib = 30,
|
|
|
|
_ioFlVersNum = 31,
|
|
|
|
_ioFlFndrInfo = 32,
|
|
|
|
_ioFlNum = 48, // ioDirID in other
|
|
|
|
_ioFlStBlk = 52,
|
|
|
|
_ioFlLgLen = 54,
|
|
|
|
_ioFlPyLen = 58,
|
|
|
|
_ioFlRStBlk = 62,
|
|
|
|
_ioFlRLgLen = 64,
|
|
|
|
_ioFlRPyLen = 68,
|
|
|
|
_ioFlCrDat = 72,
|
|
|
|
_ioFlMdDat = 76,
|
2015-01-05 00:12:35 +00:00
|
|
|
|
|
|
|
_ioDirID = 48,
|
2013-05-23 00:37:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::string sname;
|
|
|
|
uint16_t d0;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t parm = cpuGetAReg(0);
|
|
|
|
|
|
|
|
Log("%04x SetFileInfo($%08x)\n", trap, parm);
|
|
|
|
|
|
|
|
//uint32_t ioCompletion = memoryReadLong(parm + _ioCompletion);
|
|
|
|
uint32_t ioNamePtr = memoryReadLong(parm + _ioNamePtr);
|
|
|
|
//uint16_t ioVRefNum = memoryReadWord(parm + _ioVRefNum);
|
|
|
|
//uint8_t ioFVersNum = memoryReadByte(parm + _ioFVersNum);
|
|
|
|
//int16_t ioFDirIndex = memoryReadWord(parm + _ioFDirIndex);
|
|
|
|
|
|
|
|
if (!ioNamePtr)
|
|
|
|
{
|
|
|
|
d0 = MacOS::bdNamErr;
|
|
|
|
memoryWriteWord(d0, parm + _ioResult);
|
|
|
|
return d0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sname = ToolBox::ReadPString(ioNamePtr, true);
|
2015-01-05 00:12:35 +00:00
|
|
|
|
|
|
|
// a20d HSetFileInfo uses a the dir id
|
|
|
|
if (trap == 0xa20d)
|
|
|
|
{
|
|
|
|
uint32_t ioDirID = memoryReadLong(parm + _ioDirID);
|
|
|
|
sname = FSSpecManager::ExpandPath(sname, ioDirID);
|
|
|
|
}
|
|
|
|
|
2013-05-23 00:37:57 +00:00
|
|
|
Log(" SetFileInfo(%s)\n", sname.c_str());
|
|
|
|
|
2015-01-05 00:12:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-23 00:37:57 +00:00
|
|
|
// check if the file actually exists
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
ok = ::stat(sname.c_str(), &st);
|
|
|
|
if (ok < 0)
|
|
|
|
{
|
2014-12-21 00:32:54 +00:00
|
|
|
d0 = macos_error_from_errno();
|
2013-05-23 00:37:57 +00:00
|
|
|
memoryWriteWord(d0, parm + _ioResult);
|
2015-02-18 14:32:01 +00:00
|
|
|
return d0;
|
2013-05-23 00:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
d0 = Internal::SetFinderInfo(sname, memoryPointer(parm + 32), false);
|
2014-12-26 21:31:58 +00:00
|
|
|
if (d0 == 0) d0 = Internal::SetFileDates(sname, memoryReadLong(parm + _ioFlCrDat), memoryReadLong(parm + _ioFlMdDat), 0);
|
2013-05-23 00:37:57 +00:00
|
|
|
memoryWriteWord(d0, parm + _ioResult);
|
|
|
|
return d0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t HGetFileInfo(uint16_t trap)
|
|
|
|
{
|
2015-02-18 14:32:01 +00:00
|
|
|
|
2013-05-23 00:37:57 +00:00
|
|
|
enum { // HFileParam
|
|
|
|
_qLink = 0,
|
|
|
|
_qType = 4,
|
|
|
|
_ioTrap = 6,
|
|
|
|
_ioCmdAddr = 8,
|
|
|
|
_ioCompletion = 12,
|
|
|
|
_ioResult = 16,
|
|
|
|
_ioNamePtr = 18,
|
|
|
|
_ioVRefNum = 22,
|
|
|
|
_ioFRefNum = 24,
|
|
|
|
_ioFVersNum = 26,
|
|
|
|
_filler1 = 27,
|
|
|
|
_ioFDirIndex = 28,
|
|
|
|
_ioFlAttrib = 30,
|
|
|
|
_ioFlVersNum = 31,
|
|
|
|
_ioFlFndrInfo = 32,
|
|
|
|
_ioDirID = 48, // ioFLNum in other
|
|
|
|
_ioFlStBlk = 52,
|
|
|
|
_ioFlLgLen = 54,
|
|
|
|
_ioFlPyLen = 58,
|
|
|
|
_ioFlRStBlk = 62,
|
|
|
|
_ioFlRLgLen = 64,
|
|
|
|
_ioFlRPyLen = 68,
|
|
|
|
_ioFlCrDat = 72,
|
|
|
|
_ioFlMdDat = 76,
|
|
|
|
};
|
|
|
|
|
|
|
|
// close enough... for now.
|
|
|
|
return GetFileInfo(trap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-17 00:23:12 +00:00
|
|
|
}
|