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.13 by cebix, 1999-11-08T18:05:55Z vs.
Revision 1.16 by cebix, 2000-04-10T18:52:22Z

# Line 1 | Line 1
1   /*
2   *  extfs.cpp - MacOS file system for access 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 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 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 <        Host2Mac_memcpy(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 1475 | 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 1485 | 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 1509 | 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 1775 | 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 <                return read_err ? read_err : 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);
# Line 1937 | Line 1957 | static int16 fs_rename(uint32 pb, uint32
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 1982 | Line 2003 | static int16 fs_cat_move(uint32 pb)
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines