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.14 by cebix, 1999-11-15T15:01:34Z

# 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  
# Line 440 | Line 436 | void InstallExtFS(void)
436          WriteMacInt16(p, 0x7006); p+= 2;        // UTAllocateVCB
437          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
438          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
439 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
439 >        WriteMacInt16(p, M68K_RTS); p+= 2;
440          if (p - fs_data != fsAddNewVCB)
441                  goto fsdat_error;
442          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 450 | Line 446 | void InstallExtFS(void)
446          WriteMacInt16(p, 0x7007); p+= 2;        // UTAddNewVCB
447          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
448          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
449 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
449 >        WriteMacInt16(p, M68K_RTS); p+= 2;
450          if (p - fs_data != fsDetermineVol)
451                  goto fsdat_error;
452          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 462 | Line 458 | void InstallExtFS(void)
458          WriteMacInt16(p, 0x701d); p+= 2;        // UTDetermineVol
459          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
460          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
461 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
461 >        WriteMacInt16(p, M68K_RTS); p+= 2;
462          if (p - fs_data != fsResolveWDCB)
463                  goto fsdat_error;
464          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
465 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
466 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
467 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
465 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
466 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
467 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
468          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
469          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
470          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
471          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
472 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
472 >        WriteMacInt16(p, M68K_RTS); p+= 2;
473          if (p - fs_data != fsGetDefaultVol)
474                  goto fsdat_error;
475          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 481 | Line 477 | void InstallExtFS(void)
477          WriteMacInt16(p, 0x7012); p+= 2;        // UTGetDefaultVol
478          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
479          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
480 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
480 >        WriteMacInt16(p, M68K_RTS); p+= 2;
481          if (p - fs_data != fsGetPathComponentName)
482                  goto fsdat_error;
483          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 489 | Line 485 | void InstallExtFS(void)
485          WriteMacInt16(p, 0x701c); p+= 2;        // UTGetPathComponentName
486          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
487          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
488 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
488 >        WriteMacInt16(p, M68K_RTS); p+= 2;
489          if (p - fs_data != fsParsePathname)
490                  goto fsdat_error;
491          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 498 | Line 494 | void InstallExtFS(void)
494          WriteMacInt16(p, 0x701b); p+= 2;        // UTParsePathname
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 != fsDisposeVCB)
499                  goto fsdat_error;
500          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 506 | Line 502 | void InstallExtFS(void)
502          WriteMacInt16(p, 0x7008); p+= 2;        // UTDisposeVCB
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 != fsCheckWDRefNum)
507                  goto fsdat_error;
508          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 514 | Line 510 | void InstallExtFS(void)
510          WriteMacInt16(p, 0x7013); p+= 2;        // UTCheckWDRefNum
511          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
512          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
513 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
513 >        WriteMacInt16(p, M68K_RTS); p+= 2;
514          if (p - fs_data != fsSetDefaultVol)
515                  goto fsdat_error;
516          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 524 | Line 520 | void InstallExtFS(void)
520          WriteMacInt16(p, 0x7011); p+= 2;        // UTSetDefaultVol
521          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
522          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
523 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
523 >        WriteMacInt16(p, M68K_RTS); p+= 2;
524          if (p - fs_data != fsAllocateFCB)
525                  goto fsdat_error;
526          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 533 | Line 529 | void InstallExtFS(void)
529          WriteMacInt16(p, 0x7000); p+= 2;        // UTAllocateFCB
530          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
531          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
532 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
532 >        WriteMacInt16(p, M68K_RTS); p+= 2;
533          if (p - fs_data != fsReleaseFCB)
534                  goto fsdat_error;
535          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 541 | Line 537 | void InstallExtFS(void)
537          WriteMacInt16(p, 0x7001); p+= 2;        // UTReleaseFCB
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 != fsIndexFCB)
542                  goto fsdat_error;
543          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 551 | Line 547 | void InstallExtFS(void)
547          WriteMacInt16(p, 0x7004); p+= 2;        // UTIndexFCB
548          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
549          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
550 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
550 >        WriteMacInt16(p, M68K_RTS); p+= 2;
551          if (p - fs_data != fsResolveFCB)
552                  goto fsdat_error;
553          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 560 | Line 556 | void InstallExtFS(void)
556          WriteMacInt16(p, 0x7005); p+= 2;        // UTResolveFCB
557          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
558          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
559 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
559 >        WriteMacInt16(p, M68K_RTS); p+= 2;
560          if (p - fs_data != fsAdjustEOF)
561                  goto fsdat_error;
562          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 568 | Line 564 | void InstallExtFS(void)
564          WriteMacInt16(p, 0x7010); p+= 2;        // UTAdjustEOF
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 != fsAllocateWDCB)
569                  goto fsdat_error;
570          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 576 | Line 572 | void InstallExtFS(void)
572          WriteMacInt16(p, 0x700c); p+= 2;        // UTAllocateWDCB
573          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
574          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
575 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
575 >        WriteMacInt16(p, M68K_RTS); p+= 2;
576          if (p - fs_data != fsReleaseWDCB)
577                  goto fsdat_error;
578          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 584 | Line 580 | void InstallExtFS(void)
580          WriteMacInt16(p, 0x700d); p+= 2;        // UTReleaseWDCB
581          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
582          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
583 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
583 >        WriteMacInt16(p, M68K_RTS); p+= 2;
584          if (p - fs_data != SIZEOF_fsdat)
585                  goto fsdat_error;
586  
# Line 608 | Line 604 | void InstallExtFS(void)
604          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
605          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
606          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
607 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
607 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
608          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
609          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
610          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 662 | Line 658 | int16 ExtFSComm(uint16 message, uint32 p
658  
659                  case ffsGetIconMessage: {               // Get disk/drive icon
660                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
661 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
661 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
662                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
663                                  return noErr;
664                          } else
# Line 736 | Line 732 | static int16 get_current_dir(uint32 pb,
732                                          current_dir = dirID;
733                                  else {
734                                          D(bug("  resolving WDCB\n"));
735 <                                        r.d[0] = ReadMacInt16(pb + ioVRefNum);
735 >                                        r.d[0] = 0;
736 >                                        r.d[1] = 0;
737 >                                        r.d[2] = ReadMacInt16(pb + ioVRefNum);
738                                          r.a[0] = fs_data + fsReturn;
739                                          Execute68k(fs_data + fsResolveWDCB, &r);
740                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
# Line 971 | Line 969 | static int16 fs_volume_mount(uint32 pb)
969          WriteMacInt32(vcb + vcbClpSiz, 1024);
970          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
971          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
972 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
972 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
973          WriteMacInt16(vcb + vcbFSID, MY_FSID);
974          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
975          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 1045 | Line 1043 | static int16 fs_get_vol_info(uint32 pb,
1043                  WriteMacInt32(pb + ioVWrCnt, 0);
1044                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1045                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1046 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1046 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1047          }
1048          return noErr;
1049   }
# Line 1065 | Line 1063 | static int16 fs_get_vol_parms(uint32 pb)
1063   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1064  
1065          // 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);
1066          uint32 actual = ReadMacInt32(pb + ioReqCount);
1067 <        if (actual > sizeof(vol))
1068 <                actual = sizeof(vol);
1078 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1067 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1068 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1069          WriteMacInt32(pb + ioActCount, actual);
1070 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1071 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1072 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1073 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1074 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1075 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1076 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1077          return noErr;
1078   }
1079  
# Line 1156 | Line 1153 | static int16 fs_get_file_info(uint32 pb,
1153          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));
1154  
1155          FSItem *fs_item;
1156 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1156 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1157          if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1158  
1159                  // Find FSItem for given file
# Line 1189 | Line 1186 | read_next_de:
1186                                  return fnfErr;
1187                          }
1188                          if (de->d_name[0] == '.')
1189 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1189 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1190                          //!! suppress directories
1191                  }
1192 <                add_path_component(de->d_name);
1192 >                add_path_comp(de->d_name);
1193  
1194                  // Get FSItem for queried item
1195                  fs_item = find_fsitem(de->d_name, p);
# Line 1220 | Line 1217 | read_next_de:
1217   #endif
1218          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1219  
1220 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1220 >        Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1221          uint32 type, creator;   // pb may point to kernel space, but stack is switched
1222          get_finder_type(full_path, type, creator);
1223          WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1239 | Line 1236 | read_next_de:
1236  
1237          if (hfs) {
1238                  WriteMacInt32(pb + ioFlBkDat, 0);
1239 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1239 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1240                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1241                  WriteMacInt32(pb + ioFlClpSiz, 0);
1242          }
# Line 1277 | Line 1274 | static int16 fs_get_cat_info(uint32 pb)
1274          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)));
1275  
1276          FSItem *fs_item;
1277 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1277 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1278          if (dir_index < 0) {                    // Query directory specified by ioDirID
1279  
1280                  // Find FSItem for directory
# Line 1318 | Line 1315 | read_next_de:
1315                                  return fnfErr;
1316                          }
1317                          if (de->d_name[0] == '.')
1318 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1318 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1319                  }
1320 <                add_path_component(de->d_name);
1320 >                add_path_comp(de->d_name);
1321  
1322                  // Get FSItem for queried item
1323                  fs_item = find_fsitem(de->d_name, p);
# Line 1354 | Line 1351 | read_next_de:
1351                  fs_item->mtime = mtime;
1352                  cached = false;
1353          }
1354 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1354 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1355          WriteMacInt32(pb + ioFlBkDat, 0);
1356          if (S_ISDIR(st.st_mode)) {
1357 <                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1358 <                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1357 >                Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
1358 >                Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo);
1359                  uint16 fflags;  // pb may point to kernel space, but stack is switched
1360                  get_finder_flags(full_path, fflags);
1361                  WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
# Line 1376 | Line 1373 | read_next_de:
1373                                          de = readdir(d);
1374                                          if (de == NULL)
1375                                                  break;
1376 +                                        if (de->d_name[0] == '.')
1377 +                                                continue;       // Suppress names beginning with '.'
1378                                          count++;
1379                                  }
1380                                  closedir(d);
# Line 1384 | Line 1383 | read_next_de:
1383                  }
1384                  WriteMacInt16(pb + ioDrNmFls, count);
1385          } else {
1386 <                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1387 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1386 >                Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1387 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1388                  uint32 type, creator;   // pb may point to kernel space, but stack is switched
1389                  get_finder_type(full_path, type, creator);
1390                  WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1475 | Line 1474 | static int16 fs_open(uint32 pb, uint32 d
1474                          return fnfErr;
1475                  fd = open_rfork(full_path, flag);
1476                  if (fd > 0) {
1477 <                        if (fstat(fd, &st) < 0)
1477 >                        if (fstat(fd, &st) < 0) {
1478 >                                close(fd);
1479                                  return errno2oserr();
1480 +                        }
1481                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1482                          st.st_size = 0;
1483                          st.st_mode = 0;
# Line 1485 | Line 1486 | static int16 fs_open(uint32 pb, uint32 d
1486                  fd = open(full_path, flag);
1487                  if (fd < 0)
1488                          return errno2oserr();
1489 <                if (fstat(fd, &st) < 0)
1489 >                if (fstat(fd, &st) < 0) {
1490 >                        close(fd);
1491                          return errno2oserr();
1492 +                }
1493          }
1494  
1495          // File open, allocate FCB
# Line 1509 | Line 1512 | static int16 fs_open(uint32 pb, uint32 d
1512          WriteMacInt32(fcb + fcbCrPs, 0);
1513          WriteMacInt32(fcb + fcbVPtr, vcb);
1514          WriteMacInt32(fcb + fcbClmpSize, 1024);
1515 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1515 >        uint32 type, creator;   // BeOS: fcb may point to kernel space, but stack is switched
1516          get_finder_type(full_path, type, creator);
1517          WriteMacInt32(fcb + fcbFType, type);
1518          WriteMacInt32(fcb + fcbCatPos, fd);
# Line 1776 | Line 1779 | static int16 fs_read(uint32 pb)
1779  
1780          // Read
1781          size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1782 +        int16 read_err = errno2oserr();
1783          D(bug("  actual %d\n", actual));
1784          WriteMacInt32(pb + ioActCount, actual);
1785          uint32 pos = lseek(fd, 0, SEEK_CUR);
1786          WriteMacInt32(fcb + fcbCrPs, pos);
1787          WriteMacInt32(pb + ioPosOffset, pos);
1788          if (actual != ReadMacInt32(pb + ioReqCount))
1789 <                if (errno)
1786 <                        return errno2oserr();
1787 <                else
1788 <                        return eofErr;
1789 >                return read_err ? read_err : eofErr;
1790          else
1791                  return noErr;
1792   }
# Line 1827 | Line 1828 | static int16 fs_write(uint32 pb)
1828  
1829          // Write
1830          size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1831 +        int16 write_err = errno2oserr();
1832          D(bug("  actual %d\n", actual));
1833          WriteMacInt32(pb + ioActCount, actual);
1834          uint32 pos = lseek(fd, 0, SEEK_CUR);
1835          WriteMacInt32(fcb + fcbCrPs, pos);
1836          WriteMacInt32(pb + ioPosOffset, pos);
1837          if (actual != ReadMacInt32(pb + ioReqCount))
1838 <                return errno2oserr();
1838 >                return write_err;
1839          else
1840                  return noErr;
1841   }
# Line 1854 | Line 1856 | static int16 fs_create(uint32 pb, uint32
1856                  return dupFNErr;
1857  
1858          // Create file
1859 <        int fd = creat(full_path, 0664);
1859 >        int fd = creat(full_path, 0666);
1860          if (fd < 0)
1861                  return errno2oserr();
1862          else {
# Line 1879 | Line 1881 | static int16 fs_dir_create(uint32 pb)
1881                  return dupFNErr;
1882  
1883          // Create directory
1884 <        if (mkdir(full_path, 0775) < 0)
1884 >        if (mkdir(full_path, 0777) < 0)
1885                  return errno2oserr();
1886          else {
1887                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1899 | Line 1901 | static int16 fs_delete(uint32 pb, uint32
1901                  return result;
1902  
1903          // Delete file
1904 <        if (remove(full_path) < 0) {
1905 <                int16 err = errno2oserr();
1906 <                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
1904 >        if (!extfs_remove(full_path))
1905 >                return errno2oserr();
1906 >        else
1907                  return noErr;
1908   }
1909  
# Line 1928 | Line 1923 | static int16 fs_rename(uint32 pb, uint32
1923          strcpy(old_path, full_path);
1924  
1925          // Find path for new name
1926 <        uint8 new_pb[SIZEOF_IOParam];
1927 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1933 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1926 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1927 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1928          FSItem *new_item;
1929 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1929 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1930          if (result != noErr)
1931                  return result;
1932  
# Line 1942 | Line 1936 | static int16 fs_rename(uint32 pb, uint32
1936  
1937          // Rename item
1938          D(bug("  renaming %s -> %s\n", old_path, full_path));
1939 <        if (rename(old_path, full_path) < 0)
1939 >        if (!extfs_rename(old_path, full_path))
1940                  return errno2oserr();
1941          else {
1942                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
# Line 1969 | Line 1963 | static int16 fs_cat_move(uint32 pb)
1963          strcpy(old_path, full_path);
1964  
1965          // Find path for new directory
1966 <        uint8 new_pb[SIZEOF_IOParam];
1967 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1974 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1966 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1967 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1968          FSItem *new_dir_item;
1969 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1969 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1970          if (result != noErr)
1971                  return result;
1972  
1973          // Append old file/dir name
1974 <        add_path_component(fs_item->name);
1974 >        add_path_comp(fs_item->name);
1975  
1976          // Does the new name already exist?
1977          if (access(full_path, F_OK) == 0)
# Line 1986 | Line 1979 | static int16 fs_cat_move(uint32 pb)
1979  
1980          // Move item
1981          D(bug("  moving %s -> %s\n", old_path, full_path));
1982 <        if (rename(old_path, full_path) < 0)
1982 >        if (!extfs_rename(old_path, full_path))
1983                  return errno2oserr();
1984          else {
1985                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
# Line 2010 | Line 2003 | static int16 fs_open_wd(uint32 pb)
2003          D(bug("  allocating WDCB\n"));
2004          r.a[0] = pb;
2005          Execute68k(fs_data + fsAllocateWDCB, &r);
2006 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2006 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2007          return r.d[0];
2008   }
2009  
# Line 2039 | Line 2032 | static int16 fs_get_wd_info(uint32 pb, u
2032                  WriteMacInt32(pb + ioWDProcID, 0);
2033                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2034                  if (ReadMacInt32(pb + ioNamePtr))
2035 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2035 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2036                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2037                  return noErr;
2038          }
# Line 2057 | Line 2050 | static int16 fs_get_wd_info(uint32 pb, u
2050                  return r.d[0];
2051  
2052          // Return information
2053 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2053 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2054          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2055          if (ReadMacInt32(pb + ioNamePtr))
2056 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2056 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2057          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2058          return noErr;
2059   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines