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 |
|
|
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 |
< |
return read_err ? read_err : 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); |
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 |
1904 |
< |
if (rmdir(full_path) < 0) |
1905 |
< |
return errno2oserr(); |
1906 |
< |
else |
1907 |
< |
return noErr; |
1908 |
< |
} else |
1909 |
< |
return err; |
1910 |
< |
} 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; |
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; |