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-2005 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 |
+ |
#if defined __APPLE__ && defined __MACH__ |
52 |
+ |
#include <sys/attr.h> |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
#include "cpu_emulation.h" |
49 |
– |
#include "macos_util.h" |
56 |
|
#include "emul_op.h" |
57 |
|
#include "main.h" |
58 |
|
#include "disk.h" |
61 |
|
#include "extfs.h" |
62 |
|
#include "extfs_defs.h" |
63 |
|
|
64 |
+ |
#ifdef WIN32 |
65 |
+ |
# include "posix_emu.h" |
66 |
+ |
#endif |
67 |
+ |
|
68 |
|
#define DEBUG 0 |
69 |
|
#include "debug.h" |
70 |
|
|
75 |
|
fsHFSProcStub = 6, |
76 |
|
fsDrvStatus = 12, // Drive Status record |
77 |
|
fsFSD = 42, // File system descriptor |
78 |
< |
fsPB = 238, // IOParam (for mounting and renaming) |
78 |
> |
fsPB = 238, // IOParam (for mounting and renaming), also used for temporary storage |
79 |
|
fsVMI = 288, // VoumeMountInfoHeader (for mounting) |
80 |
|
fsParseRec = 296, // ParsePathRec struct |
81 |
|
fsReturn = 306, // Area for return data of 68k routines |
111 |
|
static struct stat root_stat; |
112 |
|
|
113 |
|
// File system ID/media type |
114 |
< |
const int16 MY_FSID = 'ba'; |
115 |
< |
const uint32 MY_MEDIA_TYPE = 'basi'; |
114 |
> |
const int16 MY_FSID = EMULATOR_ID_2; |
115 |
> |
const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4; |
116 |
|
|
117 |
|
// CNID of root and root's parent |
118 |
|
const uint32 ROOT_ID = 2; |
121 |
|
// File system stack size |
122 |
|
const int STACK_SIZE = 0x10000; |
123 |
|
|
124 |
+ |
// Allocation block and clump size as reported to MacOS (these are of course |
125 |
+ |
// not the real values and have no meaning on the host OS) |
126 |
+ |
const int AL_BLK_SIZE = 0x4000; |
127 |
+ |
const int CLUMP_SIZE = 0x4000; |
128 |
+ |
|
129 |
|
// Drive number of our pseudo-drive |
130 |
|
static int drive_number; |
131 |
|
|
169 |
|
|
170 |
|
|
171 |
|
/* |
172 |
+ |
* Get object creation time |
173 |
+ |
*/ |
174 |
+ |
|
175 |
+ |
#if defined __APPLE__ && defined __MACH__ |
176 |
+ |
struct crtimebuf { |
177 |
+ |
unsigned long length; |
178 |
+ |
struct timespec crtime; |
179 |
+ |
}; |
180 |
+ |
|
181 |
+ |
static uint32 do_get_creation_time(const char *path) |
182 |
+ |
{ |
183 |
+ |
struct attrlist attr; |
184 |
+ |
memset(&attr, 0, sizeof(attr)); |
185 |
+ |
attr.bitmapcount = ATTR_BIT_MAP_COUNT; |
186 |
+ |
attr.commonattr = ATTR_CMN_CRTIME; |
187 |
+ |
|
188 |
+ |
crtimebuf buf; |
189 |
+ |
if (getattrlist(path, &attr, &buf, sizeof(buf), FSOPT_NOFOLLOW) < 0) |
190 |
+ |
return 0; |
191 |
+ |
return TimeToMacTime(buf.crtime.tv_sec); |
192 |
+ |
} |
193 |
+ |
|
194 |
+ |
static uint32 get_creation_time(const char *path) |
195 |
+ |
{ |
196 |
+ |
if (path == NULL) |
197 |
+ |
return 0; |
198 |
+ |
if (path == RootPath) { |
199 |
+ |
static uint32 root_crtime = UINT_MAX; |
200 |
+ |
if (root_crtime == UINT_MAX) |
201 |
+ |
root_crtime = do_get_creation_time(path); |
202 |
+ |
return root_crtime; |
203 |
+ |
} |
204 |
+ |
return do_get_creation_time(path); |
205 |
+ |
} |
206 |
+ |
#endif |
207 |
+ |
|
208 |
+ |
|
209 |
+ |
/* |
210 |
|
* Find FSItem for given CNID |
211 |
|
*/ |
212 |
|
|
310 |
|
*dst++ = strlen(src); |
311 |
|
char c; |
312 |
|
while ((c = *src++) != 0) { |
313 |
+ |
// Note: we are converting host ':' characters to Mac '/' characters here |
314 |
+ |
// '/' is not a path separator as this function is only used on object names |
315 |
|
if (c == ':') |
316 |
|
c = '/'; |
317 |
|
*dst++ = c; |
318 |
|
} |
319 |
|
} |
320 |
|
|
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 |
– |
|
321 |
|
// Convert string (no length byte) to C string, length given separately |
322 |
|
static void strn2cstr(char *dst, const char *src, int size) |
323 |
|
{ |
324 |
|
while (size--) { |
325 |
|
char c = *src++; |
326 |
+ |
// Note: we are converting Mac '/' characters to host ':' characters here |
327 |
+ |
// '/' is not a path separator as this function is only used on object names |
328 |
|
if (c == '/') |
329 |
|
c = ':'; |
330 |
|
*dst++ = c; |
400 |
|
p->parent_id = ROOT_PARENT_ID; |
401 |
|
p->parent = first_fs_item; |
402 |
|
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
403 |
+ |
p->name[31] = 0; |
404 |
|
|
405 |
|
// Find path for root |
406 |
|
if ((RootPath = PrefsFindString("extfs")) != NULL) { |
449 |
|
// FSM present? |
450 |
|
r.d[0] = gestaltFSAttr; |
451 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
452 |
< |
D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); |
452 |
> |
D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); |
453 |
|
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { |
454 |
|
printf("WARNING: No FSM present, disabling ExtFS\n"); |
455 |
|
return; |
458 |
|
// Yes, version >=1.2? |
459 |
|
r.d[0] = gestaltFSMVersion; |
460 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
461 |
< |
D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); |
461 |
> |
D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); |
462 |
|
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { |
463 |
|
printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); |
464 |
|
return; |
728 |
|
} |
729 |
|
|
730 |
|
case ffsIDDiskMessage: { // Check if volume is handled by our FS |
731 |
< |
if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
731 |
> |
if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
732 |
|
return noErr; |
733 |
|
else |
734 |
|
return extFSErr; |
772 |
|
if (no_vol_name) |
773 |
|
WriteMacInt32(pb + ioNamePtr, name_ptr); |
774 |
|
int16 status = ReadMacInt16(fs_data + fsReturn); |
730 |
– |
int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); |
731 |
– |
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
732 |
– |
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
775 |
|
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
776 |
< |
result = r.d[0] & 0xffff; |
776 |
> |
result = (int16)(r.d[0] & 0xffff); |
777 |
|
|
778 |
|
if (result == noErr) { |
779 |
|
switch (status) { |
798 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
799 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
800 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
801 |
< |
result = r.d[0] & 0xffff; |
801 |
> |
result = (int16)(r.d[0] & 0xffff); |
802 |
|
if (result == noErr) |
803 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
804 |
|
} |
814 |
|
r.a[0] = wdpb; |
815 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
816 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
817 |
< |
result = r.d[0] & 0xffff; |
817 |
> |
result = (int16)(r.d[0] & 0xffff); |
818 |
|
if (result == noErr) |
819 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
820 |
|
} |
840 |
|
r.a[0] = rec; |
841 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
842 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
843 |
< |
return r.d[0] & 0xffff; |
843 |
> |
return (int16)(r.d[0] & 0xffff); |
844 |
|
} |
845 |
|
|
846 |
|
|
876 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
877 |
|
Execute68k(fs_data + fsParsePathname, &r); |
878 |
|
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
879 |
< |
result = r.d[0] & 0xffff; |
879 |
> |
result = (int16)(r.d[0] & 0xffff); |
880 |
|
if (result == noErr) { |
881 |
|
|
882 |
|
// Check for leading delimiter of the partial pathname |
989 |
|
static int16 fs_mount_vol(uint32 pb) |
990 |
|
{ |
991 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
992 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
992 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
993 |
|
return noErr; |
994 |
|
else |
995 |
|
return extFSErr; |
1006 |
|
r.a[0] = fs_data + fsReturn; |
1007 |
|
r.a[1] = fs_data + fsReturn + 2; |
1008 |
|
Execute68k(fs_data + fsAllocateVCB, &r); |
1009 |
+ |
#if DEBUG |
1010 |
|
uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn); |
1011 |
+ |
#endif |
1012 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
1013 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
1014 |
|
if (r.d[0] & 0xffff) |
1015 |
< |
return r.d[0]; |
1015 |
> |
return (int16)r.d[0]; |
1016 |
|
|
1017 |
|
// Init VCB |
1018 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
1019 |
< |
#ifdef __BEOS__ |
1020 |
< |
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
1019 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1020 |
> |
WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime)); |
1021 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1022 |
> |
WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath)); |
1023 |
|
#else |
1024 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
1025 |
|
#endif |
1026 |
< |
WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET); |
1026 |
> |
WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime)); |
1027 |
|
WriteMacInt32(vcb + vcbVolBkUp, 0); |
1028 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
1029 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
1030 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
1031 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
1032 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
1031 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
1032 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); |
1033 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
1034 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
1035 |
|
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
1043 |
|
r.a[0] = fs_data + fsReturn; |
1044 |
|
r.a[1] = vcb; |
1045 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1046 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1046 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1047 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1048 |
|
if (r.d[0] & 0xffff) |
1049 |
< |
return r.d[0]; |
1049 |
> |
return (int16)r.d[0]; |
1050 |
|
|
1051 |
|
// Post diskInsertEvent |
1052 |
|
D(bug(" posting diskInsertEvent\n")); |
1070 |
|
r.a[0] = vcb; |
1071 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1072 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1073 |
< |
return r.d[0]; |
1073 |
> |
return (int16)r.d[0]; |
1074 |
|
} |
1075 |
|
|
1076 |
|
// Get information about a volume (HVolumeParam) |
1081 |
|
// Fill in struct |
1082 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1083 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1084 |
< |
#ifdef __BEOS__ |
1085 |
< |
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1084 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1085 |
> |
WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime)); |
1086 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1087 |
> |
WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath)); |
1088 |
|
#else |
1089 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1090 |
|
#endif |
1091 |
< |
WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET); |
1091 |
> |
WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime)); |
1092 |
|
WriteMacInt16(pb + ioVAtrb, 0); |
1093 |
|
WriteMacInt16(pb + ioVNmFls, 1); //!! |
1094 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1095 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1096 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1097 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1098 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1097 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1098 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1099 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1100 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1101 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1153 |
|
r.a[0] = pb; |
1154 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1155 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1156 |
< |
return r.d[0]; |
1156 |
> |
return (int16)r.d[0]; |
1157 |
|
} |
1158 |
|
|
1159 |
|
// Set default volume (WDParam) |
1209 |
|
r.d[2] = refNum; |
1210 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1211 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1212 |
< |
return r.d[0]; |
1212 |
> |
return (int16)r.d[0]; |
1213 |
|
} |
1214 |
|
|
1215 |
|
// Query file attributes (HFileParam) |
1275 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1276 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1277 |
|
|
1278 |
< |
#ifdef __BEOS__ |
1279 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1278 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1279 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1280 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1281 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1282 |
|
#else |
1283 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1284 |
|
#endif |
1285 |
< |
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1285 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime)); |
1286 |
|
|
1287 |
< |
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); |
1287 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1288 |
|
|
1289 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1290 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1291 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1291 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1292 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1293 |
|
uint32 rf_size = get_rfork_size(full_path); |
1294 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1295 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1295 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1296 |
|
|
1297 |
|
if (hfs) { |
1298 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1256 |
– |
Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); |
1299 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1300 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1301 |
|
} |
1320 |
|
if (S_ISDIR(st.st_mode)) |
1321 |
|
return fnfErr; |
1322 |
|
|
1323 |
< |
// Set attributes |
1324 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1325 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1323 |
> |
// Set Finder info |
1324 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1325 |
> |
|
1326 |
|
//!! times |
1327 |
|
return noErr; |
1328 |
|
} |
1399 |
|
WriteMacInt8(pb + ioACUser, 0); |
1400 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1401 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1402 |
< |
#ifdef __BEOS__ |
1403 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1402 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1403 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1404 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1405 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1406 |
|
#else |
1407 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1408 |
|
#endif |
1412 |
|
fs_item->mtime = mtime; |
1413 |
|
cached = false; |
1414 |
|
} |
1415 |
< |
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); |
1415 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime)); |
1416 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1417 |
+ |
|
1418 |
+ |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1419 |
+ |
|
1420 |
|
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); |
1421 |
|
|
1422 |
|
// Determine number of files in directory (cached) |
1423 |
|
int count; |
1442 |
|
} |
1443 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1444 |
|
} 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); |
1445 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1446 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1447 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1447 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1448 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1449 |
|
uint32 rf_size = get_rfork_size(full_path); |
1450 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1451 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1451 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1452 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1453 |
|
} |
1454 |
|
return noErr; |
1470 |
|
if (stat(full_path, &st) < 0) |
1471 |
|
return errno2oserr(); |
1472 |
|
|
1473 |
< |
// Set attributes |
1474 |
< |
if (S_ISDIR(st.st_mode)) |
1475 |
< |
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 |
< |
} |
1473 |
> |
// Set Finder info |
1474 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1475 |
> |
|
1476 |
|
//!! times |
1477 |
|
return noErr; |
1478 |
|
} |
1519 |
|
if (access(full_path, F_OK)) |
1520 |
|
return fnfErr; |
1521 |
|
fd = open_rfork(full_path, flag); |
1522 |
< |
if (fd > 0) { |
1522 |
> |
if (fd >= 0) { |
1523 |
|
if (fstat(fd, &st) < 0) { |
1524 |
|
close(fd); |
1525 |
|
return errno2oserr(); |
1547 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1548 |
|
if (r.d[0] & 0xffff) { |
1549 |
|
close(fd); |
1550 |
< |
return r.d[0]; |
1550 |
> |
return (int16)r.d[0]; |
1551 |
|
} |
1552 |
|
|
1553 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1554 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1555 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1556 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1557 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1557 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1558 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1559 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1560 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1561 |
< |
uint32 type, creator; // BeOS: fcb may point to kernel space, but stack is switched |
1562 |
< |
get_finder_type(full_path, type, creator); |
1563 |
< |
WriteMacInt32(fcb + fcbFType, type); |
1560 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1561 |
> |
|
1562 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1563 |
> |
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1564 |
> |
|
1565 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1566 |
|
WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); |
1567 |
|
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); |
1598 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1599 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1600 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1601 |
< |
return r.d[0]; |
1601 |
> |
return (int16)r.d[0]; |
1602 |
|
} |
1603 |
|
|
1604 |
|
// Query information about FCB (FCBPBRec) |
1617 |
|
|
1618 |
|
// Find FCB by index |
1619 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1620 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1620 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1621 |
|
D(bug(" indexing FCBs\n")); |
1622 |
|
r.a[0] = vcb; |
1623 |
|
r.a[1] = pb + ioRefNum; |
1626 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1627 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1628 |
|
if (r.d[0] & 0xffff) |
1629 |
< |
return r.d[0]; |
1629 |
> |
return (int16)r.d[0]; |
1630 |
|
} |
1631 |
|
} |
1632 |
|
if (fcb == 0) |
1674 |
|
|
1675 |
|
// Adjust FCBs |
1676 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1677 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1677 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1678 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1679 |
|
D(bug(" adjusting FCBs\n")); |
1680 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1709 |
|
|
1710 |
|
// Adjust FCBs |
1711 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1712 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1712 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1713 |
|
D(bug(" adjusting FCBs\n")); |
1714 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1715 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1794 |
|
{ |
1795 |
|
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))); |
1796 |
|
|
1797 |
+ |
// Check parameters |
1798 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1799 |
+ |
return paramErr; |
1800 |
+ |
|
1801 |
|
// Find FCB and fd for file |
1802 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1803 |
|
if (fcb == 0) |
1836 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1837 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1838 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1839 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1839 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1840 |
|
return actual < 0 ? read_err : eofErr; |
1841 |
|
else |
1842 |
|
return noErr; |
1847 |
|
{ |
1848 |
|
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))); |
1849 |
|
|
1850 |
+ |
// Check parameters |
1851 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1852 |
+ |
return paramErr; |
1853 |
+ |
|
1854 |
|
// Find FCB and fd for file |
1855 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1856 |
|
if (fcb == 0) |
1889 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1890 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1891 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1892 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1892 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1893 |
|
return write_err; |
1894 |
|
else |
1895 |
|
return noErr; |
2061 |
|
r.a[0] = pb; |
2062 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2063 |
|
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2064 |
< |
return r.d[0]; |
2064 |
> |
return (int16)r.d[0]; |
2065 |
|
} |
2066 |
|
|
2067 |
|
// Close working directory (WDParam) |
2075 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2076 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2077 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2078 |
< |
return r.d[0]; |
2078 |
> |
return (int16)r.d[0]; |
2079 |
|
} |
2080 |
|
|
2081 |
|
// Query information about working directory (WDParam) |
2104 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2105 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2106 |
|
if (r.d[0] & 0xffff) |
2107 |
< |
return r.d[0]; |
2107 |
> |
return (int16)r.d[0]; |
2108 |
|
|
2109 |
|
// Return information |
2110 |
|
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |