1 |
|
/* |
2 |
< |
* extfs.cpp - MacOS file system for access native file system access |
2 |
> |
* extfs.cpp - MacOS file system for native file system access |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 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 |
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" |
49 |
– |
#include "macos_util.h" |
52 |
|
#include "emul_op.h" |
53 |
|
#include "main.h" |
54 |
|
#include "disk.h" |
57 |
|
#include "extfs.h" |
58 |
|
#include "extfs_defs.h" |
59 |
|
|
60 |
+ |
#ifdef WIN32 |
61 |
+ |
# include "posix_emu.h" |
62 |
+ |
#endif |
63 |
+ |
|
64 |
|
#define DEBUG 0 |
65 |
|
#include "debug.h" |
66 |
|
|
71 |
|
fsHFSProcStub = 6, |
72 |
|
fsDrvStatus = 12, // Drive Status record |
73 |
|
fsFSD = 42, // File system descriptor |
74 |
< |
fsPB = 238, // IOParam (for mounting and renaming) |
74 |
> |
fsPB = 238, // IOParam (for mounting and renaming), also used for temporary storage |
75 |
|
fsVMI = 288, // VoumeMountInfoHeader (for mounting) |
76 |
|
fsParseRec = 296, // ParsePathRec struct |
77 |
|
fsReturn = 306, // Area for return data of 68k routines |
107 |
|
static struct stat root_stat; |
108 |
|
|
109 |
|
// File system ID/media type |
110 |
< |
const int16 MY_FSID = 'ba'; |
111 |
< |
const uint32 MY_MEDIA_TYPE = 'basi'; |
110 |
> |
const int16 MY_FSID = EMULATOR_ID_2; |
111 |
> |
const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4; |
112 |
|
|
113 |
|
// CNID of root and root's parent |
114 |
|
const uint32 ROOT_ID = 2; |
117 |
|
// File system stack size |
118 |
|
const int STACK_SIZE = 0x10000; |
119 |
|
|
120 |
+ |
// Allocation block and clump size as reported to MacOS (these are of course |
121 |
+ |
// not the real values and have no meaning on the host OS) |
122 |
+ |
const int AL_BLK_SIZE = 0x4000; |
123 |
+ |
const int CLUMP_SIZE = 0x4000; |
124 |
+ |
|
125 |
|
// Drive number of our pseudo-drive |
126 |
|
static int drive_number; |
127 |
|
|
234 |
|
|
235 |
|
|
236 |
|
/* |
237 |
+ |
* Exchange parent CNIDs in all FSItems |
238 |
+ |
*/ |
239 |
+ |
|
240 |
+ |
static void swap_parent_ids(uint32 parent1, uint32 parent2) |
241 |
+ |
{ |
242 |
+ |
FSItem *p = first_fs_item; |
243 |
+ |
while (p) { |
244 |
+ |
if (p->parent_id == parent1) |
245 |
+ |
p->parent_id = parent2; |
246 |
+ |
else if (p->parent_id == parent2) |
247 |
+ |
p->parent_id = parent1; |
248 |
+ |
p = p->next; |
249 |
+ |
} |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
|
253 |
+ |
/* |
254 |
|
* String handling functions |
255 |
|
*/ |
256 |
|
|
268 |
|
*dst++ = strlen(src); |
269 |
|
char c; |
270 |
|
while ((c = *src++) != 0) { |
271 |
+ |
// Note: we are converting host ':' characters to Mac '/' characters here |
272 |
+ |
// '/' is not a path separator as this function is only used on object names |
273 |
|
if (c == ':') |
274 |
|
c = '/'; |
275 |
|
*dst++ = c; |
276 |
|
} |
277 |
|
} |
278 |
|
|
249 |
– |
// Convert pascal string to C string |
250 |
– |
static void pstr2cstr(char *dst, const char *src) |
251 |
– |
{ |
252 |
– |
int size = *src++; |
253 |
– |
while (size--) { |
254 |
– |
char c = *src++; |
255 |
– |
if (c == '/') |
256 |
– |
c = ':'; |
257 |
– |
*dst++ = c; |
258 |
– |
} |
259 |
– |
*dst = 0; |
260 |
– |
} |
261 |
– |
|
279 |
|
// Convert string (no length byte) to C string, length given separately |
280 |
|
static void strn2cstr(char *dst, const char *src, int size) |
281 |
|
{ |
282 |
|
while (size--) { |
283 |
|
char c = *src++; |
284 |
+ |
// Note: we are converting Mac '/' characters to host ':' characters here |
285 |
+ |
// '/' is not a path separator as this function is only used on object names |
286 |
|
if (c == '/') |
287 |
|
c = ':'; |
288 |
|
*dst++ = c; |
358 |
|
p->parent_id = ROOT_PARENT_ID; |
359 |
|
p->parent = first_fs_item; |
360 |
|
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
361 |
+ |
p->name[31] = 0; |
362 |
|
|
363 |
|
// Find path for root |
364 |
|
if ((RootPath = PrefsFindString("extfs")) != NULL) { |
407 |
|
// FSM present? |
408 |
|
r.d[0] = gestaltFSAttr; |
409 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
410 |
< |
D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); |
410 |
> |
D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); |
411 |
|
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { |
412 |
|
printf("WARNING: No FSM present, disabling ExtFS\n"); |
413 |
|
return; |
416 |
|
// Yes, version >=1.2? |
417 |
|
r.d[0] = gestaltFSMVersion; |
418 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
419 |
< |
D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); |
419 |
> |
D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); |
420 |
|
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { |
421 |
|
printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); |
422 |
|
return; |
686 |
|
} |
687 |
|
|
688 |
|
case ffsIDDiskMessage: { // Check if volume is handled by our FS |
689 |
< |
if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
689 |
> |
if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
690 |
|
return noErr; |
691 |
|
else |
692 |
|
return extFSErr; |
734 |
|
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
735 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
736 |
|
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
737 |
< |
result = r.d[0] & 0xffff; |
737 |
> |
result = (int16)(r.d[0] & 0xffff); |
738 |
|
|
739 |
|
if (result == noErr) { |
740 |
|
switch (status) { |
759 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
760 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
761 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
762 |
< |
result = r.d[0] & 0xffff; |
762 |
> |
result = (int16)(r.d[0] & 0xffff); |
763 |
|
if (result == noErr) |
764 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
765 |
|
} |
775 |
|
r.a[0] = wdpb; |
776 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
777 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
778 |
< |
result = r.d[0] & 0xffff; |
778 |
> |
result = (int16)(r.d[0] & 0xffff); |
779 |
|
if (result == noErr) |
780 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
781 |
|
} |
801 |
|
r.a[0] = rec; |
802 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
803 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
804 |
< |
return r.d[0] & 0xffff; |
804 |
> |
return (int16)(r.d[0] & 0xffff); |
805 |
|
} |
806 |
|
|
807 |
|
|
837 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
838 |
|
Execute68k(fs_data + fsParsePathname, &r); |
839 |
|
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
840 |
< |
result = r.d[0] & 0xffff; |
840 |
> |
result = (int16)(r.d[0] & 0xffff); |
841 |
|
if (result == noErr) { |
842 |
|
|
843 |
|
// Check for leading delimiter of the partial pathname |
950 |
|
static int16 fs_mount_vol(uint32 pb) |
951 |
|
{ |
952 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
953 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
953 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
954 |
|
return noErr; |
955 |
|
else |
956 |
|
return extFSErr; |
971 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
972 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
973 |
|
if (r.d[0] & 0xffff) |
974 |
< |
return r.d[0]; |
974 |
> |
return (int16)r.d[0]; |
975 |
|
|
976 |
|
// Init VCB |
977 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
978 |
< |
#ifdef __BEOS__ |
978 |
> |
#if defined(__BEOS__) || defined(WIN32) |
979 |
|
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
980 |
|
#else |
981 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
985 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
986 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
987 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
988 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
989 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
988 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
989 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); |
990 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
991 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
992 |
|
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
1000 |
|
r.a[0] = fs_data + fsReturn; |
1001 |
|
r.a[1] = vcb; |
1002 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1003 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1003 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1004 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1005 |
|
if (r.d[0] & 0xffff) |
1006 |
< |
return r.d[0]; |
1006 |
> |
return (int16)r.d[0]; |
1007 |
|
|
1008 |
|
// Post diskInsertEvent |
1009 |
|
D(bug(" posting diskInsertEvent\n")); |
1027 |
|
r.a[0] = vcb; |
1028 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1029 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1030 |
< |
return r.d[0]; |
1030 |
> |
return (int16)r.d[0]; |
1031 |
|
} |
1032 |
|
|
1033 |
|
// Get information about a volume (HVolumeParam) |
1038 |
|
// Fill in struct |
1039 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1040 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1041 |
< |
#ifdef __BEOS__ |
1041 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1042 |
|
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1043 |
|
#else |
1044 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1049 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1050 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1051 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1052 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1053 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1052 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1053 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1054 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1055 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1056 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1083 |
|
// D(bug(" fs_get_vol_parms(%08lx)\n", pb)); |
1084 |
|
|
1085 |
|
// 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); |
1086 |
|
uint32 actual = ReadMacInt32(pb + ioReqCount); |
1087 |
< |
if (actual > sizeof(vol)) |
1088 |
< |
actual = sizeof(vol); |
1076 |
< |
Host2Mac_memcpy(ReadMacInt32(pb + ioBuffer), vol, actual); |
1087 |
> |
if (actual > SIZEOF_GetVolParmsInfoBuffer) |
1088 |
> |
actual = SIZEOF_GetVolParmsInfoBuffer; |
1089 |
|
WriteMacInt32(pb + ioActCount, actual); |
1090 |
+ |
uint32 p = ReadMacInt32(pb + ioBuffer); |
1091 |
+ |
if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2); |
1092 |
+ |
if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol); |
1093 |
+ |
if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0); |
1094 |
+ |
if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0); |
1095 |
+ |
if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0); |
1096 |
+ |
if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0); |
1097 |
|
return noErr; |
1098 |
|
} |
1099 |
|
|
1108 |
|
r.a[0] = pb; |
1109 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1110 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1111 |
< |
return r.d[0]; |
1111 |
> |
return (int16)r.d[0]; |
1112 |
|
} |
1113 |
|
|
1114 |
|
// Set default volume (WDParam) |
1164 |
|
r.d[2] = refNum; |
1165 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1166 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1167 |
< |
return r.d[0]; |
1167 |
> |
return (int16)r.d[0]; |
1168 |
|
} |
1169 |
|
|
1170 |
|
// Query file attributes (HFileParam) |
1230 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1231 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1232 |
|
|
1233 |
< |
#ifdef __BEOS__ |
1233 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1234 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1235 |
|
#else |
1236 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1237 |
|
#endif |
1238 |
|
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1239 |
|
|
1240 |
< |
Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo); |
1222 |
< |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1223 |
< |
get_finder_type(full_path, type, creator); |
1224 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1225 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1226 |
< |
uint16 fflags; |
1227 |
< |
get_finder_flags(full_path, fflags); |
1228 |
< |
WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags); |
1240 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1241 |
|
|
1242 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1243 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1244 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1244 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1245 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1246 |
|
uint32 rf_size = get_rfork_size(full_path); |
1247 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1248 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1248 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1249 |
|
|
1250 |
|
if (hfs) { |
1251 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1240 |
– |
Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); |
1252 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1253 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1254 |
|
} |
1273 |
|
if (S_ISDIR(st.st_mode)) |
1274 |
|
return fnfErr; |
1275 |
|
|
1276 |
< |
// Set attributes |
1277 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1278 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1276 |
> |
// Set Finder info |
1277 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1278 |
> |
|
1279 |
|
//!! times |
1280 |
|
return noErr; |
1281 |
|
} |
1352 |
|
WriteMacInt8(pb + ioACUser, 0); |
1353 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1354 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1355 |
< |
#ifdef __BEOS__ |
1355 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1356 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1357 |
|
#else |
1358 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1365 |
|
} |
1366 |
|
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); |
1367 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1368 |
+ |
|
1369 |
+ |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1370 |
+ |
|
1371 |
|
if (S_ISDIR(st.st_mode)) { |
1358 |
– |
Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo); |
1359 |
– |
Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo); |
1360 |
– |
uint16 fflags; // pb may point to kernel space, but stack is switched |
1361 |
– |
get_finder_flags(full_path, fflags); |
1362 |
– |
WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags); |
1372 |
|
|
1373 |
|
// Determine number of files in directory (cached) |
1374 |
|
int count; |
1393 |
|
} |
1394 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1395 |
|
} else { |
1387 |
– |
Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo); |
1388 |
– |
Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); |
1389 |
– |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1390 |
– |
get_finder_type(full_path, type, creator); |
1391 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1392 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1393 |
– |
uint16 fflags; |
1394 |
– |
get_finder_flags(full_path, fflags); |
1395 |
– |
WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags); |
1396 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1397 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1398 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1398 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1399 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1400 |
|
uint32 rf_size = get_rfork_size(full_path); |
1401 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1402 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1402 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1403 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1404 |
|
} |
1405 |
|
return noErr; |
1421 |
|
if (stat(full_path, &st) < 0) |
1422 |
|
return errno2oserr(); |
1423 |
|
|
1424 |
< |
// Set attributes |
1425 |
< |
if (S_ISDIR(st.st_mode)) |
1426 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags)); |
1427 |
< |
else { |
1428 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1429 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1430 |
< |
} |
1424 |
> |
// Set Finder info |
1425 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1426 |
> |
|
1427 |
|
//!! times |
1428 |
|
return noErr; |
1429 |
|
} |
1470 |
|
if (access(full_path, F_OK)) |
1471 |
|
return fnfErr; |
1472 |
|
fd = open_rfork(full_path, flag); |
1473 |
< |
if (fd > 0) { |
1474 |
< |
if (fstat(fd, &st) < 0) |
1473 |
> |
if (fd >= 0) { |
1474 |
> |
if (fstat(fd, &st) < 0) { |
1475 |
> |
close(fd); |
1476 |
|
return errno2oserr(); |
1477 |
+ |
} |
1478 |
|
} else { // Resource fork not supported, silently ignore it ("pseudo" resource fork) |
1479 |
|
st.st_size = 0; |
1480 |
|
st.st_mode = 0; |
1483 |
|
fd = open(full_path, flag); |
1484 |
|
if (fd < 0) |
1485 |
|
return errno2oserr(); |
1486 |
< |
if (fstat(fd, &st) < 0) |
1486 |
> |
if (fstat(fd, &st) < 0) { |
1487 |
> |
close(fd); |
1488 |
|
return errno2oserr(); |
1489 |
+ |
} |
1490 |
|
} |
1491 |
|
|
1492 |
|
// File open, allocate FCB |
1498 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1499 |
|
if (r.d[0] & 0xffff) { |
1500 |
|
close(fd); |
1501 |
< |
return r.d[0]; |
1501 |
> |
return (int16)r.d[0]; |
1502 |
|
} |
1503 |
|
|
1504 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1505 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1506 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1507 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1508 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1508 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1509 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1510 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1511 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1512 |
< |
uint32 type, creator; // fcb may point to kernel space, but stack is switched |
1513 |
< |
get_finder_type(full_path, type, creator); |
1514 |
< |
WriteMacInt32(fcb + fcbFType, type); |
1511 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1512 |
> |
|
1513 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1514 |
> |
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1515 |
> |
|
1516 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1517 |
|
WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); |
1518 |
|
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); |
1549 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1550 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1551 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1552 |
< |
return r.d[0]; |
1552 |
> |
return (int16)r.d[0]; |
1553 |
|
} |
1554 |
|
|
1555 |
|
// Query information about FCB (FCBPBRec) |
1568 |
|
|
1569 |
|
// Find FCB by index |
1570 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1571 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1571 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1572 |
|
D(bug(" indexing FCBs\n")); |
1573 |
|
r.a[0] = vcb; |
1574 |
|
r.a[1] = pb + ioRefNum; |
1577 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1578 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1579 |
|
if (r.d[0] & 0xffff) |
1580 |
< |
return r.d[0]; |
1580 |
> |
return (int16)r.d[0]; |
1581 |
|
} |
1582 |
|
} |
1583 |
|
if (fcb == 0) |
1625 |
|
|
1626 |
|
// Adjust FCBs |
1627 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1628 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1628 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1629 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1630 |
|
D(bug(" adjusting FCBs\n")); |
1631 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1660 |
|
|
1661 |
|
// Adjust FCBs |
1662 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1663 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1663 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1664 |
|
D(bug(" adjusting FCBs\n")); |
1665 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1666 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1745 |
|
{ |
1746 |
|
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))); |
1747 |
|
|
1748 |
+ |
// Check parameters |
1749 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1750 |
+ |
return paramErr; |
1751 |
+ |
|
1752 |
|
// Find FCB and fd for file |
1753 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1754 |
|
if (fcb == 0) |
1780 |
|
} |
1781 |
|
|
1782 |
|
// Read |
1783 |
< |
size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1783 |
> |
ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1784 |
|
int16 read_err = errno2oserr(); |
1785 |
|
D(bug(" actual %d\n", actual)); |
1786 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1786 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1787 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1788 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1789 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1790 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1791 |
< |
return read_err ? read_err : eofErr; |
1790 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1791 |
> |
return actual < 0 ? read_err : eofErr; |
1792 |
|
else |
1793 |
|
return noErr; |
1794 |
|
} |
1798 |
|
{ |
1799 |
|
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))); |
1800 |
|
|
1801 |
+ |
// Check parameters |
1802 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1803 |
+ |
return paramErr; |
1804 |
+ |
|
1805 |
|
// Find FCB and fd for file |
1806 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1807 |
|
if (fcb == 0) |
1833 |
|
} |
1834 |
|
|
1835 |
|
// Write |
1836 |
< |
size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1836 |
> |
ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1837 |
|
int16 write_err = errno2oserr(); |
1838 |
|
D(bug(" actual %d\n", actual)); |
1839 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1839 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1840 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1841 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1842 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1843 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1843 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1844 |
|
return write_err; |
1845 |
|
else |
1846 |
|
return noErr; |
1942 |
|
|
1943 |
|
// Rename item |
1944 |
|
D(bug(" renaming %s -> %s\n", old_path, full_path)); |
1945 |
< |
if (rename(old_path, full_path) < 0) |
1945 |
> |
if (!extfs_rename(old_path, full_path)) |
1946 |
|
return errno2oserr(); |
1947 |
|
else { |
1948 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1949 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1950 |
|
uint32 t = fs_item->id; |
1951 |
|
fs_item->id = new_item->id; |
1952 |
|
new_item->id = t; |
1986 |
|
|
1987 |
|
// Move item |
1988 |
|
D(bug(" moving %s -> %s\n", old_path, full_path)); |
1989 |
< |
if (rename(old_path, full_path) < 0) |
1989 |
> |
if (!extfs_rename(old_path, full_path)) |
1990 |
|
return errno2oserr(); |
1991 |
|
else { |
1992 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1993 |
|
FSItem *new_item = find_fsitem(fs_item->name, new_dir_item); |
1994 |
|
if (new_item) { |
1995 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1996 |
|
uint32 t = fs_item->id; |
1997 |
|
fs_item->id = new_item->id; |
1998 |
|
new_item->id = t; |
2012 |
|
r.a[0] = pb; |
2013 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2014 |
|
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2015 |
< |
return r.d[0]; |
2015 |
> |
return (int16)r.d[0]; |
2016 |
|
} |
2017 |
|
|
2018 |
|
// Close working directory (WDParam) |
2026 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2027 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2028 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2029 |
< |
return r.d[0]; |
2029 |
> |
return (int16)r.d[0]; |
2030 |
|
} |
2031 |
|
|
2032 |
|
// Query information about working directory (WDParam) |
2055 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2056 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2057 |
|
if (r.d[0] & 0xffff) |
2058 |
< |
return r.d[0]; |
2058 |
> |
return (int16)r.d[0]; |
2059 |
|
|
2060 |
|
// Return information |
2061 |
|
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |