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-2008 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 |
|
|
158 |
|
uint32 id; // CNID of this file/dir |
159 |
|
uint32 parent_id; // CNID of parent file/dir |
160 |
|
FSItem *parent; // Pointer to parent |
161 |
< |
char name[32]; // Object name (C string) |
161 |
> |
char *name; // Object name (C string) - Host OS |
162 |
> |
char guest_name[32]; // Object name (C string) - Guest OS |
163 |
|
time_t mtime; // Modification time for get_cat_info caching |
164 |
|
int cache_dircount; // Cached number of files in directory |
165 |
|
}; |
170 |
|
|
171 |
|
|
172 |
|
/* |
173 |
+ |
* Get object creation time |
174 |
+ |
*/ |
175 |
+ |
|
176 |
+ |
#if defined __APPLE__ && defined __MACH__ |
177 |
+ |
struct crtimebuf { |
178 |
+ |
unsigned long length; |
179 |
+ |
struct timespec crtime; |
180 |
+ |
}; |
181 |
+ |
|
182 |
+ |
static uint32 do_get_creation_time(const char *path) |
183 |
+ |
{ |
184 |
+ |
struct attrlist attr; |
185 |
+ |
memset(&attr, 0, sizeof(attr)); |
186 |
+ |
attr.bitmapcount = ATTR_BIT_MAP_COUNT; |
187 |
+ |
attr.commonattr = ATTR_CMN_CRTIME; |
188 |
+ |
|
189 |
+ |
crtimebuf buf; |
190 |
+ |
if (getattrlist(path, &attr, &buf, sizeof(buf), FSOPT_NOFOLLOW) < 0) |
191 |
+ |
return 0; |
192 |
+ |
return TimeToMacTime(buf.crtime.tv_sec); |
193 |
+ |
} |
194 |
+ |
|
195 |
+ |
static uint32 get_creation_time(const char *path) |
196 |
+ |
{ |
197 |
+ |
if (path == NULL) |
198 |
+ |
return 0; |
199 |
+ |
if (path == RootPath) { |
200 |
+ |
static uint32 root_crtime = UINT_MAX; |
201 |
+ |
if (root_crtime == UINT_MAX) |
202 |
+ |
root_crtime = do_get_creation_time(path); |
203 |
+ |
return root_crtime; |
204 |
+ |
} |
205 |
+ |
return do_get_creation_time(path); |
206 |
+ |
} |
207 |
+ |
#endif |
208 |
+ |
|
209 |
+ |
|
210 |
+ |
/* |
211 |
|
* Find FSItem for given CNID |
212 |
|
*/ |
213 |
|
|
222 |
|
return NULL; |
223 |
|
} |
224 |
|
|
225 |
+ |
/* |
226 |
+ |
* Create FSItem with the given parameters |
227 |
+ |
*/ |
228 |
+ |
|
229 |
+ |
static FSItem *create_fsitem(const char *name, const char *guest_name, FSItem *parent) |
230 |
+ |
{ |
231 |
+ |
FSItem *p = new FSItem; |
232 |
+ |
last_fs_item->next = p; |
233 |
+ |
p->next = NULL; |
234 |
+ |
last_fs_item = p; |
235 |
+ |
p->id = next_cnid++; |
236 |
+ |
p->parent_id = parent->id; |
237 |
+ |
p->parent = parent; |
238 |
+ |
p->name = new char[strlen(name) + 1]; |
239 |
+ |
strcpy(p->name, name); |
240 |
+ |
strncpy(p->guest_name, guest_name, 31); |
241 |
+ |
p->guest_name[31] = 0; |
242 |
+ |
p->mtime = 0; |
243 |
+ |
return p; |
244 |
+ |
} |
245 |
|
|
246 |
|
/* |
247 |
|
* Find FSItem for given name and parent, construct new FSItem if not found |
257 |
|
} |
258 |
|
|
259 |
|
// Not found, construct new FSItem |
260 |
< |
p = new FSItem; |
187 |
< |
last_fs_item->next = p; |
188 |
< |
p->next = NULL; |
189 |
< |
last_fs_item = p; |
190 |
< |
p->id = next_cnid++; |
191 |
< |
p->parent_id = parent->id; |
192 |
< |
p->parent = parent; |
193 |
< |
strncpy(p->name, name, 31); |
194 |
< |
p->name[31] = 0; |
195 |
< |
p->mtime = 0; |
196 |
< |
return p; |
260 |
> |
return create_fsitem(name, host_encoding_to_macroman(name), parent); |
261 |
|
} |
262 |
|
|
263 |
+ |
/* |
264 |
+ |
* Find FSItem for given guest_name and parent, construct new FSItem if not found |
265 |
+ |
*/ |
266 |
+ |
|
267 |
+ |
static FSItem *find_fsitem_guest(const char *guest_name, FSItem *parent) |
268 |
+ |
{ |
269 |
+ |
FSItem *p = first_fs_item; |
270 |
+ |
while (p) { |
271 |
+ |
if (p->parent == parent && !strcmp(p->guest_name, guest_name)) |
272 |
+ |
return p; |
273 |
+ |
p = p->next; |
274 |
+ |
} |
275 |
+ |
|
276 |
+ |
// Not found, construct new FSItem |
277 |
+ |
return create_fsitem(macroman_to_host_encoding(guest_name), guest_name, parent); |
278 |
+ |
} |
279 |
|
|
280 |
|
/* |
281 |
|
* Get full path (->full_path) for given FSItem |
337 |
|
*dst++ = strlen(src); |
338 |
|
char c; |
339 |
|
while ((c = *src++) != 0) { |
340 |
+ |
// Note: we are converting host ':' characters to Mac '/' characters here |
341 |
+ |
// '/' is not a path separator as this function is only used on object names |
342 |
|
if (c == ':') |
343 |
|
c = '/'; |
344 |
|
*dst++ = c; |
345 |
|
} |
346 |
|
} |
347 |
|
|
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 |
– |
|
348 |
|
// Convert string (no length byte) to C string, length given separately |
349 |
|
static void strn2cstr(char *dst, const char *src, int size) |
350 |
|
{ |
351 |
|
while (size--) { |
352 |
|
char c = *src++; |
353 |
+ |
// Note: we are converting Mac '/' characters to host ':' characters here |
354 |
+ |
// '/' is not a path separator as this function is only used on object names |
355 |
|
if (c == '/') |
356 |
|
c = ':'; |
357 |
|
*dst++ = c; |
416 |
|
p->id = ROOT_PARENT_ID; |
417 |
|
p->parent_id = 0; |
418 |
|
p->parent = NULL; |
419 |
+ |
p->name = new char[1]; |
420 |
|
p->name[0] = 0; |
421 |
+ |
p->guest_name[0] = 0; |
422 |
|
|
423 |
|
// Create root FSItem |
424 |
|
p = new FSItem; |
428 |
|
p->id = ROOT_ID; |
429 |
|
p->parent_id = ROOT_PARENT_ID; |
430 |
|
p->parent = first_fs_item; |
431 |
< |
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
431 |
> |
const char *volume_name = GetString(STR_EXTFS_VOLUME_NAME); |
432 |
> |
p->name = new char[strlen(volume_name) + 1]; |
433 |
> |
strcpy(p->name, volume_name); |
434 |
> |
strncpy(p->guest_name, host_encoding_to_macroman(p->name), 32); |
435 |
> |
p->guest_name[31] = 0; |
436 |
|
|
437 |
|
// Find path for root |
438 |
|
if ((RootPath = PrefsFindString("extfs")) != NULL) { |
455 |
|
FSItem *p = first_fs_item, *next; |
456 |
|
while (p) { |
457 |
|
next = p->next; |
458 |
+ |
delete[] p->name; |
459 |
|
delete p; |
460 |
|
p = next; |
461 |
|
} |
482 |
|
// FSM present? |
483 |
|
r.d[0] = gestaltFSAttr; |
484 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
485 |
< |
D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); |
485 |
> |
D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); |
486 |
|
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { |
487 |
|
printf("WARNING: No FSM present, disabling ExtFS\n"); |
488 |
|
return; |
491 |
|
// Yes, version >=1.2? |
492 |
|
r.d[0] = gestaltFSMVersion; |
493 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
494 |
< |
D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); |
494 |
> |
D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); |
495 |
|
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { |
496 |
|
printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); |
497 |
|
return; |
761 |
|
} |
762 |
|
|
763 |
|
case ffsIDDiskMessage: { // Check if volume is handled by our FS |
764 |
< |
if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
764 |
> |
if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
765 |
|
return noErr; |
766 |
|
else |
767 |
|
return extFSErr; |
805 |
|
if (no_vol_name) |
806 |
|
WriteMacInt32(pb + ioNamePtr, name_ptr); |
807 |
|
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); |
808 |
|
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
809 |
< |
result = r.d[0] & 0xffff; |
809 |
> |
result = (int16)(r.d[0] & 0xffff); |
810 |
|
|
811 |
|
if (result == noErr) { |
812 |
|
switch (status) { |
831 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
832 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
833 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
834 |
< |
result = r.d[0] & 0xffff; |
834 |
> |
result = (int16)(r.d[0] & 0xffff); |
835 |
|
if (result == noErr) |
836 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
837 |
|
} |
847 |
|
r.a[0] = wdpb; |
848 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
849 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
850 |
< |
result = r.d[0] & 0xffff; |
850 |
> |
result = (int16)(r.d[0] & 0xffff); |
851 |
|
if (result == noErr) |
852 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
853 |
|
} |
873 |
|
r.a[0] = rec; |
874 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
875 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
876 |
< |
return r.d[0] & 0xffff; |
876 |
> |
return (int16)(r.d[0] & 0xffff); |
877 |
|
} |
878 |
|
|
879 |
|
|
909 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
910 |
|
Execute68k(fs_data + fsParsePathname, &r); |
911 |
|
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
912 |
< |
result = r.d[0] & 0xffff; |
912 |
> |
result = (int16)(r.d[0] & 0xffff); |
913 |
|
if (result == noErr) { |
914 |
|
|
915 |
|
// Check for leading delimiter of the partial pathname |
944 |
|
char name[32]; |
945 |
|
strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength)); |
946 |
|
D(bug(" entering %s\n", name)); |
947 |
< |
p = find_fsitem(name, p); |
947 |
> |
p = find_fsitem_guest(name, p); |
948 |
|
current_dir = p->id; |
949 |
|
|
950 |
|
// startOffset = start of next component |
967 |
|
char name[32]; |
968 |
|
strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength)); |
969 |
|
D(bug(" object is %s\n", name)); |
970 |
< |
item = find_fsitem(name, p); |
970 |
> |
item = find_fsitem_guest(name, p); |
971 |
|
} |
972 |
|
} |
973 |
|
} |
1022 |
|
static int16 fs_mount_vol(uint32 pb) |
1023 |
|
{ |
1024 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
1025 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
1025 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
1026 |
|
return noErr; |
1027 |
|
else |
1028 |
|
return extFSErr; |
1039 |
|
r.a[0] = fs_data + fsReturn; |
1040 |
|
r.a[1] = fs_data + fsReturn + 2; |
1041 |
|
Execute68k(fs_data + fsAllocateVCB, &r); |
1042 |
+ |
#if DEBUG |
1043 |
|
uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn); |
1044 |
+ |
#endif |
1045 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
1046 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
1047 |
|
if (r.d[0] & 0xffff) |
1048 |
< |
return r.d[0]; |
1048 |
> |
return (int16)r.d[0]; |
1049 |
|
|
1050 |
|
// Init VCB |
1051 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
1052 |
< |
#ifdef __BEOS__ |
1053 |
< |
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
1052 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1053 |
> |
WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime)); |
1054 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1055 |
> |
WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath)); |
1056 |
|
#else |
1057 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
1058 |
|
#endif |
1059 |
< |
WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET); |
1059 |
> |
WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime)); |
1060 |
|
WriteMacInt32(vcb + vcbVolBkUp, 0); |
1061 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
1062 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
1063 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
1064 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
1065 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
1064 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
1065 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); |
1066 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
1067 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
1068 |
|
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
1076 |
|
r.a[0] = fs_data + fsReturn; |
1077 |
|
r.a[1] = vcb; |
1078 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1079 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1079 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1080 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1081 |
|
if (r.d[0] & 0xffff) |
1082 |
< |
return r.d[0]; |
1082 |
> |
return (int16)r.d[0]; |
1083 |
|
|
1084 |
|
// Post diskInsertEvent |
1085 |
|
D(bug(" posting diskInsertEvent\n")); |
1103 |
|
r.a[0] = vcb; |
1104 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1105 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1106 |
< |
return r.d[0]; |
1106 |
> |
return (int16)r.d[0]; |
1107 |
|
} |
1108 |
|
|
1109 |
|
// Get information about a volume (HVolumeParam) |
1114 |
|
// Fill in struct |
1115 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1116 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1117 |
< |
#ifdef __BEOS__ |
1118 |
< |
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1117 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1118 |
> |
WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime)); |
1119 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1120 |
> |
WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath)); |
1121 |
|
#else |
1122 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1123 |
|
#endif |
1124 |
< |
WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET); |
1124 |
> |
WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime)); |
1125 |
|
WriteMacInt16(pb + ioVAtrb, 0); |
1126 |
|
WriteMacInt16(pb + ioVNmFls, 1); //!! |
1127 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1128 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1129 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1130 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1131 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1130 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1131 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1132 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1133 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1134 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1186 |
|
r.a[0] = pb; |
1187 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1188 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1189 |
< |
return r.d[0]; |
1189 |
> |
return (int16)r.d[0]; |
1190 |
|
} |
1191 |
|
|
1192 |
|
// Set default volume (WDParam) |
1242 |
|
r.d[2] = refNum; |
1243 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1244 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1245 |
< |
return r.d[0]; |
1245 |
> |
return (int16)r.d[0]; |
1246 |
|
} |
1247 |
|
|
1248 |
|
// Query file attributes (HFileParam) |
1303 |
|
|
1304 |
|
// Fill in struct from fs_item and stats |
1305 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1306 |
< |
cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name); |
1306 |
> |
cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name); |
1307 |
|
WriteMacInt16(pb + ioFRefNum, 0); |
1308 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1309 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1310 |
|
|
1311 |
< |
#ifdef __BEOS__ |
1312 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1311 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1312 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1313 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1314 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1315 |
|
#else |
1316 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1317 |
|
#endif |
1318 |
< |
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1318 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime)); |
1319 |
|
|
1320 |
< |
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); |
1320 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1321 |
|
|
1322 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1323 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1324 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1324 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1325 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1326 |
|
uint32 rf_size = get_rfork_size(full_path); |
1327 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1328 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1328 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1329 |
|
|
1330 |
|
if (hfs) { |
1331 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1256 |
– |
Mac_memset(pb + ioFlXFndrInfo, 0, SIZEOF_FXInfo); |
1332 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1333 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1334 |
|
} |
1353 |
|
if (S_ISDIR(st.st_mode)) |
1354 |
|
return fnfErr; |
1355 |
|
|
1356 |
< |
// Set attributes |
1357 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1358 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1356 |
> |
// Set Finder info |
1357 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1358 |
> |
|
1359 |
|
//!! times |
1360 |
|
return noErr; |
1361 |
|
} |
1426 |
|
|
1427 |
|
// Fill in struct from fs_item and stats |
1428 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1429 |
< |
cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name); |
1429 |
> |
cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name); |
1430 |
|
WriteMacInt16(pb + ioFRefNum, 0); |
1431 |
|
WriteMacInt8(pb + ioFlAttrib, (S_ISDIR(st.st_mode) ? faIsDir : 0) | (access(full_path, W_OK) == 0 ? 0 : faLocked)); |
1432 |
|
WriteMacInt8(pb + ioACUser, 0); |
1433 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1434 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1435 |
< |
#ifdef __BEOS__ |
1436 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1435 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1436 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1437 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1438 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1439 |
|
#else |
1440 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1441 |
|
#endif |
1445 |
|
fs_item->mtime = mtime; |
1446 |
|
cached = false; |
1447 |
|
} |
1448 |
< |
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); |
1448 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime)); |
1449 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1450 |
+ |
|
1451 |
+ |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1452 |
+ |
|
1453 |
|
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); |
1454 |
|
|
1455 |
|
// Determine number of files in directory (cached) |
1456 |
|
int count; |
1475 |
|
} |
1476 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1477 |
|
} 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); |
1478 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1479 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1480 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1480 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1481 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1482 |
|
uint32 rf_size = get_rfork_size(full_path); |
1483 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1484 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1484 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1485 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1486 |
|
} |
1487 |
|
return noErr; |
1503 |
|
if (stat(full_path, &st) < 0) |
1504 |
|
return errno2oserr(); |
1505 |
|
|
1506 |
< |
// Set attributes |
1507 |
< |
if (S_ISDIR(st.st_mode)) |
1508 |
< |
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 |
< |
} |
1506 |
> |
// Set Finder info |
1507 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1508 |
> |
|
1509 |
|
//!! times |
1510 |
|
return noErr; |
1511 |
|
} |
1552 |
|
if (access(full_path, F_OK)) |
1553 |
|
return fnfErr; |
1554 |
|
fd = open_rfork(full_path, flag); |
1555 |
< |
if (fd > 0) { |
1555 |
> |
if (fd >= 0) { |
1556 |
|
if (fstat(fd, &st) < 0) { |
1557 |
|
close(fd); |
1558 |
|
return errno2oserr(); |
1580 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1581 |
|
if (r.d[0] & 0xffff) { |
1582 |
|
close(fd); |
1583 |
< |
return r.d[0]; |
1583 |
> |
return (int16)r.d[0]; |
1584 |
|
} |
1585 |
|
|
1586 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1587 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1588 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1589 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1590 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1590 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1591 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1592 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1593 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1594 |
< |
uint32 type, creator; // BeOS: fcb may point to kernel space, but stack is switched |
1595 |
< |
get_finder_type(full_path, type, creator); |
1596 |
< |
WriteMacInt32(fcb + fcbFType, type); |
1593 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1594 |
> |
|
1595 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1596 |
> |
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1597 |
> |
|
1598 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1599 |
|
WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); |
1600 |
< |
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); |
1600 |
> |
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->guest_name); |
1601 |
|
return noErr; |
1602 |
|
} |
1603 |
|
|
1631 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1632 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1633 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1634 |
< |
return r.d[0]; |
1634 |
> |
return (int16)r.d[0]; |
1635 |
|
} |
1636 |
|
|
1637 |
|
// Query information about FCB (FCBPBRec) |
1650 |
|
|
1651 |
|
// Find FCB by index |
1652 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1653 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1653 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1654 |
|
D(bug(" indexing FCBs\n")); |
1655 |
|
r.a[0] = vcb; |
1656 |
|
r.a[1] = pb + ioRefNum; |
1659 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1660 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1661 |
|
if (r.d[0] & 0xffff) |
1662 |
< |
return r.d[0]; |
1662 |
> |
return (int16)r.d[0]; |
1663 |
|
} |
1664 |
|
} |
1665 |
|
if (fcb == 0) |
1707 |
|
|
1708 |
|
// Adjust FCBs |
1709 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1710 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1710 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1711 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1712 |
|
D(bug(" adjusting FCBs\n")); |
1713 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1742 |
|
|
1743 |
|
// Adjust FCBs |
1744 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1745 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1745 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1746 |
|
D(bug(" adjusting FCBs\n")); |
1747 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1748 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1827 |
|
{ |
1828 |
|
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))); |
1829 |
|
|
1830 |
+ |
// Check parameters |
1831 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1832 |
+ |
return paramErr; |
1833 |
+ |
|
1834 |
|
// Find FCB and fd for file |
1835 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1836 |
|
if (fcb == 0) |
1869 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1870 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1871 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1872 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1872 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1873 |
|
return actual < 0 ? read_err : eofErr; |
1874 |
|
else |
1875 |
|
return noErr; |
1880 |
|
{ |
1881 |
|
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))); |
1882 |
|
|
1883 |
+ |
// Check parameters |
1884 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1885 |
+ |
return paramErr; |
1886 |
+ |
|
1887 |
|
// Find FCB and fd for file |
1888 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1889 |
|
if (fcb == 0) |
1922 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1923 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1924 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1925 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1925 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1926 |
|
return write_err; |
1927 |
|
else |
1928 |
|
return noErr; |
2094 |
|
r.a[0] = pb; |
2095 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2096 |
|
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2097 |
< |
return r.d[0]; |
2097 |
> |
return (int16)r.d[0]; |
2098 |
|
} |
2099 |
|
|
2100 |
|
// Close working directory (WDParam) |
2108 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2109 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2110 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2111 |
< |
return r.d[0]; |
2111 |
> |
return (int16)r.d[0]; |
2112 |
|
} |
2113 |
|
|
2114 |
|
// Query information about working directory (WDParam) |
2137 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2138 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2139 |
|
if (r.d[0] & 0xffff) |
2140 |
< |
return r.d[0]; |
2140 |
> |
return (int16)r.d[0]; |
2141 |
|
|
2142 |
|
// Return information |
2143 |
|
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |