ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/extfs.cpp
(Generate patch)

Comparing BasiliskII/src/extfs.cpp (file contents):
Revision 1.5 by cebix, 1999-10-21T22:39:51Z vs.
Revision 1.29 by cebix, 2004-01-12T15:29:21Z

# Line 1 | Line 1
1   /*
2 < *  extfs.cpp - MacOS file system for access native file system access
2 > *  extfs.cpp - MacOS file system for native file system access
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2004 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 40 | Line 40
40   #include <string.h>
41   #include <stdio.h>
42   #include <stdlib.h>
43 #include <unistd.h>
43   #include <fcntl.h>
45 #include <dirent.h>
44   #include <errno.h>
45  
46 + #ifndef WIN32
47 + #include <unistd.h>
48 + #include <dirent.h>
49 + #endif
50 +
51   #include "cpu_emulation.h"
49 #include "macos_util.h"
52   #include "emul_op.h"
53   #include "main.h"
54   #include "disk.h"
# Line 55 | Line 57
57   #include "extfs.h"
58   #include "extfs_defs.h"
59  
60 + #ifdef WIN32
61 + # include "posix_emu.h"
62 + #endif
63 +
64   #define DEBUG 0
65   #include "debug.h"
66  
# Line 65 | Line 71 | enum {
71          fsHFSProcStub = 6,
72          fsDrvStatus = 12,                               // Drive Status record
73          fsFSD = 42,                                             // File system descriptor
74 <        fsPB = 238,                                             // IOParam (for mounting)
74 >        fsPB = 238,                                             // IOParam (for mounting and renaming), also used for temporary storage
75          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
76          fsParseRec = 296,                               // ParsePathRec struct
77          fsReturn = 306,                                 // Area for return data of 68k routines
78          fsAllocateVCB = 562,                    // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1})
79          fsAddNewVCB = 578,                              // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1})
80          fsDetermineVol = 594,                   // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4})
81 <        fsResolveWDCB = 614,                    // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0})
81 >        fsResolveWDCB = 614,                    // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0})
82          fsGetDefaultVol = 632,                  // UTGetDefaultVol(uint32 wdpb{a0})
83          fsGetPathComponentName = 644,   // UTGetPathComponentName(uint32 rec{a0})
84          fsParsePathname = 656,                  // UTParsePathname(uint32 *start{a0}, uint32 name{a1})
# Line 101 | Line 107 | static bool ready = false;
107   static struct stat root_stat;
108  
109   // File system ID/media type
110 < const int16 MY_FSID = 'ba';
111 < const uint32 MY_MEDIA_TYPE = 'basi';
110 > const int16 MY_FSID = EMULATOR_ID_2;
111 > const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4;
112  
113   // CNID of root and root's parent
114   const uint32 ROOT_ID = 2;
# Line 111 | Line 117 | const uint32 ROOT_PARENT_ID = 1;
117   // File system stack size
118   const int STACK_SIZE = 0x10000;
119  
120 + // Allocation block and clump size as reported to MacOS (these are of course
121 + // not the real values and have no meaning on the host OS)
122 + const int AL_BLK_SIZE = 0x4000;
123 + const int CLUMP_SIZE = 0x4000;
124 +
125   // Drive number of our pseudo-drive
126   static int drive_number;
127  
# Line 201 | Line 212 | static FSItem *find_fsitem(const char *n
212   *  Get full path (->full_path) for given FSItem
213   */
214  
204 const int MAX_PATH_LENGTH = 1024;
215   static char full_path[MAX_PATH_LENGTH];
216  
217   static void add_path_comp(const char *s)
218   {
219 <        add_path_component(full_path, s, MAX_PATH_LENGTH);
219 >        add_path_component(full_path, s);
220   }
221  
222   static void get_path_for_fsitem(FSItem *p)
223   {
224 <        if (p->id == ROOT_ID) {
224 >        if (p->id == ROOT_PARENT_ID) {
225 >                full_path[0] = 0;
226 >        } else if (p->id == ROOT_ID) {
227                  strncpy(full_path, RootPath, MAX_PATH_LENGTH-1);
228                  full_path[MAX_PATH_LENGTH-1] = 0;
229          } else {
# Line 222 | Line 234 | static void get_path_for_fsitem(FSItem *
234  
235  
236   /*
237 + *  Exchange parent CNIDs in all FSItems
238 + */
239 +
240 + static void swap_parent_ids(uint32 parent1, uint32 parent2)
241 + {
242 +        FSItem *p = first_fs_item;
243 +        while (p) {
244 +                if (p->parent_id == parent1)
245 +                        p->parent_id = parent2;
246 +                else if (p->parent_id == parent2)
247 +                        p->parent_id = parent1;
248 +                p = p->next;
249 +        }
250 + }
251 +
252 +
253 + /*
254   *  String handling functions
255   */
256  
# Line 239 | Line 268 | static void cstr2pstr(char *dst, const c
268          *dst++ = strlen(src);
269          char c;
270          while ((c = *src++) != 0) {
271 +                // Note: we are converting host ':' characters to Mac '/' characters here
272 +                // '/' is not a path separator as this function is only used on object names
273                  if (c == ':')
274                          c = '/';
275                  *dst++ = c;
276          }
277   }
278  
248 // Convert pascal string to C string
249 static void pstr2cstr(char *dst, const char *src)
250 {
251        int size = *src++;
252        while (size--) {
253                char c = *src++;
254                if (c == '/')
255                        c = ':';
256                *dst++ = c;
257        }
258        *dst = 0;
259 }
260
279   // Convert string (no length byte) to C string, length given separately
280   static void strn2cstr(char *dst, const char *src, int size)
281   {
282          while (size--) {
283                  char c = *src++;
284 +                // Note: we are converting Mac '/' characters to host ':' characters here
285 +                // '/' is not a path separator as this function is only used on object names
286                  if (c == '/')
287                          c = ':';
288                  *dst++ = c;
# Line 338 | Line 358 | void ExtFSInit(void)
358          p->parent_id = ROOT_PARENT_ID;
359          p->parent = first_fs_item;
360          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
361 +        p->name[31] = 0;
362  
363          // Find path for root
364          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 386 | Line 407 | void InstallExtFS(void)
407          // FSM present?
408          r.d[0] = gestaltFSAttr;
409          Execute68kTrap(0xa1ad, &r);     // Gestalt()
410 <        D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
410 >        D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0]));
411          if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
412                  printf("WARNING: No FSM present, disabling ExtFS\n");
413                  return;
# Line 395 | Line 416 | void InstallExtFS(void)
416          // Yes, version >=1.2?
417          r.d[0] = gestaltFSMVersion;
418          Execute68kTrap(0xa1ad, &r);     // Gestalt()
419 <        D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
419 >        D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0]));
420          if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
421                  printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
422                  return;
# Line 461 | Line 482 | void InstallExtFS(void)
482          if (p - fs_data != fsResolveWDCB)
483                  goto fsdat_error;
484          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
485 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
486 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
487 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
485 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
486 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
487 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
488          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
489          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
490          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
# Line 603 | Line 624 | void InstallExtFS(void)
624          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
625          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
626          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
627 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
627 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
628          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
629          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
630          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 657 | Line 678 | int16 ExtFSComm(uint16 message, uint32 p
678  
679                  case ffsGetIconMessage: {               // Get disk/drive icon
680                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
681 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
681 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
682                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
683                                  return noErr;
684                          } else
# Line 665 | Line 686 | int16 ExtFSComm(uint16 message, uint32 p
686                  }
687  
688                  case ffsIDDiskMessage: {                // Check if volume is handled by our FS
689 <                        if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
689 >                        if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
690                                  return noErr;
691                          else
692                                  return extFSErr;
# Line 709 | Line 730 | static int16 get_current_dir(uint32 pb,
730          if (no_vol_name)
731                  WriteMacInt32(pb + ioNamePtr, name_ptr);
732          int16 status = ReadMacInt16(fs_data + fsReturn);
712        int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
713        int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
714        uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
733          D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
734 <        result = r.d[0] & 0xffff;
734 >        result = (int16)(r.d[0] & 0xffff);
735  
736          if (result == noErr) {
737                  switch (status) {
# Line 731 | Line 749 | static int16 get_current_dir(uint32 pb,
749                                          current_dir = dirID;
750                                  else {
751                                          D(bug("  resolving WDCB\n"));
752 <                                        r.d[0] = ReadMacInt16(pb + ioVRefNum);
752 >                                        r.d[0] = 0;
753 >                                        r.d[1] = 0;
754 >                                        r.d[2] = ReadMacInt16(pb + ioVRefNum);
755                                          r.a[0] = fs_data + fsReturn;
756                                          Execute68k(fs_data + fsResolveWDCB, &r);
757                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
758                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
759 <                                        result = r.d[0] & 0xffff;
759 >                                        result = (int16)(r.d[0] & 0xffff);
760                                          if (result == noErr)
761                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
762                                  }
# Line 752 | Line 772 | static int16 get_current_dir(uint32 pb,
772                                          r.a[0] = wdpb;
773                                          Execute68k(fs_data + fsGetDefaultVol, &r);
774                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
775 <                                        result = r.d[0] & 0xffff;
775 >                                        result = (int16)(r.d[0] & 0xffff);
776                                          if (result == noErr)
777                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
778                                  }
# Line 778 | Line 798 | static int16 get_path_component_name(uin
798          r.a[0] = rec;
799          Execute68k(fs_data + fsGetPathComponentName, &r);
800   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
801 <        return r.d[0] & 0xffff;
801 >        return (int16)(r.d[0] & 0xffff);
802   }
803  
804  
# Line 814 | Line 834 | static int16 get_item_and_path(uint32 pb
834          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
835          Execute68k(fs_data + fsParsePathname, &r);
836          D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
837 <        result = r.d[0] & 0xffff;
837 >        result = (int16)(r.d[0] & 0xffff);
838          if (result == noErr) {
839  
840                  // Check for leading delimiter of the partial pathname
# Line 927 | Line 947 | static uint32 find_fcb(int16 refNum)
947   static int16 fs_mount_vol(uint32 pb)
948   {
949          D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum)));
950 <        if (ReadMacInt16(pb + ioVRefNum) == drive_number)
950 >        if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number)
951                  return noErr;
952          else
953                  return extFSErr;
# Line 944 | Line 964 | static int16 fs_volume_mount(uint32 pb)
964          r.a[0] = fs_data + fsReturn;
965          r.a[1] = fs_data + fsReturn + 2;
966          Execute68k(fs_data + fsAllocateVCB, &r);
967 + #if DEBUG
968          uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn);
969 + #endif
970          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
971          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
972          if (r.d[0] & 0xffff)
973 <                return r.d[0];
973 >                return (int16)r.d[0];
974  
975          // Init VCB
976          WriteMacInt16(vcb + vcbSigWord, 0x4244);
977 < #ifdef __BEOS__
978 <        WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
977 > #if defined(__BEOS__) || defined(WIN32)
978 >        WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
979   #else
980          WriteMacInt32(vcb + vcbCrDate, 0);
981   #endif
982 <        WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET);
982 >        WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime));
983          WriteMacInt32(vcb + vcbVolBkUp, 0);
984          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
985          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
986          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
987 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
988 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
987 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
988 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
989          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
990          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
991 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
991 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
992          WriteMacInt16(vcb + vcbFSID, MY_FSID);
993          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
994          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 977 | Line 999 | static int16 fs_volume_mount(uint32 pb)
999          r.a[0] = fs_data + fsReturn;
1000          r.a[1] = vcb;
1001          Execute68k(fs_data + fsAddNewVCB, &r);
1002 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1002 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1003          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1004          if (r.d[0] & 0xffff)
1005 <                return r.d[0];
1005 >                return (int16)r.d[0];
1006  
1007          // Post diskInsertEvent
1008          D(bug("  posting diskInsertEvent\n"));
# Line 1004 | Line 1026 | static int16 fs_unmount_vol(uint32 vcb)
1026          r.a[0] = vcb;
1027          Execute68k(fs_data + fsDisposeVCB, &r);
1028          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1029 <        return r.d[0];
1029 >        return (int16)r.d[0];
1030   }
1031  
1032   // Get information about a volume (HVolumeParam)
# Line 1015 | Line 1037 | static int16 fs_get_vol_info(uint32 pb,
1037          // Fill in struct
1038          if (ReadMacInt32(pb + ioNamePtr))
1039                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1040 < #ifdef __BEOS__
1041 <        WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1040 > #if defined(__BEOS__) || defined(WIN32)
1041 >        WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
1042   #else
1043          WriteMacInt32(pb + ioVCrDate, 0);
1044   #endif
1045 <        WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET);
1045 >        WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime));
1046          WriteMacInt16(pb + ioVAtrb, 0);
1047          WriteMacInt16(pb + ioVNmFls, 1);                        //!!
1048          WriteMacInt16(pb + ioVBitMap, 0);
1049          WriteMacInt16(pb + ioAllocPtr, 0);
1050          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1051 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1052 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1051 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1052 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1053          WriteMacInt16(pb + ioAlBlSt, 0);
1054          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1055          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1040 | Line 1062 | static int16 fs_get_vol_info(uint32 pb,
1062                  WriteMacInt32(pb + ioVWrCnt, 0);
1063                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1064                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1065 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1065 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1066          }
1067          return noErr;
1068   }
# Line 1060 | Line 1082 | static int16 fs_get_vol_parms(uint32 pb)
1082   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1083  
1084          // Return parameter block
1063        uint8 vol[SIZEOF_GetVolParmsInfoBuffer];
1064        WriteMacInt16((uint32)vol + vMVersion, 2);
1065        WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1066        WriteMacInt32((uint32)vol + vMLocalHand, 0);
1067        WriteMacInt32((uint32)vol + vMServerAdr, 0);
1068        WriteMacInt32((uint32)vol + vMVolumeGrade, 0);
1069        WriteMacInt16((uint32)vol + vMForeignPrivID, 0);
1085          uint32 actual = ReadMacInt32(pb + ioReqCount);
1086 <        if (actual > sizeof(vol))
1087 <                actual = sizeof(vol);
1073 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1086 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1087 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1088          WriteMacInt32(pb + ioActCount, actual);
1089 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1090 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1091 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1092 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1093 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1094 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1095 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1096          return noErr;
1097   }
1098  
# Line 1086 | Line 1107 | static int16 fs_get_vol(uint32 pb)
1107          r.a[0] = pb;
1108          Execute68k(fs_data + fsGetDefaultVol, &r);
1109          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1110 <        return r.d[0];
1110 >        return (int16)r.d[0];
1111   }
1112  
1113   // Set default volume (WDParam)
# Line 1142 | Line 1163 | static int16 fs_set_vol(uint32 pb, bool
1163          r.d[2] = refNum;
1164          Execute68k(fs_data + fsSetDefaultVol, &r);
1165          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1166 <        return r.d[0];
1166 >        return (int16)r.d[0];
1167   }
1168  
1169   // Query file attributes (HFileParam)
# Line 1151 | Line 1172 | static int16 fs_get_file_info(uint32 pb,
1172          D(bug(" fs_get_file_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), dirID));
1173  
1174          FSItem *fs_item;
1175 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1175 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1176          if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1177  
1178                  // Find FSItem for given file
# Line 1184 | Line 1205 | read_next_de:
1205                                  return fnfErr;
1206                          }
1207                          if (de->d_name[0] == '.')
1208 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1208 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1209                          //!! suppress directories
1210                  }
1211                  add_path_comp(de->d_name);
# Line 1208 | Line 1229 | read_next_de:
1229          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1230          WriteMacInt32(pb + ioDirID, fs_item->id);
1231  
1232 < #ifdef __BEOS__
1233 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1232 > #if defined(__BEOS__) || defined(WIN32)
1233 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1234   #else
1235          WriteMacInt32(pb + ioFlCrDat, 0);
1236   #endif
1237 <        WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1237 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime));
1238  
1239 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1219 <        uint32 type, creator;   // pb may point to kernel space, but stack is switched
1220 <        get_finder_type(full_path, type, creator);
1221 <        WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1222 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1223 <        uint16 fflags;
1224 <        get_finder_flags(full_path, fflags);
1225 <        WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1239 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1240  
1241          WriteMacInt16(pb + ioFlStBlk, 0);
1242          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1243 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1243 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1244          WriteMacInt16(pb + ioFlRStBlk, 0);
1245          uint32 rf_size = get_rfork_size(full_path);
1246          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1247 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1247 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1248  
1249          if (hfs) {
1250                  WriteMacInt32(pb + ioFlBkDat, 0);
1237                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1251                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1252                  WriteMacInt32(pb + ioFlClpSiz, 0);
1253          }
# Line 1259 | Line 1272 | static int16 fs_set_file_info(uint32 pb,
1272          if (S_ISDIR(st.st_mode))
1273                  return fnfErr;
1274  
1275 <        // Set attributes
1276 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1277 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1275 >        // Set Finder info
1276 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1277 >
1278          //!! times
1279          return noErr;
1280   }
# Line 1272 | Line 1285 | static int16 fs_get_cat_info(uint32 pb)
1285          D(bug(" fs_get_cat_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID)));
1286  
1287          FSItem *fs_item;
1288 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1288 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1289          if (dir_index < 0) {                    // Query directory specified by ioDirID
1290  
1291                  // Find FSItem for directory
# Line 1313 | Line 1326 | read_next_de:
1326                                  return fnfErr;
1327                          }
1328                          if (de->d_name[0] == '.')
1329 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1329 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1330                  }
1331                  add_path_comp(de->d_name);
1332  
# Line 1338 | Line 1351 | read_next_de:
1351          WriteMacInt8(pb + ioACUser, 0);
1352          WriteMacInt32(pb + ioDirID, fs_item->id);
1353          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1354 < #ifdef __BEOS__
1355 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1354 > #if defined(__BEOS__) || defined(WIN32)
1355 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1356   #else
1357          WriteMacInt32(pb + ioFlCrDat, 0);
1358   #endif
# Line 1349 | Line 1362 | read_next_de:
1362                  fs_item->mtime = mtime;
1363                  cached = false;
1364          }
1365 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1365 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime));
1366          WriteMacInt32(pb + ioFlBkDat, 0);
1367 +
1368 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1369 +
1370          if (S_ISDIR(st.st_mode)) {
1355                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1356                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1357                uint16 fflags;  // pb may point to kernel space, but stack is switched
1358                get_finder_flags(full_path, fflags);
1359                WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
1371  
1372                  // Determine number of files in directory (cached)
1373                  int count;
# Line 1371 | Line 1382 | read_next_de:
1382                                          de = readdir(d);
1383                                          if (de == NULL)
1384                                                  break;
1385 +                                        if (de->d_name[0] == '.')
1386 +                                                continue;       // Suppress names beginning with '.'
1387                                          count++;
1388                                  }
1389                                  closedir(d);
# Line 1379 | Line 1392 | read_next_de:
1392                  }
1393                  WriteMacInt16(pb + ioDrNmFls, count);
1394          } else {
1382                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1383                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1384                uint32 type, creator;   // pb may point to kernel space, but stack is switched
1385                get_finder_type(full_path, type, creator);
1386                WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1387                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1388                uint16 fflags;
1389                get_finder_flags(full_path, fflags);
1390                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1395                  WriteMacInt16(pb + ioFlStBlk, 0);
1396                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1397 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1397 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1398                  WriteMacInt16(pb + ioFlRStBlk, 0);
1399                  uint32 rf_size = get_rfork_size(full_path);
1400                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1401 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1401 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1402                  WriteMacInt32(pb + ioFlClpSiz, 0);
1403          }
1404          return noErr;
# Line 1416 | Line 1420 | static int16 fs_set_cat_info(uint32 pb)
1420          if (stat(full_path, &st) < 0)
1421                  return errno2oserr();
1422  
1423 <        // Set attributes
1424 <        if (S_ISDIR(st.st_mode))
1425 <                set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags));
1422 <        else {
1423 <                set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1424 <                set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1425 <        }
1423 >        // Set Finder info
1424 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1425 >
1426          //!! times
1427          return noErr;
1428   }
# Line 1469 | Line 1469 | static int16 fs_open(uint32 pb, uint32 d
1469                  if (access(full_path, F_OK))
1470                          return fnfErr;
1471                  fd = open_rfork(full_path, flag);
1472 <                if (fd > 0) {
1473 <                        if (fstat(fd, &st) < 0)
1472 >                if (fd >= 0) {
1473 >                        if (fstat(fd, &st) < 0) {
1474 >                                close(fd);
1475                                  return errno2oserr();
1476 +                        }
1477                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1478                          st.st_size = 0;
1479                          st.st_mode = 0;
# Line 1480 | Line 1482 | static int16 fs_open(uint32 pb, uint32 d
1482                  fd = open(full_path, flag);
1483                  if (fd < 0)
1484                          return errno2oserr();
1485 <                if (fstat(fd, &st) < 0)
1485 >                if (fstat(fd, &st) < 0) {
1486 >                        close(fd);
1487                          return errno2oserr();
1488 +                }
1489          }
1490  
1491          // File open, allocate FCB
# Line 1493 | Line 1497 | static int16 fs_open(uint32 pb, uint32 d
1497          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1498          if (r.d[0] & 0xffff) {
1499                  close(fd);
1500 <                return r.d[0];
1500 >                return (int16)r.d[0];
1501          }
1502  
1503          // Initialize FCB, fd is stored in fcbCatPos
1504          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1505          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1506          WriteMacInt32(fcb + fcbEOF, st.st_size);
1507 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1507 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1508          WriteMacInt32(fcb + fcbCrPs, 0);
1509          WriteMacInt32(fcb + fcbVPtr, vcb);
1510 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1511 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1512 <        get_finder_type(full_path, type, creator);
1513 <        WriteMacInt32(fcb + fcbFType, type);
1510 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1511 >
1512 >        get_finfo(full_path, fs_data + fsPB, 0, false);
1513 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1514 >
1515          WriteMacInt32(fcb + fcbCatPos, fd);
1516          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1517          cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
# Line 1543 | Line 1548 | static int16 fs_close(uint32 pb)
1548          r.d[0] = ReadMacInt16(pb + ioRefNum);
1549          Execute68k(fs_data + fsReleaseFCB, &r);
1550          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1551 <        return r.d[0];
1551 >        return (int16)r.d[0];
1552   }
1553  
1554   // Query information about FCB (FCBPBRec)
# Line 1562 | Line 1567 | static int16 fs_get_fcb_info(uint32 pb,
1567  
1568                  // Find FCB by index
1569                  WriteMacInt16(pb + ioRefNum, 0);
1570 <                for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) {
1570 >                for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) {
1571                          D(bug("  indexing FCBs\n"));
1572                          r.a[0] = vcb;
1573                          r.a[1] = pb + ioRefNum;
# Line 1571 | Line 1576 | static int16 fs_get_fcb_info(uint32 pb,
1576                          fcb = ReadMacInt32(fs_data + fsReturn);
1577                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1578                          if (r.d[0] & 0xffff)
1579 <                                return r.d[0];
1579 >                                return (int16)r.d[0];
1580                  }
1581          }
1582          if (fcb == 0)
# Line 1619 | Line 1624 | static int16 fs_get_eof(uint32 pb)
1624  
1625          // Adjust FCBs
1626          WriteMacInt32(fcb + fcbEOF, st.st_size);
1627 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1627 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1628          WriteMacInt32(pb + ioMisc, st.st_size);
1629          D(bug("  adjusting FCBs\n"));
1630          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1654 | Line 1659 | static int16 fs_set_eof(uint32 pb)
1659  
1660          // Adjust FCBs
1661          WriteMacInt32(fcb + fcbEOF, size);
1662 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1662 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1663          D(bug("  adjusting FCBs\n"));
1664          r.d[0] = ReadMacInt16(pb + ioRefNum);
1665          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1739 | Line 1744 | static int16 fs_read(uint32 pb)
1744   {
1745          D(bug(" fs_read(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset)));
1746  
1747 +        // Check parameters
1748 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1749 +                return paramErr;
1750 +
1751          // Find FCB and fd for file
1752          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1753          if (fcb == 0)
# Line 1770 | Line 1779 | static int16 fs_read(uint32 pb)
1779          }
1780  
1781          // Read
1782 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1782 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1783 >        int16 read_err = errno2oserr();
1784          D(bug("  actual %d\n", actual));
1785 <        WriteMacInt32(pb + ioActCount, actual);
1785 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1786          uint32 pos = lseek(fd, 0, SEEK_CUR);
1787          WriteMacInt32(fcb + fcbCrPs, pos);
1788          WriteMacInt32(pb + ioPosOffset, pos);
1789 <        if (actual != ReadMacInt32(pb + ioReqCount))
1790 <                if (errno)
1781 <                        return errno2oserr();
1782 <                else
1783 <                        return eofErr;
1789 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1790 >                return actual < 0 ? read_err : eofErr;
1791          else
1792                  return noErr;
1793   }
# Line 1790 | Line 1797 | static int16 fs_write(uint32 pb)
1797   {
1798          D(bug(" fs_write(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset)));
1799  
1800 +        // Check parameters
1801 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1802 +                return paramErr;
1803 +
1804          // Find FCB and fd for file
1805          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1806          if (fcb == 0)
# Line 1821 | Line 1832 | static int16 fs_write(uint32 pb)
1832          }
1833  
1834          // Write
1835 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1835 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1836 >        int16 write_err = errno2oserr();
1837          D(bug("  actual %d\n", actual));
1838 <        WriteMacInt32(pb + ioActCount, actual);
1838 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1839          uint32 pos = lseek(fd, 0, SEEK_CUR);
1840          WriteMacInt32(fcb + fcbCrPs, pos);
1841          WriteMacInt32(pb + ioPosOffset, pos);
1842 <        if (actual != ReadMacInt32(pb + ioReqCount))
1843 <                return errno2oserr();
1842 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1843 >                return write_err;
1844          else
1845                  return noErr;
1846   }
# Line 1849 | Line 1861 | static int16 fs_create(uint32 pb, uint32
1861                  return dupFNErr;
1862  
1863          // Create file
1864 <        int fd = creat(full_path, 0664);
1864 >        int fd = creat(full_path, 0666);
1865          if (fd < 0)
1866                  return errno2oserr();
1867          else {
# Line 1874 | Line 1886 | static int16 fs_dir_create(uint32 pb)
1886                  return dupFNErr;
1887  
1888          // Create directory
1889 <        if (mkdir(full_path, 0775) < 0)
1889 >        if (mkdir(full_path, 0777) < 0)
1890                  return errno2oserr();
1891          else {
1892                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1894 | Line 1906 | static int16 fs_delete(uint32 pb, uint32
1906                  return result;
1907  
1908          // Delete file
1909 <        if (remove(full_path) < 0) {
1910 <                int16 err = errno2oserr();
1911 <                if (errno == EISDIR) {  // Workaround for BeOS bug
1900 <                        if (rmdir(full_path) < 0)
1901 <                                return errno2oserr();
1902 <                        else
1903 <                                return noErr;
1904 <                } else
1905 <                        return err;
1906 <        } else
1909 >        if (!extfs_remove(full_path))
1910 >                return errno2oserr();
1911 >        else
1912                  return noErr;
1913   }
1914  
# Line 1923 | Line 1928 | static int16 fs_rename(uint32 pb, uint32
1928          strcpy(old_path, full_path);
1929  
1930          // Find path for new name
1931 <        uint8 new_pb[SIZEOF_IOParam];
1932 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1928 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1931 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1932 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1933          FSItem *new_item;
1934 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1934 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1935          if (result != noErr)
1936                  return result;
1937  
# Line 1937 | Line 1941 | static int16 fs_rename(uint32 pb, uint32
1941  
1942          // Rename item
1943          D(bug("  renaming %s -> %s\n", old_path, full_path));
1944 <        if (rename(old_path, full_path) < 0)
1944 >        if (!extfs_rename(old_path, full_path))
1945                  return errno2oserr();
1946          else {
1947                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1948 +                swap_parent_ids(fs_item->id, new_item->id);
1949                  uint32 t = fs_item->id;
1950                  fs_item->id = new_item->id;
1951                  new_item->id = t;
# Line 1964 | Line 1969 | static int16 fs_cat_move(uint32 pb)
1969          strcpy(old_path, full_path);
1970  
1971          // Find path for new directory
1972 <        uint8 new_pb[SIZEOF_IOParam];
1973 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1969 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1972 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1973 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1974          FSItem *new_dir_item;
1975 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1975 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1976          if (result != noErr)
1977                  return result;
1978  
# Line 1981 | Line 1985 | static int16 fs_cat_move(uint32 pb)
1985  
1986          // Move item
1987          D(bug("  moving %s -> %s\n", old_path, full_path));
1988 <        if (rename(old_path, full_path) < 0)
1988 >        if (!extfs_rename(old_path, full_path))
1989                  return errno2oserr();
1990          else {
1991                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1992                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
1993                  if (new_item) {
1994 +                        swap_parent_ids(fs_item->id, new_item->id);
1995                          uint32 t = fs_item->id;
1996                          fs_item->id = new_item->id;
1997                          new_item->id = t;
# Line 2005 | Line 2010 | static int16 fs_open_wd(uint32 pb)
2010          D(bug("  allocating WDCB\n"));
2011          r.a[0] = pb;
2012          Execute68k(fs_data + fsAllocateWDCB, &r);
2013 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2014 <        return r.d[0];
2013 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2014 >        return (int16)r.d[0];
2015   }
2016  
2017   // Close working directory (WDParam)
# Line 2020 | Line 2025 | static int16 fs_close_wd(uint32 pb)
2025          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2026          Execute68k(fs_data + fsReleaseWDCB, &r);
2027          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2028 <        return r.d[0];
2028 >        return (int16)r.d[0];
2029   }
2030  
2031   // Query information about working directory (WDParam)
# Line 2034 | Line 2039 | static int16 fs_get_wd_info(uint32 pb, u
2039                  WriteMacInt32(pb + ioWDProcID, 0);
2040                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2041                  if (ReadMacInt32(pb + ioNamePtr))
2042 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2042 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2043                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2044                  return noErr;
2045          }
# Line 2049 | Line 2054 | static int16 fs_get_wd_info(uint32 pb, u
2054          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2055          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2056          if (r.d[0] & 0xffff)
2057 <                return r.d[0];
2057 >                return (int16)r.d[0];
2058  
2059          // Return information
2060 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2060 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2061          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2062          if (ReadMacInt32(pb + ioNamePtr))
2063 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2063 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2064          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2065          return noErr;
2066   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines