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 |
|
|
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 |
|
|
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); |
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 |
|
|
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 |
|
Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo); |
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); |
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; |
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 |
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); |
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 |
|
} |
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 |
|
} |
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 |
|
|
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; |
1981 |
|
strcpy(old_path, full_path); |
1982 |
|
|
1983 |
|
// Find path for new directory |
1984 |
< |
Mac2Host_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
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(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
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; |
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 |
|
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28); |