--- BasiliskII/src/extfs.cpp 1999/11/01 16:24:06 1.8 +++ BasiliskII/src/extfs.cpp 1999/11/08 18:05:55 1.13 @@ -65,7 +65,7 @@ enum { fsHFSProcStub = 6, fsDrvStatus = 12, // Drive Status record fsFSD = 42, // File system descriptor - fsPB = 238, // IOParam (for mounting) + fsPB = 238, // IOParam (for mounting and renaming) fsVMI = 288, // VoumeMountInfoHeader (for mounting) fsParseRec = 296, // ParsePathRec struct fsReturn = 306, // Area for return data of 68k routines @@ -604,7 +604,7 @@ void InstallExtFS(void) WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec); WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1); WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID); - memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32); + Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32); WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub); WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub); WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE); @@ -658,7 +658,7 @@ int16 ExtFSComm(uint16 message, uint32 p case ffsGetIconMessage: { // Get disk/drive icon if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) { - memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon)); + Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon)); WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon)); return noErr; } else @@ -969,7 +969,7 @@ static int16 fs_volume_mount(uint32 pb) WriteMacInt32(vcb + vcbClpSiz, 1024); WriteMacInt32(vcb + vcbNxtCNID, next_cnid); WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! - memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28); + Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); WriteMacInt16(vcb + vcbFSID, MY_FSID); WriteMacInt32(vcb + vcbFilCnt, 1); //!! WriteMacInt32(vcb + vcbDirCnt, 1); //!! @@ -1043,7 +1043,7 @@ static int16 fs_get_vol_info(uint32 pb, WriteMacInt32(pb + ioVWrCnt, 0); WriteMacInt32(pb + ioVFilCnt, 1); //!! WriteMacInt32(pb + ioVDirCnt, 1); //!! - memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32); + Mac_memset(pb + ioVFndrInfo, 0, 32); } return noErr; } @@ -1073,7 +1073,7 @@ static int16 fs_get_vol_parms(uint32 pb) uint32 actual = ReadMacInt32(pb + ioReqCount); if (actual > sizeof(vol)) actual = sizeof(vol); - memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual); + Host2Mac_memcpy(ReadMacInt32(pb + ioBuffer), vol, actual); WriteMacInt32(pb + ioActCount, actual); return noErr; } @@ -1187,7 +1187,7 @@ read_next_de: return fnfErr; } if (de->d_name[0] == '.') - goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) + goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) //!! suppress directories } add_path_comp(de->d_name); @@ -1218,7 +1218,7 @@ read_next_de: #endif WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); - memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo); + 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); @@ -1237,7 +1237,7 @@ read_next_de: if (hfs) { WriteMacInt32(pb + ioFlBkDat, 0); - memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); + Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); WriteMacInt32(pb + ioFlParID, fs_item->parent_id); WriteMacInt32(pb + ioFlClpSiz, 0); } @@ -1316,7 +1316,7 @@ read_next_de: return fnfErr; } if (de->d_name[0] == '.') - goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) + goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) } add_path_comp(de->d_name); @@ -1352,11 +1352,11 @@ read_next_de: fs_item->mtime = mtime; cached = false; } - WriteMacInt32(pb + ioFlMdDat, mtime); + WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); WriteMacInt32(pb + ioFlBkDat, 0); if (S_ISDIR(st.st_mode)) { - memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo); - memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo); + 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); @@ -1374,6 +1374,8 @@ read_next_de: de = readdir(d); if (de == NULL) break; + if (de->d_name[0] == '.') + continue; // Suppress names beginning with '.' count++; } closedir(d); @@ -1382,8 +1384,8 @@ read_next_de: } WriteMacInt16(pb + ioDrNmFls, count); } else { - memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo); - memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); + 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); @@ -1774,16 +1776,14 @@ static int16 fs_read(uint32 pb) // Read size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); + int16 read_err = errno2oserr(); D(bug(" actual %d\n", actual)); WriteMacInt32(pb + ioActCount, actual); uint32 pos = lseek(fd, 0, SEEK_CUR); WriteMacInt32(fcb + fcbCrPs, pos); WriteMacInt32(pb + ioPosOffset, pos); if (actual != ReadMacInt32(pb + ioReqCount)) - if (errno) - return errno2oserr(); - else - return eofErr; + return read_err ? read_err : eofErr; else return noErr; } @@ -1825,13 +1825,14 @@ static int16 fs_write(uint32 pb) // Write size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); + int16 write_err = errno2oserr(); D(bug(" actual %d\n", actual)); WriteMacInt32(pb + ioActCount, actual); uint32 pos = lseek(fd, 0, SEEK_CUR); WriteMacInt32(fcb + fcbCrPs, pos); WriteMacInt32(pb + ioPosOffset, pos); if (actual != ReadMacInt32(pb + ioReqCount)) - return errno2oserr(); + return write_err; else return noErr; } @@ -1897,16 +1898,9 @@ static int16 fs_delete(uint32 pb, uint32 return result; // Delete file - if (remove(full_path) < 0) { - int16 err = errno2oserr(); - if (errno == EISDIR) { // Workaround for BeOS bug - if (rmdir(full_path) < 0) - return errno2oserr(); - else - return noErr; - } else - return err; - } else + if (!extfs_remove(full_path)) + return errno2oserr(); + else return noErr; } @@ -1926,11 +1920,10 @@ static int16 fs_rename(uint32 pb, uint32 strcpy(old_path, full_path); // Find path for new name - uint8 new_pb[SIZEOF_IOParam]; - memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); - WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc)); + Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); + WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc)); FSItem *new_item; - result = get_item_and_path((uint32)new_pb, dirID, new_item); + result = get_item_and_path(fs_data + fsPB, dirID, new_item); if (result != noErr) return result; @@ -1940,7 +1933,7 @@ static int16 fs_rename(uint32 pb, uint32 // Rename item D(bug(" renaming %s -> %s\n", old_path, full_path)); - if (rename(old_path, full_path) < 0) + if (!extfs_rename(old_path, full_path)) return errno2oserr(); else { // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems @@ -1967,11 +1960,10 @@ static int16 fs_cat_move(uint32 pb) strcpy(old_path, full_path); // Find path for new directory - uint8 new_pb[SIZEOF_IOParam]; - memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); - WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName)); + Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); + WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName)); FSItem *new_dir_item; - result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item); + result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item); if (result != noErr) return result; @@ -1984,7 +1976,7 @@ static int16 fs_cat_move(uint32 pb) // Move item D(bug(" moving %s -> %s\n", old_path, full_path)); - if (rename(old_path, full_path) < 0) + if (!extfs_rename(old_path, full_path)) return errno2oserr(); else { // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems @@ -2037,7 +2029,7 @@ static int16 fs_get_wd_info(uint32 pb, u WriteMacInt32(pb + ioWDProcID, 0); WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum)); if (ReadMacInt32(pb + ioNamePtr)) - memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28); + Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28); WriteMacInt32(pb + ioWDDirID, ROOT_ID); return noErr; } @@ -2055,10 +2047,10 @@ static int16 fs_get_wd_info(uint32 pb, u return r.d[0]; // Return information - WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); + WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum)); if (ReadMacInt32(pb + ioNamePtr)) - memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28); + Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28); WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID)); return noErr; }