--- BasiliskII/src/BeOS/extfs_beos.cpp 1999/12/22 16:16:14 1.9 +++ BasiliskII/src/BeOS/extfs_beos.cpp 2008/01/01 09:40:32 1.18 @@ -1,7 +1,7 @@ /* * extfs_beos.cpp - MacOS file system for access native file system access, BeOS specific stuff * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -87,7 +87,7 @@ void add_path_component(char *path, cons /* - * Get/set finder type/creator for file specified by full path + * Get/set finder info for file/directory specified by full path */ struct mime2type { @@ -137,114 +137,99 @@ static const mime2type m2t_translation[] {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, bool is_dir) { - type = 0; - creator = 0; + // Set default finder info + 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 int fd = open(path, O_RDONLY); if (fd < 0) return; - // Read BeOS MIME type and close file - char mime[256]; - ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256); - mime[255] = 0; + if (!is_dir) { - if (actual > 0) { - - // Translate MIME type to MacOS type/creator - char mactype[4]; - if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) { - - // MacOS style type - memcpy(&type, mactype, 4); - - } else { - - // MIME string, look in table - for (int i=0; m2t_translation[i].mime; i++) { - if (!strcmp(mime, m2t_translation[i].mime)) { - type = m2t_translation[i].type; - creator = m2t_translation[i].creator; - break; + // Read BeOS MIME type + 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((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]); + + } else { + + // MIME string, look in table + for (int i=0; m2t_translation[i].mime; i++) { + if (!strcmp((char *)tmp_buf, m2t_translation[i].mime)) { + WriteMacInt32(finfo + fdType, m2t_translation[i].type); + WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator); + break; + } } } } + + // Override file type with MACOS:CREATOR attribute + 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]); } - // Override file type with MACOS:CREATOR attribute - fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4); + // Read MACOS:HFS_FLAGS attribute + 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_finder_type(const char *path, uint32 type, uint32 creator) +void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir) { // Open file int fd = open(path, O_WRONLY); if (fd < 0) return; - // Set BEOS:TYPE attribute - 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 (!is_dir) { + + // Set BEOS:TYPE attribute + uint32 type = ReadMacInt32(finfo + fdType); + if (type) { + 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); + break; + } } } - if (!written) { - char mime[256]; - 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 + fdCreator); + if (creator) { + 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); } } - // Set MACOS:CREATOR attribute - if (creator) - fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4); - - // Close file - close(fd); -} - - -/* - * 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 - if (flags != DEFAULT_FINDER_FLAGS) - fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2); - else + uint16 flags = ReadMacInt16(finfo + fdFlags); + if (flags != DEFAULT_FINDER_FLAGS) { + 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"); // Close file