- fixed bugs in the BeOS extfs file types handling

This commit is contained in:
cebix 2001-03-31 14:32:01 +00:00
parent 085855e083
commit 5ffe6505dc
7 changed files with 63 additions and 68 deletions

View File

@ -7,6 +7,7 @@ V0.9 - <insert date here>
- Unix: FreeBSD configure script cleanups [Michael Alyn Miller]
- Unix: ether_linux.cpp moved and renamed to ether_unix.cpp, now
also works with the tap driver under FreeBSD [Michael Alyn Miller]
- BeOS: fixed some bugs in the extfs file types handling
V0.9 (snapshot) - 17.Feb.2001
- adapted for mon V3.0 which is now the required minimum

View File

@ -211,7 +211,7 @@ static const ext2type e2t_translation[] = {
{NULL, 0, 0} // End marker
};
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
// Set default finder info
Mac_memset(finfo, 0, SIZEOF_FInfo);
@ -232,8 +232,7 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
}
// No Finder info file, translate file name extension to MacOS type/creator
struct stat st;
if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
if (!is_dir) {
int path_len = strlen(path);
for (int i=0; e2t_translation[i].ext; i++) {
int ext_len = strlen(e2t_translation[i].ext);
@ -248,7 +247,7 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
}
}
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
// Open Finder info file
int fd = open_finf(path, O_RDWR);

View File

@ -137,7 +137,7 @@ static const mime2type m2t_translation[] = {
{NULL, 0, 0, false} // End marker
};
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
// Set default finder info
Mac_memset(finfo, 0, SIZEOF_FInfo);
@ -151,16 +151,17 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
if (fd < 0)
return;
if (!is_dir) {
// Read BeOS MIME type
char mime[256];
ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256);
mime[255] = 0;
ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, tmp_buf, 256);
tmp_buf[255] = 0;
if (actual > 0) {
// Translate MIME type to MacOS type/creator
uint8 mactype[4];
if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
if (sscanf((char *)tmp_buf, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
// MacOS style type
WriteMacInt32(finfo + fdType, (mactype[0] << 24) | (mactype[1] << 16) | (mactype[2] << 8) | mactype[3]);
@ -169,7 +170,7 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
// MIME string, look in table
for (int i=0; m2t_translation[i].mime; i++) {
if (!strcmp(mime, m2t_translation[i].mime)) {
if (!strcmp((char *)tmp_buf, m2t_translation[i].mime)) {
WriteMacInt32(finfo + fdType, m2t_translation[i].type);
WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator);
break;
@ -179,59 +180,55 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
}
// Override file type with MACOS:CREATOR attribute
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]);
if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4) == 4)
WriteMacInt32(finfo + fdCreator, (tmp_buf[0] << 24) | (tmp_buf[1] << 16) | (tmp_buf[2] << 8) | tmp_buf[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]);
if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2) == 2)
WriteMacInt16(finfo + fdFlags, (tmp_buf[0] << 8) | tmp_buf[1]);
// Close file
close(fd);
}
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
char mime[256];
// Open file
int fd = open(path, O_WRONLY);
if (fd < 0)
return;
if (!is_dir) {
// Set BEOS:TYPE attribute
uint32 type = ReadMacInt32(finfo + fdType);
if (type) {
bool written = false;
for (int i=0; m2t_translation[i].mime; i++) {
if (m2t_translation[i].type == type && m2t_translation[i].reversible) {
fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1);
written = true;
break;
}
}
if (!written) {
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);
}
}
// Set MACOS:CREATOR attribute
uint32 creator = ReadMacInt32(finfo + fdType);
uint32 creator = ReadMacInt32(finfo + fdCreator);
if (creator) {
mime[0] = creator >> 24;
mime[1] = creator >> 16;
mime[2] = creator >> 8;
mime[3] = creator;
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4);
tmp_buf[0] = creator >> 24;
tmp_buf[1] = creator >> 16;
tmp_buf[2] = creator >> 8;
tmp_buf[3] = creator;
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4);
}
}
// Write MACOS:HFS_FLAGS attribute
uint16 flags = ReadMacInt16(finfo + fdFlags);
if (flags != DEFAULT_FINDER_FLAGS) {
mime[0] = flags >> 8;
mime[1] = flags;
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2);
tmp_buf[0] = flags >> 8;
tmp_buf[1] = flags;
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2);
} else
fs_remove_attr(fd, "MACOS:HFS_FLAGS");

View File

@ -41,7 +41,6 @@
#include "memory.h"
#include "readcpu.h"
#include "newcpu.h"
#include "compiler.h"
#define DEBUG 0
#include "debug.h"

View File

@ -218,7 +218,7 @@ static const ext2type e2t_translation[] = {
{NULL, 0, 0} // End marker
};
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
// Set default finder info
Mac_memset(finfo, 0, SIZEOF_FInfo);
@ -239,8 +239,7 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
}
// No Finder info file, translate file name extension to MacOS type/creator
struct stat st;
if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
if (!is_dir) {
int path_len = strlen(path);
for (int i=0; e2t_translation[i].ext; i++) {
int ext_len = strlen(e2t_translation[i].ext);
@ -255,7 +254,7 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
}
}
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
// Open Finder info file
int fd = open_finf(path, O_RDWR);

View File

@ -1237,7 +1237,7 @@ read_next_de:
#endif
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
WriteMacInt16(pb + ioFlStBlk, 0);
WriteMacInt32(pb + ioFlLgLen, st.st_size);
@ -1274,7 +1274,7 @@ static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID)
return fnfErr;
// Set Finder info
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
//!! times
return noErr;
@ -1366,7 +1366,7 @@ read_next_de:
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
WriteMacInt32(pb + ioFlBkDat, 0);
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
if (S_ISDIR(st.st_mode)) {
@ -1422,7 +1422,7 @@ static int16 fs_set_cat_info(uint32 pb)
return errno2oserr();
// Set Finder info
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
//!! times
return noErr;
@ -1510,7 +1510,7 @@ static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork)
WriteMacInt32(fcb + fcbVPtr, vcb);
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
get_finfo(full_path, fs_data + fsPB, 0);
get_finfo(full_path, fs_data + fsPB, 0, false);
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
WriteMacInt32(fcb + fcbCatPos, fd);

View File

@ -33,8 +33,8 @@ extern int16 ExtFSHFS(uint32 vcb, uint16 selectCode, uint32 paramBlock, uint32 g
extern void extfs_init(void);
extern void extfs_exit(void);
extern void add_path_component(char *path, const char *component);
extern void get_finfo(const char *path, uint32 finfo, uint32 fxinfo);
extern void set_finfo(const char *path, uint32 finfo, uint32 fxinfo);
extern void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir);
extern void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir);
extern uint32 get_rfork_size(const char *path);
extern int open_rfork(const char *path, int flag);
extern void close_rfork(const char *path, int fd);