create finder info from prodos file type/aux type, if available.

This commit is contained in:
Kelvin Sherlock 2013-05-16 00:11:05 -04:00
parent 5293a49d7f
commit 40d3f9a69b
3 changed files with 79 additions and 43 deletions

View File

@ -685,26 +685,8 @@ namespace OS
return d0;
}
// finder info
{
uint8_t buffer[32];
std::memset(buffer, 0, sizeof(buffer));
int rv;
int xerrno;
rv = ::getxattr(sname.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0);
xerrno = errno;
// override for source files.
if (IsTextFile(sname))
{
std::memcpy(buffer, "TEXTMPS ", 8);
}
// only 16 bytes copied.
std::memcpy(memoryPointer(parm + 32), buffer, 16);
}
Internal::GetFinderInfo(sname, memoryPointer(parm + 32), false);
// file reference number

View File

@ -214,29 +214,7 @@ namespace OS {
// todo -- move to separate function? used in multiple places.
uint8_t buffer[32];
std::memset(buffer, 0, sizeof(buffer));
int rv;
rv = ::getxattr(path.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0);
if (rv < 0)
{
switch (errno)
{
case ENOENT:
case EACCES:
return errno_to_oserr(errno);
}
}
// override for source files.
if (IsTextFile(path))
{
std::memcpy(buffer, "TEXTMPS ", 8);
}
std::memmove(memoryPointer(finderInfo), buffer, 16);
Internal::GetFinderInfo(path, memoryPointer(finderInfo), false);
return 0;
}

View File

@ -9,7 +9,7 @@
#include <fcntl.h>
#include <sys/xattr.h>
#include <machine/endian.h>
namespace OS { namespace Internal {
@ -98,6 +98,80 @@ namespace OS { namespace Internal {
case EACCES:
return errno_to_oserr(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.
@ -114,6 +188,8 @@ namespace OS { namespace Internal {
// 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";