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-2000 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 |
|
|
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 |
|
|
266 |
– |
// Convert pascal string to C string |
267 |
– |
static void pstr2cstr(char *dst, const char *src) |
268 |
– |
{ |
269 |
– |
int size = *src++; |
270 |
– |
while (size--) { |
271 |
– |
char c = *src++; |
272 |
– |
if (c == '/') |
273 |
– |
c = ':'; |
274 |
– |
*dst++ = c; |
275 |
– |
} |
276 |
– |
*dst = 0; |
277 |
– |
} |
278 |
– |
|
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); //!! |
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); |
1238 |
< |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1239 |
< |
get_finder_type(full_path, type, creator); |
1240 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1241 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1242 |
< |
uint16 fflags; |
1243 |
< |
get_finder_flags(full_path, fflags); |
1244 |
< |
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); |
1256 |
– |
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)) { |
1374 |
– |
Mac_memset(pb + ioDrUsrWds, 0, SIZEOF_DInfo); |
1375 |
– |
Mac_memset(pb + ioDrFndrInfo, 0, SIZEOF_DXInfo); |
1376 |
– |
uint16 fflags; // pb may point to kernel space, but stack is switched |
1377 |
– |
get_finder_flags(full_path, fflags); |
1378 |
– |
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 { |
1403 |
– |
Mac_memset(pb + ioFlFndrInfo, 0, SIZEOF_FInfo); |
1404 |
– |
Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); |
1405 |
– |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1406 |
– |
get_finder_type(full_path, type, creator); |
1407 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1408 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1409 |
– |
uint16 fflags; |
1410 |
– |
get_finder_flags(full_path, fflags); |
1411 |
– |
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)); |
1443 |
< |
else { |
1444 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1445 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1446 |
< |
} |
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) { |
1473 |
> |
if (fd >= 0) { |
1474 |
|
if (fstat(fd, &st) < 0) { |
1475 |
|
close(fd); |
1476 |
|
return errno2oserr(); |
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; // BeOS: 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) |
1787 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1788 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1789 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1790 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1790 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1791 |
|
return actual < 0 ? read_err : eofErr; |
1792 |
|
else |
1793 |
|
return noErr; |
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) |
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; |
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)); |