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.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 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 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;
# Line 252 | 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 264 | 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 339 | 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 714 | 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 739 | Line 775 | static int16 get_current_dir(uint32 pb,
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 755 | 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 781 | 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 817 | 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 951 | 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 965 | 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          Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
# Line 980 | 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 1007 | 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 1018 | 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 1029 | 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 1063 | 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
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);
1102          uint32 actual = ReadMacInt32(pb + ioReqCount);
1103 <        if (actual > sizeof(vol))
1104 <                actual = sizeof(vol);
1076 <        Host2Mac_memcpy(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 1089 | 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 1145 | 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 1211 | 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 <        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);
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);
1240                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1268                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1269                  WriteMacInt32(pb + ioFlClpSiz, 0);
1270          }
# Line 1262 | 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 1341 | 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 1381 | read_next_de:
1381          }
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)) {
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);
1388  
1389                  // Determine number of files in directory (cached)
1390                  int count;
# Line 1384 | Line 1409 | read_next_de:
1409                  }
1410                  WriteMacInt16(pb + ioDrNmFls, count);
1411          } 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);
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 <                return read_err ? read_err : eofErr;
1807 >                return actual < 0 ? read_err : eofErr;
1808          else
1809                  return noErr;
1810   }
# Line 1793 | 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 1824 | 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);
# Line 1933 | 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 1976 | 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 2001 | Line 2028 | static int16 fs_open_wd(uint32 pb)
2028          r.a[0] = pb;
2029          Execute68k(fs_data + fsAllocateWDCB, &r);
2030          D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2031 <        return r.d[0];
2031 >        return (int16)r.d[0];
2032   }
2033  
2034   // Close working directory (WDParam)
# Line 2015 | 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 2044 | 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          WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines