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.9 by cebix, 1999-11-03T10:56:14Z vs.
Revision 1.18 by cebix, 2000-07-14T21:29:08Z

# 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 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 ALBLK_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, CLUMPSIZE);
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 1187 | 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_comp(de->d_name);
# 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);
# Line 1229 | Line 1264 | read_next_de:
1264  
1265          WriteMacInt16(pb + ioFlStBlk, 0);
1266          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1267 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1267 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1268          WriteMacInt16(pb + ioFlRStBlk, 0);
1269          uint32 rf_size = get_rfork_size(full_path);
1270          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1271 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1271 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1272  
1273          if (hfs) {
1274                  WriteMacInt32(pb + ioFlBkDat, 0);
# Line 1316 | Line 1351 | read_next_de:
1351                                  return fnfErr;
1352                          }
1353                          if (de->d_name[0] == '.')
1354 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1354 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1355                  }
1356                  add_path_comp(de->d_name);
1357  
# Line 1341 | Line 1376 | read_next_de:
1376          WriteMacInt8(pb + ioACUser, 0);
1377          WriteMacInt32(pb + ioDirID, fs_item->id);
1378          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1379 < #ifdef __BEOS__
1379 > #if defined(__BEOS__) || defined(WIN32)
1380          WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1381   #else
1382          WriteMacInt32(pb + ioFlCrDat, 0);
# Line 1352 | Line 1387 | read_next_de:
1387                  fs_item->mtime = mtime;
1388                  cached = false;
1389          }
1390 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1390 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1391          WriteMacInt32(pb + ioFlBkDat, 0);
1392          if (S_ISDIR(st.st_mode)) {
1393                  Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
# Line 1374 | Line 1409 | read_next_de:
1409                                          de = readdir(d);
1410                                          if (de == NULL)
1411                                                  break;
1412 +                                        if (de->d_name[0] == '.')
1413 +                                                continue;       // Suppress names beginning with '.'
1414                                          count++;
1415                                  }
1416                                  closedir(d);
# Line 1393 | Line 1430 | read_next_de:
1430                  WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1431                  WriteMacInt16(pb + ioFlStBlk, 0);
1432                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1433 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1433 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1434                  WriteMacInt16(pb + ioFlRStBlk, 0);
1435                  uint32 rf_size = get_rfork_size(full_path);
1436                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1437 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1437 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1438                  WriteMacInt32(pb + ioFlClpSiz, 0);
1439          }
1440          return noErr;
# Line 1420 | Line 1457 | static int16 fs_set_cat_info(uint32 pb)
1457                  return errno2oserr();
1458  
1459          // Set attributes
1460 <        if (S_ISDIR(st.st_mode))
1460 >        if (S_ISDIR(st.st_mode)) {
1461                  set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags));
1462 <        else {
1462 >        } else {
1463                  set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1464                  set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1465          }
# Line 1472 | Line 1509 | static int16 fs_open(uint32 pb, uint32 d
1509                  if (access(full_path, F_OK))
1510                          return fnfErr;
1511                  fd = open_rfork(full_path, flag);
1512 <                if (fd > 0) {
1513 <                        if (fstat(fd, &st) < 0)
1512 >                if (fd >= 0) {
1513 >                        if (fstat(fd, &st) < 0) {
1514 >                                close(fd);
1515                                  return errno2oserr();
1516 +                        }
1517                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1518                          st.st_size = 0;
1519                          st.st_mode = 0;
# Line 1483 | Line 1522 | static int16 fs_open(uint32 pb, uint32 d
1522                  fd = open(full_path, flag);
1523                  if (fd < 0)
1524                          return errno2oserr();
1525 <                if (fstat(fd, &st) < 0)
1525 >                if (fstat(fd, &st) < 0) {
1526 >                        close(fd);
1527                          return errno2oserr();
1528 +                }
1529          }
1530  
1531          // File open, allocate FCB
# Line 1496 | Line 1537 | static int16 fs_open(uint32 pb, uint32 d
1537          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1538          if (r.d[0] & 0xffff) {
1539                  close(fd);
1540 <                return r.d[0];
1540 >                return (int16)r.d[0];
1541          }
1542  
1543          // Initialize FCB, fd is stored in fcbCatPos
1544          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1545          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1546          WriteMacInt32(fcb + fcbEOF, st.st_size);
1547 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1547 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1548          WriteMacInt32(fcb + fcbCrPs, 0);
1549          WriteMacInt32(fcb + fcbVPtr, vcb);
1550 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1551 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1550 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1551 >        uint32 type, creator;   // BeOS: fcb may point to kernel space, but stack is switched
1552          get_finder_type(full_path, type, creator);
1553          WriteMacInt32(fcb + fcbFType, type);
1554          WriteMacInt32(fcb + fcbCatPos, fd);
# Line 1546 | Line 1587 | static int16 fs_close(uint32 pb)
1587          r.d[0] = ReadMacInt16(pb + ioRefNum);
1588          Execute68k(fs_data + fsReleaseFCB, &r);
1589          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1590 <        return r.d[0];
1590 >        return (int16)r.d[0];
1591   }
1592  
1593   // Query information about FCB (FCBPBRec)
# Line 1574 | Line 1615 | static int16 fs_get_fcb_info(uint32 pb,
1615                          fcb = ReadMacInt32(fs_data + fsReturn);
1616                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1617                          if (r.d[0] & 0xffff)
1618 <                                return r.d[0];
1618 >                                return (int16)r.d[0];
1619                  }
1620          }
1621          if (fcb == 0)
# Line 1622 | Line 1663 | static int16 fs_get_eof(uint32 pb)
1663  
1664          // Adjust FCBs
1665          WriteMacInt32(fcb + fcbEOF, st.st_size);
1666 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1666 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1667          WriteMacInt32(pb + ioMisc, st.st_size);
1668          D(bug("  adjusting FCBs\n"));
1669          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1657 | Line 1698 | static int16 fs_set_eof(uint32 pb)
1698  
1699          // Adjust FCBs
1700          WriteMacInt32(fcb + fcbEOF, size);
1701 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1701 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1702          D(bug("  adjusting FCBs\n"));
1703          r.d[0] = ReadMacInt16(pb + ioRefNum);
1704          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1742 | Line 1783 | static int16 fs_read(uint32 pb)
1783   {
1784          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)));
1785  
1786 +        // Check parameters
1787 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1788 +                return paramErr;
1789 +
1790          // Find FCB and fd for file
1791          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1792          if (fcb == 0)
# Line 1773 | Line 1818 | static int16 fs_read(uint32 pb)
1818          }
1819  
1820          // Read
1821 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1821 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1822 >        int16 read_err = errno2oserr();
1823          D(bug("  actual %d\n", actual));
1824 <        WriteMacInt32(pb + ioActCount, actual);
1824 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1825          uint32 pos = lseek(fd, 0, SEEK_CUR);
1826          WriteMacInt32(fcb + fcbCrPs, pos);
1827          WriteMacInt32(pb + ioPosOffset, pos);
1828          if (actual != ReadMacInt32(pb + ioReqCount))
1829 <                if (errno)
1784 <                        return errno2oserr();
1785 <                else
1786 <                        return eofErr;
1829 >                return actual < 0 ? read_err : eofErr;
1830          else
1831                  return noErr;
1832   }
# Line 1793 | Line 1836 | static int16 fs_write(uint32 pb)
1836   {
1837          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)));
1838  
1839 +        // Check parameters
1840 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1841 +                return paramErr;
1842 +
1843          // Find FCB and fd for file
1844          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1845          if (fcb == 0)
# Line 1824 | Line 1871 | static int16 fs_write(uint32 pb)
1871          }
1872  
1873          // Write
1874 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1874 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1875 >        int16 write_err = errno2oserr();
1876          D(bug("  actual %d\n", actual));
1877 <        WriteMacInt32(pb + ioActCount, actual);
1877 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1878          uint32 pos = lseek(fd, 0, SEEK_CUR);
1879          WriteMacInt32(fcb + fcbCrPs, pos);
1880          WriteMacInt32(pb + ioPosOffset, pos);
1881          if (actual != ReadMacInt32(pb + ioReqCount))
1882 <                return errno2oserr();
1882 >                return write_err;
1883          else
1884                  return noErr;
1885   }
# Line 1897 | Line 1945 | static int16 fs_delete(uint32 pb, uint32
1945                  return result;
1946  
1947          // Delete file
1948 <        if (remove(full_path) < 0) {
1949 <                int16 err = errno2oserr();
1950 <                if (errno == EISDIR) {  // Workaround for BeOS bug
1903 <                        if (rmdir(full_path) < 0)
1904 <                                return errno2oserr();
1905 <                        else
1906 <                                return noErr;
1907 <                } else
1908 <                        return err;
1909 <        } else
1948 >        if (!extfs_remove(full_path))
1949 >                return errno2oserr();
1950 >        else
1951                  return noErr;
1952   }
1953  
# Line 1939 | Line 1980 | static int16 fs_rename(uint32 pb, uint32
1980  
1981          // Rename item
1982          D(bug("  renaming %s -> %s\n", old_path, full_path));
1983 <        if (rename(old_path, full_path) < 0)
1983 >        if (!extfs_rename(old_path, full_path))
1984                  return errno2oserr();
1985          else {
1986                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1987 +                swap_parent_ids(fs_item->id, new_item->id);
1988                  uint32 t = fs_item->id;
1989                  fs_item->id = new_item->id;
1990                  new_item->id = t;
# Line 1966 | Line 2008 | static int16 fs_cat_move(uint32 pb)
2008          strcpy(old_path, full_path);
2009  
2010          // Find path for new directory
2011 <        Mac2Host_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2011 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2012          WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
2013          FSItem *new_dir_item;
2014          result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
# Line 1982 | Line 2024 | static int16 fs_cat_move(uint32 pb)
2024  
2025          // Move item
2026          D(bug("  moving %s -> %s\n", old_path, full_path));
2027 <        if (rename(old_path, full_path) < 0)
2027 >        if (!extfs_rename(old_path, full_path))
2028                  return errno2oserr();
2029          else {
2030                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2031                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2032                  if (new_item) {
2033 +                        swap_parent_ids(fs_item->id, new_item->id);
2034                          uint32 t = fs_item->id;
2035                          fs_item->id = new_item->id;
2036                          new_item->id = t;
# Line 2007 | Line 2050 | static int16 fs_open_wd(uint32 pb)
2050          r.a[0] = pb;
2051          Execute68k(fs_data + fsAllocateWDCB, &r);
2052          D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2053 <        return r.d[0];
2053 >        return (int16)r.d[0];
2054   }
2055  
2056   // Close working directory (WDParam)
# Line 2021 | Line 2064 | static int16 fs_close_wd(uint32 pb)
2064          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2065          Execute68k(fs_data + fsReleaseWDCB, &r);
2066          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2067 <        return r.d[0];
2067 >        return (int16)r.d[0];
2068   }
2069  
2070   // Query information about working directory (WDParam)
# Line 2050 | Line 2093 | static int16 fs_get_wd_info(uint32 pb, u
2093          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2094          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2095          if (r.d[0] & 0xffff)
2096 <                return r.d[0];
2096 >                return (int16)r.d[0];
2097  
2098          // Return information
2099 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2099 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2100          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2101          if (ReadMacInt32(pb + ioNamePtr))
2102                  Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines