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.7 by cebix, 1999-10-27T16:59:35Z vs.
Revision 1.15 by cebix, 1999-12-22T16:16:09Z

# Line 65 | Line 65 | enum {
65          fsHFSProcStub = 6,
66          fsDrvStatus = 12,                               // Drive Status record
67          fsFSD = 42,                                             // File system descriptor
68 <        fsPB = 238,                                             // IOParam (for mounting)
68 >        fsPB = 238,                                             // IOParam (for mounting and renaming)
69          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
70          fsParseRec = 296,                               // ParsePathRec struct
71          fsReturn = 306,                                 // Area for return data of 68k routines
# Line 223 | Line 223 | static void get_path_for_fsitem(FSItem *
223  
224  
225   /*
226 + *  Exchange parent CNIDs in all FSItems
227 + */
228 +
229 + static void swap_parent_ids(uint32 parent1, uint32 parent2)
230 + {
231 +        FSItem *p = first_fs_item;
232 +        while (p) {
233 +                if (p->parent_id == parent1)
234 +                        p->parent_id = parent2;
235 +                else if (p->parent_id == parent2)
236 +                        p->parent_id = parent1;
237 +                p = p->next;
238 +        }
239 + }
240 +
241 +
242 + /*
243   *  String handling functions
244   */
245  
# Line 604 | Line 621 | void InstallExtFS(void)
621          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
622          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
623          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
624 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
624 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
625          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
626          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
627          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 658 | Line 675 | int16 ExtFSComm(uint16 message, uint32 p
675  
676                  case ffsGetIconMessage: {               // Get disk/drive icon
677                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
678 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
678 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
679                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
680                                  return noErr;
681                          } else
# Line 969 | Line 986 | static int16 fs_volume_mount(uint32 pb)
986          WriteMacInt32(vcb + vcbClpSiz, 1024);
987          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
988          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
989 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
989 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
990          WriteMacInt16(vcb + vcbFSID, MY_FSID);
991          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
992          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 1043 | Line 1060 | static int16 fs_get_vol_info(uint32 pb,
1060                  WriteMacInt32(pb + ioVWrCnt, 0);
1061                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1062                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1063 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1063 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1064          }
1065          return noErr;
1066   }
# Line 1063 | Line 1080 | static int16 fs_get_vol_parms(uint32 pb)
1080   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1081  
1082          // 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);
1083          uint32 actual = ReadMacInt32(pb + ioReqCount);
1084 <        if (actual > sizeof(vol))
1085 <                actual = sizeof(vol);
1076 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1084 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1085 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1086          WriteMacInt32(pb + ioActCount, actual);
1087 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1088 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1089 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1090 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1091 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1092 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1093 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1094          return noErr;
1095   }
1096  
# Line 1187 | Line 1203 | read_next_de:
1203                                  return fnfErr;
1204                          }
1205                          if (de->d_name[0] == '.')
1206 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1206 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1207                          //!! suppress directories
1208                  }
1209                  add_path_comp(de->d_name);
# Line 1218 | Line 1234 | read_next_de:
1234   #endif
1235          WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1236  
1237 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1237 >        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);
# Line 1237 | Line 1253 | read_next_de:
1253  
1254          if (hfs) {
1255                  WriteMacInt32(pb + ioFlBkDat, 0);
1256 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1256 >                Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo);
1257                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1258                  WriteMacInt32(pb + ioFlClpSiz, 0);
1259          }
# Line 1316 | Line 1332 | read_next_de:
1332                                  return fnfErr;
1333                          }
1334                          if (de->d_name[0] == '.')
1335 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1335 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1336                  }
1337                  add_path_comp(de->d_name);
1338  
# Line 1352 | Line 1368 | read_next_de:
1368                  fs_item->mtime = mtime;
1369                  cached = false;
1370          }
1371 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1371 >        WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
1372          WriteMacInt32(pb + ioFlBkDat, 0);
1373          if (S_ISDIR(st.st_mode)) {
1374 <                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1375 <                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
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);
# Line 1374 | Line 1390 | read_next_de:
1390                                          de = readdir(d);
1391                                          if (de == NULL)
1392                                                  break;
1393 +                                        if (de->d_name[0] == '.')
1394 +                                                continue;       // Suppress names beginning with '.'
1395                                          count++;
1396                                  }
1397                                  closedir(d);
# Line 1382 | Line 1400 | read_next_de:
1400                  }
1401                  WriteMacInt16(pb + ioDrNmFls, count);
1402          } else {
1403 <                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1404 <                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
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);
# Line 1473 | Line 1491 | static int16 fs_open(uint32 pb, uint32 d
1491                          return fnfErr;
1492                  fd = open_rfork(full_path, flag);
1493                  if (fd > 0) {
1494 <                        if (fstat(fd, &st) < 0)
1494 >                        if (fstat(fd, &st) < 0) {
1495 >                                close(fd);
1496                                  return errno2oserr();
1497 +                        }
1498                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1499                          st.st_size = 0;
1500                          st.st_mode = 0;
# Line 1483 | Line 1503 | static int16 fs_open(uint32 pb, uint32 d
1503                  fd = open(full_path, flag);
1504                  if (fd < 0)
1505                          return errno2oserr();
1506 <                if (fstat(fd, &st) < 0)
1506 >                if (fstat(fd, &st) < 0) {
1507 >                        close(fd);
1508                          return errno2oserr();
1509 +                }
1510          }
1511  
1512          // File open, allocate FCB
# Line 1507 | Line 1529 | static int16 fs_open(uint32 pb, uint32 d
1529          WriteMacInt32(fcb + fcbCrPs, 0);
1530          WriteMacInt32(fcb + fcbVPtr, vcb);
1531          WriteMacInt32(fcb + fcbClmpSize, 1024);
1532 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1532 >        uint32 type, creator;   // BeOS: fcb may point to kernel space, but stack is switched
1533          get_finder_type(full_path, type, creator);
1534          WriteMacInt32(fcb + fcbFType, type);
1535          WriteMacInt32(fcb + fcbCatPos, fd);
# Line 1773 | Line 1795 | static int16 fs_read(uint32 pb)
1795          }
1796  
1797          // Read
1798 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1798 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1799 >        int16 read_err = errno2oserr();
1800          D(bug("  actual %d\n", actual));
1801 <        WriteMacInt32(pb + ioActCount, actual);
1801 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1802          uint32 pos = lseek(fd, 0, SEEK_CUR);
1803          WriteMacInt32(fcb + fcbCrPs, pos);
1804          WriteMacInt32(pb + ioPosOffset, pos);
1805          if (actual != ReadMacInt32(pb + ioReqCount))
1806 <                if (errno)
1784 <                        return errno2oserr();
1785 <                else
1786 <                        return eofErr;
1806 >                return actual < 0 ? read_err : eofErr;
1807          else
1808                  return noErr;
1809   }
# Line 1824 | Line 1844 | static int16 fs_write(uint32 pb)
1844          }
1845  
1846          // Write
1847 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1847 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1848 >        int16 write_err = errno2oserr();
1849          D(bug("  actual %d\n", actual));
1850 <        WriteMacInt32(pb + ioActCount, actual);
1850 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1851          uint32 pos = lseek(fd, 0, SEEK_CUR);
1852          WriteMacInt32(fcb + fcbCrPs, pos);
1853          WriteMacInt32(pb + ioPosOffset, pos);
1854          if (actual != ReadMacInt32(pb + ioReqCount))
1855 <                return errno2oserr();
1855 >                return write_err;
1856          else
1857                  return noErr;
1858   }
# Line 1852 | Line 1873 | static int16 fs_create(uint32 pb, uint32
1873                  return dupFNErr;
1874  
1875          // Create file
1876 <        int fd = creat(full_path, 0664);
1876 >        int fd = creat(full_path, 0666);
1877          if (fd < 0)
1878                  return errno2oserr();
1879          else {
# Line 1877 | Line 1898 | static int16 fs_dir_create(uint32 pb)
1898                  return dupFNErr;
1899  
1900          // Create directory
1901 <        if (mkdir(full_path, 0775) < 0)
1901 >        if (mkdir(full_path, 0777) < 0)
1902                  return errno2oserr();
1903          else {
1904                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1897 | Line 1918 | static int16 fs_delete(uint32 pb, uint32
1918                  return result;
1919  
1920          // Delete file
1921 <        if (remove(full_path) < 0) {
1922 <                int16 err = errno2oserr();
1923 <                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
1921 >        if (!extfs_remove(full_path))
1922 >                return errno2oserr();
1923 >        else
1924                  return noErr;
1925   }
1926  
# Line 1926 | Line 1940 | static int16 fs_rename(uint32 pb, uint32
1940          strcpy(old_path, full_path);
1941  
1942          // Find path for new name
1943 <        uint8 new_pb[SIZEOF_IOParam];
1944 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1931 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
1943 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1944 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
1945          FSItem *new_item;
1946 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
1946 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
1947          if (result != noErr)
1948                  return result;
1949  
# Line 1940 | Line 1953 | static int16 fs_rename(uint32 pb, uint32
1953  
1954          // Rename item
1955          D(bug("  renaming %s -> %s\n", old_path, full_path));
1956 <        if (rename(old_path, full_path) < 0)
1956 >        if (!extfs_rename(old_path, full_path))
1957                  return errno2oserr();
1958          else {
1959                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
1960 +                swap_parent_ids(fs_item->id, new_item->id);
1961                  uint32 t = fs_item->id;
1962                  fs_item->id = new_item->id;
1963                  new_item->id = t;
# Line 1967 | Line 1981 | static int16 fs_cat_move(uint32 pb)
1981          strcpy(old_path, full_path);
1982  
1983          // Find path for new directory
1984 <        uint8 new_pb[SIZEOF_IOParam];
1985 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1972 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
1984 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
1985 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
1986          FSItem *new_dir_item;
1987 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1987 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
1988          if (result != noErr)
1989                  return result;
1990  
# Line 1984 | Line 1997 | static int16 fs_cat_move(uint32 pb)
1997  
1998          // Move item
1999          D(bug("  moving %s -> %s\n", old_path, full_path));
2000 <        if (rename(old_path, full_path) < 0)
2000 >        if (!extfs_rename(old_path, full_path))
2001                  return errno2oserr();
2002          else {
2003                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2004                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2005                  if (new_item) {
2006 +                        swap_parent_ids(fs_item->id, new_item->id);
2007                          uint32 t = fs_item->id;
2008                          fs_item->id = new_item->id;
2009                          new_item->id = t;
# Line 2037 | Line 2051 | static int16 fs_get_wd_info(uint32 pb, u
2051                  WriteMacInt32(pb + ioWDProcID, 0);
2052                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2053                  if (ReadMacInt32(pb + ioNamePtr))
2054 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2054 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2055                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2056                  return noErr;
2057          }
# Line 2055 | Line 2069 | static int16 fs_get_wd_info(uint32 pb, u
2069                  return r.d[0];
2070  
2071          // Return information
2072 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2072 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2073          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2074          if (ReadMacInt32(pb + ioNamePtr))
2075 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2075 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2076          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2077          return noErr;
2078   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines