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-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 |
19 |
|
*/ |
20 |
|
|
21 |
|
/* |
22 |
< |
TODO: |
23 |
< |
LockRng |
24 |
< |
UnlockRng |
25 |
< |
(CatSearch) |
26 |
< |
(MakeFSSpec) |
27 |
< |
(GetVolMountInfoSize) |
28 |
< |
(GetVolMountInfo) |
29 |
< |
(GetForeignPrivs) |
30 |
< |
(SetForeignPrivs) |
31 |
< |
*/ |
22 |
> |
* SEE ALSO |
23 |
> |
* Guide to the File System Manager (from FSM 1.2 SDK) |
24 |
> |
* |
25 |
> |
* TODO |
26 |
> |
* LockRng |
27 |
> |
* UnlockRng |
28 |
> |
* (CatSearch) |
29 |
> |
* (MakeFSSpec) |
30 |
> |
* (GetVolMountInfoSize) |
31 |
> |
* (GetVolMountInfo) |
32 |
> |
* (GetForeignPrivs) |
33 |
> |
* (SetForeignPrivs) |
34 |
> |
*/ |
35 |
|
|
36 |
|
#include "sysdeps.h" |
37 |
|
|
40 |
|
#include <string.h> |
41 |
|
#include <stdio.h> |
42 |
|
#include <stdlib.h> |
40 |
– |
#include <unistd.h> |
43 |
|
#include <fcntl.h> |
42 |
– |
#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" |
46 |
– |
#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) |
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 |
82 |
|
fsAllocateVCB = 562, // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1}) |
83 |
|
fsAddNewVCB = 578, // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1}) |
84 |
|
fsDetermineVol = 594, // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4}) |
85 |
< |
fsResolveWDCB = 614, // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0}) |
85 |
> |
fsResolveWDCB = 614, // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0}) |
86 |
|
fsGetDefaultVol = 632, // UTGetDefaultVol(uint32 wdpb{a0}) |
87 |
|
fsGetPathComponentName = 644, // UTGetPathComponentName(uint32 rec{a0}) |
88 |
|
fsParsePathname = 656, // UTParsePathname(uint32 *start{a0}, uint32 name{a1}) |
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 |
|
|
254 |
|
* Get full path (->full_path) for given FSItem |
255 |
|
*/ |
256 |
|
|
201 |
– |
const int MAX_PATH_LENGTH = 1024; |
257 |
|
static char full_path[MAX_PATH_LENGTH]; |
258 |
|
|
259 |
< |
static void add_path_component(const char *s) |
259 |
> |
static void add_path_comp(const char *s) |
260 |
|
{ |
261 |
< |
int l = strlen(full_path); |
207 |
< |
if (l < MAX_PATH_LENGTH-1 && full_path[l-1] != '/') { |
208 |
< |
full_path[l] = '/'; |
209 |
< |
full_path[l+1] = 0; |
210 |
< |
} |
211 |
< |
strncat(full_path, s, MAX_PATH_LENGTH-1); |
261 |
> |
add_path_component(full_path, s); |
262 |
|
} |
263 |
|
|
264 |
|
static void get_path_for_fsitem(FSItem *p) |
265 |
|
{ |
266 |
< |
if (p->id == ROOT_ID) { |
266 |
> |
if (p->id == ROOT_PARENT_ID) { |
267 |
> |
full_path[0] = 0; |
268 |
> |
} else if (p->id == ROOT_ID) { |
269 |
|
strncpy(full_path, RootPath, MAX_PATH_LENGTH-1); |
270 |
|
full_path[MAX_PATH_LENGTH-1] = 0; |
271 |
|
} else { |
272 |
|
get_path_for_fsitem(p->parent); |
273 |
< |
add_path_component(p->name); |
273 |
> |
add_path_comp(p->name); |
274 |
> |
} |
275 |
> |
} |
276 |
> |
|
277 |
> |
|
278 |
> |
/* |
279 |
> |
* Exchange parent CNIDs in all FSItems |
280 |
> |
*/ |
281 |
> |
|
282 |
> |
static void swap_parent_ids(uint32 parent1, uint32 parent2) |
283 |
> |
{ |
284 |
> |
FSItem *p = first_fs_item; |
285 |
> |
while (p) { |
286 |
> |
if (p->parent_id == parent1) |
287 |
> |
p->parent_id = parent2; |
288 |
> |
else if (p->parent_id == parent2) |
289 |
> |
p->parent_id = parent1; |
290 |
> |
p = p->next; |
291 |
|
} |
292 |
|
} |
293 |
|
|
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 |
|
|
250 |
– |
// Convert pascal string to C string |
251 |
– |
static void pstr2cstr(char *dst, const char *src) |
252 |
– |
{ |
253 |
– |
int size = *src++; |
254 |
– |
while (size--) { |
255 |
– |
char c = *src++; |
256 |
– |
if (c == '/') |
257 |
– |
c = ':'; |
258 |
– |
*dst++ = c; |
259 |
– |
} |
260 |
– |
*dst = 0; |
261 |
– |
} |
262 |
– |
|
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; |
382 |
|
cstr2pstr(FS_NAME, GetString(STR_EXTFS_NAME)); |
383 |
|
cstr2pstr(VOLUME_NAME, GetString(STR_EXTFS_VOLUME_NAME)); |
384 |
|
|
385 |
< |
// Create root FSItem |
385 |
> |
// Create root's parent FSItem |
386 |
|
FSItem *p = new FSItem; |
387 |
|
first_fs_item = last_fs_item = p; |
388 |
|
p->next = NULL; |
389 |
+ |
p->id = ROOT_PARENT_ID; |
390 |
+ |
p->parent_id = 0; |
391 |
+ |
p->parent = NULL; |
392 |
+ |
p->name[0] = 0; |
393 |
+ |
|
394 |
+ |
// Create root FSItem |
395 |
+ |
p = new FSItem; |
396 |
+ |
last_fs_item->next = p; |
397 |
+ |
p->next = NULL; |
398 |
+ |
last_fs_item = p; |
399 |
|
p->id = ROOT_ID; |
400 |
|
p->parent_id = ROOT_PARENT_ID; |
401 |
< |
p->parent = NULL; |
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])); |
453 |
< |
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) |
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; |
456 |
+ |
} |
457 |
|
|
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])); |
462 |
< |
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) |
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; |
465 |
+ |
} |
466 |
|
|
467 |
|
D(bug("FSM present\n")); |
468 |
|
|
498 |
|
WriteMacInt16(p, 0x7006); p+= 2; // UTAllocateVCB |
499 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
500 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
501 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
501 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
502 |
|
if (p - fs_data != fsAddNewVCB) |
503 |
|
goto fsdat_error; |
504 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
508 |
|
WriteMacInt16(p, 0x7007); p+= 2; // UTAddNewVCB |
509 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
510 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
511 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
511 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
512 |
|
if (p - fs_data != fsDetermineVol) |
513 |
|
goto fsdat_error; |
514 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
520 |
|
WriteMacInt16(p, 0x701d); p+= 2; // UTDetermineVol |
521 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
522 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
523 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
523 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
524 |
|
if (p - fs_data != fsResolveWDCB) |
525 |
|
goto fsdat_error; |
526 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
527 |
< |
WriteMacInt16(p, 0x42a7); p+= 2; // clr.l -(sp) |
528 |
< |
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
529 |
< |
WriteMacInt16(p, 0x3f00); p+= 2; // move.w d0,-(sp) |
527 |
> |
WriteMacInt16(p, 0x2f00); p+= 2; // move.l d0,-(sp) |
528 |
> |
WriteMacInt16(p, 0x3f01); p+= 2; // move.w d1,-(sp) |
529 |
> |
WriteMacInt16(p, 0x3f02); p+= 2; // move.w d2,-(sp) |
530 |
|
WriteMacInt16(p, 0x2f08); p+= 2; // move.l a0,-(sp) |
531 |
|
WriteMacInt16(p, 0x700e); p+= 2; // UTResolveWDCB |
532 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
533 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
534 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
534 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
535 |
|
if (p - fs_data != fsGetDefaultVol) |
536 |
|
goto fsdat_error; |
537 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
539 |
|
WriteMacInt16(p, 0x7012); p+= 2; // UTGetDefaultVol |
540 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
541 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
542 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
542 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
543 |
|
if (p - fs_data != fsGetPathComponentName) |
544 |
|
goto fsdat_error; |
545 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
547 |
|
WriteMacInt16(p, 0x701c); p+= 2; // UTGetPathComponentName |
548 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
549 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
550 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
550 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
551 |
|
if (p - fs_data != fsParsePathname) |
552 |
|
goto fsdat_error; |
553 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
556 |
|
WriteMacInt16(p, 0x701b); p+= 2; // UTParsePathname |
557 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
558 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
559 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
559 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
560 |
|
if (p - fs_data != fsDisposeVCB) |
561 |
|
goto fsdat_error; |
562 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
564 |
|
WriteMacInt16(p, 0x7008); p+= 2; // UTDisposeVCB |
565 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
566 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
567 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
567 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
568 |
|
if (p - fs_data != fsCheckWDRefNum) |
569 |
|
goto fsdat_error; |
570 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
572 |
|
WriteMacInt16(p, 0x7013); p+= 2; // UTCheckWDRefNum |
573 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
574 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
575 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
575 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
576 |
|
if (p - fs_data != fsSetDefaultVol) |
577 |
|
goto fsdat_error; |
578 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
582 |
|
WriteMacInt16(p, 0x7011); p+= 2; // UTSetDefaultVol |
583 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
584 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
585 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
585 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
586 |
|
if (p - fs_data != fsAllocateFCB) |
587 |
|
goto fsdat_error; |
588 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
591 |
|
WriteMacInt16(p, 0x7000); p+= 2; // UTAllocateFCB |
592 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
593 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
594 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
594 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
595 |
|
if (p - fs_data != fsReleaseFCB) |
596 |
|
goto fsdat_error; |
597 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
599 |
|
WriteMacInt16(p, 0x7001); p+= 2; // UTReleaseFCB |
600 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
601 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
602 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
602 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
603 |
|
if (p - fs_data != fsIndexFCB) |
604 |
|
goto fsdat_error; |
605 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
609 |
|
WriteMacInt16(p, 0x7004); p+= 2; // UTIndexFCB |
610 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
611 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
612 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
612 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
613 |
|
if (p - fs_data != fsResolveFCB) |
614 |
|
goto fsdat_error; |
615 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
618 |
|
WriteMacInt16(p, 0x7005); p+= 2; // UTResolveFCB |
619 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
620 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
621 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
621 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
622 |
|
if (p - fs_data != fsAdjustEOF) |
623 |
|
goto fsdat_error; |
624 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
626 |
|
WriteMacInt16(p, 0x7010); p+= 2; // UTAdjustEOF |
627 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
628 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
629 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
629 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
630 |
|
if (p - fs_data != fsAllocateWDCB) |
631 |
|
goto fsdat_error; |
632 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
634 |
|
WriteMacInt16(p, 0x700c); p+= 2; // UTAllocateWDCB |
635 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
636 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
637 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
637 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
638 |
|
if (p - fs_data != fsReleaseWDCB) |
639 |
|
goto fsdat_error; |
640 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
642 |
|
WriteMacInt16(p, 0x700d); p+= 2; // UTReleaseWDCB |
643 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
644 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
645 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
645 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
646 |
|
if (p - fs_data != SIZEOF_fsdat) |
647 |
|
goto fsdat_error; |
648 |
|
|
666 |
|
WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec); |
667 |
|
WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1); |
668 |
|
WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID); |
669 |
< |
memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32); |
669 |
> |
Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32); |
670 |
|
WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub); |
671 |
|
WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub); |
672 |
|
WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE); |
720 |
|
|
721 |
|
case ffsGetIconMessage: { // Get disk/drive icon |
722 |
|
if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) { |
723 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon)); |
723 |
> |
Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon)); |
724 |
|
WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon)); |
725 |
|
return noErr; |
726 |
|
} else |
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; |
757 |
|
int16 result; |
758 |
|
|
759 |
|
// Determine volume |
760 |
< |
// D(bug(" determining volume\n")); |
760 |
> |
D(bug(" determining volume, dirID %d\n", dirID)); |
761 |
|
r.a[0] = pb; |
762 |
|
r.a[1] = fs_data + fsReturn; |
763 |
|
r.a[2] = fs_data + fsReturn + 2; |
772 |
|
if (no_vol_name) |
773 |
|
WriteMacInt32(pb + ioNamePtr, name_ptr); |
774 |
|
int16 status = ReadMacInt16(fs_data + fsReturn); |
775 |
< |
int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); |
776 |
< |
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
702 |
< |
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
703 |
< |
// D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
704 |
< |
result = r.d[0] & 0xffff; |
775 |
> |
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
776 |
> |
result = (int16)(r.d[0] & 0xffff); |
777 |
|
|
778 |
|
if (result == noErr) { |
779 |
|
switch (status) { |
791 |
|
current_dir = dirID; |
792 |
|
else { |
793 |
|
D(bug(" resolving WDCB\n")); |
794 |
< |
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
794 |
> |
r.d[0] = 0; |
795 |
> |
r.d[1] = 0; |
796 |
> |
r.d[2] = ReadMacInt16(pb + ioVRefNum); |
797 |
|
r.a[0] = fs_data + fsReturn; |
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 |
|
|
857 |
|
uint32 current_dir; |
858 |
|
if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr) |
859 |
|
return result; |
860 |
+ |
D(bug(" current dir %08x\n", current_dir)); |
861 |
|
FSItem *p = find_fsitem_by_id(current_dir); |
862 |
|
if (p == NULL) |
863 |
|
return dirNFErr; |
871 |
|
WriteMacInt8(parseRec + ppFoundDelimiter, false); |
872 |
|
|
873 |
|
// Get length of volume name |
874 |
< |
// D(bug(" parsing pathname\n")); |
874 |
> |
D(bug(" parsing pathname\n")); |
875 |
|
r.a[0] = parseRec + ppStartOffset; |
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; |
878 |
> |
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
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 |
< |
memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28); |
1035 |
> |
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
1036 |
|
WriteMacInt16(vcb + vcbFSID, MY_FSID); |
1037 |
|
WriteMacInt32(vcb + vcbFilCnt, 1); //!! |
1038 |
|
WriteMacInt32(vcb + vcbDirCnt, 1); //!! |
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); //!! |
1108 |
|
WriteMacInt32(pb + ioVWrCnt, 0); |
1109 |
|
WriteMacInt32(pb + ioVFilCnt, 1); //!! |
1110 |
|
WriteMacInt32(pb + ioVDirCnt, 1); //!! |
1111 |
< |
memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32); |
1111 |
> |
Mac_memset(pb + ioVFndrInfo, 0, 32); |
1112 |
|
} |
1113 |
|
return noErr; |
1114 |
|
} |
1128 |
|
// D(bug(" fs_get_vol_parms(%08lx)\n", pb)); |
1129 |
|
|
1130 |
|
// Return parameter block |
1050 |
– |
uint8 vol[SIZEOF_GetVolParmsInfoBuffer]; |
1051 |
– |
WriteMacInt16((uint32)vol + vMVersion, 2); |
1052 |
– |
WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol); |
1053 |
– |
WriteMacInt32((uint32)vol + vMLocalHand, 0); |
1054 |
– |
WriteMacInt32((uint32)vol + vMServerAdr, 0); |
1055 |
– |
WriteMacInt32((uint32)vol + vMVolumeGrade, 0); |
1056 |
– |
WriteMacInt16((uint32)vol + vMForeignPrivID, 0); |
1131 |
|
uint32 actual = ReadMacInt32(pb + ioReqCount); |
1132 |
< |
if (actual > sizeof(vol)) |
1133 |
< |
actual = sizeof(vol); |
1060 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual); |
1132 |
> |
if (actual > SIZEOF_GetVolParmsInfoBuffer) |
1133 |
> |
actual = SIZEOF_GetVolParmsInfoBuffer; |
1134 |
|
WriteMacInt32(pb + ioActCount, actual); |
1135 |
+ |
uint32 p = ReadMacInt32(pb + ioBuffer); |
1136 |
+ |
if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2); |
1137 |
+ |
if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol); |
1138 |
+ |
if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0); |
1139 |
+ |
if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0); |
1140 |
+ |
if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0); |
1141 |
+ |
if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0); |
1142 |
|
return noErr; |
1143 |
|
} |
1144 |
|
|
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) |
1160 |
|
static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb) |
1161 |
|
{ |
1162 |
< |
D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
1162 |
> |
D(bug(" fs_set_vol(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioWDDirID))); |
1163 |
|
M68kRegisters r; |
1164 |
|
|
1165 |
|
// Determine parameters |
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) |
1216 |
|
static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID) |
1217 |
|
{ |
1218 |
< |
D(bug(" fs_get_file_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), dirID)); |
1218 |
> |
D(bug(" fs_get_file_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), dirID)); |
1219 |
|
|
1220 |
|
FSItem *fs_item; |
1221 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1222 |
< |
if (dir_index == 0) { // Query item specified by ioDirID and ioNamePtr |
1222 |
> |
if (dir_index <= 0) { // Query item specified by ioDirID and ioNamePtr |
1223 |
|
|
1224 |
|
// Find FSItem for given file |
1225 |
|
int16 result = get_item_and_path(pb, dirID, fs_item); |
1251 |
|
return fnfErr; |
1252 |
|
} |
1253 |
|
if (de->d_name[0] == '.') |
1254 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1254 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1255 |
|
//!! suppress directories |
1256 |
|
} |
1257 |
< |
add_path_component(de->d_name); |
1257 |
> |
add_path_comp(de->d_name); |
1258 |
|
|
1259 |
|
// Get FSItem for queried item |
1260 |
|
fs_item = find_fsitem(de->d_name, p); |
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 |
< |
memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo); |
1206 |
< |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1207 |
< |
get_finder_type(full_path, type, creator); |
1208 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1209 |
< |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1210 |
< |
uint16 fflags; |
1211 |
< |
get_finder_flags(full_path, fflags); |
1212 |
< |
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); |
1224 |
– |
memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); |
1299 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1300 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1301 |
|
} |
1305 |
|
// Set file attributes (HFileParam) |
1306 |
|
static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID) |
1307 |
|
{ |
1308 |
< |
D(bug(" fs_set_file_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), dirID)); |
1308 |
> |
D(bug(" fs_set_file_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), dirID)); |
1309 |
|
|
1310 |
|
// Find FSItem for given file/dir |
1311 |
|
FSItem *fs_item; |
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 |
|
} |
1330 |
|
// Query file/directory attributes |
1331 |
|
static int16 fs_get_cat_info(uint32 pb) |
1332 |
|
{ |
1333 |
< |
D(bug(" fs_get_cat_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID))); |
1333 |
> |
D(bug(" fs_get_cat_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID))); |
1334 |
|
|
1335 |
|
FSItem *fs_item; |
1336 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1337 |
< |
if (dir_index == -1) { // Query directory specified by ioDirID |
1337 |
> |
if (dir_index < 0) { // Query directory specified by ioDirID |
1338 |
|
|
1339 |
|
// Find FSItem for directory |
1340 |
|
fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID)); |
1374 |
|
return fnfErr; |
1375 |
|
} |
1376 |
|
if (de->d_name[0] == '.') |
1377 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1377 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1378 |
|
} |
1379 |
< |
add_path_component(de->d_name); |
1379 |
> |
add_path_comp(de->d_name); |
1380 |
|
|
1381 |
|
// Get FSItem for queried item |
1382 |
|
fs_item = find_fsitem(de->d_name, p); |
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); |
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)) { |
1342 |
– |
memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo); |
1343 |
– |
memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo); |
1344 |
– |
uint16 fflags; // pb may point to kernel space, but stack is switched |
1345 |
– |
get_finder_flags(full_path, fflags); |
1346 |
– |
WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags); |
1421 |
|
|
1422 |
|
// Determine number of files in directory (cached) |
1423 |
|
int count; |
1432 |
|
de = readdir(d); |
1433 |
|
if (de == NULL) |
1434 |
|
break; |
1435 |
+ |
if (de->d_name[0] == '.') |
1436 |
+ |
continue; // Suppress names beginning with '.' |
1437 |
|
count++; |
1438 |
|
} |
1439 |
|
closedir(d); |
1442 |
|
} |
1443 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1444 |
|
} else { |
1369 |
– |
memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo); |
1370 |
– |
memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); |
1371 |
– |
uint32 type, creator; // pb may point to kernel space, but stack is switched |
1372 |
– |
get_finder_type(full_path, type, creator); |
1373 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdType, type); |
1374 |
– |
WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator); |
1375 |
– |
uint16 fflags; |
1376 |
– |
get_finder_flags(full_path, fflags); |
1377 |
– |
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; |
1457 |
|
// Set file/directory attributes |
1458 |
|
static int16 fs_set_cat_info(uint32 pb) |
1459 |
|
{ |
1460 |
< |
D(bug(" fs_set_cat_info(%08lx), vRefNum %d, name %#s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID))); |
1460 |
> |
D(bug(" fs_set_cat_info(%08lx), vRefNum %d, name %.31s, idx %d, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt16(pb + ioFDirIndex), ReadMacInt32(pb + ioDirID))); |
1461 |
|
|
1462 |
|
// Find FSItem for given file/dir |
1463 |
|
FSItem *fs_item; |
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)); |
1409 |
< |
else { |
1410 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1411 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1412 |
< |
} |
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 |
|
} |
1480 |
|
// Open file |
1481 |
|
static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork) |
1482 |
|
{ |
1483 |
< |
D(bug(" fs_open(%08lx), %s, vRefNum %d, name %#s, dirID %d, perm %d\n", pb, resource_fork ? "rsrc" : "data", ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID, ReadMacInt8(pb + ioPermssn))); |
1483 |
> |
D(bug(" fs_open(%08lx), %s, vRefNum %d, name %.31s, dirID %d, perm %d\n", pb, resource_fork ? "rsrc" : "data", ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID, ReadMacInt8(pb + ioPermssn))); |
1484 |
|
M68kRegisters r; |
1485 |
|
|
1486 |
|
// Find FSItem for given file |
1519 |
|
if (access(full_path, F_OK)) |
1520 |
|
return fnfErr; |
1521 |
|
fd = open_rfork(full_path, flag); |
1522 |
< |
if (fd > 0) { |
1523 |
< |
if (fstat(fd, &st) < 0) |
1522 |
> |
if (fd >= 0) { |
1523 |
> |
if (fstat(fd, &st) < 0) { |
1524 |
> |
close(fd); |
1525 |
|
return errno2oserr(); |
1526 |
+ |
} |
1527 |
|
} else { // Resource fork not supported, silently ignore it ("pseudo" resource fork) |
1528 |
|
st.st_size = 0; |
1529 |
|
st.st_mode = 0; |
1532 |
|
fd = open(full_path, flag); |
1533 |
|
if (fd < 0) |
1534 |
|
return errno2oserr(); |
1535 |
< |
if (fstat(fd, &st) < 0) |
1535 |
> |
if (fstat(fd, &st) < 0) { |
1536 |
> |
close(fd); |
1537 |
|
return errno2oserr(); |
1538 |
+ |
} |
1539 |
|
} |
1540 |
|
|
1541 |
|
// File open, allocate FCB |
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; // 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); |
1772 |
|
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0) |
1773 |
|
return posErr; |
1774 |
|
break; |
1775 |
+ |
case fsFromLEOF: |
1776 |
+ |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0) |
1777 |
+ |
return posErr; |
1778 |
+ |
break; |
1779 |
|
case fsFromMark: |
1780 |
< |
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1780 |
> |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1781 |
|
return posErr; |
1782 |
+ |
break; |
1783 |
|
default: |
1784 |
|
break; |
1785 |
|
} |
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) |
1829 |
|
} |
1830 |
|
|
1831 |
|
// Read |
1832 |
< |
size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1832 |
> |
ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1833 |
> |
int16 read_err = errno2oserr(); |
1834 |
|
D(bug(" actual %d\n", actual)); |
1835 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1835 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 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)) |
1840 |
< |
if (errno) |
1763 |
< |
return errno2oserr(); |
1764 |
< |
else |
1765 |
< |
return eofErr; |
1839 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1840 |
> |
return actual < 0 ? read_err : eofErr; |
1841 |
|
else |
1842 |
|
return noErr; |
1843 |
|
} |
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) |
1882 |
|
} |
1883 |
|
|
1884 |
|
// Write |
1885 |
< |
size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1885 |
> |
ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1886 |
> |
int16 write_err = errno2oserr(); |
1887 |
|
D(bug(" actual %d\n", actual)); |
1888 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1888 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 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)) |
1893 |
< |
return errno2oserr(); |
1892 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1893 |
> |
return write_err; |
1894 |
|
else |
1895 |
|
return noErr; |
1896 |
|
} |
1898 |
|
// Create file |
1899 |
|
static int16 fs_create(uint32 pb, uint32 dirID) |
1900 |
|
{ |
1901 |
< |
D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1901 |
> |
D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID)); |
1902 |
|
|
1903 |
|
// Find FSItem for given file |
1904 |
|
FSItem *fs_item; |
1911 |
|
return dupFNErr; |
1912 |
|
|
1913 |
|
// Create file |
1914 |
< |
int fd = creat(full_path, 0664); |
1914 |
> |
int fd = creat(full_path, 0666); |
1915 |
|
if (fd < 0) |
1916 |
|
return errno2oserr(); |
1917 |
|
else { |
1923 |
|
// Create directory |
1924 |
|
static int16 fs_dir_create(uint32 pb) |
1925 |
|
{ |
1926 |
< |
D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID))); |
1926 |
> |
D(bug(" fs_dir_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioDirID))); |
1927 |
|
|
1928 |
|
// Find FSItem for given directory |
1929 |
|
FSItem *fs_item; |
1936 |
|
return dupFNErr; |
1937 |
|
|
1938 |
|
// Create directory |
1939 |
< |
if (mkdir(full_path, 0775) < 0) |
1939 |
> |
if (mkdir(full_path, 0777) < 0) |
1940 |
|
return errno2oserr(); |
1941 |
|
else { |
1942 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1947 |
|
// Delete file/directory |
1948 |
|
static int16 fs_delete(uint32 pb, uint32 dirID) |
1949 |
|
{ |
1950 |
< |
D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1950 |
> |
D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID)); |
1951 |
|
|
1952 |
|
// Find FSItem for given file/dir |
1953 |
|
FSItem *fs_item; |
1956 |
|
return result; |
1957 |
|
|
1958 |
|
// Delete file |
1959 |
< |
if (remove(full_path) < 0) { |
1960 |
< |
int16 err = errno2oserr(); |
1961 |
< |
if (errno == EISDIR) { // Workaround for BeOS bug |
1882 |
< |
if (rmdir(full_path) < 0) |
1883 |
< |
return errno2oserr(); |
1884 |
< |
else |
1885 |
< |
return noErr; |
1886 |
< |
} else |
1887 |
< |
return err; |
1888 |
< |
} else |
1959 |
> |
if (!extfs_remove(full_path)) |
1960 |
> |
return errno2oserr(); |
1961 |
> |
else |
1962 |
|
return noErr; |
1963 |
|
} |
1964 |
|
|
1965 |
|
// Rename file/directory |
1966 |
|
static int16 fs_rename(uint32 pb, uint32 dirID) |
1967 |
|
{ |
1968 |
< |
D(bug(" fs_rename(%08lx), vRefNum %d, name %#s, dirID %d, new name %#s\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID, Mac2HostAddr(ReadMacInt32(pb + ioMisc)))); |
1968 |
> |
D(bug(" fs_rename(%08lx), vRefNum %d, name %.31s, dirID %d, new name %.31s\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID, Mac2HostAddr(ReadMacInt32(pb + ioMisc) + 1))); |
1969 |
|
|
1970 |
|
// Find path of given file/dir |
1971 |
|
FSItem *fs_item; |
1978 |
|
strcpy(old_path, full_path); |
1979 |
|
|
1980 |
|
// Find path for new name |
1981 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
1982 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1910 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1981 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
1982 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1983 |
|
FSItem *new_item; |
1984 |
< |
result = get_item_and_path((uint32)new_pb, dirID, new_item); |
1984 |
> |
result = get_item_and_path(fs_data + fsPB, dirID, new_item); |
1985 |
|
if (result != noErr) |
1986 |
|
return result; |
1987 |
|
|
1991 |
|
|
1992 |
|
// Rename item |
1993 |
|
D(bug(" renaming %s -> %s\n", old_path, full_path)); |
1994 |
< |
if (rename(old_path, full_path) < 0) |
1994 |
> |
if (!extfs_rename(old_path, full_path)) |
1995 |
|
return errno2oserr(); |
1996 |
|
else { |
1997 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1998 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1999 |
|
uint32 t = fs_item->id; |
2000 |
|
fs_item->id = new_item->id; |
2001 |
|
new_item->id = t; |
2006 |
|
// Move file/directory (CMovePBRec) |
2007 |
|
static int16 fs_cat_move(uint32 pb) |
2008 |
|
{ |
2009 |
< |
D(bug(" fs_cat_move(%08lx), vRefNum %d, name %#s, dirID %d, new name %#s, new dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID), Mac2HostAddr(ReadMacInt32(pb + ioNewName)), ReadMacInt32(pb + ioNewDirID))); |
2009 |
> |
D(bug(" fs_cat_move(%08lx), vRefNum %d, name %.31s, dirID %d, new name %.31s, new dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioDirID), Mac2HostAddr(ReadMacInt32(pb + ioNewName) + 1), ReadMacInt32(pb + ioNewDirID))); |
2010 |
|
|
2011 |
|
// Find path of given file/dir |
2012 |
|
FSItem *fs_item; |
2019 |
|
strcpy(old_path, full_path); |
2020 |
|
|
2021 |
|
// Find path for new directory |
2022 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
2023 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1951 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
2022 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
2023 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
2024 |
|
FSItem *new_dir_item; |
2025 |
< |
result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
2025 |
> |
result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
2026 |
|
if (result != noErr) |
2027 |
|
return result; |
2028 |
|
|
2029 |
|
// Append old file/dir name |
2030 |
< |
add_path_component(fs_item->name); |
2030 |
> |
add_path_comp(fs_item->name); |
2031 |
|
|
2032 |
|
// Does the new name already exist? |
2033 |
|
if (access(full_path, F_OK) == 0) |
2035 |
|
|
2036 |
|
// Move item |
2037 |
|
D(bug(" moving %s -> %s\n", old_path, full_path)); |
2038 |
< |
if (rename(old_path, full_path) < 0) |
2038 |
> |
if (!extfs_rename(old_path, full_path)) |
2039 |
|
return errno2oserr(); |
2040 |
|
else { |
2041 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
2042 |
|
FSItem *new_item = find_fsitem(fs_item->name, new_dir_item); |
2043 |
|
if (new_item) { |
2044 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
2045 |
|
uint32 t = fs_item->id; |
2046 |
|
fs_item->id = new_item->id; |
2047 |
|
new_item->id = t; |
2053 |
|
// Open working directory (WDParam) |
2054 |
|
static int16 fs_open_wd(uint32 pb) |
2055 |
|
{ |
2056 |
< |
D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
2056 |
> |
D(bug(" fs_open_wd(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), ReadMacInt32(pb + ioWDDirID))); |
2057 |
|
M68kRegisters r; |
2058 |
|
|
2059 |
|
// Allocate WDCB |
2060 |
|
D(bug(" allocating WDCB\n")); |
2061 |
|
r.a[0] = pb; |
2062 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2063 |
< |
D(bug(" UTAllocateWDCB returned %d\n", r.d[0])); |
2064 |
< |
return r.d[0]; |
2063 |
> |
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
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) |
2089 |
|
WriteMacInt32(pb + ioWDProcID, 0); |
2090 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum)); |
2091 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2092 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28); |
2092 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28); |
2093 |
|
WriteMacInt32(pb + ioWDDirID, ROOT_ID); |
2094 |
|
return noErr; |
2095 |
|
} |
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 |
< |
WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2110 |
> |
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2111 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum)); |
2112 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2113 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28); |
2113 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28); |
2114 |
|
WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID)); |
2115 |
|
return noErr; |
2116 |
|
} |