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.4 by cebix, 1999-10-20T17:23: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 440 | 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 450 | 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 462 | 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 481 | 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 489 | 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 498 | 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 506 | 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 514 | 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 524 | 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 533 | 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 541 | 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 551 | 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 560 | 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 568 | 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 576 | 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 584 | 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 608 | 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 662 | 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 736 | 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 971 | 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 1045 | 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 1065 | 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
1068        uint8 vol[SIZEOF_GetVolParmsInfoBuffer];
1069        WriteMacInt16((uint32)vol + vMVersion, 2);
1070        WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1071        WriteMacInt32((uint32)vol + vMLocalHand, 0);
1072        WriteMacInt32((uint32)vol + vMServerAdr, 0);
1073        WriteMacInt32((uint32)vol + vMVolumeGrade, 0);
1074        WriteMacInt16((uint32)vol + vMForeignPrivID, 0);
1083          uint32 actual = ReadMacInt32(pb + ioReqCount);
1084 <        if (actual > sizeof(vol))
1085 <                actual = sizeof(vol);
1078 <        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 1156 | Line 1170 | static int16 fs_get_file_info(uint32 pb,
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 = (int16)ReadMacInt16(pb + ioFDirIndex);
1173 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1174          if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1175  
1176                  // Find FSItem for given file
# Line 1189 | 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 1220 | 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 1239 | 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 1277 | Line 1291 | static int16 fs_get_cat_info(uint32 pb)
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 = (int16)ReadMacInt16(pb + ioFDirIndex);
1294 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1295          if (dir_index < 0) {                    // Query directory specified by ioDirID
1296  
1297                  // Find FSItem for directory
# Line 1318 | 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 1354 | 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 1376 | 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 1384 | 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 1475 | 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 1485 | 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 1509 | 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 1775 | 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)
1786 <                        return errno2oserr();
1787 <                else
1788 <                        return eofErr;
1806 >                return actual < 0 ? read_err : eofErr;
1807          else
1808                  return noErr;
1809   }
# Line 1826 | 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 1854 | 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 1879 | 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 1899 | 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
1905 <                        if (rmdir(full_path) < 0)
1906 <                                return errno2oserr();
1907 <                        else
1908 <                                return noErr;
1909 <                } else
1910 <                        return err;
1911 <        } else
1921 >        if (!extfs_remove(full_path))
1922 >                return errno2oserr();
1923 >        else
1924                  return noErr;
1925   }
1926  
# Line 1928 | 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);
1933 <        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 1942 | 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 1969 | 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);
1974 <        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 1986 | 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 2010 | Line 2022 | static int16 fs_open_wd(uint32 pb)
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 2039 | 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 2057 | 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