40 |
|
#include <string.h> |
41 |
|
#include <stdio.h> |
42 |
|
#include <stdlib.h> |
43 |
– |
#include <unistd.h> |
43 |
|
#include <fcntl.h> |
45 |
– |
#include <dirent.h> |
44 |
|
#include <errno.h> |
45 |
|
|
46 |
+ |
#ifndef WIN32 |
47 |
+ |
#include <unistd.h> |
48 |
+ |
#include <dirent.h> |
49 |
+ |
#endif |
50 |
+ |
|
51 |
|
#include "cpu_emulation.h" |
52 |
|
#include "macos_util.h" |
53 |
|
#include "emul_op.h" |
58 |
|
#include "extfs.h" |
59 |
|
#include "extfs_defs.h" |
60 |
|
|
61 |
+ |
#ifdef WIN32 |
62 |
+ |
# include "posix_emu.h" |
63 |
+ |
#endif |
64 |
+ |
|
65 |
|
#define DEBUG 0 |
66 |
|
#include "debug.h" |
67 |
|
|
118 |
|
// File system stack size |
119 |
|
const int STACK_SIZE = 0x10000; |
120 |
|
|
121 |
+ |
// Allocation block and clump size as reported to MacOS (these are of course |
122 |
+ |
// not the real values and have no meaning on the host OS) |
123 |
+ |
const int ALBLK_SIZE = 0x4000; |
124 |
+ |
const int CLUMP_SIZE = 0x4000; |
125 |
+ |
|
126 |
|
// Drive number of our pseudo-drive |
127 |
|
static int drive_number; |
128 |
|
|
269 |
|
*dst++ = strlen(src); |
270 |
|
char c; |
271 |
|
while ((c = *src++) != 0) { |
272 |
+ |
// Note: we are converting host ':' characters to Mac '/' characters here |
273 |
+ |
// '/' is not a path separator as this function is only used on object names |
274 |
|
if (c == ':') |
275 |
|
c = '/'; |
276 |
|
*dst++ = c; |
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; |
297 |
|
{ |
298 |
|
while (size--) { |
299 |
|
char c = *src++; |
300 |
+ |
// Note: we are converting Mac '/' characters to host ':' characters here |
301 |
+ |
// '/' is not a path separator as this function is only used on object names |
302 |
|
if (c == '/') |
303 |
|
c = ':'; |
304 |
|
*dst++ = c; |
374 |
|
p->parent_id = ROOT_PARENT_ID; |
375 |
|
p->parent = first_fs_item; |
376 |
|
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
377 |
+ |
p->name[31] = 0; |
378 |
|
|
379 |
|
// Find path for root |
380 |
|
if ((RootPath = PrefsFindString("extfs")) != NULL) { |
750 |
|
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
751 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
752 |
|
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
753 |
< |
result = r.d[0] & 0xffff; |
753 |
> |
result = (int16)(r.d[0] & 0xffff); |
754 |
|
|
755 |
|
if (result == noErr) { |
756 |
|
switch (status) { |
775 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
776 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
777 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
778 |
< |
result = r.d[0] & 0xffff; |
778 |
> |
result = (int16)(r.d[0] & 0xffff); |
779 |
|
if (result == noErr) |
780 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
781 |
|
} |
791 |
|
r.a[0] = wdpb; |
792 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
793 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
794 |
< |
result = r.d[0] & 0xffff; |
794 |
> |
result = (int16)(r.d[0] & 0xffff); |
795 |
|
if (result == noErr) |
796 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
797 |
|
} |
817 |
|
r.a[0] = rec; |
818 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
819 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
820 |
< |
return r.d[0] & 0xffff; |
820 |
> |
return (int16)(r.d[0] & 0xffff); |
821 |
|
} |
822 |
|
|
823 |
|
|
853 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
854 |
|
Execute68k(fs_data + fsParsePathname, &r); |
855 |
|
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
856 |
< |
result = r.d[0] & 0xffff; |
856 |
> |
result = (int16)(r.d[0] & 0xffff); |
857 |
|
if (result == noErr) { |
858 |
|
|
859 |
|
// Check for leading delimiter of the partial pathname |
987 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
988 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
989 |
|
if (r.d[0] & 0xffff) |
990 |
< |
return r.d[0]; |
990 |
> |
return (int16)r.d[0]; |
991 |
|
|
992 |
|
// Init VCB |
993 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
994 |
< |
#ifdef __BEOS__ |
994 |
> |
#if defined(__BEOS__) || defined(WIN32) |
995 |
|
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
996 |
|
#else |
997 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
1001 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
1002 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
1003 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
1004 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
1005 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
1004 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
1005 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMPSIZE); |
1006 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
1007 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
1008 |
|
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
1016 |
|
r.a[0] = fs_data + fsReturn; |
1017 |
|
r.a[1] = vcb; |
1018 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1019 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1019 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1020 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1021 |
|
if (r.d[0] & 0xffff) |
1022 |
< |
return r.d[0]; |
1022 |
> |
return (int16)r.d[0]; |
1023 |
|
|
1024 |
|
// Post diskInsertEvent |
1025 |
|
D(bug(" posting diskInsertEvent\n")); |
1043 |
|
r.a[0] = vcb; |
1044 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1045 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1046 |
< |
return r.d[0]; |
1046 |
> |
return (int16)r.d[0]; |
1047 |
|
} |
1048 |
|
|
1049 |
|
// Get information about a volume (HVolumeParam) |
1054 |
|
// Fill in struct |
1055 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1056 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1057 |
< |
#ifdef __BEOS__ |
1057 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1058 |
|
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1059 |
|
#else |
1060 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1065 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1066 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1067 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1068 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1069 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1068 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1069 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1070 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1071 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1072 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1124 |
|
r.a[0] = pb; |
1125 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1126 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1127 |
< |
return r.d[0]; |
1127 |
> |
return (int16)r.d[0]; |
1128 |
|
} |
1129 |
|
|
1130 |
|
// Set default volume (WDParam) |
1180 |
|
r.d[2] = refNum; |
1181 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1182 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1183 |
< |
return r.d[0]; |
1183 |
> |
return (int16)r.d[0]; |
1184 |
|
} |
1185 |
|
|
1186 |
|
// Query file attributes (HFileParam) |
1246 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1247 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1248 |
|
|
1249 |
< |
#ifdef __BEOS__ |
1249 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1250 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1251 |
|
#else |
1252 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1264 |
|
|
1265 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1266 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1267 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1267 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1268 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1269 |
|
uint32 rf_size = get_rfork_size(full_path); |
1270 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1271 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1271 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1272 |
|
|
1273 |
|
if (hfs) { |
1274 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1376 |
|
WriteMacInt8(pb + ioACUser, 0); |
1377 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1378 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1379 |
< |
#ifdef __BEOS__ |
1379 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1380 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1381 |
|
#else |
1382 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1430 |
|
WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags); |
1431 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1432 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1433 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1433 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1434 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1435 |
|
uint32 rf_size = get_rfork_size(full_path); |
1436 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1437 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1437 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1438 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1439 |
|
} |
1440 |
|
return noErr; |
1457 |
|
return errno2oserr(); |
1458 |
|
|
1459 |
|
// Set attributes |
1460 |
< |
if (S_ISDIR(st.st_mode)) |
1460 |
> |
if (S_ISDIR(st.st_mode)) { |
1461 |
|
set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags)); |
1462 |
< |
else { |
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 |
|
} |
1509 |
|
if (access(full_path, F_OK)) |
1510 |
|
return fnfErr; |
1511 |
|
fd = open_rfork(full_path, flag); |
1512 |
< |
if (fd > 0) { |
1512 |
> |
if (fd >= 0) { |
1513 |
|
if (fstat(fd, &st) < 0) { |
1514 |
|
close(fd); |
1515 |
|
return errno2oserr(); |
1537 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1538 |
|
if (r.d[0] & 0xffff) { |
1539 |
|
close(fd); |
1540 |
< |
return r.d[0]; |
1540 |
> |
return (int16)r.d[0]; |
1541 |
|
} |
1542 |
|
|
1543 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1544 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1545 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1546 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1547 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1547 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1548 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1549 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1550 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1550 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1551 |
|
uint32 type, creator; // BeOS: fcb may point to kernel space, but stack is switched |
1552 |
|
get_finder_type(full_path, type, creator); |
1553 |
|
WriteMacInt32(fcb + fcbFType, type); |
1587 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1588 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1589 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1590 |
< |
return r.d[0]; |
1590 |
> |
return (int16)r.d[0]; |
1591 |
|
} |
1592 |
|
|
1593 |
|
// Query information about FCB (FCBPBRec) |
1615 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1616 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1617 |
|
if (r.d[0] & 0xffff) |
1618 |
< |
return r.d[0]; |
1618 |
> |
return (int16)r.d[0]; |
1619 |
|
} |
1620 |
|
} |
1621 |
|
if (fcb == 0) |
1663 |
|
|
1664 |
|
// Adjust FCBs |
1665 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1666 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1666 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1667 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1668 |
|
D(bug(" adjusting FCBs\n")); |
1669 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1698 |
|
|
1699 |
|
// Adjust FCBs |
1700 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1701 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1701 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1702 |
|
D(bug(" adjusting FCBs\n")); |
1703 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1704 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1783 |
|
{ |
1784 |
|
D(bug(" fs_read(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset))); |
1785 |
|
|
1786 |
+ |
// Check parameters |
1787 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1788 |
+ |
return paramErr; |
1789 |
+ |
|
1790 |
|
// Find FCB and fd for file |
1791 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1792 |
|
if (fcb == 0) |
1836 |
|
{ |
1837 |
|
D(bug(" fs_write(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset))); |
1838 |
|
|
1839 |
+ |
// Check parameters |
1840 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1841 |
+ |
return paramErr; |
1842 |
+ |
|
1843 |
|
// Find FCB and fd for file |
1844 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1845 |
|
if (fcb == 0) |
2050 |
|
r.a[0] = pb; |
2051 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2052 |
|
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2053 |
< |
return r.d[0]; |
2053 |
> |
return (int16)r.d[0]; |
2054 |
|
} |
2055 |
|
|
2056 |
|
// Close working directory (WDParam) |
2064 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2065 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2066 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2067 |
< |
return r.d[0]; |
2067 |
> |
return (int16)r.d[0]; |
2068 |
|
} |
2069 |
|
|
2070 |
|
// Query information about working directory (WDParam) |
2093 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2094 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2095 |
|
if (r.d[0] & 0xffff) |
2096 |
< |
return r.d[0]; |
2096 |
> |
return (int16)r.d[0]; |
2097 |
|
|
2098 |
|
// Return information |
2099 |
|
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |