use native code for finder info and file date.

This commit is contained in:
Kelvin Sherlock 2016-07-31 15:35:30 -04:00
parent 2aae28fedf
commit a788d145fa
6 changed files with 34 additions and 232 deletions

View File

@ -292,26 +292,14 @@ namespace OS {
Log(" SetFileInfo(%s)\n", sname.c_str());
native::file_info fi;
fi.create_date = memoryReadLong(parm + _ioFlCrDat);
fi.modify_date = memoryReadLong(parm + _ioFlMdDat);
native::get_finder_info(sname, fi.finder_info); // get extended bits.
std::memcpy(fi.finder_info, memoryPointer(parm + _ioFlFndrInfo), 16);
d0 = native::set_file_info(sname, fi);
// check if the file actually exists
{
struct stat st;
int ok;
ok = ::stat(sname.c_str(), &st);
if (ok < 0)
{
d0 = macos_error_from_errno();
memoryWriteWord(d0, parm + _ioResult);
return d0;
}
}
d0 = Internal::SetFinderInfo(sname, memoryPointer(parm + 32), false);
if (d0 == 0) d0 = Internal::SetFileDates(sname, memoryReadLong(parm + _ioFlCrDat), memoryReadLong(parm + _ioFlMdDat), 0);
memoryWriteWord(d0, parm + _ioResult);
return d0;
}

View File

@ -59,11 +59,6 @@
#include <native/native.h>
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#define st_birthtime st_mtime
#endif
using ToolBox::Log;
using MacOS::macos_error_from_errno;
@ -487,44 +482,17 @@ namespace OS {
Log(" PBSetCatInfo(%s)\n", sname.c_str());
native::file_info fi;
// check if the file actually exists
{
struct stat st;
int ok;
ok = ::stat(sname.c_str(), &st);
if (ok < 0)
{
d0 = macos_error_from_errno();
memoryWriteWord(d0, parm + _ioResult);
return d0;
}
// just nop if it's a directory.
if (S_ISDIR(st.st_mode))
{
d0 = 0;
d0 = Internal::SetFileDates(sname,
memoryReadLong(parm + _ioDrCrDat),
memoryReadLong(parm + _ioDrMdDat),
memoryReadLong(parm + _ioDrBkDat));
memoryWriteWord(d0, parm + _ioResult);
return d0;
}
}
fi.create_date = memoryReadLong(parm + _ioFlCrDat);
fi.modify_date = memoryReadLong(parm + _ioFlMdDat);
fi.backup_date = memoryReadLong(parm + _ioFlBkDat);
// set the finder info. could also call utimes or setattrlist, I suppose.
d0 = Internal::SetFinderInfo(sname, memoryPointer(parm + _ioFlFndrInfo), false);
if (d0 == 0) d0 = Internal::SetFileDates(sname,
memoryReadLong(parm + _ioFlCrDat),
memoryReadLong(parm + _ioFlMdDat),
memoryReadLong(parm + _ioFlBkDat));
memcpy(fi.finder_info, memoryPointer(parm + _ioFlFndrInfo), 16);
memcpy(fi.finder_info+16, memoryPointer(parm + _ioFlXFndrInfo), 16);
d0 = native::set_file_info(sname, fi);
memoryWriteWord(d0, parm + _ioResult);
return d0;

View File

@ -58,6 +58,8 @@
#include "stackframe.h"
#include "fs_spec.h"
#include <native/native.h>
using ToolBox::Log;
using MacOS::macos_error_from_errno;
@ -239,7 +241,8 @@ namespace OS {
Log(" FSpGetFInfo(%s, %08x)\n", path.c_str(), finderInfo);
d0 = Internal::GetFinderInfo(path, memoryPointer(finderInfo), false);
d0 = native::get_finder_info(path, memoryPointer(finderInfo), false);
//d0 = Internal::GetFinderInfo(path, memoryPointer(finderInfo), false);
return d0;
}
@ -263,8 +266,8 @@ namespace OS {
Log(" FSpSetFInfo(%s, %08x)\n", path.c_str(), finderInfo);
d0 = Internal::SetFinderInfo(path, memoryPointer(finderInfo), false);
//d0 = Internal::SetFinderInfo(path, memoryPointer(finderInfo), false);
d0 = native::set_finder_info(path, memoryPointer(finderInfo), false);
return d0;
}
@ -314,8 +317,8 @@ namespace OS {
::close(fd);
}
d0 = OS::Internal::SetFinderInfo(sname, fileType, creator);
//d0 = OS::Internal::SetFinderInfo(sname, fileType, creator);
d0 = native::set_finder_info(sname, fileType, creator);
return d0;
}

View File

@ -51,171 +51,6 @@ namespace OS { namespace Internal {
/*
tech note PT515
ProDOS -> Macintosh conversion
ProDOS Macintosh
Filetype Auxtype Creator Filetype
$00 $0000 'pdos' 'BINA'
$B0 (SRC) (any) 'pdos' 'TEXT'
$04 (TXT) $0000 'pdos' 'TEXT'
$FF (SYS) (any) 'pdos' 'PSYS'
$B3 (S16) (any) 'pdos' 'PS16'
$uv $wxyz 'pdos' 'p' $uv $wx $yz
Programmer's Reference for System 6.0:
ProDOS Macintosh
File Type Auxiliary Type Creator Type File Type
$00 $0000 pdos BINA
$04 (TXT) $0000 pdos TEXT
$FF (SYS) (any) pdos PSYS
$B3 (S16) $DByz pdos p $B3 $DB $yz
$B3 (S16) (any) pdos PS16
$D7 $0000 pdos MIDI
$D8 $0000 pdos AIFF
$D8 $0001 pdos AIFC
$E0 $0005 dCpy dImg
$FF (SYS) (any) pdos PSYS
$uv $wxyz pdos p $uv $wx $yz
mpw standard:
$uv (any) "pdos" printf("%02x ",$uv)
*/
uint16_t GetFinderInfo(const std::string &pathName, void *info, bool extended)
{
// todo -- move to separate function? used in multiple places.
uint8_t buffer[32];
std::memset(buffer, 0, sizeof(buffer));
int rv;
rv = ::getxattr(pathName.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0);
if (rv < 0)
{
switch (errno)
{
case ENOENT:
case EACCES:
return macos_error_from_errno();
}
// check for prodos ftype/auxtype
uint8_t ftype;
uint16_t atype;
int rv1, rv2;
rv1 = ::getxattr(pathName.c_str(), "prodos.FileType", &ftype, 1, 0, 0);
rv2 = ::getxattr(pathName.c_str(), "prodos.AuxType", &atype, 2, 0, 0);
if (rv1 == 1 && rv2 == 2)
{
#if BYTE_ORDER == BIG_ENDIAN
ftype = (ftype >> 8) | (ftype << 8);
#endif
char tmp[8] = {
'p', ' ', ' ', ' ',
'p', 'd', 'o', 's'
};
tmp[1] = (char)ftype;
tmp[2] = (char)((atype >> 8) & 0xff);
tmp[3] = (char)(atype & 0xff);
switch (atype)
{
case 0x00:
std::memcpy(tmp, "BINA", 4);
break;
case 0x04:
case 0xb0:
std::memcpy(tmp, "TEXT", 4);
break;
case 0xff:
std::memcpy(tmp, "PSYS", 4);
break;
case 0xd7:
std::memcpy(tmp, "MIDI", 4);
break;
case 0xd8:
switch (atype)
{
case 0x0000:
std::memcpy(tmp, "AIFF", 4);
break;
case 0x0001:
std::memcpy(tmp, "AIFC", 4);
break;
}
break;
case 0xe0:
switch (atype)
{
case 0x0005:
std::memcpy(tmp, "dImgdCpy", 8);
break;
}
case 0xb3:
if (atype == 0)
{
std::memcpy(tmp, "PS16", 4); // verify dumpobj.
break;
}
}
std::memcpy(buffer, tmp, 8);
}
}
// override for source files.
// TODO -- only override if missing?
if (IsTextFile(pathName))
{
std::memcpy(buffer, "TEXTMPS ", 8);
}
// convert pdos types...
if (std::memcmp(buffer + 4, "pdos", 4) == 0)
{
// mpw expects 'xx ' where
// xx are the ascii-encode hex value of the file type.
// the hfs fst uses 'p' ftype8 auxtype16
// todo -- but only if auxtype is $0000 ??
if (buffer[0] == 'p')
{
static char Hex[] = "0123456789ABCDEF";
uint8_t ftype = buffer[1];
buffer[0] = Hex[ftype >> 4];
buffer[1] = Hex[ftype & 0x0f];
buffer[2] = ' ';
buffer[3] = ' ';
}
}
if (extended)
std::memcpy(info, buffer, 32);
else
std::memcpy(info, buffer, 16);
return 0;
}
unsigned tox(unsigned x)
{
if (x >= '0' && x <= '9') return x - '0';
@ -224,6 +59,7 @@ namespace OS { namespace Internal {
return 0;
}
#if 0
uint16_t SetFinderInfo(const std::string &pathName, uint32_t fileType, uint32_t creator)
{
uint8_t buffer[32];
@ -290,8 +126,9 @@ namespace OS { namespace Internal {
return 0;
}
#endif
#if 0
uint16_t SetFileDates(const std::string &pathname, uint32_t createDate, uint32_t modificationDate, uint32_t backupDate)
{
// utimes(2) sets the access and mod times.
@ -354,7 +191,7 @@ namespace OS { namespace Internal {
return 0;
}
#endif
int32_t mac_seek(uint16_t refNum, uint16_t mode, int32_t offset)
{

View File

@ -11,15 +11,17 @@ namespace OS {
namespace Internal {
#if 0
uint16_t GetFinderInfo(const std::string &pathname, void *info, bool extended);
uint16_t SetFinderInfo(const std::string &pathname, void *info, bool extended);
uint16_t SetFinderInfo(const std::string &pathName, uint32_t fileType, uint32_t creator);
uint16_t SetFileDates(const std::string &pathname, uint32_t createDate, uint32_t modificationDate, uint32_t backupDate);
uint16_t GetFileType(const std::string &pathname, uint16_t *fileType, uint32_t *auxType);
uint16_t SetFileDates(const std::string &pathname, uint32_t createDate, uint32_t modificationDate, uint32_t backupDate);
#endif
int32_t mac_seek(uint16_t refNum, uint16_t mode, int32_t offset);

View File

@ -49,6 +49,9 @@
#include "stackframe.h"
#include "fs_spec.h"
#include <native/native.h>
using ToolBox::Log;
using namespace OS::Internal;
@ -495,7 +498,8 @@ namespace RM
else
{
if (creator || fileType)
OS::Internal::SetFinderInfo(path, fileType, creator);
native::set_finder_info(path, fileType, creator);
//OS::Internal::SetFinderInfo(path, fileType, creator);
close(fd);
}