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.2 by cebix, 1999-10-19T21:33:56Z vs.
Revision 1.12 by cebix, 1999-11-08T17:00:04Z

# Line 19 | Line 19
19   */
20  
21   /*
22 < TODO:
23 < LockRng
24 < UnlockRng
25 < (CatSearch)
26 < (MakeFSSpec)
27 < (GetVolMountInfoSize)
28 < (GetVolMountInfo)
29 < (GetForeignPrivs)
30 < (SetForeignPrivs)
31 < */
22 > *  SEE ALSO
23 > *    Guide to the File System Manager (from FSM 1.2 SDK)
24 > *
25 > *  TODO
26 > *    LockRng
27 > *    UnlockRng
28 > *    (CatSearch)
29 > *    (MakeFSSpec)
30 > *    (GetVolMountInfoSize)
31 > *    (GetVolMountInfo)
32 > *    (GetForeignPrivs)
33 > *    (SetForeignPrivs)
34 > */
35  
36   #include "sysdeps.h"
37  
# Line 62 | 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 198 | Line 201 | static FSItem *find_fsitem(const char *n
201   *  Get full path (->full_path) for given FSItem
202   */
203  
201 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);
207 <        if (l < MAX_PATH_LENGTH-1 && full_path[l-1] != '/') {
208 <                full_path[l] = '/';
209 <                full_path[l+1] = 0;
210 <        }
211 <        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 322 | Line 321 | void ExtFSInit(void)
321          cstr2pstr(FS_NAME, GetString(STR_EXTFS_NAME));
322          cstr2pstr(VOLUME_NAME, GetString(STR_EXTFS_VOLUME_NAME));
323  
324 <        // Create root FSItem
324 >        // Create root's parent FSItem
325          FSItem *p = new FSItem;
326          first_fs_item = last_fs_item = p;
327          p->next = NULL;
328 +        p->id = ROOT_PARENT_ID;
329 +        p->parent_id = 0;
330 +        p->parent = NULL;
331 +        p->name[0] = 0;
332 +
333 +        // Create root FSItem
334 +        p = new FSItem;
335 +        last_fs_item->next = p;
336 +        p->next = NULL;
337 +        last_fs_item = p;
338          p->id = ROOT_ID;
339          p->parent_id = ROOT_PARENT_ID;
340 <        p->parent = NULL;
340 >        p->parent = first_fs_item;
341          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
342  
343          // Find path for root
# Line 379 | Line 388 | void InstallExtFS(void)
388          r.d[0] = gestaltFSAttr;
389          Execute68kTrap(0xa1ad, &r);     // Gestalt()
390          D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
391 <        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager)))
391 >        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
392 >                printf("WARNING: No FSM present, disabling ExtFS\n");
393                  return;
394 +        }
395  
396          // Yes, version >=1.2?
397          r.d[0] = gestaltFSMVersion;
398          Execute68kTrap(0xa1ad, &r);     // Gestalt()
399          D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
400 <        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120))
400 >        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
401 >                printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
402                  return;
403 +        }
404  
405          D(bug("FSM present\n"));
406  
# Line 423 | 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 433 | 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 445 | 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 464 | 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 472 | 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 481 | 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 489 | 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 497 | 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 507 | 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 516 | 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 524 | 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 534 | 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 543 | 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 551 | 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 559 | 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 567 | 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 591 | 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 645 | 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 682 | Line 695 | static int16 get_current_dir(uint32 pb,
695          int16 result;
696  
697          // Determine volume
698 < //      D(bug("  determining volume\n"));
698 >        D(bug("  determining volume, dirID %d\n", dirID));
699          r.a[0] = pb;
700          r.a[1] = fs_data + fsReturn;
701          r.a[2] = fs_data + fsReturn + 2;
# Line 700 | Line 713 | static int16 get_current_dir(uint32 pb,
713          int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
714          int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
715          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
716 < //      D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
716 >        D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
717          result = r.d[0] & 0xffff;
718  
719          if (result == noErr) {
# Line 719 | 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 783 | Line 798 | static int16 get_item_and_path(uint32 pb
798          uint32 current_dir;
799          if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr)
800                  return result;
801 +        D(bug("  current dir %08x\n", current_dir));
802          FSItem *p = find_fsitem_by_id(current_dir);
803          if (p == NULL)
804                  return dirNFErr;
# Line 796 | Line 812 | static int16 get_item_and_path(uint32 pb
812          WriteMacInt8(parseRec + ppFoundDelimiter, false);
813  
814          // Get length of volume name
815 < //      D(bug("  parsing pathname\n"));
815 >        D(bug("  parsing pathname\n"));
816          r.a[0] = parseRec + ppStartOffset;
817          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
818          Execute68k(fs_data + fsParsePathname, &r);
819 < //      D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
819 >        D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
820          result = r.d[0] & 0xffff;
821          if (result == noErr) {
822  
# Line 953 | 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 1027 | 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 1057 | Line 1073 | static int16 fs_get_vol_parms(uint32 pb)
1073          uint32 actual = ReadMacInt32(pb + ioReqCount);
1074          if (actual > sizeof(vol))
1075                  actual = sizeof(vol);
1076 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1076 >        Host2Mac_memcpy(ReadMacInt32(pb + ioBuffer), vol, actual);
1077          WriteMacInt32(pb + ioActCount, actual);
1078          return noErr;
1079   }
# Line 1079 | Line 1095 | static int16 fs_get_vol(uint32 pb)
1095   // Set default volume (WDParam)
1096   static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb)
1097   {
1098 <        D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
1098 >        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)));
1099          M68kRegisters r;
1100  
1101          // Determine parameters
# Line 1135 | Line 1151 | static int16 fs_set_vol(uint32 pb, bool
1151   // Query file attributes (HFileParam)
1152   static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID)
1153   {
1154 <        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));
1154 >        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));
1155  
1156          FSItem *fs_item;
1157          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1158 <        if (dir_index == 0) {   // Query item specified by ioDirID and ioNamePtr
1158 >        if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1159  
1160                  // Find FSItem for given file
1161                  int16 result = get_item_and_path(pb, dirID, fs_item);
# Line 1171 | Line 1187 | read_next_de:
1187                                  return fnfErr;
1188                          }
1189                          if (de->d_name[0] == '.')
1190 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1190 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1191                          //!! suppress directories
1192                  }
1193 <                add_path_component(de->d_name);
1193 >                add_path_comp(de->d_name);
1194  
1195                  // Get FSItem for queried item
1196                  fs_item = find_fsitem(de->d_name, p);
# Line 1202 | Line 1218 | read_next_de:
1218   #endif
1219          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1220  
1221 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1221 >        Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1222          uint32 type, creator;   // pb may point to kernel space, but stack is switched
1223          get_finder_type(full_path, type, creator);
1224          WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1221 | Line 1237 | read_next_de:
1237  
1238          if (hfs) {
1239                  WriteMacInt32(pb + ioFlBkDat, 0);
1240 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1240 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1241                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1242                  WriteMacInt32(pb + ioFlClpSiz, 0);
1243          }
# Line 1231 | Line 1247 | read_next_de:
1247   // Set file attributes (HFileParam)
1248   static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID)
1249   {
1250 <        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));
1250 >        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));
1251  
1252          // Find FSItem for given file/dir
1253          FSItem *fs_item;
# Line 1256 | Line 1272 | static int16 fs_set_file_info(uint32 pb,
1272   // Query file/directory attributes
1273   static int16 fs_get_cat_info(uint32 pb)
1274   {
1275 <        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)));
1275 >        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)));
1276  
1277          FSItem *fs_item;
1278          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1279 <        if (dir_index == -1) {          // Query directory specified by ioDirID
1279 >        if (dir_index < 0) {                    // Query directory specified by ioDirID
1280  
1281                  // Find FSItem for directory
1282                  fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID));
# Line 1300 | Line 1316 | read_next_de:
1316                                  return fnfErr;
1317                          }
1318                          if (de->d_name[0] == '.')
1319 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1319 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1320                  }
1321 <                add_path_component(de->d_name);
1321 >                add_path_comp(de->d_name);
1322  
1323                  // Get FSItem for queried item
1324                  fs_item = find_fsitem(de->d_name, p);
# Line 1336 | Line 1352 | read_next_de:
1352                  fs_item->mtime = mtime;
1353                  cached = false;
1354          }
1355 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1355 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1356          WriteMacInt32(pb + ioFlBkDat, 0);
1357          if (S_ISDIR(st.st_mode)) {
1358 <                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1359 <                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1358 >                Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
1359 >                Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo);
1360                  uint16 fflags;  // pb may point to kernel space, but stack is switched
1361                  get_finder_flags(full_path, fflags);
1362                  WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
# Line 1358 | Line 1374 | read_next_de:
1374                                          de = readdir(d);
1375                                          if (de == NULL)
1376                                                  break;
1377 +                                        if (de->d_name[0] == '.')
1378 +                                                continue;       // Suppress names beginning with '.'
1379                                          count++;
1380                                  }
1381                                  closedir(d);
# Line 1366 | Line 1384 | read_next_de:
1384                  }
1385                  WriteMacInt16(pb + ioDrNmFls, count);
1386          } else {
1387 <                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1388 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1387 >                Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1388 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1389                  uint32 type, creator;   // pb may point to kernel space, but stack is switched
1390                  get_finder_type(full_path, type, creator);
1391                  WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
# Line 1390 | Line 1408 | read_next_de:
1408   // Set file/directory attributes
1409   static int16 fs_set_cat_info(uint32 pb)
1410   {
1411 <        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)));
1411 >        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)));
1412  
1413          // Find FSItem for given file/dir
1414          FSItem *fs_item;
# Line 1417 | Line 1435 | static int16 fs_set_cat_info(uint32 pb)
1435   // Open file
1436   static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork)
1437   {
1438 <        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)));
1438 >        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)));
1439          M68kRegisters r;
1440  
1441          // Find FSItem for given file
# Line 1704 | Line 1722 | static int16 fs_set_fpos(uint32 pb)
1722                          if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0)
1723                                  return posErr;
1724                          break;
1725 +                case fsFromLEOF:
1726 +                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0)
1727 +                                return posErr;
1728 +                        break;
1729                  case fsFromMark:
1730 <                        if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1730 >                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1731                                  return posErr;
1732 +                        break;
1733                  default:
1734                          break;
1735          }
# Line 1753 | Line 1776 | static int16 fs_read(uint32 pb)
1776  
1777          // Read
1778          size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1779 +        int16 read_err = errno2oserr();
1780          D(bug("  actual %d\n", actual));
1781          WriteMacInt32(pb + ioActCount, actual);
1782          uint32 pos = lseek(fd, 0, SEEK_CUR);
1783          WriteMacInt32(fcb + fcbCrPs, pos);
1784          WriteMacInt32(pb + ioPosOffset, pos);
1785          if (actual != ReadMacInt32(pb + ioReqCount))
1786 <                if (errno)
1763 <                        return errno2oserr();
1764 <                else
1765 <                        return eofErr;
1786 >                return read_err ? read_err : eofErr;
1787          else
1788                  return noErr;
1789   }
# Line 1804 | Line 1825 | static int16 fs_write(uint32 pb)
1825  
1826          // Write
1827          size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1828 +        int16 write_err = errno2oserr();
1829          D(bug("  actual %d\n", actual));
1830          WriteMacInt32(pb + ioActCount, actual);
1831          uint32 pos = lseek(fd, 0, SEEK_CUR);
1832          WriteMacInt32(fcb + fcbCrPs, pos);
1833          WriteMacInt32(pb + ioPosOffset, pos);
1834          if (actual != ReadMacInt32(pb + ioReqCount))
1835 <                return errno2oserr();
1835 >                return write_err;
1836          else
1837                  return noErr;
1838   }
# Line 1818 | Line 1840 | static int16 fs_write(uint32 pb)
1840   // Create file
1841   static int16 fs_create(uint32 pb, uint32 dirID)
1842   {
1843 <        D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1843 >        D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1844  
1845          // Find FSItem for given file
1846          FSItem *fs_item;
# Line 1831 | Line 1853 | static int16 fs_create(uint32 pb, uint32
1853                  return dupFNErr;
1854  
1855          // Create file
1856 <        int fd = creat(full_path, 0664);
1856 >        int fd = creat(full_path, 0666);
1857          if (fd < 0)
1858                  return errno2oserr();
1859          else {
# Line 1843 | Line 1865 | static int16 fs_create(uint32 pb, uint32
1865   // Create directory
1866   static int16 fs_dir_create(uint32 pb)
1867   {
1868 <        D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID)));
1868 >        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)));
1869  
1870          // Find FSItem for given directory
1871          FSItem *fs_item;
# Line 1856 | Line 1878 | static int16 fs_dir_create(uint32 pb)
1878                  return dupFNErr;
1879  
1880          // Create directory
1881 <        if (mkdir(full_path, 0775) < 0)
1881 >        if (mkdir(full_path, 0777) < 0)
1882                  return errno2oserr();
1883          else {
1884                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1867 | Line 1889 | static int16 fs_dir_create(uint32 pb)
1889   // Delete file/directory
1890   static int16 fs_delete(uint32 pb, uint32 dirID)
1891   {
1892 <        D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1892 >        D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1893  
1894          // Find FSItem for given file/dir
1895          FSItem *fs_item;
# Line 1876 | Line 1898 | static int16 fs_delete(uint32 pb, uint32
1898                  return result;
1899  
1900          // Delete file
1901 <        if (remove(full_path) < 0) {
1902 <                int16 err = errno2oserr();
1903 <                if (errno == EISDIR) {  // Workaround for BeOS bug
1882 <                        if (rmdir(full_path) < 0)
1883 <                                return errno2oserr();
1884 <                        else
1885 <                                return noErr;
1886 <                } else
1887 <                        return err;
1888 <        } else
1901 >        if (!extfs_remove(full_path))
1902 >                return errno2oserr();
1903 >        else
1904                  return noErr;
1905   }
1906  
1907   // Rename file/directory
1908   static int16 fs_rename(uint32 pb, uint32 dirID)
1909   {
1910 <        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))));
1910 >        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)));
1911  
1912          // Find path of given file/dir
1913          FSItem *fs_item;
# Line 1905 | Line 1920 | static int16 fs_rename(uint32 pb, uint32
1920          strcpy(old_path, full_path);
1921  
1922          // Find path for new name
1923 <        uint8 new_pb[SIZEOF_IOParam];
1924 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1910 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1923 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1924 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1925          FSItem *new_item;
1926 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1926 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1927          if (result != noErr)
1928                  return result;
1929  
# Line 1933 | Line 1947 | static int16 fs_rename(uint32 pb, uint32
1947   // Move file/directory (CMovePBRec)
1948   static int16 fs_cat_move(uint32 pb)
1949   {
1950 <        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)));
1950 >        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)));
1951  
1952          // Find path of given file/dir
1953          FSItem *fs_item;
# Line 1946 | Line 1960 | static int16 fs_cat_move(uint32 pb)
1960          strcpy(old_path, full_path);
1961  
1962          // Find path for new directory
1963 <        uint8 new_pb[SIZEOF_IOParam];
1964 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1951 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1963 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1964 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1965          FSItem *new_dir_item;
1966 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1966 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1967          if (result != noErr)
1968                  return result;
1969  
1970          // Append old file/dir name
1971 <        add_path_component(fs_item->name);
1971 >        add_path_comp(fs_item->name);
1972  
1973          // Does the new name already exist?
1974          if (access(full_path, F_OK) == 0)
# Line 1980 | Line 1993 | static int16 fs_cat_move(uint32 pb)
1993   // Open working directory (WDParam)
1994   static int16 fs_open_wd(uint32 pb)
1995   {
1996 <        D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
1996 >        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)));
1997          M68kRegisters r;
1998  
1999          // Allocate WDCB
2000          D(bug("  allocating WDCB\n"));
2001          r.a[0] = pb;
2002          Execute68k(fs_data + fsAllocateWDCB, &r);
2003 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2003 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2004          return r.d[0];
2005   }
2006  
# Line 2016 | Line 2029 | static int16 fs_get_wd_info(uint32 pb, u
2029                  WriteMacInt32(pb + ioWDProcID, 0);
2030                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2031                  if (ReadMacInt32(pb + ioNamePtr))
2032 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2032 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2033                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2034                  return noErr;
2035          }
# Line 2034 | Line 2047 | static int16 fs_get_wd_info(uint32 pb, u
2047                  return r.d[0];
2048  
2049          // Return information
2050 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2050 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2051          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2052          if (ReadMacInt32(pb + ioNamePtr))
2053 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2053 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2054          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2055          return noErr;
2056   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines