- modified BeOS/extfs_beos.cpp to implement new get_finfo/set_finfo functions

(untested)
This commit is contained in:
cebix 2000-08-14 14:38:16 +00:00
parent 00f389d047
commit a1d4587df6
2 changed files with 37 additions and 49 deletions

View File

@ -87,7 +87,7 @@ void add_path_component(char *path, const char *component)
/* /*
* Get/set finder type/creator for file specified by full path * Get/set finder info for file/directory specified by full path
*/ */
struct mime2type { struct mime2type {
@ -137,17 +137,21 @@ static const mime2type m2t_translation[] = {
{NULL, 0, 0, false} // End marker {NULL, 0, 0, false} // End marker
}; };
void get_finder_type(const char *path, uint32 &type, uint32 &creator) void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
{ {
type = 0; // Set default finder info
creator = 0; Mac_memset(finfo, 0, SIZEOF_FInfo);
if (fxinfo)
Mac_memset(fxinfo, 0, SIZEOF_FXInfo);
WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS);
WriteMacInt32(finfo + fdLocation, (uint32)-1);
// Open file // Open file
int fd = open(path, O_RDONLY); int fd = open(path, O_RDONLY);
if (fd < 0) if (fd < 0)
return; return;
// Read BeOS MIME type and close file // Read BeOS MIME type
char mime[256]; char mime[256];
ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256); ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256);
mime[255] = 0; mime[255] = 0;
@ -159,15 +163,15 @@ void get_finder_type(const char *path, uint32 &type, uint32 &creator)
if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) { if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
// MacOS style type // MacOS style type
memcpy(&type, mactype, 4); WriteMacInt32(finfo + fdType, mactype);
} else { } else {
// MIME string, look in table // MIME string, look in table
for (int i=0; m2t_translation[i].mime; i++) { for (int i=0; m2t_translation[i].mime; i++) {
if (!strcmp(mime, m2t_translation[i].mime)) { if (!strcmp(mime, m2t_translation[i].mime)) {
type = m2t_translation[i].type; WriteMacInt32(finfo + fdType, m2t_translation[i].type);
creator = m2t_translation[i].creator; WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator);
break; break;
} }
} }
@ -175,20 +179,28 @@ void get_finder_type(const char *path, uint32 &type, uint32 &creator)
} }
// Override file type with MACOS:CREATOR attribute // Override file type with MACOS:CREATOR attribute
fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4); if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4) == 4)
WriteMacInt32(finfo + fdCreator, (mime[0] << 24) | (mime[1] << 16) | (mime[2] << 8) | mime[3]);
// Read MACOS:HFS_FLAGS attribute
if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2) == 2)
WriteMacInt16(finfo + fdFlags, (mime[0] << 8) | mime[1]);
// Close file // Close file
close(fd); close(fd);
} }
void set_finder_type(const char *path, uint32 type, uint32 creator) void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
{ {
char mime[256];
// Open file // Open file
int fd = open(path, O_WRONLY); int fd = open(path, O_WRONLY);
if (fd < 0) if (fd < 0)
return; return;
// Set BEOS:TYPE attribute // Set BEOS:TYPE attribute
uint32 type = ReadMacInt32(finfo + fdType);
if (type) { if (type) {
bool written = false; bool written = false;
for (int i=0; m2t_translation[i].mime; i++) { for (int i=0; m2t_translation[i].mime; i++) {
@ -199,52 +211,28 @@ void set_finder_type(const char *path, uint32 type, uint32 creator)
} }
} }
if (!written) { if (!written) {
char mime[256];
sprintf(mime, "application/x-MacOS-%c%c%c%c", type >> 24, type >> 16, type >> 8, type); sprintf(mime, "application/x-MacOS-%c%c%c%c", type >> 24, type >> 16, type >> 8, type);
fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, strlen(mime) + 1); fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, strlen(mime) + 1);
} }
} }
// Set MACOS:CREATOR attribute // Set MACOS:CREATOR attribute
if (creator) uint32 creator = ReadMacInt32(finfo + fdType);
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4); if (creator) {
mime[0] = creator >> 24;
// Close file mime[1] = creator >> 16;
close(fd); mime[2] = creator >> 8;
} mime[3] = creator;
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4);
}
/*
* Get/set finder flags for file/dir specified by full path (MACOS:HFS_FLAGS attribute)
*/
void get_finder_flags(const char *path, uint16 &flags)
{
flags = DEFAULT_FINDER_FLAGS; // Default
// Open file
int fd = open(path, O_RDONLY);
if (fd < 0)
return;
// Read MACOS:HFS_FLAGS attribute
fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2);
// Close file
close(fd);
}
void set_finder_flags(const char *path, uint16 flags)
{
// Open file
int fd = open(path, O_WRONLY);
if (fd < 0)
return;
// Write MACOS:HFS_FLAGS attribute // Write MACOS:HFS_FLAGS attribute
if (flags != DEFAULT_FINDER_FLAGS) uint16 flags = ReadMacInt16(finfo + fdFlags);
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2); if (flags != DEFAULT_FINDER_FLAGS) {
else mime[0] = flags >> 8;
mime[1] = flags;
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2);
} else
fs_remove_attr(fd, "MACOS:HFS_FLAGS"); fs_remove_attr(fd, "MACOS:HFS_FLAGS");
// Close file // Close file

View File

@ -1,5 +1,5 @@
/* /*
* pwoerrom_cpu.cpp - Using the 680x0 emulator in PowerMac ROMs for Basilisk II * powerrom_cpu.cpp - Using the 680x0 emulator in PowerMac ROMs for Basilisk II
* *
* Basilisk II (C) 1997-2000 Christian Bauer * Basilisk II (C) 1997-2000 Christian Bauer
*/ */