From 40d3f9a69b20d31a5295caa4ec3fd5a6eb75ffa8 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 16 May 2013 00:11:05 -0400 Subject: [PATCH] create finder info from prodos file type/aux type, if available. --- toolbox/os.cpp | 20 +---------- toolbox/os_highlevel.cpp | 24 +------------ toolbox/os_internal.cpp | 78 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 43 deletions(-) diff --git a/toolbox/os.cpp b/toolbox/os.cpp index 04b0649..19f513f 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -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 diff --git a/toolbox/os_highlevel.cpp b/toolbox/os_highlevel.cpp index a664378..252d0be 100644 --- a/toolbox/os_highlevel.cpp +++ b/toolbox/os_highlevel.cpp @@ -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; } diff --git a/toolbox/os_internal.cpp b/toolbox/os_internal.cpp index 92388af..bf452bd 100644 --- a/toolbox/os_internal.cpp +++ b/toolbox/os_internal.cpp @@ -9,7 +9,7 @@ #include #include - +#include 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";