mirror of
https://github.com/ksherlock/mpw.git
synced 2025-02-16 12:30:53 +00:00
Initial Solaris support.
This commit is contained in:
parent
62224b9c1d
commit
8bdad6281e
@ -1,3 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Kelvin W Sherlock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "native_internal.h"
|
||||
#include <sys/attr.h>
|
||||
@ -9,7 +34,7 @@
|
||||
using namespace MacOS;
|
||||
|
||||
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
|
||||
#define st_birthtime st_mtime
|
||||
#define st_birthtime st_ctime
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@ -24,6 +49,7 @@ namespace {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
uint32_t rforksize(int fd)
|
||||
{
|
||||
ssize_t rv;
|
||||
@ -33,26 +59,8 @@ namespace {
|
||||
return rv;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void fixup_prodos(uint8_t *buffer) {
|
||||
if (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' && buffer[2] == 0 && buffer[3] == 0)
|
||||
{
|
||||
static char Hex[] = "0123456789ABCDEF";
|
||||
|
||||
uint8_t ftype = buffer[1];
|
||||
buffer[0] = Hex[ftype >> 4];
|
||||
buffer[1] = Hex[ftype & 0x0f];
|
||||
buffer[2] = ' ';
|
||||
buffer[3] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -105,7 +113,7 @@ namespace native {
|
||||
|
||||
rv = getxattr(path_name.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0);
|
||||
if (rv == 16 || rv == 32) {
|
||||
fixup_prodos(buffer);
|
||||
fixup_prodos_ftype(buffer);
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return noErr;
|
||||
}
|
||||
@ -188,7 +196,7 @@ namespace native {
|
||||
}
|
||||
|
||||
}
|
||||
fixup_prodos(buffer);
|
||||
fixup_prodos_ftype(buffer);
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return noErr;
|
||||
}
|
||||
@ -196,7 +204,6 @@ namespace native {
|
||||
/* if it's a text file, call it a text file */
|
||||
if (is_text_file_internal(path_name)) {
|
||||
memcpy(buffer, "TEXTMPS ", 8);
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
}
|
||||
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
@ -213,7 +220,7 @@ namespace native {
|
||||
|
||||
fi.create_date = unix_to_mac(st.st_birthtime);
|
||||
fi.modify_date = unix_to_mac(st.st_mtime);
|
||||
fi.backup_date = unix_to_mac(st.st_mtime);
|
||||
fi.backup_date = 0;
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
fi.type = file_info::directory;
|
||||
|
26
native/Linux.cpp
Normal file
26
native/Linux.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Kelvin W Sherlock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
139
native/SunOS.cpp
Normal file
139
native/SunOS.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Kelvin W Sherlock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define XATTR_FINDERINFO_NAME "com.apple.FinderInfo"
|
||||
#define XATTR_RESOURCEFORK_NAME "com.apple.ResourceFork"
|
||||
|
||||
#define XATTR_FILETYPE_NAME "prodos.FileType"
|
||||
#define XATTR_AUXTYPE_NAME "prodos.AuxType"
|
||||
|
||||
|
||||
using namespace MacOS;
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t rforksize(const std::string &path_name)
|
||||
{
|
||||
int fd;
|
||||
uint32_t rv = 0;
|
||||
struct stat st;
|
||||
|
||||
fd = attropen(path_name.c_str(), XATTR_RESOURCEFORK_NAME, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
|
||||
if (fstat(fd, &st) == 0) rv = st.st_size;
|
||||
|
||||
close(fd);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace native {
|
||||
|
||||
|
||||
macos_error get_finder_info(const std::string &path_name, void *info, bool extended) {
|
||||
|
||||
uint8_t buffer[32];
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
int fd;
|
||||
fd = attropen(path_name.c_str(), XATTR_FINDERINFO_NAME, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
ssize_t x = read(fd, buffer, 32);
|
||||
close(fd);
|
||||
if (x == 32 || x == 16){
|
||||
fixup_prodos_ftype(buffer);
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* if it's a text file, call it a text file */
|
||||
if (is_text_file_internal(path_name)) {
|
||||
memcpy(buffer, "TEXTMPS ", 8);
|
||||
}
|
||||
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return noErr;
|
||||
|
||||
}
|
||||
|
||||
macos_error get_file_info(const std::string &path_name, file_info &fi)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path_name.c_str(), &st) < 0)
|
||||
return macos_error_from_errno();
|
||||
|
||||
fi.create_date = unix_to_mac(st.st_ctime);
|
||||
fi.modify_date = unix_to_mac(st.st_mtime);
|
||||
fi.backup_date = 0;
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
fi.type = file_info::directory;
|
||||
|
||||
|
||||
int links = st.st_nlink - 2;
|
||||
if (links < 0) links = 0;
|
||||
if (links > 65535) links = 65535;
|
||||
|
||||
fi.entry_count = links;
|
||||
return noErr;
|
||||
}
|
||||
|
||||
// todo -- get actual block size instead of assuming 512. oh well!
|
||||
|
||||
fi.type = file_info::file;
|
||||
fi.data_logical_size = st.st_size;
|
||||
fi.data_physical_size = (st.st_size + 511) & ~511;
|
||||
fi.resource_physical_size = 0;
|
||||
fi.resource_logical_size = 0;
|
||||
|
||||
get_finder_info(path_name, fi.finder_info);
|
||||
|
||||
ssize_t rsize = rforksize(path_name);
|
||||
if (rsize > 0) {
|
||||
fi.resource_physical_size = rsize;
|
||||
fi.resource_logical_size = (rsize + 511) & ~511;
|
||||
}
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
26
native/Windows.cpp
Normal file
26
native/Windows.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Kelvin W Sherlock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
@ -1,3 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Kelvin W Sherlock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "native_internal.h"
|
||||
@ -6,6 +31,7 @@
|
||||
using namespace MacOS;
|
||||
|
||||
namespace {
|
||||
|
||||
const long epoch_adjust = 86400 * (365 * (1970 - 1904) + 17); // 17 leap years.
|
||||
|
||||
|
||||
@ -48,6 +74,26 @@ namespace native {
|
||||
|
||||
}
|
||||
|
||||
void fixup_prodos_ftype(uint8_t *buffer) {
|
||||
if (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' && buffer[2] == 0 && buffer[3] == 0)
|
||||
{
|
||||
static char Hex[] = "0123456789ABCDEF";
|
||||
|
||||
uint8_t ftype = buffer[1];
|
||||
buffer[0] = Hex[ftype >> 4];
|
||||
buffer[1] = Hex[ftype & 0x0f];
|
||||
buffer[2] = ' ';
|
||||
buffer[3] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
macos_error get_finder_info(const std::string &path_name, uint32_t &ftype, uint32_t &ctype) {
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef __native_internal_h__
|
||||
#define __native_internal_h__
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "native.h"
|
||||
|
||||
namespace native {
|
||||
@ -9,6 +12,7 @@ namespace native {
|
||||
bool is_text_file_internal(const std::string &path_name);
|
||||
bool is_binary_file_internal(const std::string &path_name);
|
||||
|
||||
void fixup_prodos_ftype(uint8_t *buffer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user