--- BasiliskII/src/extfs.cpp 2000/05/16 17:11:35 1.17 +++ BasiliskII/src/extfs.cpp 2008/06/20 00:39:47 1.36 @@ -1,7 +1,7 @@ /* * extfs.cpp - MacOS file system for native file system access * - * Basilisk II (C) 1997-2000 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 @@ -40,13 +40,19 @@ #include #include #include -#include #include -#include #include +#ifndef WIN32 +#include +#include +#endif + +#if defined __APPLE__ && defined __MACH__ +#include +#endif + #include "cpu_emulation.h" -#include "macos_util.h" #include "emul_op.h" #include "main.h" #include "disk.h" @@ -55,6 +61,10 @@ #include "extfs.h" #include "extfs_defs.h" +#ifdef WIN32 +# include "posix_emu.h" +#endif + #define DEBUG 0 #include "debug.h" @@ -65,7 +75,7 @@ enum { fsHFSProcStub = 6, fsDrvStatus = 12, // Drive Status record fsFSD = 42, // File system descriptor - fsPB = 238, // IOParam (for mounting and renaming) + fsPB = 238, // IOParam (for mounting and renaming), also used for temporary storage fsVMI = 288, // VoumeMountInfoHeader (for mounting) fsParseRec = 296, // ParsePathRec struct fsReturn = 306, // Area for return data of 68k routines @@ -101,8 +111,8 @@ static bool ready = false; static struct stat root_stat; // File system ID/media type -const int16 MY_FSID = 'ba'; -const uint32 MY_MEDIA_TYPE = 'basi'; +const int16 MY_FSID = EMULATOR_ID_2; +const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4; // CNID of root and root's parent const uint32 ROOT_ID = 2; @@ -111,6 +121,11 @@ const uint32 ROOT_PARENT_ID = 1; // File system stack size const int STACK_SIZE = 0x10000; +// Allocation block and clump size as reported to MacOS (these are of course +// not the real values and have no meaning on the host OS) +const int AL_BLK_SIZE = 0x4000; +const int CLUMP_SIZE = 0x4000; + // Drive number of our pseudo-drive static int drive_number; @@ -143,7 +158,8 @@ struct FSItem { uint32 id; // CNID of this file/dir uint32 parent_id; // CNID of parent file/dir FSItem *parent; // Pointer to parent - char name[32]; // Object name (C string) + char *name; // Object name (C string) - Host OS + char guest_name[32]; // Object name (C string) - Guest OS time_t mtime; // Modification time for get_cat_info caching int cache_dircount; // Cached number of files in directory }; @@ -154,6 +170,44 @@ static uint32 next_cnid = fsUsrCNID; // /* + * Get object creation time + */ + +#if defined __APPLE__ && defined __MACH__ +struct crtimebuf { + unsigned long length; + struct timespec crtime; +}; + +static uint32 do_get_creation_time(const char *path) +{ + struct attrlist attr; + memset(&attr, 0, sizeof(attr)); + attr.bitmapcount = ATTR_BIT_MAP_COUNT; + attr.commonattr = ATTR_CMN_CRTIME; + + crtimebuf buf; + if (getattrlist(path, &attr, &buf, sizeof(buf), FSOPT_NOFOLLOW) < 0) + return 0; + return TimeToMacTime(buf.crtime.tv_sec); +} + +static uint32 get_creation_time(const char *path) +{ + if (path == NULL) + return 0; + if (path == RootPath) { + static uint32 root_crtime = UINT_MAX; + if (root_crtime == UINT_MAX) + root_crtime = do_get_creation_time(path); + return root_crtime; + } + return do_get_creation_time(path); +} +#endif + + +/* * Find FSItem for given CNID */ @@ -168,6 +222,26 @@ static FSItem *find_fsitem_by_id(uint32 return NULL; } +/* + * Create FSItem with the given parameters + */ + +static FSItem *create_fsitem(const char *name, const char *guest_name, FSItem *parent) +{ + FSItem *p = new FSItem; + last_fs_item->next = p; + p->next = NULL; + last_fs_item = p; + p->id = next_cnid++; + p->parent_id = parent->id; + p->parent = parent; + p->name = new char[strlen(name) + 1]; + strcpy(p->name, name); + strncpy(p->guest_name, guest_name, 31); + p->guest_name[31] = 0; + p->mtime = 0; + return p; +} /* * Find FSItem for given name and parent, construct new FSItem if not found @@ -183,19 +257,25 @@ static FSItem *find_fsitem(const char *n } // Not found, construct new FSItem - p = new FSItem; - last_fs_item->next = p; - p->next = NULL; - last_fs_item = p; - p->id = next_cnid++; - p->parent_id = parent->id; - p->parent = parent; - strncpy(p->name, name, 31); - p->name[31] = 0; - p->mtime = 0; - return p; + return create_fsitem(name, host_encoding_to_macroman(name), parent); } +/* + * Find FSItem for given guest_name and parent, construct new FSItem if not found + */ + +static FSItem *find_fsitem_guest(const char *guest_name, FSItem *parent) +{ + FSItem *p = first_fs_item; + while (p) { + if (p->parent == parent && !strcmp(p->guest_name, guest_name)) + return p; + p = p->next; + } + + // Not found, construct new FSItem + return create_fsitem(macroman_to_host_encoding(guest_name), guest_name, parent); +} /* * Get full path (->full_path) for given FSItem @@ -257,30 +337,21 @@ static void cstr2pstr(char *dst, const c *dst++ = strlen(src); char c; while ((c = *src++) != 0) { + // Note: we are converting host ':' characters to Mac '/' characters here + // '/' is not a path separator as this function is only used on object names if (c == ':') c = '/'; *dst++ = c; } } -// Convert pascal string to C string -static void pstr2cstr(char *dst, const char *src) -{ - int size = *src++; - while (size--) { - char c = *src++; - if (c == '/') - c = ':'; - *dst++ = c; - } - *dst = 0; -} - // Convert string (no length byte) to C string, length given separately static void strn2cstr(char *dst, const char *src, int size) { while (size--) { char c = *src++; + // Note: we are converting Mac '/' characters to host ':' characters here + // '/' is not a path separator as this function is only used on object names if (c == '/') c = ':'; *dst++ = c; @@ -345,7 +416,9 @@ void ExtFSInit(void) p->id = ROOT_PARENT_ID; p->parent_id = 0; p->parent = NULL; + p->name = new char[1]; p->name[0] = 0; + p->guest_name[0] = 0; // Create root FSItem p = new FSItem; @@ -355,7 +428,11 @@ void ExtFSInit(void) p->id = ROOT_ID; p->parent_id = ROOT_PARENT_ID; p->parent = first_fs_item; - strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); + const char *volume_name = GetString(STR_EXTFS_VOLUME_NAME); + p->name = new char[strlen(volume_name) + 1]; + strcpy(p->name, volume_name); + strncpy(p->guest_name, host_encoding_to_macroman(p->name), 32); + p->guest_name[31] = 0; // Find path for root if ((RootPath = PrefsFindString("extfs")) != NULL) { @@ -378,6 +455,7 @@ void ExtFSExit(void) FSItem *p = first_fs_item, *next; while (p) { next = p->next; + delete[] p->name; delete p; p = next; } @@ -404,7 +482,7 @@ void InstallExtFS(void) // FSM present? r.d[0] = gestaltFSAttr; Execute68kTrap(0xa1ad, &r); // Gestalt() - D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); + D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { printf("WARNING: No FSM present, disabling ExtFS\n"); return; @@ -413,7 +491,7 @@ void InstallExtFS(void) // Yes, version >=1.2? r.d[0] = gestaltFSMVersion; Execute68kTrap(0xa1ad, &r); // Gestalt() - D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); + D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); return; @@ -683,7 +761,7 @@ int16 ExtFSComm(uint16 message, uint32 p } case ffsIDDiskMessage: { // Check if volume is handled by our FS - if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) + if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) return noErr; else return extFSErr; @@ -727,11 +805,8 @@ static int16 get_current_dir(uint32 pb, if (no_vol_name) WriteMacInt32(pb + ioNamePtr, name_ptr); int16 status = ReadMacInt16(fs_data + fsReturn); - int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); - int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); - uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); - result = r.d[0] & 0xffff; + result = (int16)(r.d[0] & 0xffff); if (result == noErr) { switch (status) { @@ -756,7 +831,7 @@ static int16 get_current_dir(uint32 pb, Execute68k(fs_data + fsResolveWDCB, &r); uint32 wdcb = ReadMacInt32(fs_data + fsReturn); D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); - result = r.d[0] & 0xffff; + result = (int16)(r.d[0] & 0xffff); if (result == noErr) current_dir = ReadMacInt32(wdcb + wdDirID); } @@ -772,7 +847,7 @@ static int16 get_current_dir(uint32 pb, r.a[0] = wdpb; Execute68k(fs_data + fsGetDefaultVol, &r); D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); - result = r.d[0] & 0xffff; + result = (int16)(r.d[0] & 0xffff); if (result == noErr) current_dir = ReadMacInt32(wdpb + ioWDDirID); } @@ -798,7 +873,7 @@ static int16 get_path_component_name(uin r.a[0] = rec; Execute68k(fs_data + fsGetPathComponentName, &r); // D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); - return r.d[0] & 0xffff; + return (int16)(r.d[0] & 0xffff); } @@ -834,7 +909,7 @@ static int16 get_item_and_path(uint32 pb r.a[1] = ReadMacInt32(parseRec + ppNamePtr); Execute68k(fs_data + fsParsePathname, &r); D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); - result = r.d[0] & 0xffff; + result = (int16)(r.d[0] & 0xffff); if (result == noErr) { // Check for leading delimiter of the partial pathname @@ -869,7 +944,7 @@ static int16 get_item_and_path(uint32 pb char name[32]; strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength)); D(bug(" entering %s\n", name)); - p = find_fsitem(name, p); + p = find_fsitem_guest(name, p); current_dir = p->id; // startOffset = start of next component @@ -892,7 +967,7 @@ static int16 get_item_and_path(uint32 pb char name[32]; strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength)); D(bug(" object is %s\n", name)); - item = find_fsitem(name, p); + item = find_fsitem_guest(name, p); } } } @@ -947,7 +1022,7 @@ static uint32 find_fcb(int16 refNum) static int16 fs_mount_vol(uint32 pb) { D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); - if (ReadMacInt16(pb + ioVRefNum) == drive_number) + if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) return noErr; else return extFSErr; @@ -964,26 +1039,30 @@ static int16 fs_volume_mount(uint32 pb) r.a[0] = fs_data + fsReturn; r.a[1] = fs_data + fsReturn + 2; Execute68k(fs_data + fsAllocateVCB, &r); +#if DEBUG uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn); +#endif uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); if (r.d[0] & 0xffff) - return r.d[0]; + return (int16)r.d[0]; // Init VCB WriteMacInt16(vcb + vcbSigWord, 0x4244); -#ifdef __BEOS__ - WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); +#if defined(__BEOS__) || defined(WIN32) + WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime)); +#elif defined __APPLE__ && defined __MACH__ + WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath)); #else WriteMacInt32(vcb + vcbCrDate, 0); #endif - WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET); + WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime)); WriteMacInt32(vcb + vcbVolBkUp, 0); WriteMacInt16(vcb + vcbNmFls, 1); //!! WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! - WriteMacInt32(vcb + vcbAlBlkSiz, 1024); - WriteMacInt32(vcb + vcbClpSiz, 1024); + WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); + WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); WriteMacInt32(vcb + vcbNxtCNID, next_cnid); WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); @@ -997,10 +1076,10 @@ static int16 fs_volume_mount(uint32 pb) r.a[0] = fs_data + fsReturn; r.a[1] = vcb; Execute68k(fs_data + fsAddNewVCB, &r); - int16 vRefNum = ReadMacInt32(fs_data + fsReturn); + int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); if (r.d[0] & 0xffff) - return r.d[0]; + return (int16)r.d[0]; // Post diskInsertEvent D(bug(" posting diskInsertEvent\n")); @@ -1024,7 +1103,7 @@ static int16 fs_unmount_vol(uint32 vcb) r.a[0] = vcb; Execute68k(fs_data + fsDisposeVCB, &r); D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); - return r.d[0]; + return (int16)r.d[0]; } // Get information about a volume (HVolumeParam) @@ -1035,19 +1114,21 @@ static int16 fs_get_vol_info(uint32 pb, // Fill in struct if (ReadMacInt32(pb + ioNamePtr)) pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); -#ifdef __BEOS__ - WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); +#if defined(__BEOS__) || defined(WIN32) + WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime)); +#elif defined __APPLE__ && defined __MACH__ + WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath)); #else WriteMacInt32(pb + ioVCrDate, 0); #endif - WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET); + WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime)); WriteMacInt16(pb + ioVAtrb, 0); WriteMacInt16(pb + ioVNmFls, 1); //!! WriteMacInt16(pb + ioVBitMap, 0); WriteMacInt16(pb + ioAllocPtr, 0); WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! - WriteMacInt32(pb + ioVAlBlkSiz, 1024); - WriteMacInt32(pb + ioVClpSiz, 1024); + WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); + WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); WriteMacInt16(pb + ioAlBlSt, 0); WriteMacInt32(pb + ioVNxtCNID, next_cnid); WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! @@ -1105,7 +1186,7 @@ static int16 fs_get_vol(uint32 pb) r.a[0] = pb; Execute68k(fs_data + fsGetDefaultVol, &r); D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); - return r.d[0]; + return (int16)r.d[0]; } // Set default volume (WDParam) @@ -1161,7 +1242,7 @@ static int16 fs_set_vol(uint32 pb, bool r.d[2] = refNum; Execute68k(fs_data + fsSetDefaultVol, &r); D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); - return r.d[0]; + return (int16)r.d[0]; } // Query file attributes (HFileParam) @@ -1222,38 +1303,32 @@ read_next_de: // Fill in struct from fs_item and stats if (ReadMacInt32(pb + ioNamePtr)) - cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name); + cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name); WriteMacInt16(pb + ioFRefNum, 0); WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); WriteMacInt32(pb + ioDirID, fs_item->id); -#ifdef __BEOS__ - WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); +#if defined(__BEOS__) || defined(WIN32) + WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); +#elif defined __APPLE__ && defined __MACH__ + WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); #else WriteMacInt32(pb + ioFlCrDat, 0); #endif - WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); + WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime)); - Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo); - uint32 type, creator; // pb may point to kernel space, but stack is switched - get_finder_type(full_path, type, creator); - WriteMacInt32(pb + ioFlFndrInfo + fdType, type); - WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); - uint16 fflags; - get_finder_flags(full_path, fflags); - WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags); + get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); WriteMacInt16(pb + ioFlStBlk, 0); WriteMacInt32(pb + ioFlLgLen, st.st_size); - WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); + WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); WriteMacInt16(pb + ioFlRStBlk, 0); uint32 rf_size = get_rfork_size(full_path); WriteMacInt32(pb + ioFlRLgLen, rf_size); - WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); + WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); if (hfs) { WriteMacInt32(pb + ioFlBkDat, 0); - Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); WriteMacInt32(pb + ioFlParID, fs_item->parent_id); WriteMacInt32(pb + ioFlClpSiz, 0); } @@ -1278,9 +1353,9 @@ static int16 fs_set_file_info(uint32 pb, if (S_ISDIR(st.st_mode)) return fnfErr; - // Set attributes - set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); - set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); + // Set Finder info + set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); + //!! times return noErr; } @@ -1351,14 +1426,16 @@ read_next_de: // Fill in struct from fs_item and stats if (ReadMacInt32(pb + ioNamePtr)) - cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name); + cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name); WriteMacInt16(pb + ioFRefNum, 0); WriteMacInt8(pb + ioFlAttrib, (S_ISDIR(st.st_mode) ? faIsDir : 0) | (access(full_path, W_OK) == 0 ? 0 : faLocked)); WriteMacInt8(pb + ioACUser, 0); WriteMacInt32(pb + ioDirID, fs_item->id); WriteMacInt32(pb + ioFlParID, fs_item->parent_id); -#ifdef __BEOS__ - WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); +#if defined(__BEOS__) || defined(WIN32) + WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); +#elif defined __APPLE__ && defined __MACH__ + WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); #else WriteMacInt32(pb + ioFlCrDat, 0); #endif @@ -1368,14 +1445,12 @@ read_next_de: fs_item->mtime = mtime; cached = false; } - WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); + WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime)); WriteMacInt32(pb + ioFlBkDat, 0); + + get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); + if (S_ISDIR(st.st_mode)) { - Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo); - Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo); - uint16 fflags; // pb may point to kernel space, but stack is switched - get_finder_flags(full_path, fflags); - WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags); // Determine number of files in directory (cached) int count; @@ -1400,22 +1475,13 @@ read_next_de: } WriteMacInt16(pb + ioDrNmFls, count); } else { - Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo); - Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); - uint32 type, creator; // pb may point to kernel space, but stack is switched - get_finder_type(full_path, type, creator); - WriteMacInt32(pb + ioFlFndrInfo + fdType, type); - WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); - uint16 fflags; - get_finder_flags(full_path, fflags); - WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags); WriteMacInt16(pb + ioFlStBlk, 0); WriteMacInt32(pb + ioFlLgLen, st.st_size); - WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); + WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); WriteMacInt16(pb + ioFlRStBlk, 0); uint32 rf_size = get_rfork_size(full_path); WriteMacInt32(pb + ioFlRLgLen, rf_size); - WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); + WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); WriteMacInt32(pb + ioFlClpSiz, 0); } return noErr; @@ -1437,13 +1503,9 @@ static int16 fs_set_cat_info(uint32 pb) if (stat(full_path, &st) < 0) return errno2oserr(); - // Set attributes - if (S_ISDIR(st.st_mode)) - set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags)); - else { - set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); - set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); - } + // Set Finder info + set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); + //!! times return noErr; } @@ -1490,7 +1552,7 @@ static int16 fs_open(uint32 pb, uint32 d if (access(full_path, F_OK)) return fnfErr; fd = open_rfork(full_path, flag); - if (fd > 0) { + if (fd >= 0) { if (fstat(fd, &st) < 0) { close(fd); return errno2oserr(); @@ -1518,23 +1580,24 @@ static int16 fs_open(uint32 pb, uint32 d D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); if (r.d[0] & 0xffff) { close(fd); - return r.d[0]; + return (int16)r.d[0]; } // Initialize FCB, fd is stored in fcbCatPos WriteMacInt32(fcb + fcbFlNm, fs_item->id); WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); WriteMacInt32(fcb + fcbEOF, st.st_size); - WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); + WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); WriteMacInt32(fcb + fcbCrPs, 0); WriteMacInt32(fcb + fcbVPtr, vcb); - WriteMacInt32(fcb + fcbClmpSize, 1024); - uint32 type, creator; // BeOS: fcb may point to kernel space, but stack is switched - get_finder_type(full_path, type, creator); - WriteMacInt32(fcb + fcbFType, type); + WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); + + get_finfo(full_path, fs_data + fsPB, 0, false); + WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); + WriteMacInt32(fcb + fcbCatPos, fd); WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); - cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); + cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->guest_name); return noErr; } @@ -1568,7 +1631,7 @@ static int16 fs_close(uint32 pb) r.d[0] = ReadMacInt16(pb + ioRefNum); Execute68k(fs_data + fsReleaseFCB, &r); D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); - return r.d[0]; + return (int16)r.d[0]; } // Query information about FCB (FCBPBRec) @@ -1587,7 +1650,7 @@ static int16 fs_get_fcb_info(uint32 pb, // Find FCB by index WriteMacInt16(pb + ioRefNum, 0); - for (int i=0; i