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.3 by cebix, 1999-10-20T15:13:53Z vs.
Revision 1.16 by cebix, 2000-04-10T18:52:22Z

# Line 1 | Line 1
1   /*
2   *  extfs.cpp - MacOS file system for access native file system access
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2000 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 65 | Line 65 | enum {
65          fsHFSProcStub = 6,
66          fsDrvStatus = 12,                               // Drive Status record
67          fsFSD = 42,                                             // File system descriptor
68 <        fsPB = 238,                                             // IOParam (for mounting)
68 >        fsPB = 238,                                             // IOParam (for mounting and renaming)
69          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
70          fsParseRec = 296,                               // ParsePathRec struct
71          fsReturn = 306,                                 // Area for return data of 68k routines
72          fsAllocateVCB = 562,                    // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1})
73          fsAddNewVCB = 578,                              // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1})
74          fsDetermineVol = 594,                   // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4})
75 <        fsResolveWDCB = 614,                    // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0})
75 >        fsResolveWDCB = 614,                    // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0})
76          fsGetDefaultVol = 632,                  // UTGetDefaultVol(uint32 wdpb{a0})
77          fsGetPathComponentName = 644,   // UTGetPathComponentName(uint32 rec{a0})
78          fsParsePathname = 656,                  // UTParsePathname(uint32 *start{a0}, uint32 name{a1})
# Line 201 | Line 201 | static FSItem *find_fsitem(const char *n
201   *  Get full path (->full_path) for given FSItem
202   */
203  
204 const int MAX_PATH_LENGTH = 1024;
204   static char full_path[MAX_PATH_LENGTH];
205  
206 < static void add_path_component(const char *s)
206 > static void add_path_comp(const char *s)
207   {
208 <        int l = strlen(full_path);
210 <        if (l < MAX_PATH_LENGTH-1 && full_path[l-1] != '/') {
211 <                full_path[l] = '/';
212 <                full_path[l+1] = 0;
213 <        }
214 <        strncat(full_path, s, MAX_PATH_LENGTH-1);
208 >        add_path_component(full_path, s);
209   }
210  
211   static void get_path_for_fsitem(FSItem *p)
212   {
213 <        if (p->id == ROOT_ID) {
213 >        if (p->id == ROOT_PARENT_ID) {
214 >                full_path[0] = 0;
215 >        } else if (p->id == ROOT_ID) {
216                  strncpy(full_path, RootPath, MAX_PATH_LENGTH-1);
217                  full_path[MAX_PATH_LENGTH-1] = 0;
218          } else {
219                  get_path_for_fsitem(p->parent);
220 <                add_path_component(p->name);
220 >                add_path_comp(p->name);
221 >        }
222 > }
223 >
224 >
225 > /*
226 > *  Exchange parent CNIDs in all FSItems
227 > */
228 >
229 > static void swap_parent_ids(uint32 parent1, uint32 parent2)
230 > {
231 >        FSItem *p = first_fs_item;
232 >        while (p) {
233 >                if (p->parent_id == parent1)
234 >                        p->parent_id = parent2;
235 >                else if (p->parent_id == parent2)
236 >                        p->parent_id = parent1;
237 >                p = p->next;
238          }
239   }
240  
# Line 325 | Line 338 | void ExtFSInit(void)
338          cstr2pstr(FS_NAME, GetString(STR_EXTFS_NAME));
339          cstr2pstr(VOLUME_NAME, GetString(STR_EXTFS_VOLUME_NAME));
340  
341 <        // Create root FSItem
341 >        // Create root's parent FSItem
342          FSItem *p = new FSItem;
343          first_fs_item = last_fs_item = p;
344          p->next = NULL;
345 +        p->id = ROOT_PARENT_ID;
346 +        p->parent_id = 0;
347 +        p->parent = NULL;
348 +        p->name[0] = 0;
349 +
350 +        // Create root FSItem
351 +        p = new FSItem;
352 +        last_fs_item->next = p;
353 +        p->next = NULL;
354 +        last_fs_item = p;
355          p->id = ROOT_ID;
356          p->parent_id = ROOT_PARENT_ID;
357 <        p->parent = NULL;
357 >        p->parent = first_fs_item;
358          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
359  
360          // Find path for root
# Line 430 | Line 453 | void InstallExtFS(void)
453          WriteMacInt16(p, 0x7006); p+= 2;        // UTAllocateVCB
454          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
455          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
456 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
456 >        WriteMacInt16(p, M68K_RTS); p+= 2;
457          if (p - fs_data != fsAddNewVCB)
458                  goto fsdat_error;
459          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 440 | Line 463 | void InstallExtFS(void)
463          WriteMacInt16(p, 0x7007); p+= 2;        // UTAddNewVCB
464          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
465          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
466 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
466 >        WriteMacInt16(p, M68K_RTS); p+= 2;
467          if (p - fs_data != fsDetermineVol)
468                  goto fsdat_error;
469          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 452 | Line 475 | void InstallExtFS(void)
475          WriteMacInt16(p, 0x701d); p+= 2;        // UTDetermineVol
476          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
477          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
478 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
478 >        WriteMacInt16(p, M68K_RTS); p+= 2;
479          if (p - fs_data != fsResolveWDCB)
480                  goto fsdat_error;
481          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
482 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
483 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
484 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
482 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
483 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
484 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
485          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
486          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
487          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
488          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
489 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
489 >        WriteMacInt16(p, M68K_RTS); p+= 2;
490          if (p - fs_data != fsGetDefaultVol)
491                  goto fsdat_error;
492          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 471 | Line 494 | void InstallExtFS(void)
494          WriteMacInt16(p, 0x7012); p+= 2;        // UTGetDefaultVol
495          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
496          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
497 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
497 >        WriteMacInt16(p, M68K_RTS); p+= 2;
498          if (p - fs_data != fsGetPathComponentName)
499                  goto fsdat_error;
500          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 479 | Line 502 | void InstallExtFS(void)
502          WriteMacInt16(p, 0x701c); p+= 2;        // UTGetPathComponentName
503          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
504          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
505 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
505 >        WriteMacInt16(p, M68K_RTS); p+= 2;
506          if (p - fs_data != fsParsePathname)
507                  goto fsdat_error;
508          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 488 | Line 511 | void InstallExtFS(void)
511          WriteMacInt16(p, 0x701b); p+= 2;        // UTParsePathname
512          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
513          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
514 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
514 >        WriteMacInt16(p, M68K_RTS); p+= 2;
515          if (p - fs_data != fsDisposeVCB)
516                  goto fsdat_error;
517          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 496 | Line 519 | void InstallExtFS(void)
519          WriteMacInt16(p, 0x7008); p+= 2;        // UTDisposeVCB
520          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
521          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
522 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
522 >        WriteMacInt16(p, M68K_RTS); p+= 2;
523          if (p - fs_data != fsCheckWDRefNum)
524                  goto fsdat_error;
525          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 504 | Line 527 | void InstallExtFS(void)
527          WriteMacInt16(p, 0x7013); p+= 2;        // UTCheckWDRefNum
528          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
529          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
530 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
530 >        WriteMacInt16(p, M68K_RTS); p+= 2;
531          if (p - fs_data != fsSetDefaultVol)
532                  goto fsdat_error;
533          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 514 | Line 537 | void InstallExtFS(void)
537          WriteMacInt16(p, 0x7011); p+= 2;        // UTSetDefaultVol
538          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
539          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
540 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
540 >        WriteMacInt16(p, M68K_RTS); p+= 2;
541          if (p - fs_data != fsAllocateFCB)
542                  goto fsdat_error;
543          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 523 | Line 546 | void InstallExtFS(void)
546          WriteMacInt16(p, 0x7000); p+= 2;        // UTAllocateFCB
547          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
548          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
549 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
549 >        WriteMacInt16(p, M68K_RTS); p+= 2;
550          if (p - fs_data != fsReleaseFCB)
551                  goto fsdat_error;
552          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 531 | Line 554 | void InstallExtFS(void)
554          WriteMacInt16(p, 0x7001); p+= 2;        // UTReleaseFCB
555          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
556          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
557 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
557 >        WriteMacInt16(p, M68K_RTS); p+= 2;
558          if (p - fs_data != fsIndexFCB)
559                  goto fsdat_error;
560          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 541 | Line 564 | void InstallExtFS(void)
564          WriteMacInt16(p, 0x7004); p+= 2;        // UTIndexFCB
565          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
566          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
567 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
567 >        WriteMacInt16(p, M68K_RTS); p+= 2;
568          if (p - fs_data != fsResolveFCB)
569                  goto fsdat_error;
570          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 550 | Line 573 | void InstallExtFS(void)
573          WriteMacInt16(p, 0x7005); p+= 2;        // UTResolveFCB
574          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
575          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
576 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
576 >        WriteMacInt16(p, M68K_RTS); p+= 2;
577          if (p - fs_data != fsAdjustEOF)
578                  goto fsdat_error;
579          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 558 | Line 581 | void InstallExtFS(void)
581          WriteMacInt16(p, 0x7010); p+= 2;        // UTAdjustEOF
582          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
583          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
584 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
584 >        WriteMacInt16(p, M68K_RTS); p+= 2;
585          if (p - fs_data != fsAllocateWDCB)
586                  goto fsdat_error;
587          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 566 | Line 589 | void InstallExtFS(void)
589          WriteMacInt16(p, 0x700c); p+= 2;        // UTAllocateWDCB
590          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
591          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
592 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
592 >        WriteMacInt16(p, M68K_RTS); p+= 2;
593          if (p - fs_data != fsReleaseWDCB)
594                  goto fsdat_error;
595          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 574 | Line 597 | void InstallExtFS(void)
597          WriteMacInt16(p, 0x700d); p+= 2;        // UTReleaseWDCB
598          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
599          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
600 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
600 >        WriteMacInt16(p, M68K_RTS); p+= 2;
601          if (p - fs_data != SIZEOF_fsdat)
602                  goto fsdat_error;
603  
# Line 598 | Line 621 | void InstallExtFS(void)
621          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
622          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
623          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
624 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
624 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
625          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
626          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
627          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 652 | Line 675 | int16 ExtFSComm(uint16 message, uint32 p
675  
676                  case ffsGetIconMessage: {               // Get disk/drive icon
677                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
678 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
678 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
679                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
680                                  return noErr;
681                          } else
# Line 689 | Line 712 | static int16 get_current_dir(uint32 pb,
712          int16 result;
713  
714          // Determine volume
715 < //      D(bug("  determining volume\n"));
715 >        D(bug("  determining volume, dirID %d\n", dirID));
716          r.a[0] = pb;
717          r.a[1] = fs_data + fsReturn;
718          r.a[2] = fs_data + fsReturn + 2;
# Line 707 | Line 730 | static int16 get_current_dir(uint32 pb,
730          int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
731          int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
732          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
733 < //      D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
733 >        D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
734          result = r.d[0] & 0xffff;
735  
736          if (result == noErr) {
# Line 726 | 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);
# Line 790 | Line 815 | static int16 get_item_and_path(uint32 pb
815          uint32 current_dir;
816          if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr)
817                  return result;
818 +        D(bug("  current dir %08x\n", current_dir));
819          FSItem *p = find_fsitem_by_id(current_dir);
820          if (p == NULL)
821                  return dirNFErr;
# Line 803 | Line 829 | static int16 get_item_and_path(uint32 pb
829          WriteMacInt8(parseRec + ppFoundDelimiter, false);
830  
831          // Get length of volume name
832 < //      D(bug("  parsing pathname\n"));
832 >        D(bug("  parsing pathname\n"));
833          r.a[0] = parseRec + ppStartOffset;
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)));
836 >        D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
837          result = r.d[0] & 0xffff;
838          if (result == noErr) {
839  
# Line 960 | Line 986 | static int16 fs_volume_mount(uint32 pb)
986          WriteMacInt32(vcb + vcbClpSiz, 1024);
987          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
988          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
989 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
989 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
990          WriteMacInt16(vcb + vcbFSID, MY_FSID);
991          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
992          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 1034 | Line 1060 | static int16 fs_get_vol_info(uint32 pb,
1060                  WriteMacInt32(pb + ioVWrCnt, 0);
1061                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1062                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1063 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1063 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1064          }
1065          return noErr;
1066   }
# Line 1054 | Line 1080 | static int16 fs_get_vol_parms(uint32 pb)
1080   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1081  
1082          // Return parameter block
1057        uint8 vol[SIZEOF_GetVolParmsInfoBuffer];
1058        WriteMacInt16((uint32)vol + vMVersion, 2);
1059        WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1060        WriteMacInt32((uint32)vol + vMLocalHand, 0);
1061        WriteMacInt32((uint32)vol + vMServerAdr, 0);
1062        WriteMacInt32((uint32)vol + vMVolumeGrade, 0);
1063        WriteMacInt16((uint32)vol + vMForeignPrivID, 0);
1083          uint32 actual = ReadMacInt32(pb + ioReqCount);
1084 <        if (actual > sizeof(vol))
1085 <                actual = sizeof(vol);
1067 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1084 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1085 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1086          WriteMacInt32(pb + ioActCount, actual);
1087 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1088 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1089 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1090 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1091 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1092 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1093 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1094          return noErr;
1095   }
1096  
# Line 1086 | Line 1111 | static int16 fs_get_vol(uint32 pb)
1111   // Set default volume (WDParam)
1112   static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb)
1113   {
1114 <        D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
1114 >        D(bug(" fs_set_vol(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioWDDirID)));
1115          M68kRegisters r;
1116  
1117          // Determine parameters
# Line 1142 | Line 1167 | static int16 fs_set_vol(uint32 pb, bool
1167   // Query file attributes (HFileParam)
1168   static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID)
1169   {
1170 <        D(bug(" fs_get_file_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), dirID));
1170 >        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));
1171  
1172          FSItem *fs_item;
1173          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1174 <        if (dir_index == 0) {   // Query item specified by ioDirID and ioNamePtr
1174 >        if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1175  
1176                  // Find FSItem for given file
1177                  int16 result = get_item_and_path(pb, dirID, fs_item);
# Line 1178 | Line 1203 | read_next_de:
1203                                  return fnfErr;
1204                          }
1205                          if (de->d_name[0] == '.')
1206 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1206 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1207                          //!! suppress directories
1208                  }
1209 <                add_path_component(de->d_name);
1209 >                add_path_comp(de->d_name);
1210  
1211                  // Get FSItem for queried item
1212                  fs_item = find_fsitem(de->d_name, p);
# Line 1209 | Line 1234 | read_next_de:
1234   #endif
1235          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1236  
1237 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1237 >        Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1238          uint32 type, creator;   // pb may point to kernel space, but stack is switched
1239          get_finder_type(full_path, type, creator);
1240          WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1228 | Line 1253 | read_next_de:
1253  
1254          if (hfs) {
1255                  WriteMacInt32(pb + ioFlBkDat, 0);
1256 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1256 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1257                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1258                  WriteMacInt32(pb + ioFlClpSiz, 0);
1259          }
# Line 1238 | Line 1263 | read_next_de:
1263   // Set file attributes (HFileParam)
1264   static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID)
1265   {
1266 <        D(bug(" fs_set_file_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), dirID));
1266 >        D(bug(" fs_set_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));
1267  
1268          // Find FSItem for given file/dir
1269          FSItem *fs_item;
# Line 1263 | Line 1288 | static int16 fs_set_file_info(uint32 pb,
1288   // Query file/directory attributes
1289   static int16 fs_get_cat_info(uint32 pb)
1290   {
1291 <        D(bug(" fs_get_cat_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID)));
1291 >        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)));
1292  
1293          FSItem *fs_item;
1294          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1295 <        if (dir_index == -1) {          // Query directory specified by ioDirID
1295 >        if (dir_index < 0) {                    // Query directory specified by ioDirID
1296  
1297                  // Find FSItem for directory
1298                  fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID));
# Line 1307 | Line 1332 | read_next_de:
1332                                  return fnfErr;
1333                          }
1334                          if (de->d_name[0] == '.')
1335 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1335 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1336                  }
1337 <                add_path_component(de->d_name);
1337 >                add_path_comp(de->d_name);
1338  
1339                  // Get FSItem for queried item
1340                  fs_item = find_fsitem(de->d_name, p);
# Line 1343 | Line 1368 | read_next_de:
1368                  fs_item->mtime = mtime;
1369                  cached = false;
1370          }
1371 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1371 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1372          WriteMacInt32(pb + ioFlBkDat, 0);
1373          if (S_ISDIR(st.st_mode)) {
1374 <                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1375 <                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1374 >                Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
1375 >                Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo);
1376                  uint16 fflags;  // pb may point to kernel space, but stack is switched
1377                  get_finder_flags(full_path, fflags);
1378                  WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
# Line 1365 | Line 1390 | read_next_de:
1390                                          de = readdir(d);
1391                                          if (de == NULL)
1392                                                  break;
1393 +                                        if (de->d_name[0] == '.')
1394 +                                                continue;       // Suppress names beginning with '.'
1395                                          count++;
1396                                  }
1397                                  closedir(d);
# Line 1373 | Line 1400 | read_next_de:
1400                  }
1401                  WriteMacInt16(pb + ioDrNmFls, count);
1402          } else {
1403 <                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1404 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1403 >                Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1404 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1405                  uint32 type, creator;   // pb may point to kernel space, but stack is switched
1406                  get_finder_type(full_path, type, creator);
1407                  WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1397 | Line 1424 | read_next_de:
1424   // Set file/directory attributes
1425   static int16 fs_set_cat_info(uint32 pb)
1426   {
1427 <        D(bug(" fs_set_cat_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID)));
1427 >        D(bug(" fs_set_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)));
1428  
1429          // Find FSItem for given file/dir
1430          FSItem *fs_item;
# Line 1424 | Line 1451 | static int16 fs_set_cat_info(uint32 pb)
1451   // Open file
1452   static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork)
1453   {
1454 <        D(bug(" fs_open(%08lx), %s, vRefNum %d, name %#s, dirID %d, perm %d\n", pb, resource_fork ? "rsrc" : "data", ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID, ReadMacInt8(pb + ioPermssn)));
1454 >        D(bug(" fs_open(%08lx), %s, vRefNum %d, name %.31s, dirID %d, perm %d\n", pb, resource_fork ? "rsrc" : "data", ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID, ReadMacInt8(pb + ioPermssn)));
1455          M68kRegisters r;
1456  
1457          // Find FSItem for given file
# Line 1464 | Line 1491 | static int16 fs_open(uint32 pb, uint32 d
1491                          return fnfErr;
1492                  fd = open_rfork(full_path, flag);
1493                  if (fd > 0) {
1494 <                        if (fstat(fd, &st) < 0)
1494 >                        if (fstat(fd, &st) < 0) {
1495 >                                close(fd);
1496                                  return errno2oserr();
1497 +                        }
1498                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1499                          st.st_size = 0;
1500                          st.st_mode = 0;
# Line 1474 | Line 1503 | static int16 fs_open(uint32 pb, uint32 d
1503                  fd = open(full_path, flag);
1504                  if (fd < 0)
1505                          return errno2oserr();
1506 <                if (fstat(fd, &st) < 0)
1506 >                if (fstat(fd, &st) < 0) {
1507 >                        close(fd);
1508                          return errno2oserr();
1509 +                }
1510          }
1511  
1512          // File open, allocate FCB
# Line 1498 | Line 1529 | static int16 fs_open(uint32 pb, uint32 d
1529          WriteMacInt32(fcb + fcbCrPs, 0);
1530          WriteMacInt32(fcb + fcbVPtr, vcb);
1531          WriteMacInt32(fcb + fcbClmpSize, 1024);
1532 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1532 >        uint32 type, creator;   // BeOS: fcb may point to kernel space, but stack is switched
1533          get_finder_type(full_path, type, creator);
1534          WriteMacInt32(fcb + fcbFType, type);
1535          WriteMacInt32(fcb + fcbCatPos, fd);
# Line 1711 | Line 1742 | static int16 fs_set_fpos(uint32 pb)
1742                          if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0)
1743                                  return posErr;
1744                          break;
1745 +                case fsFromLEOF:
1746 +                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0)
1747 +                                return posErr;
1748 +                        break;
1749                  case fsFromMark:
1750 <                        if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1750 >                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1751                                  return posErr;
1752 +                        break;
1753                  default:
1754                          break;
1755          }
# Line 1759 | Line 1795 | static int16 fs_read(uint32 pb)
1795          }
1796  
1797          // Read
1798 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1798 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1799 >        int16 read_err = errno2oserr();
1800          D(bug("  actual %d\n", actual));
1801 <        WriteMacInt32(pb + ioActCount, actual);
1801 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1802          uint32 pos = lseek(fd, 0, SEEK_CUR);
1803          WriteMacInt32(fcb + fcbCrPs, pos);
1804          WriteMacInt32(pb + ioPosOffset, pos);
1805          if (actual != ReadMacInt32(pb + ioReqCount))
1806 <                if (errno)
1770 <                        return errno2oserr();
1771 <                else
1772 <                        return eofErr;
1806 >                return actual < 0 ? read_err : eofErr;
1807          else
1808                  return noErr;
1809   }
# Line 1810 | Line 1844 | static int16 fs_write(uint32 pb)
1844          }
1845  
1846          // Write
1847 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1847 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1848 >        int16 write_err = errno2oserr();
1849          D(bug("  actual %d\n", actual));
1850 <        WriteMacInt32(pb + ioActCount, actual);
1850 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1851          uint32 pos = lseek(fd, 0, SEEK_CUR);
1852          WriteMacInt32(fcb + fcbCrPs, pos);
1853          WriteMacInt32(pb + ioPosOffset, pos);
1854          if (actual != ReadMacInt32(pb + ioReqCount))
1855 <                return errno2oserr();
1855 >                return write_err;
1856          else
1857                  return noErr;
1858   }
# Line 1825 | Line 1860 | static int16 fs_write(uint32 pb)
1860   // Create file
1861   static int16 fs_create(uint32 pb, uint32 dirID)
1862   {
1863 <        D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1863 >        D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1864  
1865          // Find FSItem for given file
1866          FSItem *fs_item;
# Line 1838 | Line 1873 | static int16 fs_create(uint32 pb, uint32
1873                  return dupFNErr;
1874  
1875          // Create file
1876 <        int fd = creat(full_path, 0664);
1876 >        int fd = creat(full_path, 0666);
1877          if (fd < 0)
1878                  return errno2oserr();
1879          else {
# Line 1850 | Line 1885 | static int16 fs_create(uint32 pb, uint32
1885   // Create directory
1886   static int16 fs_dir_create(uint32 pb)
1887   {
1888 <        D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID)));
1888 >        D(bug(" fs_dir_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioDirID)));
1889  
1890          // Find FSItem for given directory
1891          FSItem *fs_item;
# Line 1863 | Line 1898 | static int16 fs_dir_create(uint32 pb)
1898                  return dupFNErr;
1899  
1900          // Create directory
1901 <        if (mkdir(full_path, 0775) < 0)
1901 >        if (mkdir(full_path, 0777) < 0)
1902                  return errno2oserr();
1903          else {
1904                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1874 | Line 1909 | static int16 fs_dir_create(uint32 pb)
1909   // Delete file/directory
1910   static int16 fs_delete(uint32 pb, uint32 dirID)
1911   {
1912 <        D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1912 >        D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1913  
1914          // Find FSItem for given file/dir
1915          FSItem *fs_item;
# Line 1883 | Line 1918 | static int16 fs_delete(uint32 pb, uint32
1918                  return result;
1919  
1920          // Delete file
1921 <        if (remove(full_path) < 0) {
1922 <                int16 err = errno2oserr();
1923 <                if (errno == EISDIR) {  // Workaround for BeOS bug
1889 <                        if (rmdir(full_path) < 0)
1890 <                                return errno2oserr();
1891 <                        else
1892 <                                return noErr;
1893 <                } else
1894 <                        return err;
1895 <        } else
1921 >        if (!extfs_remove(full_path))
1922 >                return errno2oserr();
1923 >        else
1924                  return noErr;
1925   }
1926  
1927   // Rename file/directory
1928   static int16 fs_rename(uint32 pb, uint32 dirID)
1929   {
1930 <        D(bug(" fs_rename(%08lx), vRefNum %d, name %#s, dirID %d, new name %#s\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID, Mac2HostAddr(ReadMacInt32(pb + ioMisc))));
1930 >        D(bug(" fs_rename(%08lx), vRefNum %d, name %.31s, dirID %d, new name %.31s\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID, Mac2HostAddr(ReadMacInt32(pb + ioMisc) + 1)));
1931  
1932          // Find path of given file/dir
1933          FSItem *fs_item;
# Line 1912 | Line 1940 | static int16 fs_rename(uint32 pb, uint32
1940          strcpy(old_path, full_path);
1941  
1942          // Find path for new name
1943 <        uint8 new_pb[SIZEOF_IOParam];
1944 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1917 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1943 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1944 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1945          FSItem *new_item;
1946 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1946 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1947          if (result != noErr)
1948                  return result;
1949  
# Line 1926 | Line 1953 | static int16 fs_rename(uint32 pb, uint32
1953  
1954          // Rename item
1955          D(bug("  renaming %s -> %s\n", old_path, full_path));
1956 <        if (rename(old_path, full_path) < 0)
1956 >        if (!extfs_rename(old_path, full_path))
1957                  return errno2oserr();
1958          else {
1959                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1960 +                swap_parent_ids(fs_item->id, new_item->id);
1961                  uint32 t = fs_item->id;
1962                  fs_item->id = new_item->id;
1963                  new_item->id = t;
# Line 1940 | Line 1968 | static int16 fs_rename(uint32 pb, uint32
1968   // Move file/directory (CMovePBRec)
1969   static int16 fs_cat_move(uint32 pb)
1970   {
1971 <        D(bug(" fs_cat_move(%08lx), vRefNum %d, name %#s, dirID %d, new name %#s, new dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID), Mac2HostAddr(ReadMacInt32(pb + ioNewName)), ReadMacInt32(pb + ioNewDirID)));
1971 >        D(bug(" fs_cat_move(%08lx), vRefNum %d, name %.31s, dirID %d, new name %.31s, new dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioDirID), Mac2HostAddr(ReadMacInt32(pb + ioNewName) + 1), ReadMacInt32(pb + ioNewDirID)));
1972  
1973          // Find path of given file/dir
1974          FSItem *fs_item;
# Line 1953 | Line 1981 | static int16 fs_cat_move(uint32 pb)
1981          strcpy(old_path, full_path);
1982  
1983          // Find path for new directory
1984 <        uint8 new_pb[SIZEOF_IOParam];
1985 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1958 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1984 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1985 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1986          FSItem *new_dir_item;
1987 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1987 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1988          if (result != noErr)
1989                  return result;
1990  
1991          // Append old file/dir name
1992 <        add_path_component(fs_item->name);
1992 >        add_path_comp(fs_item->name);
1993  
1994          // Does the new name already exist?
1995          if (access(full_path, F_OK) == 0)
# Line 1970 | Line 1997 | static int16 fs_cat_move(uint32 pb)
1997  
1998          // Move item
1999          D(bug("  moving %s -> %s\n", old_path, full_path));
2000 <        if (rename(old_path, full_path) < 0)
2000 >        if (!extfs_rename(old_path, full_path))
2001                  return errno2oserr();
2002          else {
2003                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2004                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2005                  if (new_item) {
2006 +                        swap_parent_ids(fs_item->id, new_item->id);
2007                          uint32 t = fs_item->id;
2008                          fs_item->id = new_item->id;
2009                          new_item->id = t;
# Line 1987 | Line 2015 | static int16 fs_cat_move(uint32 pb)
2015   // Open working directory (WDParam)
2016   static int16 fs_open_wd(uint32 pb)
2017   {
2018 <        D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
2018 >        D(bug(" fs_open_wd(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioWDDirID)));
2019          M68kRegisters r;
2020  
2021          // Allocate WDCB
2022          D(bug("  allocating WDCB\n"));
2023          r.a[0] = pb;
2024          Execute68k(fs_data + fsAllocateWDCB, &r);
2025 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2025 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2026          return r.d[0];
2027   }
2028  
# Line 2023 | Line 2051 | static int16 fs_get_wd_info(uint32 pb, u
2051                  WriteMacInt32(pb + ioWDProcID, 0);
2052                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2053                  if (ReadMacInt32(pb + ioNamePtr))
2054 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2054 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2055                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2056                  return noErr;
2057          }
# Line 2041 | Line 2069 | static int16 fs_get_wd_info(uint32 pb, u
2069                  return r.d[0];
2070  
2071          // Return information
2072 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2072 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2073          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2074          if (ReadMacInt32(pb + ioNamePtr))
2075 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2075 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2076          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2077          return noErr;
2078   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines