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.15 by cebix, 1999-12-22T16:16:09Z vs.
Revision 1.28 by cebix, 2002-01-15T14:58:32Z

# 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-2002 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"
49 #include "macos_util.h"
52   #include "emul_op.h"
53   #include "main.h"
54   #include "disk.h"
# Line 55 | Line 57
57   #include "extfs.h"
58   #include "extfs_defs.h"
59  
60 + #ifdef WIN32
61 + # include "posix_emu.h"
62 + #endif
63 +
64   #define DEBUG 0
65   #include "debug.h"
66  
# Line 65 | Line 71 | enum {
71          fsHFSProcStub = 6,
72          fsDrvStatus = 12,                               // Drive Status record
73          fsFSD = 42,                                             // File system descriptor
74 <        fsPB = 238,                                             // IOParam (for mounting and renaming)
74 >        fsPB = 238,                                             // IOParam (for mounting and renaming), also used for temporary storage
75          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
76          fsParseRec = 296,                               // ParsePathRec struct
77          fsReturn = 306,                                 // Area for return data of 68k routines
# Line 101 | Line 107 | static bool ready = false;
107   static struct stat root_stat;
108  
109   // File system ID/media type
110 < const int16 MY_FSID = 'ba';
111 < const uint32 MY_MEDIA_TYPE = 'basi';
110 > const int16 MY_FSID = EMULATOR_ID_2;
111 > const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4;
112  
113   // CNID of root and root's parent
114   const uint32 ROOT_ID = 2;
# Line 111 | Line 117 | const uint32 ROOT_PARENT_ID = 1;
117   // File system stack size
118   const int STACK_SIZE = 0x10000;
119  
120 + // Allocation block and clump size as reported to MacOS (these are of course
121 + // not the real values and have no meaning on the host OS)
122 + const int AL_BLK_SIZE = 0x4000;
123 + const int CLUMP_SIZE = 0x4000;
124 +
125   // Drive number of our pseudo-drive
126   static int drive_number;
127  
# Line 257 | Line 268 | static void cstr2pstr(char *dst, const c
268          *dst++ = strlen(src);
269          char c;
270          while ((c = *src++) != 0) {
271 +                // Note: we are converting host ':' characters to Mac '/' characters here
272 +                // '/' is not a path separator as this function is only used on object names
273                  if (c == ':')
274                          c = '/';
275                  *dst++ = c;
276          }
277   }
278  
266 // Convert pascal string to C string
267 static void pstr2cstr(char *dst, const char *src)
268 {
269        int size = *src++;
270        while (size--) {
271                char c = *src++;
272                if (c == '/')
273                        c = ':';
274                *dst++ = c;
275        }
276        *dst = 0;
277 }
278
279   // Convert string (no length byte) to C string, length given separately
280   static void strn2cstr(char *dst, const char *src, int size)
281   {
282          while (size--) {
283                  char c = *src++;
284 +                // Note: we are converting Mac '/' characters to host ':' characters here
285 +                // '/' is not a path separator as this function is only used on object names
286                  if (c == '/')
287                          c = ':';
288                  *dst++ = c;
# Line 356 | Line 358 | void ExtFSInit(void)
358          p->parent_id = ROOT_PARENT_ID;
359          p->parent = first_fs_item;
360          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
361 +        p->name[31] = 0;
362  
363          // Find path for root
364          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 404 | Line 407 | void InstallExtFS(void)
407          // FSM present?
408          r.d[0] = gestaltFSAttr;
409          Execute68kTrap(0xa1ad, &r);     // Gestalt()
410 <        D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
410 >        D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0]));
411          if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
412                  printf("WARNING: No FSM present, disabling ExtFS\n");
413                  return;
# Line 413 | Line 416 | void InstallExtFS(void)
416          // Yes, version >=1.2?
417          r.d[0] = gestaltFSMVersion;
418          Execute68kTrap(0xa1ad, &r);     // Gestalt()
419 <        D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
419 >        D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0]));
420          if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
421                  printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
422                  return;
# Line 683 | Line 686 | int16 ExtFSComm(uint16 message, uint32 p
686                  }
687  
688                  case ffsIDDiskMessage: {                // Check if volume is handled by our FS
689 <                        if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
689 >                        if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
690                                  return noErr;
691                          else
692                                  return extFSErr;
# Line 727 | Line 730 | static int16 get_current_dir(uint32 pb,
730          if (no_vol_name)
731                  WriteMacInt32(pb + ioNamePtr, name_ptr);
732          int16 status = ReadMacInt16(fs_data + fsReturn);
730        int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
731        int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
732        uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
733          D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
734 <        result = r.d[0] & 0xffff;
734 >        result = (int16)(r.d[0] & 0xffff);
735  
736          if (result == noErr) {
737                  switch (status) {
# Line 756 | Line 756 | static int16 get_current_dir(uint32 pb,
756                                          Execute68k(fs_data + fsResolveWDCB, &r);
757                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
758                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
759 <                                        result = r.d[0] & 0xffff;
759 >                                        result = (int16)(r.d[0] & 0xffff);
760                                          if (result == noErr)
761                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
762                                  }
# Line 772 | Line 772 | static int16 get_current_dir(uint32 pb,
772                                          r.a[0] = wdpb;
773                                          Execute68k(fs_data + fsGetDefaultVol, &r);
774                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
775 <                                        result = r.d[0] & 0xffff;
775 >                                        result = (int16)(r.d[0] & 0xffff);
776                                          if (result == noErr)
777                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
778                                  }
# Line 798 | Line 798 | static int16 get_path_component_name(uin
798          r.a[0] = rec;
799          Execute68k(fs_data + fsGetPathComponentName, &r);
800   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
801 <        return r.d[0] & 0xffff;
801 >        return (int16)(r.d[0] & 0xffff);
802   }
803  
804  
# Line 834 | Line 834 | static int16 get_item_and_path(uint32 pb
834          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
835          Execute68k(fs_data + fsParsePathname, &r);
836          D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
837 <        result = r.d[0] & 0xffff;
837 >        result = (int16)(r.d[0] & 0xffff);
838          if (result == noErr) {
839  
840                  // Check for leading delimiter of the partial pathname
# Line 947 | Line 947 | static uint32 find_fcb(int16 refNum)
947   static int16 fs_mount_vol(uint32 pb)
948   {
949          D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum)));
950 <        if (ReadMacInt16(pb + ioVRefNum) == drive_number)
950 >        if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number)
951                  return noErr;
952          else
953                  return extFSErr;
# Line 964 | Line 964 | static int16 fs_volume_mount(uint32 pb)
964          r.a[0] = fs_data + fsReturn;
965          r.a[1] = fs_data + fsReturn + 2;
966          Execute68k(fs_data + fsAllocateVCB, &r);
967 + #if DEBUG
968          uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn);
969 + #endif
970          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
971          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
972          if (r.d[0] & 0xffff)
973 <                return r.d[0];
973 >                return (int16)r.d[0];
974  
975          // Init VCB
976          WriteMacInt16(vcb + vcbSigWord, 0x4244);
977 < #ifdef __BEOS__
978 <        WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
977 > #if defined(__BEOS__) || defined(WIN32)
978 >        WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
979   #else
980          WriteMacInt32(vcb + vcbCrDate, 0);
981   #endif
982 <        WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET);
982 >        WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime));
983          WriteMacInt32(vcb + vcbVolBkUp, 0);
984          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
985          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
986          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
987 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
988 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
987 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
988 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
989          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
990          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
991          Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
# Line 997 | Line 999 | static int16 fs_volume_mount(uint32 pb)
999          r.a[0] = fs_data + fsReturn;
1000          r.a[1] = vcb;
1001          Execute68k(fs_data + fsAddNewVCB, &r);
1002 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1002 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1003          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1004          if (r.d[0] & 0xffff)
1005 <                return r.d[0];
1005 >                return (int16)r.d[0];
1006  
1007          // Post diskInsertEvent
1008          D(bug("  posting diskInsertEvent\n"));
# Line 1024 | Line 1026 | static int16 fs_unmount_vol(uint32 vcb)
1026          r.a[0] = vcb;
1027          Execute68k(fs_data + fsDisposeVCB, &r);
1028          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1029 <        return r.d[0];
1029 >        return (int16)r.d[0];
1030   }
1031  
1032   // Get information about a volume (HVolumeParam)
# Line 1035 | Line 1037 | static int16 fs_get_vol_info(uint32 pb,
1037          // Fill in struct
1038          if (ReadMacInt32(pb + ioNamePtr))
1039                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1040 < #ifdef __BEOS__
1041 <        WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1040 > #if defined(__BEOS__) || defined(WIN32)
1041 >        WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
1042   #else
1043          WriteMacInt32(pb + ioVCrDate, 0);
1044   #endif
1045 <        WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET);
1045 >        WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime));
1046          WriteMacInt16(pb + ioVAtrb, 0);
1047          WriteMacInt16(pb + ioVNmFls, 1);                        //!!
1048          WriteMacInt16(pb + ioVBitMap, 0);
1049          WriteMacInt16(pb + ioAllocPtr, 0);
1050          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1051 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1052 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1051 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1052 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1053          WriteMacInt16(pb + ioAlBlSt, 0);
1054          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1055          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1105 | Line 1107 | static int16 fs_get_vol(uint32 pb)
1107          r.a[0] = pb;
1108          Execute68k(fs_data + fsGetDefaultVol, &r);
1109          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1110 <        return r.d[0];
1110 >        return (int16)r.d[0];
1111   }
1112  
1113   // Set default volume (WDParam)
# Line 1161 | Line 1163 | static int16 fs_set_vol(uint32 pb, bool
1163          r.d[2] = refNum;
1164          Execute68k(fs_data + fsSetDefaultVol, &r);
1165          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1166 <        return r.d[0];
1166 >        return (int16)r.d[0];
1167   }
1168  
1169   // Query file attributes (HFileParam)
# Line 1227 | Line 1229 | read_next_de:
1229          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1230          WriteMacInt32(pb + ioDirID, fs_item->id);
1231  
1232 < #ifdef __BEOS__
1233 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1232 > #if defined(__BEOS__) || defined(WIN32)
1233 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1234   #else
1235          WriteMacInt32(pb + ioFlCrDat, 0);
1236   #endif
1237 <        WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1237 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime));
1238  
1239 <        Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1238 <        uint32 type, creator;   // pb may point to kernel space, but stack is switched
1239 <        get_finder_type(full_path, type, creator);
1240 <        WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1241 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1242 <        uint16 fflags;
1243 <        get_finder_flags(full_path, fflags);
1244 <        WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1239 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1240  
1241          WriteMacInt16(pb + ioFlStBlk, 0);
1242          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1243 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1243 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1244          WriteMacInt16(pb + ioFlRStBlk, 0);
1245          uint32 rf_size = get_rfork_size(full_path);
1246          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1247 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1247 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1248  
1249          if (hfs) {
1250                  WriteMacInt32(pb + ioFlBkDat, 0);
1256                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1251                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1252                  WriteMacInt32(pb + ioFlClpSiz, 0);
1253          }
# Line 1278 | Line 1272 | static int16 fs_set_file_info(uint32 pb,
1272          if (S_ISDIR(st.st_mode))
1273                  return fnfErr;
1274  
1275 <        // Set attributes
1276 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1277 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1275 >        // Set Finder info
1276 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1277 >
1278          //!! times
1279          return noErr;
1280   }
# Line 1357 | Line 1351 | read_next_de:
1351          WriteMacInt8(pb + ioACUser, 0);
1352          WriteMacInt32(pb + ioDirID, fs_item->id);
1353          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1354 < #ifdef __BEOS__
1355 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1354 > #if defined(__BEOS__) || defined(WIN32)
1355 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1356   #else
1357          WriteMacInt32(pb + ioFlCrDat, 0);
1358   #endif
# Line 1368 | Line 1362 | read_next_de:
1362                  fs_item->mtime = mtime;
1363                  cached = false;
1364          }
1365 <        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1365 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime));
1366          WriteMacInt32(pb + ioFlBkDat, 0);
1367 +
1368 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1369 +
1370          if (S_ISDIR(st.st_mode)) {
1374                Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
1375                Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo);
1376                uint16 fflags;  // pb may point to kernel space, but stack is switched
1377                get_finder_flags(full_path, fflags);
1378                WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
1371  
1372                  // Determine number of files in directory (cached)
1373                  int count;
# Line 1400 | Line 1392 | read_next_de:
1392                  }
1393                  WriteMacInt16(pb + ioDrNmFls, count);
1394          } else {
1403                Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1404                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1405                uint32 type, creator;   // pb may point to kernel space, but stack is switched
1406                get_finder_type(full_path, type, creator);
1407                WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1408                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1409                uint16 fflags;
1410                get_finder_flags(full_path, fflags);
1411                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1395                  WriteMacInt16(pb + ioFlStBlk, 0);
1396                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1397 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1397 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1398                  WriteMacInt16(pb + ioFlRStBlk, 0);
1399                  uint32 rf_size = get_rfork_size(full_path);
1400                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1401 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1401 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1402                  WriteMacInt32(pb + ioFlClpSiz, 0);
1403          }
1404          return noErr;
# Line 1437 | Line 1420 | static int16 fs_set_cat_info(uint32 pb)
1420          if (stat(full_path, &st) < 0)
1421                  return errno2oserr();
1422  
1423 <        // Set attributes
1424 <        if (S_ISDIR(st.st_mode))
1425 <                set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags));
1443 <        else {
1444 <                set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1445 <                set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1446 <        }
1423 >        // Set Finder info
1424 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1425 >
1426          //!! times
1427          return noErr;
1428   }
# Line 1490 | Line 1469 | static int16 fs_open(uint32 pb, uint32 d
1469                  if (access(full_path, F_OK))
1470                          return fnfErr;
1471                  fd = open_rfork(full_path, flag);
1472 <                if (fd > 0) {
1472 >                if (fd >= 0) {
1473                          if (fstat(fd, &st) < 0) {
1474                                  close(fd);
1475                                  return errno2oserr();
# Line 1518 | Line 1497 | static int16 fs_open(uint32 pb, uint32 d
1497          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1498          if (r.d[0] & 0xffff) {
1499                  close(fd);
1500 <                return r.d[0];
1500 >                return (int16)r.d[0];
1501          }
1502  
1503          // Initialize FCB, fd is stored in fcbCatPos
1504          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1505          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1506          WriteMacInt32(fcb + fcbEOF, st.st_size);
1507 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1507 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1508          WriteMacInt32(fcb + fcbCrPs, 0);
1509          WriteMacInt32(fcb + fcbVPtr, vcb);
1510 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1511 <        uint32 type, creator;   // BeOS: fcb may point to kernel space, but stack is switched
1512 <        get_finder_type(full_path, type, creator);
1513 <        WriteMacInt32(fcb + fcbFType, type);
1510 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1511 >
1512 >        get_finfo(full_path, fs_data + fsPB, 0, false);
1513 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1514 >
1515          WriteMacInt32(fcb + fcbCatPos, fd);
1516          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1517          cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
# Line 1568 | Line 1548 | static int16 fs_close(uint32 pb)
1548          r.d[0] = ReadMacInt16(pb + ioRefNum);
1549          Execute68k(fs_data + fsReleaseFCB, &r);
1550          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1551 <        return r.d[0];
1551 >        return (int16)r.d[0];
1552   }
1553  
1554   // Query information about FCB (FCBPBRec)
# Line 1587 | Line 1567 | static int16 fs_get_fcb_info(uint32 pb,
1567  
1568                  // Find FCB by index
1569                  WriteMacInt16(pb + ioRefNum, 0);
1570 <                for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) {
1570 >                for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) {
1571                          D(bug("  indexing FCBs\n"));
1572                          r.a[0] = vcb;
1573                          r.a[1] = pb + ioRefNum;
# Line 1596 | Line 1576 | static int16 fs_get_fcb_info(uint32 pb,
1576                          fcb = ReadMacInt32(fs_data + fsReturn);
1577                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1578                          if (r.d[0] & 0xffff)
1579 <                                return r.d[0];
1579 >                                return (int16)r.d[0];
1580                  }
1581          }
1582          if (fcb == 0)
# Line 1644 | Line 1624 | static int16 fs_get_eof(uint32 pb)
1624  
1625          // Adjust FCBs
1626          WriteMacInt32(fcb + fcbEOF, st.st_size);
1627 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1627 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1628          WriteMacInt32(pb + ioMisc, st.st_size);
1629          D(bug("  adjusting FCBs\n"));
1630          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1679 | Line 1659 | static int16 fs_set_eof(uint32 pb)
1659  
1660          // Adjust FCBs
1661          WriteMacInt32(fcb + fcbEOF, size);
1662 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1662 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1663          D(bug("  adjusting FCBs\n"));
1664          r.d[0] = ReadMacInt16(pb + ioRefNum);
1665          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1764 | Line 1744 | static int16 fs_read(uint32 pb)
1744   {
1745          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)));
1746  
1747 +        // Check parameters
1748 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1749 +                return paramErr;
1750 +
1751          // Find FCB and fd for file
1752          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1753          if (fcb == 0)
# Line 1802 | Line 1786 | static int16 fs_read(uint32 pb)
1786          uint32 pos = lseek(fd, 0, SEEK_CUR);
1787          WriteMacInt32(fcb + fcbCrPs, pos);
1788          WriteMacInt32(pb + ioPosOffset, pos);
1789 <        if (actual != ReadMacInt32(pb + ioReqCount))
1789 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1790                  return actual < 0 ? read_err : eofErr;
1791          else
1792                  return noErr;
# Line 1813 | Line 1797 | static int16 fs_write(uint32 pb)
1797   {
1798          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)));
1799  
1800 +        // Check parameters
1801 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1802 +                return paramErr;
1803 +
1804          // Find FCB and fd for file
1805          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1806          if (fcb == 0)
# Line 1851 | Line 1839 | static int16 fs_write(uint32 pb)
1839          uint32 pos = lseek(fd, 0, SEEK_CUR);
1840          WriteMacInt32(fcb + fcbCrPs, pos);
1841          WriteMacInt32(pb + ioPosOffset, pos);
1842 <        if (actual != ReadMacInt32(pb + ioReqCount))
1842 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1843                  return write_err;
1844          else
1845                  return noErr;
# Line 2023 | Line 2011 | static int16 fs_open_wd(uint32 pb)
2011          r.a[0] = pb;
2012          Execute68k(fs_data + fsAllocateWDCB, &r);
2013          D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2014 <        return r.d[0];
2014 >        return (int16)r.d[0];
2015   }
2016  
2017   // Close working directory (WDParam)
# Line 2037 | Line 2025 | static int16 fs_close_wd(uint32 pb)
2025          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2026          Execute68k(fs_data + fsReleaseWDCB, &r);
2027          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2028 <        return r.d[0];
2028 >        return (int16)r.d[0];
2029   }
2030  
2031   // Query information about working directory (WDParam)
# Line 2066 | Line 2054 | static int16 fs_get_wd_info(uint32 pb, u
2054          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2055          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2056          if (r.d[0] & 0xffff)
2057 <                return r.d[0];
2057 >                return (int16)r.d[0];
2058  
2059          // Return information
2060          WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines