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.20 by cebix, 2000-07-21T18:01:05Z

# Line 1 | Line 1
1   /*
2 < *  extfs.cpp - MacOS file system for access native file system access
2 > *  extfs.cpp - MacOS file system for native file system access
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-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 40 | Line 40
40   #include <string.h>
41   #include <stdio.h>
42   #include <stdlib.h>
43 #include <unistd.h>
43   #include <fcntl.h>
45 #include <dirent.h>
44   #include <errno.h>
45  
46 + #ifndef WIN32
47 + #include <unistd.h>
48 + #include <dirent.h>
49 + #endif
50 +
51   #include "cpu_emulation.h"
52   #include "macos_util.h"
53   #include "emul_op.h"
# Line 55 | Line 58
58   #include "extfs.h"
59   #include "extfs_defs.h"
60  
61 + #ifdef WIN32
62 + # include "posix_emu.h"
63 + #endif
64 +
65   #define DEBUG 0
66   #include "debug.h"
67  
# Line 65 | Line 72 | enum {
72          fsHFSProcStub = 6,
73          fsDrvStatus = 12,                               // Drive Status record
74          fsFSD = 42,                                             // File system descriptor
75 <        fsPB = 238,                                             // IOParam (for mounting)
75 >        fsPB = 238,                                             // IOParam (for mounting and renaming), also used for temporary storage
76          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
77          fsParseRec = 296,                               // ParsePathRec struct
78          fsReturn = 306,                                 // Area for return data of 68k routines
79          fsAllocateVCB = 562,                    // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1})
80          fsAddNewVCB = 578,                              // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1})
81          fsDetermineVol = 594,                   // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4})
82 <        fsResolveWDCB = 614,                    // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0})
82 >        fsResolveWDCB = 614,                    // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0})
83          fsGetDefaultVol = 632,                  // UTGetDefaultVol(uint32 wdpb{a0})
84          fsGetPathComponentName = 644,   // UTGetPathComponentName(uint32 rec{a0})
85          fsParsePathname = 656,                  // UTParsePathname(uint32 *start{a0}, uint32 name{a1})
# Line 111 | Line 118 | const uint32 ROOT_PARENT_ID = 1;
118   // File system stack size
119   const int STACK_SIZE = 0x10000;
120  
121 + // Allocation block and clump size as reported to MacOS (these are of course
122 + // not the real values and have no meaning on the host OS)
123 + const int AL_BLK_SIZE = 0x4000;
124 + const int CLUMP_SIZE = 0x4000;
125 +
126   // Drive number of our pseudo-drive
127   static int drive_number;
128  
# Line 201 | Line 213 | static FSItem *find_fsitem(const char *n
213   *  Get full path (->full_path) for given FSItem
214   */
215  
204 const int MAX_PATH_LENGTH = 1024;
216   static char full_path[MAX_PATH_LENGTH];
217  
218 < static void add_path_component(const char *s)
218 > static void add_path_comp(const char *s)
219   {
220 <        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);
220 >        add_path_component(full_path, s);
221   }
222  
223   static void get_path_for_fsitem(FSItem *p)
224   {
225 <        if (p->id == ROOT_ID) {
225 >        if (p->id == ROOT_PARENT_ID) {
226 >                full_path[0] = 0;
227 >        } else if (p->id == ROOT_ID) {
228                  strncpy(full_path, RootPath, MAX_PATH_LENGTH-1);
229                  full_path[MAX_PATH_LENGTH-1] = 0;
230          } else {
231                  get_path_for_fsitem(p->parent);
232 <                add_path_component(p->name);
232 >                add_path_comp(p->name);
233 >        }
234 > }
235 >
236 >
237 > /*
238 > *  Exchange parent CNIDs in all FSItems
239 > */
240 >
241 > static void swap_parent_ids(uint32 parent1, uint32 parent2)
242 > {
243 >        FSItem *p = first_fs_item;
244 >        while (p) {
245 >                if (p->parent_id == parent1)
246 >                        p->parent_id = parent2;
247 >                else if (p->parent_id == parent2)
248 >                        p->parent_id = parent1;
249 >                p = p->next;
250          }
251   }
252  
# Line 244 | Line 269 | static void cstr2pstr(char *dst, const c
269          *dst++ = strlen(src);
270          char c;
271          while ((c = *src++) != 0) {
272 +                // Note: we are converting host ':' characters to Mac '/' characters here
273 +                // '/' is not a path separator as this function is only used on object names
274                  if (c == ':')
275                          c = '/';
276                  *dst++ = c;
# Line 256 | Line 283 | static void pstr2cstr(char *dst, const c
283          int size = *src++;
284          while (size--) {
285                  char c = *src++;
286 +                // Note: we are converting Mac '/' characters to host ':' characters here
287 +                // '/' is not a path separator as this function is only used on object names
288                  if (c == '/')
289                          c = ':';
290                  *dst++ = c;
# Line 268 | Line 297 | static void strn2cstr(char *dst, const c
297   {
298          while (size--) {
299                  char c = *src++;
300 +                // Note: we are converting Mac '/' characters to host ':' characters here
301 +                // '/' is not a path separator as this function is only used on object names
302                  if (c == '/')
303                          c = ':';
304                  *dst++ = c;
# Line 343 | Line 374 | void ExtFSInit(void)
374          p->parent_id = ROOT_PARENT_ID;
375          p->parent = first_fs_item;
376          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
377 +        p->name[31] = 0;
378  
379          // Find path for root
380          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 440 | Line 472 | void InstallExtFS(void)
472          WriteMacInt16(p, 0x7006); p+= 2;        // UTAllocateVCB
473          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
474          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
475 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
475 >        WriteMacInt16(p, M68K_RTS); p+= 2;
476          if (p - fs_data != fsAddNewVCB)
477                  goto fsdat_error;
478          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 450 | Line 482 | void InstallExtFS(void)
482          WriteMacInt16(p, 0x7007); p+= 2;        // UTAddNewVCB
483          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
484          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
485 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
485 >        WriteMacInt16(p, M68K_RTS); p+= 2;
486          if (p - fs_data != fsDetermineVol)
487                  goto fsdat_error;
488          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 462 | Line 494 | void InstallExtFS(void)
494          WriteMacInt16(p, 0x701d); p+= 2;        // UTDetermineVol
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 != fsResolveWDCB)
499                  goto fsdat_error;
500          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
501 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
502 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
503 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
501 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
502 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
503 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
504          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
505          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
506          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
507          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
508 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
508 >        WriteMacInt16(p, M68K_RTS); p+= 2;
509          if (p - fs_data != fsGetDefaultVol)
510                  goto fsdat_error;
511          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 481 | Line 513 | void InstallExtFS(void)
513          WriteMacInt16(p, 0x7012); p+= 2;        // UTGetDefaultVol
514          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
515          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
516 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
516 >        WriteMacInt16(p, M68K_RTS); p+= 2;
517          if (p - fs_data != fsGetPathComponentName)
518                  goto fsdat_error;
519          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 489 | Line 521 | void InstallExtFS(void)
521          WriteMacInt16(p, 0x701c); p+= 2;        // UTGetPathComponentName
522          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
523          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
524 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
524 >        WriteMacInt16(p, M68K_RTS); p+= 2;
525          if (p - fs_data != fsParsePathname)
526                  goto fsdat_error;
527          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 498 | Line 530 | void InstallExtFS(void)
530          WriteMacInt16(p, 0x701b); p+= 2;        // UTParsePathname
531          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
532          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
533 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
533 >        WriteMacInt16(p, M68K_RTS); p+= 2;
534          if (p - fs_data != fsDisposeVCB)
535                  goto fsdat_error;
536          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 506 | Line 538 | void InstallExtFS(void)
538          WriteMacInt16(p, 0x7008); p+= 2;        // UTDisposeVCB
539          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
540          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
541 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
541 >        WriteMacInt16(p, M68K_RTS); p+= 2;
542          if (p - fs_data != fsCheckWDRefNum)
543                  goto fsdat_error;
544          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 514 | Line 546 | void InstallExtFS(void)
546          WriteMacInt16(p, 0x7013); p+= 2;        // UTCheckWDRefNum
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 != fsSetDefaultVol)
551                  goto fsdat_error;
552          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 524 | Line 556 | void InstallExtFS(void)
556          WriteMacInt16(p, 0x7011); p+= 2;        // UTSetDefaultVol
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 != fsAllocateFCB)
561                  goto fsdat_error;
562          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 533 | Line 565 | void InstallExtFS(void)
565          WriteMacInt16(p, 0x7000); p+= 2;        // UTAllocateFCB
566          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
567          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
568 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
568 >        WriteMacInt16(p, M68K_RTS); p+= 2;
569          if (p - fs_data != fsReleaseFCB)
570                  goto fsdat_error;
571          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 541 | Line 573 | void InstallExtFS(void)
573          WriteMacInt16(p, 0x7001); p+= 2;        // UTReleaseFCB
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 != fsIndexFCB)
578                  goto fsdat_error;
579          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 551 | Line 583 | void InstallExtFS(void)
583          WriteMacInt16(p, 0x7004); p+= 2;        // UTIndexFCB
584          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
585          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
586 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
586 >        WriteMacInt16(p, M68K_RTS); p+= 2;
587          if (p - fs_data != fsResolveFCB)
588                  goto fsdat_error;
589          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 560 | Line 592 | void InstallExtFS(void)
592          WriteMacInt16(p, 0x7005); p+= 2;        // UTResolveFCB
593          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
594          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
595 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
595 >        WriteMacInt16(p, M68K_RTS); p+= 2;
596          if (p - fs_data != fsAdjustEOF)
597                  goto fsdat_error;
598          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 568 | Line 600 | void InstallExtFS(void)
600          WriteMacInt16(p, 0x7010); p+= 2;        // UTAdjustEOF
601          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
602          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
603 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
603 >        WriteMacInt16(p, M68K_RTS); p+= 2;
604          if (p - fs_data != fsAllocateWDCB)
605                  goto fsdat_error;
606          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 576 | Line 608 | void InstallExtFS(void)
608          WriteMacInt16(p, 0x700c); p+= 2;        // UTAllocateWDCB
609          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
610          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
611 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
611 >        WriteMacInt16(p, M68K_RTS); p+= 2;
612          if (p - fs_data != fsReleaseWDCB)
613                  goto fsdat_error;
614          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 584 | Line 616 | void InstallExtFS(void)
616          WriteMacInt16(p, 0x700d); p+= 2;        // UTReleaseWDCB
617          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
618          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
619 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
619 >        WriteMacInt16(p, M68K_RTS); p+= 2;
620          if (p - fs_data != SIZEOF_fsdat)
621                  goto fsdat_error;
622  
# Line 608 | Line 640 | void InstallExtFS(void)
640          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
641          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
642          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
643 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
643 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
644          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
645          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
646          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 662 | Line 694 | int16 ExtFSComm(uint16 message, uint32 p
694  
695                  case ffsGetIconMessage: {               // Get disk/drive icon
696                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
697 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
697 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
698                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
699                                  return noErr;
700                          } else
# Line 718 | Line 750 | static int16 get_current_dir(uint32 pb,
750          int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
751          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
752          D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
753 <        result = r.d[0] & 0xffff;
753 >        result = (int16)(r.d[0] & 0xffff);
754  
755          if (result == noErr) {
756                  switch (status) {
# Line 736 | Line 768 | static int16 get_current_dir(uint32 pb,
768                                          current_dir = dirID;
769                                  else {
770                                          D(bug("  resolving WDCB\n"));
771 <                                        r.d[0] = ReadMacInt16(pb + ioVRefNum);
771 >                                        r.d[0] = 0;
772 >                                        r.d[1] = 0;
773 >                                        r.d[2] = ReadMacInt16(pb + ioVRefNum);
774                                          r.a[0] = fs_data + fsReturn;
775                                          Execute68k(fs_data + fsResolveWDCB, &r);
776                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
777                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
778 <                                        result = r.d[0] & 0xffff;
778 >                                        result = (int16)(r.d[0] & 0xffff);
779                                          if (result == noErr)
780                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
781                                  }
# Line 757 | Line 791 | static int16 get_current_dir(uint32 pb,
791                                          r.a[0] = wdpb;
792                                          Execute68k(fs_data + fsGetDefaultVol, &r);
793                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
794 <                                        result = r.d[0] & 0xffff;
794 >                                        result = (int16)(r.d[0] & 0xffff);
795                                          if (result == noErr)
796                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
797                                  }
# Line 783 | Line 817 | static int16 get_path_component_name(uin
817          r.a[0] = rec;
818          Execute68k(fs_data + fsGetPathComponentName, &r);
819   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
820 <        return r.d[0] & 0xffff;
820 >        return (int16)(r.d[0] & 0xffff);
821   }
822  
823  
# Line 819 | Line 853 | static int16 get_item_and_path(uint32 pb
853          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
854          Execute68k(fs_data + fsParsePathname, &r);
855          D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
856 <        result = r.d[0] & 0xffff;
856 >        result = (int16)(r.d[0] & 0xffff);
857          if (result == noErr) {
858  
859                  // Check for leading delimiter of the partial pathname
# Line 953 | Line 987 | static int16 fs_volume_mount(uint32 pb)
987          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
988          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
989          if (r.d[0] & 0xffff)
990 <                return r.d[0];
990 >                return (int16)r.d[0];
991  
992          // Init VCB
993          WriteMacInt16(vcb + vcbSigWord, 0x4244);
994 < #ifdef __BEOS__
994 > #if defined(__BEOS__) || defined(WIN32)
995          WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
996   #else
997          WriteMacInt32(vcb + vcbCrDate, 0);
# Line 967 | Line 1001 | static int16 fs_volume_mount(uint32 pb)
1001          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
1002          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
1003          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
1004 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
1005 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
1004 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
1005 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
1006          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
1007          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
1008 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
1008 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
1009          WriteMacInt16(vcb + vcbFSID, MY_FSID);
1010          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
1011          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 982 | Line 1016 | static int16 fs_volume_mount(uint32 pb)
1016          r.a[0] = fs_data + fsReturn;
1017          r.a[1] = vcb;
1018          Execute68k(fs_data + fsAddNewVCB, &r);
1019 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1019 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1020          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1021          if (r.d[0] & 0xffff)
1022 <                return r.d[0];
1022 >                return (int16)r.d[0];
1023  
1024          // Post diskInsertEvent
1025          D(bug("  posting diskInsertEvent\n"));
# Line 1009 | Line 1043 | static int16 fs_unmount_vol(uint32 vcb)
1043          r.a[0] = vcb;
1044          Execute68k(fs_data + fsDisposeVCB, &r);
1045          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1046 <        return r.d[0];
1046 >        return (int16)r.d[0];
1047   }
1048  
1049   // Get information about a volume (HVolumeParam)
# Line 1020 | Line 1054 | static int16 fs_get_vol_info(uint32 pb,
1054          // Fill in struct
1055          if (ReadMacInt32(pb + ioNamePtr))
1056                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1057 < #ifdef __BEOS__
1057 > #if defined(__BEOS__) || defined(WIN32)
1058          WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1059   #else
1060          WriteMacInt32(pb + ioVCrDate, 0);
# Line 1031 | Line 1065 | static int16 fs_get_vol_info(uint32 pb,
1065          WriteMacInt16(pb + ioVBitMap, 0);
1066          WriteMacInt16(pb + ioAllocPtr, 0);
1067          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1068 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1069 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1068 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1069 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1070          WriteMacInt16(pb + ioAlBlSt, 0);
1071          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1072          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1045 | Line 1079 | static int16 fs_get_vol_info(uint32 pb,
1079                  WriteMacInt32(pb + ioVWrCnt, 0);
1080                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1081                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1082 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1082 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1083          }
1084          return noErr;
1085   }
# Line 1065 | Line 1099 | static int16 fs_get_vol_parms(uint32 pb)
1099   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1100  
1101          // 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);
1102          uint32 actual = ReadMacInt32(pb + ioReqCount);
1103 <        if (actual > sizeof(vol))
1104 <                actual = sizeof(vol);
1078 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1103 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1104 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1105          WriteMacInt32(pb + ioActCount, actual);
1106 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1107 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1108 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1109 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1110 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1111 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1112 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1113          return noErr;
1114   }
1115  
# Line 1091 | Line 1124 | static int16 fs_get_vol(uint32 pb)
1124          r.a[0] = pb;
1125          Execute68k(fs_data + fsGetDefaultVol, &r);
1126          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1127 <        return r.d[0];
1127 >        return (int16)r.d[0];
1128   }
1129  
1130   // Set default volume (WDParam)
# Line 1147 | Line 1180 | static int16 fs_set_vol(uint32 pb, bool
1180          r.d[2] = refNum;
1181          Execute68k(fs_data + fsSetDefaultVol, &r);
1182          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1183 <        return r.d[0];
1183 >        return (int16)r.d[0];
1184   }
1185  
1186   // Query file attributes (HFileParam)
# Line 1156 | Line 1189 | static int16 fs_get_file_info(uint32 pb,
1189          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));
1190  
1191          FSItem *fs_item;
1192 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1192 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1193          if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1194  
1195                  // Find FSItem for given file
# Line 1189 | Line 1222 | read_next_de:
1222                                  return fnfErr;
1223                          }
1224                          if (de->d_name[0] == '.')
1225 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1225 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1226                          //!! suppress directories
1227                  }
1228 <                add_path_component(de->d_name);
1228 >                add_path_comp(de->d_name);
1229  
1230                  // Get FSItem for queried item
1231                  fs_item = find_fsitem(de->d_name, p);
# Line 1213 | Line 1246 | read_next_de:
1246          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1247          WriteMacInt32(pb + ioDirID, fs_item->id);
1248  
1249 < #ifdef __BEOS__
1249 > #if defined(__BEOS__) || defined(WIN32)
1250          WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1251   #else
1252          WriteMacInt32(pb + ioFlCrDat, 0);
1253   #endif
1254          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1255  
1256 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1224 <        uint32 type, creator;   // pb may point to kernel space, but stack is switched
1225 <        get_finder_type(full_path, type, creator);
1226 <        WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1227 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1228 <        uint16 fflags;
1229 <        get_finder_flags(full_path, fflags);
1230 <        WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1256 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
1257  
1258          WriteMacInt16(pb + ioFlStBlk, 0);
1259          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1260 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1260 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1261          WriteMacInt16(pb + ioFlRStBlk, 0);
1262          uint32 rf_size = get_rfork_size(full_path);
1263          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1264 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1264 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1265  
1266          if (hfs) {
1267                  WriteMacInt32(pb + ioFlBkDat, 0);
1242                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1268                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1269                  WriteMacInt32(pb + ioFlClpSiz, 0);
1270          }
# Line 1264 | Line 1289 | static int16 fs_set_file_info(uint32 pb,
1289          if (S_ISDIR(st.st_mode))
1290                  return fnfErr;
1291  
1292 <        // Set attributes
1293 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1294 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1292 >        // Set Finder info
1293 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
1294 >
1295          //!! times
1296          return noErr;
1297   }
# Line 1277 | Line 1302 | static int16 fs_get_cat_info(uint32 pb)
1302          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)));
1303  
1304          FSItem *fs_item;
1305 <        int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex);
1305 >        int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1306          if (dir_index < 0) {                    // Query directory specified by ioDirID
1307  
1308                  // Find FSItem for directory
# Line 1318 | Line 1343 | read_next_de:
1343                                  return fnfErr;
1344                          }
1345                          if (de->d_name[0] == '.')
1346 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1346 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1347                  }
1348 <                add_path_component(de->d_name);
1348 >                add_path_comp(de->d_name);
1349  
1350                  // Get FSItem for queried item
1351                  fs_item = find_fsitem(de->d_name, p);
# Line 1343 | Line 1368 | read_next_de:
1368          WriteMacInt8(pb + ioACUser, 0);
1369          WriteMacInt32(pb + ioDirID, fs_item->id);
1370          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1371 < #ifdef __BEOS__
1371 > #if defined(__BEOS__) || defined(WIN32)
1372          WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1373   #else
1374          WriteMacInt32(pb + ioFlCrDat, 0);
# Line 1354 | Line 1379 | read_next_de:
1379                  fs_item->mtime = mtime;
1380                  cached = false;
1381          }
1382 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1382 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1383          WriteMacInt32(pb + ioFlBkDat, 0);
1384 +
1385 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
1386 +
1387          if (S_ISDIR(st.st_mode)) {
1360                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1361                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1362                uint16 fflags;  // pb may point to kernel space, but stack is switched
1363                get_finder_flags(full_path, fflags);
1364                WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
1388  
1389                  // Determine number of files in directory (cached)
1390                  int count;
# Line 1376 | Line 1399 | read_next_de:
1399                                          de = readdir(d);
1400                                          if (de == NULL)
1401                                                  break;
1402 +                                        if (de->d_name[0] == '.')
1403 +                                                continue;       // Suppress names beginning with '.'
1404                                          count++;
1405                                  }
1406                                  closedir(d);
# Line 1384 | Line 1409 | read_next_de:
1409                  }
1410                  WriteMacInt16(pb + ioDrNmFls, count);
1411          } else {
1387                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1388                memset(Mac2HostAddr(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);
1392                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1393                uint16 fflags;
1394                get_finder_flags(full_path, fflags);
1395                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1412                  WriteMacInt16(pb + ioFlStBlk, 0);
1413                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1414 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1414 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1415                  WriteMacInt16(pb + ioFlRStBlk, 0);
1416                  uint32 rf_size = get_rfork_size(full_path);
1417                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1418 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1418 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1419                  WriteMacInt32(pb + ioFlClpSiz, 0);
1420          }
1421          return noErr;
# Line 1421 | Line 1437 | static int16 fs_set_cat_info(uint32 pb)
1437          if (stat(full_path, &st) < 0)
1438                  return errno2oserr();
1439  
1440 <        // Set attributes
1441 <        if (S_ISDIR(st.st_mode))
1442 <                set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags));
1427 <        else {
1428 <                set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1429 <                set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1430 <        }
1440 >        // Set Finder info
1441 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
1442 >
1443          //!! times
1444          return noErr;
1445   }
# Line 1474 | Line 1486 | static int16 fs_open(uint32 pb, uint32 d
1486                  if (access(full_path, F_OK))
1487                          return fnfErr;
1488                  fd = open_rfork(full_path, flag);
1489 <                if (fd > 0) {
1490 <                        if (fstat(fd, &st) < 0)
1489 >                if (fd >= 0) {
1490 >                        if (fstat(fd, &st) < 0) {
1491 >                                close(fd);
1492                                  return errno2oserr();
1493 +                        }
1494                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1495                          st.st_size = 0;
1496                          st.st_mode = 0;
# Line 1485 | Line 1499 | static int16 fs_open(uint32 pb, uint32 d
1499                  fd = open(full_path, flag);
1500                  if (fd < 0)
1501                          return errno2oserr();
1502 <                if (fstat(fd, &st) < 0)
1502 >                if (fstat(fd, &st) < 0) {
1503 >                        close(fd);
1504                          return errno2oserr();
1505 +                }
1506          }
1507  
1508          // File open, allocate FCB
# Line 1498 | Line 1514 | static int16 fs_open(uint32 pb, uint32 d
1514          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1515          if (r.d[0] & 0xffff) {
1516                  close(fd);
1517 <                return r.d[0];
1517 >                return (int16)r.d[0];
1518          }
1519  
1520          // Initialize FCB, fd is stored in fcbCatPos
1521          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1522          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1523          WriteMacInt32(fcb + fcbEOF, st.st_size);
1524 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1524 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1525          WriteMacInt32(fcb + fcbCrPs, 0);
1526          WriteMacInt32(fcb + fcbVPtr, vcb);
1527 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1528 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1529 <        get_finder_type(full_path, type, creator);
1530 <        WriteMacInt32(fcb + fcbFType, type);
1527 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1528 >
1529 >        get_finfo(full_path, fs_data + fsPB, 0);
1530 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1531 >
1532          WriteMacInt32(fcb + fcbCatPos, fd);
1533          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1534          cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
# Line 1548 | Line 1565 | static int16 fs_close(uint32 pb)
1565          r.d[0] = ReadMacInt16(pb + ioRefNum);
1566          Execute68k(fs_data + fsReleaseFCB, &r);
1567          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1568 <        return r.d[0];
1568 >        return (int16)r.d[0];
1569   }
1570  
1571   // Query information about FCB (FCBPBRec)
# Line 1576 | Line 1593 | static int16 fs_get_fcb_info(uint32 pb,
1593                          fcb = ReadMacInt32(fs_data + fsReturn);
1594                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1595                          if (r.d[0] & 0xffff)
1596 <                                return r.d[0];
1596 >                                return (int16)r.d[0];
1597                  }
1598          }
1599          if (fcb == 0)
# Line 1624 | Line 1641 | static int16 fs_get_eof(uint32 pb)
1641  
1642          // Adjust FCBs
1643          WriteMacInt32(fcb + fcbEOF, st.st_size);
1644 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1644 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1645          WriteMacInt32(pb + ioMisc, st.st_size);
1646          D(bug("  adjusting FCBs\n"));
1647          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1659 | Line 1676 | static int16 fs_set_eof(uint32 pb)
1676  
1677          // Adjust FCBs
1678          WriteMacInt32(fcb + fcbEOF, size);
1679 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1679 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1680          D(bug("  adjusting FCBs\n"));
1681          r.d[0] = ReadMacInt16(pb + ioRefNum);
1682          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1744 | Line 1761 | static int16 fs_read(uint32 pb)
1761   {
1762          D(bug(" fs_read(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset)));
1763  
1764 +        // Check parameters
1765 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1766 +                return paramErr;
1767 +
1768          // Find FCB and fd for file
1769          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1770          if (fcb == 0)
# Line 1775 | Line 1796 | static int16 fs_read(uint32 pb)
1796          }
1797  
1798          // Read
1799 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1799 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1800 >        int16 read_err = errno2oserr();
1801          D(bug("  actual %d\n", actual));
1802 <        WriteMacInt32(pb + ioActCount, actual);
1802 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1803          uint32 pos = lseek(fd, 0, SEEK_CUR);
1804          WriteMacInt32(fcb + fcbCrPs, pos);
1805          WriteMacInt32(pb + ioPosOffset, pos);
1806          if (actual != ReadMacInt32(pb + ioReqCount))
1807 <                if (errno)
1786 <                        return errno2oserr();
1787 <                else
1788 <                        return eofErr;
1807 >                return actual < 0 ? read_err : eofErr;
1808          else
1809                  return noErr;
1810   }
# Line 1795 | Line 1814 | static int16 fs_write(uint32 pb)
1814   {
1815          D(bug(" fs_write(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset)));
1816  
1817 +        // Check parameters
1818 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1819 +                return paramErr;
1820 +
1821          // Find FCB and fd for file
1822          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1823          if (fcb == 0)
# Line 1826 | Line 1849 | static int16 fs_write(uint32 pb)
1849          }
1850  
1851          // Write
1852 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1852 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1853 >        int16 write_err = errno2oserr();
1854          D(bug("  actual %d\n", actual));
1855 <        WriteMacInt32(pb + ioActCount, actual);
1855 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1856          uint32 pos = lseek(fd, 0, SEEK_CUR);
1857          WriteMacInt32(fcb + fcbCrPs, pos);
1858          WriteMacInt32(pb + ioPosOffset, pos);
1859          if (actual != ReadMacInt32(pb + ioReqCount))
1860 <                return errno2oserr();
1860 >                return write_err;
1861          else
1862                  return noErr;
1863   }
# Line 1854 | Line 1878 | static int16 fs_create(uint32 pb, uint32
1878                  return dupFNErr;
1879  
1880          // Create file
1881 <        int fd = creat(full_path, 0664);
1881 >        int fd = creat(full_path, 0666);
1882          if (fd < 0)
1883                  return errno2oserr();
1884          else {
# Line 1879 | Line 1903 | static int16 fs_dir_create(uint32 pb)
1903                  return dupFNErr;
1904  
1905          // Create directory
1906 <        if (mkdir(full_path, 0775) < 0)
1906 >        if (mkdir(full_path, 0777) < 0)
1907                  return errno2oserr();
1908          else {
1909                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1899 | Line 1923 | static int16 fs_delete(uint32 pb, uint32
1923                  return result;
1924  
1925          // Delete file
1926 <        if (remove(full_path) < 0) {
1927 <                int16 err = errno2oserr();
1928 <                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
1926 >        if (!extfs_remove(full_path))
1927 >                return errno2oserr();
1928 >        else
1929                  return noErr;
1930   }
1931  
# Line 1928 | Line 1945 | static int16 fs_rename(uint32 pb, uint32
1945          strcpy(old_path, full_path);
1946  
1947          // Find path for new name
1948 <        uint8 new_pb[SIZEOF_IOParam];
1949 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1933 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1948 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1949 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1950          FSItem *new_item;
1951 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1951 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1952          if (result != noErr)
1953                  return result;
1954  
# Line 1942 | Line 1958 | static int16 fs_rename(uint32 pb, uint32
1958  
1959          // Rename item
1960          D(bug("  renaming %s -> %s\n", old_path, full_path));
1961 <        if (rename(old_path, full_path) < 0)
1961 >        if (!extfs_rename(old_path, full_path))
1962                  return errno2oserr();
1963          else {
1964                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1965 +                swap_parent_ids(fs_item->id, new_item->id);
1966                  uint32 t = fs_item->id;
1967                  fs_item->id = new_item->id;
1968                  new_item->id = t;
# Line 1969 | Line 1986 | static int16 fs_cat_move(uint32 pb)
1986          strcpy(old_path, full_path);
1987  
1988          // Find path for new directory
1989 <        uint8 new_pb[SIZEOF_IOParam];
1990 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1974 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1989 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1990 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1991          FSItem *new_dir_item;
1992 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1992 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1993          if (result != noErr)
1994                  return result;
1995  
1996          // Append old file/dir name
1997 <        add_path_component(fs_item->name);
1997 >        add_path_comp(fs_item->name);
1998  
1999          // Does the new name already exist?
2000          if (access(full_path, F_OK) == 0)
# Line 1986 | Line 2002 | static int16 fs_cat_move(uint32 pb)
2002  
2003          // Move item
2004          D(bug("  moving %s -> %s\n", old_path, full_path));
2005 <        if (rename(old_path, full_path) < 0)
2005 >        if (!extfs_rename(old_path, full_path))
2006                  return errno2oserr();
2007          else {
2008                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2009                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2010                  if (new_item) {
2011 +                        swap_parent_ids(fs_item->id, new_item->id);
2012                          uint32 t = fs_item->id;
2013                          fs_item->id = new_item->id;
2014                          new_item->id = t;
# Line 2010 | Line 2027 | static int16 fs_open_wd(uint32 pb)
2027          D(bug("  allocating WDCB\n"));
2028          r.a[0] = pb;
2029          Execute68k(fs_data + fsAllocateWDCB, &r);
2030 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2031 <        return r.d[0];
2030 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2031 >        return (int16)r.d[0];
2032   }
2033  
2034   // Close working directory (WDParam)
# Line 2025 | Line 2042 | static int16 fs_close_wd(uint32 pb)
2042          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2043          Execute68k(fs_data + fsReleaseWDCB, &r);
2044          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2045 <        return r.d[0];
2045 >        return (int16)r.d[0];
2046   }
2047  
2048   // Query information about working directory (WDParam)
# Line 2039 | Line 2056 | static int16 fs_get_wd_info(uint32 pb, u
2056                  WriteMacInt32(pb + ioWDProcID, 0);
2057                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2058                  if (ReadMacInt32(pb + ioNamePtr))
2059 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2059 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2060                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2061                  return noErr;
2062          }
# Line 2054 | Line 2071 | static int16 fs_get_wd_info(uint32 pb, u
2071          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2072          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2073          if (r.d[0] & 0xffff)
2074 <                return r.d[0];
2074 >                return (int16)r.d[0];
2075  
2076          // Return information
2077 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2077 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2078          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2079          if (ReadMacInt32(pb + ioNamePtr))
2080 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2080 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2081          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2082          return noErr;
2083   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines