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.18 by cebix, 2000-07-14T21:29:08Z vs.
Revision 1.28 by cebix, 2002-01-15T14:58:32Z

# Line 1 | Line 1
1   /*
2   *  extfs.cpp - MacOS file system for native file system access
3   *
4 < *  Basilisk II (C) 1997-2000 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 49 | Line 49
49   #endif
50  
51   #include "cpu_emulation.h"
52 #include "macos_util.h"
52   #include "emul_op.h"
53   #include "main.h"
54   #include "disk.h"
# Line 72 | 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 108 | 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 120 | Line 119 | 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 ALBLK_SIZE = 0x4000;
122 > const int AL_BLK_SIZE = 0x4000;
123   const int CLUMP_SIZE = 0x4000;
124  
125   // Drive number of our pseudo-drive
# Line 277 | Line 276 | static void cstr2pstr(char *dst, const c
276          }
277   }
278  
280 // Convert pascal string to C string
281 static void pstr2cstr(char *dst, const char *src)
282 {
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;
291        }
292        *dst = 0;
293 }
294
279   // Convert string (no length byte) to C string, length given separately
280   static void strn2cstr(char *dst, const char *src, int size)
281   {
# Line 423 | 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 432 | 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 702 | 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 746 | 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);
749        int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
750        int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
751        uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
733          D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
734          result = (int16)(r.d[0] & 0xffff);
735  
# Line 966 | 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 983 | 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)
# Line 992 | Line 975 | static int16 fs_volume_mount(uint32 pb)
975          // Init VCB
976          WriteMacInt16(vcb + vcbSigWord, 0x4244);
977   #if defined(__BEOS__) || defined(WIN32)
978 <        WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
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, AL_BLK_SIZE);
988 <        WriteMacInt32(vcb + vcbClpSiz, CLUMPSIZE);
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 1055 | Line 1038 | static int16 fs_get_vol_info(uint32 pb,
1038          if (ReadMacInt32(pb + ioNamePtr))
1039                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1040   #if defined(__BEOS__) || defined(WIN32)
1041 <        WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
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);
# Line 1247 | Line 1230 | read_next_de:
1230          WriteMacInt32(pb + ioDirID, fs_item->id);
1231  
1232   #if defined(__BEOS__) || defined(WIN32)
1233 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
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);
1257 <        uint32 type, creator;   // pb may point to kernel space, but stack is switched
1258 <        get_finder_type(full_path, type, creator);
1259 <        WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1260 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1261 <        uint16 fflags;
1262 <        get_finder_flags(full_path, fflags);
1263 <        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);
# Line 1272 | Line 1248 | read_next_de:
1248  
1249          if (hfs) {
1250                  WriteMacInt32(pb + ioFlBkDat, 0);
1275                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1251                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1252                  WriteMacInt32(pb + ioFlClpSiz, 0);
1253          }
# Line 1297 | 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 1377 | Line 1352 | read_next_de:
1352          WriteMacInt32(pb + ioDirID, fs_item->id);
1353          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1354   #if defined(__BEOS__) || defined(WIN32)
1355 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1355 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1356   #else
1357          WriteMacInt32(pb + ioFlCrDat, 0);
1358   #endif
# Line 1387 | 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)) {
1393                Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo);
1394                Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo);
1395                uint16 fflags;  // pb may point to kernel space, but stack is switched
1396                get_finder_flags(full_path, fflags);
1397                WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
1371  
1372                  // Determine number of files in directory (cached)
1373                  int count;
# Line 1419 | Line 1392 | read_next_de:
1392                  }
1393                  WriteMacInt16(pb + ioDrNmFls, count);
1394          } else {
1422                Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo);
1423                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1424                uint32 type, creator;   // pb may point to kernel space, but stack is switched
1425                get_finder_type(full_path, type, creator);
1426                WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1427                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1428                uint16 fflags;
1429                get_finder_flags(full_path, fflags);
1430                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1395                  WriteMacInt16(pb + ioFlStBlk, 0);
1396                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1397                  WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
# Line 1456 | 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));
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 <        }
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 1548 | Line 1508 | static int16 fs_open(uint32 pb, uint32 d
1508          WriteMacInt32(fcb + fcbCrPs, 0);
1509          WriteMacInt32(fcb + fcbVPtr, vcb);
1510          WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
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);
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 1606 | 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 1825 | 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 1878 | 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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines