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.12 by cebix, 1999-11-08T17:00:04Z vs.
Revision 1.21 by cebix, 2000-07-22T16:07:16Z

# 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 and renaming)
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
# Line 101 | Line 108 | static bool ready = false;
108   static struct stat root_stat;
109  
110   // File system ID/media type
111 < const int16 MY_FSID = 'ba';
112 < const uint32 MY_MEDIA_TYPE = 'basi';
111 > const int16 MY_FSID = 0x6261;   // 'ba'
112 > const uint32 MY_MEDIA_TYPE = FOURCC('b','a','s','i');
113  
114   // CNID of root and root's parent
115   const uint32 ROOT_ID = 2;
# 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 223 | Line 235 | static void get_path_for_fsitem(FSItem *
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 +
253 +
254 + /*
255   *  String handling functions
256   */
257  
# Line 240 | 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;
277          }
278   }
279  
249 // Convert pascal string to C string
250 static void pstr2cstr(char *dst, const char *src)
251 {
252        int size = *src++;
253        while (size--) {
254                char c = *src++;
255                if (c == '/')
256                        c = ':';
257                *dst++ = c;
258        }
259        *dst = 0;
260 }
261
280   // Convert string (no length byte) to C string, length given separately
281   static void strn2cstr(char *dst, const char *src, int size)
282   {
283          while (size--) {
284                  char c = *src++;
285 +                // Note: we are converting Mac '/' characters to host ':' characters here
286 +                // '/' is not a path separator as this function is only used on object names
287                  if (c == '/')
288                          c = ':';
289                  *dst++ = c;
# Line 339 | Line 359 | void ExtFSInit(void)
359          p->parent_id = ROOT_PARENT_ID;
360          p->parent = first_fs_item;
361          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
362 +        p->name[31] = 0;
363  
364          // Find path for root
365          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 387 | Line 408 | void InstallExtFS(void)
408          // FSM present?
409          r.d[0] = gestaltFSAttr;
410          Execute68kTrap(0xa1ad, &r);     // Gestalt()
411 <        D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
411 >        D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0]));
412          if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
413                  printf("WARNING: No FSM present, disabling ExtFS\n");
414                  return;
# Line 396 | Line 417 | void InstallExtFS(void)
417          // Yes, version >=1.2?
418          r.d[0] = gestaltFSMVersion;
419          Execute68kTrap(0xa1ad, &r);     // Gestalt()
420 <        D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
420 >        D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0]));
421          if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
422                  printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
423                  return;
# Line 666 | Line 687 | int16 ExtFSComm(uint16 message, uint32 p
687                  }
688  
689                  case ffsIDDiskMessage: {                // Check if volume is handled by our FS
690 <                        if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
690 >                        if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
691                                  return noErr;
692                          else
693                                  return extFSErr;
# Line 714 | Line 735 | static int16 get_current_dir(uint32 pb,
735          int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
736          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
737          D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
738 <        result = r.d[0] & 0xffff;
738 >        result = (int16)(r.d[0] & 0xffff);
739  
740          if (result == noErr) {
741                  switch (status) {
# Line 739 | Line 760 | static int16 get_current_dir(uint32 pb,
760                                          Execute68k(fs_data + fsResolveWDCB, &r);
761                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
762                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
763 <                                        result = r.d[0] & 0xffff;
763 >                                        result = (int16)(r.d[0] & 0xffff);
764                                          if (result == noErr)
765                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
766                                  }
# Line 755 | Line 776 | static int16 get_current_dir(uint32 pb,
776                                          r.a[0] = wdpb;
777                                          Execute68k(fs_data + fsGetDefaultVol, &r);
778                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
779 <                                        result = r.d[0] & 0xffff;
779 >                                        result = (int16)(r.d[0] & 0xffff);
780                                          if (result == noErr)
781                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
782                                  }
# Line 781 | Line 802 | static int16 get_path_component_name(uin
802          r.a[0] = rec;
803          Execute68k(fs_data + fsGetPathComponentName, &r);
804   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
805 <        return r.d[0] & 0xffff;
805 >        return (int16)(r.d[0] & 0xffff);
806   }
807  
808  
# Line 817 | Line 838 | static int16 get_item_and_path(uint32 pb
838          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
839          Execute68k(fs_data + fsParsePathname, &r);
840          D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
841 <        result = r.d[0] & 0xffff;
841 >        result = (int16)(r.d[0] & 0xffff);
842          if (result == noErr) {
843  
844                  // Check for leading delimiter of the partial pathname
# Line 930 | Line 951 | static uint32 find_fcb(int16 refNum)
951   static int16 fs_mount_vol(uint32 pb)
952   {
953          D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum)));
954 <        if (ReadMacInt16(pb + ioVRefNum) == drive_number)
954 >        if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number)
955                  return noErr;
956          else
957                  return extFSErr;
# Line 951 | Line 972 | static int16 fs_volume_mount(uint32 pb)
972          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
973          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
974          if (r.d[0] & 0xffff)
975 <                return r.d[0];
975 >                return (int16)r.d[0];
976  
977          // Init VCB
978          WriteMacInt16(vcb + vcbSigWord, 0x4244);
979 < #ifdef __BEOS__
979 > #if defined(__BEOS__) || defined(WIN32)
980          WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
981   #else
982          WriteMacInt32(vcb + vcbCrDate, 0);
# Line 965 | Line 986 | static int16 fs_volume_mount(uint32 pb)
986          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
987          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
988          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
989 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
990 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
989 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
990 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
991          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
992          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
993          Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
# Line 980 | Line 1001 | static int16 fs_volume_mount(uint32 pb)
1001          r.a[0] = fs_data + fsReturn;
1002          r.a[1] = vcb;
1003          Execute68k(fs_data + fsAddNewVCB, &r);
1004 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1004 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1005          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1006          if (r.d[0] & 0xffff)
1007 <                return r.d[0];
1007 >                return (int16)r.d[0];
1008  
1009          // Post diskInsertEvent
1010          D(bug("  posting diskInsertEvent\n"));
# Line 1007 | Line 1028 | static int16 fs_unmount_vol(uint32 vcb)
1028          r.a[0] = vcb;
1029          Execute68k(fs_data + fsDisposeVCB, &r);
1030          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1031 <        return r.d[0];
1031 >        return (int16)r.d[0];
1032   }
1033  
1034   // Get information about a volume (HVolumeParam)
# Line 1018 | Line 1039 | static int16 fs_get_vol_info(uint32 pb,
1039          // Fill in struct
1040          if (ReadMacInt32(pb + ioNamePtr))
1041                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1042 < #ifdef __BEOS__
1042 > #if defined(__BEOS__) || defined(WIN32)
1043          WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1044   #else
1045          WriteMacInt32(pb + ioVCrDate, 0);
# Line 1029 | Line 1050 | static int16 fs_get_vol_info(uint32 pb,
1050          WriteMacInt16(pb + ioVBitMap, 0);
1051          WriteMacInt16(pb + ioAllocPtr, 0);
1052          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1053 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1054 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1053 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1054 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1055          WriteMacInt16(pb + ioAlBlSt, 0);
1056          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1057          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1063 | Line 1084 | static int16 fs_get_vol_parms(uint32 pb)
1084   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1085  
1086          // Return parameter block
1066        uint8 vol[SIZEOF_GetVolParmsInfoBuffer];
1067        WriteMacInt16((uint32)vol + vMVersion, 2);
1068        WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1069        WriteMacInt32((uint32)vol + vMLocalHand, 0);
1070        WriteMacInt32((uint32)vol + vMServerAdr, 0);
1071        WriteMacInt32((uint32)vol + vMVolumeGrade, 0);
1072        WriteMacInt16((uint32)vol + vMForeignPrivID, 0);
1087          uint32 actual = ReadMacInt32(pb + ioReqCount);
1088 <        if (actual > sizeof(vol))
1089 <                actual = sizeof(vol);
1076 <        Host2Mac_memcpy(ReadMacInt32(pb + ioBuffer), vol, actual);
1088 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1089 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1090          WriteMacInt32(pb + ioActCount, actual);
1091 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1092 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1093 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1094 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1095 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1096 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1097 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1098          return noErr;
1099   }
1100  
# Line 1089 | Line 1109 | static int16 fs_get_vol(uint32 pb)
1109          r.a[0] = pb;
1110          Execute68k(fs_data + fsGetDefaultVol, &r);
1111          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1112 <        return r.d[0];
1112 >        return (int16)r.d[0];
1113   }
1114  
1115   // Set default volume (WDParam)
# Line 1145 | Line 1165 | static int16 fs_set_vol(uint32 pb, bool
1165          r.d[2] = refNum;
1166          Execute68k(fs_data + fsSetDefaultVol, &r);
1167          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1168 <        return r.d[0];
1168 >        return (int16)r.d[0];
1169   }
1170  
1171   // Query file attributes (HFileParam)
# Line 1211 | Line 1231 | read_next_de:
1231          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1232          WriteMacInt32(pb + ioDirID, fs_item->id);
1233  
1234 < #ifdef __BEOS__
1234 > #if defined(__BEOS__) || defined(WIN32)
1235          WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1236   #else
1237          WriteMacInt32(pb + ioFlCrDat, 0);
1238   #endif
1239          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1240  
1241 <        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);
1225 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1226 <        uint16 fflags;
1227 <        get_finder_flags(full_path, fflags);
1228 <        WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1241 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
1242  
1243          WriteMacInt16(pb + ioFlStBlk, 0);
1244          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1245 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1245 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1246          WriteMacInt16(pb + ioFlRStBlk, 0);
1247          uint32 rf_size = get_rfork_size(full_path);
1248          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1249 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1249 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1250  
1251          if (hfs) {
1252                  WriteMacInt32(pb + ioFlBkDat, 0);
1240                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1253                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1254                  WriteMacInt32(pb + ioFlClpSiz, 0);
1255          }
# Line 1262 | Line 1274 | static int16 fs_set_file_info(uint32 pb,
1274          if (S_ISDIR(st.st_mode))
1275                  return fnfErr;
1276  
1277 <        // Set attributes
1278 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1279 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1277 >        // Set Finder info
1278 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0);
1279 >
1280          //!! times
1281          return noErr;
1282   }
# Line 1341 | Line 1353 | read_next_de:
1353          WriteMacInt8(pb + ioACUser, 0);
1354          WriteMacInt32(pb + ioDirID, fs_item->id);
1355          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1356 < #ifdef __BEOS__
1356 > #if defined(__BEOS__) || defined(WIN32)
1357          WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1358   #else
1359          WriteMacInt32(pb + ioFlCrDat, 0);
# Line 1354 | Line 1366 | read_next_de:
1366          }
1367          WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1368          WriteMacInt32(pb + ioFlBkDat, 0);
1369 +
1370 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
1371 +
1372          if (S_ISDIR(st.st_mode)) {
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);
1373  
1374                  // Determine number of files in directory (cached)
1375                  int count;
# Line 1384 | Line 1394 | read_next_de:
1394                  }
1395                  WriteMacInt16(pb + ioDrNmFls, count);
1396          } else {
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);
1392                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1393                uint16 fflags;
1394                get_finder_flags(full_path, fflags);
1395                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1397                  WriteMacInt16(pb + ioFlStBlk, 0);
1398                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1399 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1399 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1400                  WriteMacInt16(pb + ioFlRStBlk, 0);
1401                  uint32 rf_size = get_rfork_size(full_path);
1402                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1403 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1403 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1404                  WriteMacInt32(pb + ioFlClpSiz, 0);
1405          }
1406          return noErr;
# Line 1421 | Line 1422 | static int16 fs_set_cat_info(uint32 pb)
1422          if (stat(full_path, &st) < 0)
1423                  return errno2oserr();
1424  
1425 <        // Set attributes
1426 <        if (S_ISDIR(st.st_mode))
1427 <                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 <        }
1425 >        // Set Finder info
1426 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo);
1427 >
1428          //!! times
1429          return noErr;
1430   }
# Line 1474 | Line 1471 | static int16 fs_open(uint32 pb, uint32 d
1471                  if (access(full_path, F_OK))
1472                          return fnfErr;
1473                  fd = open_rfork(full_path, flag);
1474 <                if (fd > 0) {
1475 <                        if (fstat(fd, &st) < 0)
1474 >                if (fd >= 0) {
1475 >                        if (fstat(fd, &st) < 0) {
1476 >                                close(fd);
1477                                  return errno2oserr();
1478 +                        }
1479                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1480                          st.st_size = 0;
1481                          st.st_mode = 0;
# Line 1485 | Line 1484 | static int16 fs_open(uint32 pb, uint32 d
1484                  fd = open(full_path, flag);
1485                  if (fd < 0)
1486                          return errno2oserr();
1487 <                if (fstat(fd, &st) < 0)
1487 >                if (fstat(fd, &st) < 0) {
1488 >                        close(fd);
1489                          return errno2oserr();
1490 +                }
1491          }
1492  
1493          // File open, allocate FCB
# Line 1498 | Line 1499 | static int16 fs_open(uint32 pb, uint32 d
1499          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1500          if (r.d[0] & 0xffff) {
1501                  close(fd);
1502 <                return r.d[0];
1502 >                return (int16)r.d[0];
1503          }
1504  
1505          // Initialize FCB, fd is stored in fcbCatPos
1506          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1507          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1508          WriteMacInt32(fcb + fcbEOF, st.st_size);
1509 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1509 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1510          WriteMacInt32(fcb + fcbCrPs, 0);
1511          WriteMacInt32(fcb + fcbVPtr, vcb);
1512 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1513 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1514 <        get_finder_type(full_path, type, creator);
1515 <        WriteMacInt32(fcb + fcbFType, type);
1512 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1513 >
1514 >        get_finfo(full_path, fs_data + fsPB, 0);
1515 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1516 >
1517          WriteMacInt32(fcb + fcbCatPos, fd);
1518          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1519          cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
# Line 1548 | Line 1550 | static int16 fs_close(uint32 pb)
1550          r.d[0] = ReadMacInt16(pb + ioRefNum);
1551          Execute68k(fs_data + fsReleaseFCB, &r);
1552          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1553 <        return r.d[0];
1553 >        return (int16)r.d[0];
1554   }
1555  
1556   // Query information about FCB (FCBPBRec)
# Line 1567 | Line 1569 | static int16 fs_get_fcb_info(uint32 pb,
1569  
1570                  // Find FCB by index
1571                  WriteMacInt16(pb + ioRefNum, 0);
1572 <                for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) {
1572 >                for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) {
1573                          D(bug("  indexing FCBs\n"));
1574                          r.a[0] = vcb;
1575                          r.a[1] = pb + ioRefNum;
# Line 1576 | Line 1578 | static int16 fs_get_fcb_info(uint32 pb,
1578                          fcb = ReadMacInt32(fs_data + fsReturn);
1579                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1580                          if (r.d[0] & 0xffff)
1581 <                                return r.d[0];
1581 >                                return (int16)r.d[0];
1582                  }
1583          }
1584          if (fcb == 0)
# Line 1624 | Line 1626 | static int16 fs_get_eof(uint32 pb)
1626  
1627          // Adjust FCBs
1628          WriteMacInt32(fcb + fcbEOF, st.st_size);
1629 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1629 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1630          WriteMacInt32(pb + ioMisc, st.st_size);
1631          D(bug("  adjusting FCBs\n"));
1632          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1659 | Line 1661 | static int16 fs_set_eof(uint32 pb)
1661  
1662          // Adjust FCBs
1663          WriteMacInt32(fcb + fcbEOF, size);
1664 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1664 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1665          D(bug("  adjusting FCBs\n"));
1666          r.d[0] = ReadMacInt16(pb + ioRefNum);
1667          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1744 | Line 1746 | static int16 fs_read(uint32 pb)
1746   {
1747          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)));
1748  
1749 +        // Check parameters
1750 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1751 +                return paramErr;
1752 +
1753          // Find FCB and fd for file
1754          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1755          if (fcb == 0)
# Line 1775 | Line 1781 | static int16 fs_read(uint32 pb)
1781          }
1782  
1783          // Read
1784 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1784 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1785          int16 read_err = errno2oserr();
1786          D(bug("  actual %d\n", actual));
1787 <        WriteMacInt32(pb + ioActCount, actual);
1787 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1788          uint32 pos = lseek(fd, 0, SEEK_CUR);
1789          WriteMacInt32(fcb + fcbCrPs, pos);
1790          WriteMacInt32(pb + ioPosOffset, pos);
1791 <        if (actual != ReadMacInt32(pb + ioReqCount))
1792 <                return read_err ? read_err : eofErr;
1791 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1792 >                return actual < 0 ? read_err : eofErr;
1793          else
1794                  return noErr;
1795   }
# Line 1793 | Line 1799 | static int16 fs_write(uint32 pb)
1799   {
1800          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)));
1801  
1802 +        // Check parameters
1803 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1804 +                return paramErr;
1805 +
1806          // Find FCB and fd for file
1807          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1808          if (fcb == 0)
# Line 1824 | Line 1834 | static int16 fs_write(uint32 pb)
1834          }
1835  
1836          // Write
1837 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1837 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1838          int16 write_err = errno2oserr();
1839          D(bug("  actual %d\n", actual));
1840 <        WriteMacInt32(pb + ioActCount, actual);
1840 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1841          uint32 pos = lseek(fd, 0, SEEK_CUR);
1842          WriteMacInt32(fcb + fcbCrPs, pos);
1843          WriteMacInt32(pb + ioPosOffset, pos);
1844 <        if (actual != ReadMacInt32(pb + ioReqCount))
1844 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1845                  return write_err;
1846          else
1847                  return noErr;
# Line 1933 | Line 1943 | static int16 fs_rename(uint32 pb, uint32
1943  
1944          // Rename item
1945          D(bug("  renaming %s -> %s\n", old_path, full_path));
1946 <        if (rename(old_path, full_path) < 0)
1946 >        if (!extfs_rename(old_path, full_path))
1947                  return errno2oserr();
1948          else {
1949                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1950 +                swap_parent_ids(fs_item->id, new_item->id);
1951                  uint32 t = fs_item->id;
1952                  fs_item->id = new_item->id;
1953                  new_item->id = t;
# Line 1976 | Line 1987 | static int16 fs_cat_move(uint32 pb)
1987  
1988          // Move item
1989          D(bug("  moving %s -> %s\n", old_path, full_path));
1990 <        if (rename(old_path, full_path) < 0)
1990 >        if (!extfs_rename(old_path, full_path))
1991                  return errno2oserr();
1992          else {
1993                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1994                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
1995                  if (new_item) {
1996 +                        swap_parent_ids(fs_item->id, new_item->id);
1997                          uint32 t = fs_item->id;
1998                          fs_item->id = new_item->id;
1999                          new_item->id = t;
# Line 2001 | Line 2013 | static int16 fs_open_wd(uint32 pb)
2013          r.a[0] = pb;
2014          Execute68k(fs_data + fsAllocateWDCB, &r);
2015          D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2016 <        return r.d[0];
2016 >        return (int16)r.d[0];
2017   }
2018  
2019   // Close working directory (WDParam)
# Line 2015 | Line 2027 | static int16 fs_close_wd(uint32 pb)
2027          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2028          Execute68k(fs_data + fsReleaseWDCB, &r);
2029          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2030 <        return r.d[0];
2030 >        return (int16)r.d[0];
2031   }
2032  
2033   // Query information about working directory (WDParam)
# Line 2044 | Line 2056 | static int16 fs_get_wd_info(uint32 pb, u
2056          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2057          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2058          if (r.d[0] & 0xffff)
2059 <                return r.d[0];
2059 >                return (int16)r.d[0];
2060  
2061          // Return information
2062          WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines