1 |
|
/* |
2 |
< |
* extfs.cpp - MacOS file system for access native file system access |
2 |
> |
* extfs.cpp - MacOS file system for native file system access |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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 |
|
#include "cpu_emulation.h" |
46 |
– |
#include "macos_util.h" |
52 |
|
#include "emul_op.h" |
53 |
|
#include "main.h" |
54 |
|
#include "disk.h" |
57 |
|
#include "extfs.h" |
58 |
|
#include "extfs_defs.h" |
59 |
|
|
60 |
+ |
#ifdef WIN32 |
61 |
+ |
# include "posix_emu.h" |
62 |
+ |
#endif |
63 |
+ |
|
64 |
|
#define DEBUG 0 |
65 |
|
#include "debug.h" |
66 |
|
|
71 |
|
fsHFSProcStub = 6, |
72 |
|
fsDrvStatus = 12, // Drive Status record |
73 |
|
fsFSD = 42, // File system descriptor |
74 |
< |
fsPB = 238, // IOParam (for mounting) |
74 |
> |
fsPB = 238, // IOParam (for mounting and renaming), also used for temporary storage |
75 |
|
fsVMI = 288, // VoumeMountInfoHeader (for mounting) |
76 |
|
fsParseRec = 296, // ParsePathRec struct |
77 |
|
fsReturn = 306, // Area for return data of 68k routines |
78 |
|
fsAllocateVCB = 562, // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1}) |
79 |
|
fsAddNewVCB = 578, // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1}) |
80 |
|
fsDetermineVol = 594, // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4}) |
81 |
< |
fsResolveWDCB = 614, // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0}) |
81 |
> |
fsResolveWDCB = 614, // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0}) |
82 |
|
fsGetDefaultVol = 632, // UTGetDefaultVol(uint32 wdpb{a0}) |
83 |
|
fsGetPathComponentName = 644, // UTGetPathComponentName(uint32 rec{a0}) |
84 |
|
fsParsePathname = 656, // UTParsePathname(uint32 *start{a0}, uint32 name{a1}) |
107 |
|
static struct stat root_stat; |
108 |
|
|
109 |
|
// File system ID/media type |
110 |
< |
const int16 MY_FSID = 'ba'; |
111 |
< |
const uint32 MY_MEDIA_TYPE = 'basi'; |
110 |
> |
const int16 MY_FSID = EMULATOR_ID_2; |
111 |
> |
const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4; |
112 |
|
|
113 |
|
// CNID of root and root's parent |
114 |
|
const uint32 ROOT_ID = 2; |
117 |
|
// File system stack size |
118 |
|
const int STACK_SIZE = 0x10000; |
119 |
|
|
120 |
+ |
// Allocation block and clump size as reported to MacOS (these are of course |
121 |
+ |
// not the real values and have no meaning on the host OS) |
122 |
+ |
const int AL_BLK_SIZE = 0x4000; |
123 |
+ |
const int CLUMP_SIZE = 0x4000; |
124 |
+ |
|
125 |
|
// Drive number of our pseudo-drive |
126 |
|
static int drive_number; |
127 |
|
|
212 |
|
* Get full path (->full_path) for given FSItem |
213 |
|
*/ |
214 |
|
|
201 |
– |
const int MAX_PATH_LENGTH = 1024; |
215 |
|
static char full_path[MAX_PATH_LENGTH]; |
216 |
|
|
217 |
< |
static void add_path_component(const char *s) |
217 |
> |
static void add_path_comp(const char *s) |
218 |
|
{ |
219 |
< |
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); |
219 |
> |
add_path_component(full_path, s); |
220 |
|
} |
221 |
|
|
222 |
|
static void get_path_for_fsitem(FSItem *p) |
223 |
|
{ |
224 |
< |
if (p->id == ROOT_ID) { |
224 |
> |
if (p->id == ROOT_PARENT_ID) { |
225 |
> |
full_path[0] = 0; |
226 |
> |
} else if (p->id == ROOT_ID) { |
227 |
|
strncpy(full_path, RootPath, MAX_PATH_LENGTH-1); |
228 |
|
full_path[MAX_PATH_LENGTH-1] = 0; |
229 |
|
} else { |
230 |
|
get_path_for_fsitem(p->parent); |
231 |
< |
add_path_component(p->name); |
231 |
> |
add_path_comp(p->name); |
232 |
> |
} |
233 |
> |
} |
234 |
> |
|
235 |
> |
|
236 |
> |
/* |
237 |
> |
* Exchange parent CNIDs in all FSItems |
238 |
> |
*/ |
239 |
> |
|
240 |
> |
static void swap_parent_ids(uint32 parent1, uint32 parent2) |
241 |
> |
{ |
242 |
> |
FSItem *p = first_fs_item; |
243 |
> |
while (p) { |
244 |
> |
if (p->parent_id == parent1) |
245 |
> |
p->parent_id = parent2; |
246 |
> |
else if (p->parent_id == parent2) |
247 |
> |
p->parent_id = parent1; |
248 |
> |
p = p->next; |
249 |
|
} |
250 |
|
} |
251 |
|
|
268 |
|
*dst++ = strlen(src); |
269 |
|
char c; |
270 |
|
while ((c = *src++) != 0) { |
271 |
+ |
// Note: we are converting host ':' characters to Mac '/' characters here |
272 |
+ |
// '/' is not a path separator as this function is only used on object names |
273 |
|
if (c == ':') |
274 |
|
c = '/'; |
275 |
|
*dst++ = c; |
276 |
|
} |
277 |
|
} |
278 |
|
|
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 |
– |
|
279 |
|
// Convert string (no length byte) to C string, length given separately |
280 |
|
static void strn2cstr(char *dst, const char *src, int size) |
281 |
|
{ |
282 |
|
while (size--) { |
283 |
|
char c = *src++; |
284 |
+ |
// Note: we are converting Mac '/' characters to host ':' characters here |
285 |
+ |
// '/' is not a path separator as this function is only used on object names |
286 |
|
if (c == '/') |
287 |
|
c = ':'; |
288 |
|
*dst++ = c; |
340 |
|
cstr2pstr(FS_NAME, GetString(STR_EXTFS_NAME)); |
341 |
|
cstr2pstr(VOLUME_NAME, GetString(STR_EXTFS_VOLUME_NAME)); |
342 |
|
|
343 |
< |
// Create root FSItem |
343 |
> |
// Create root's parent FSItem |
344 |
|
FSItem *p = new FSItem; |
345 |
|
first_fs_item = last_fs_item = p; |
346 |
|
p->next = NULL; |
347 |
+ |
p->id = ROOT_PARENT_ID; |
348 |
+ |
p->parent_id = 0; |
349 |
+ |
p->parent = NULL; |
350 |
+ |
p->name[0] = 0; |
351 |
+ |
|
352 |
+ |
// Create root FSItem |
353 |
+ |
p = new FSItem; |
354 |
+ |
last_fs_item->next = p; |
355 |
+ |
p->next = NULL; |
356 |
+ |
last_fs_item = p; |
357 |
|
p->id = ROOT_ID; |
358 |
|
p->parent_id = ROOT_PARENT_ID; |
359 |
< |
p->parent = NULL; |
359 |
> |
p->parent = first_fs_item; |
360 |
|
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
361 |
+ |
p->name[31] = 0; |
362 |
|
|
363 |
|
// Find path for root |
364 |
|
if ((RootPath = PrefsFindString("extfs")) != NULL) { |
407 |
|
// FSM present? |
408 |
|
r.d[0] = gestaltFSAttr; |
409 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
410 |
< |
D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); |
411 |
< |
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) |
410 |
> |
D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); |
411 |
> |
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { |
412 |
> |
printf("WARNING: No FSM present, disabling ExtFS\n"); |
413 |
|
return; |
414 |
+ |
} |
415 |
|
|
416 |
|
// Yes, version >=1.2? |
417 |
|
r.d[0] = gestaltFSMVersion; |
418 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
419 |
< |
D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); |
420 |
< |
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) |
419 |
> |
D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); |
420 |
> |
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { |
421 |
> |
printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); |
422 |
|
return; |
423 |
+ |
} |
424 |
|
|
425 |
|
D(bug("FSM present\n")); |
426 |
|
|
456 |
|
WriteMacInt16(p, 0x7006); p+= 2; // UTAllocateVCB |
457 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
458 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
459 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
459 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
460 |
|
if (p - fs_data != fsAddNewVCB) |
461 |
|
goto fsdat_error; |
462 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
466 |
|
WriteMacInt16(p, 0x7007); p+= 2; // UTAddNewVCB |
467 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
468 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
469 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
469 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
470 |
|
if (p - fs_data != fsDetermineVol) |
471 |
|
goto fsdat_error; |
472 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
478 |
|
WriteMacInt16(p, 0x701d); p+= 2; // UTDetermineVol |
479 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
480 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
481 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
481 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
482 |
|
if (p - fs_data != fsResolveWDCB) |
483 |
|
goto fsdat_error; |
484 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
485 |
< |
WriteMacInt16(p, 0x42a7); p+= 2; // clr.l -(sp) |
486 |
< |
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
487 |
< |
WriteMacInt16(p, 0x3f00); p+= 2; // move.w d0,-(sp) |
485 |
> |
WriteMacInt16(p, 0x2f00); p+= 2; // move.l d0,-(sp) |
486 |
> |
WriteMacInt16(p, 0x3f01); p+= 2; // move.w d1,-(sp) |
487 |
> |
WriteMacInt16(p, 0x3f02); p+= 2; // move.w d2,-(sp) |
488 |
|
WriteMacInt16(p, 0x2f08); p+= 2; // move.l a0,-(sp) |
489 |
|
WriteMacInt16(p, 0x700e); p+= 2; // UTResolveWDCB |
490 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
491 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
492 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
492 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
493 |
|
if (p - fs_data != fsGetDefaultVol) |
494 |
|
goto fsdat_error; |
495 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
497 |
|
WriteMacInt16(p, 0x7012); p+= 2; // UTGetDefaultVol |
498 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
499 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
500 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
500 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
501 |
|
if (p - fs_data != fsGetPathComponentName) |
502 |
|
goto fsdat_error; |
503 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
505 |
|
WriteMacInt16(p, 0x701c); p+= 2; // UTGetPathComponentName |
506 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
507 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
508 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
508 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
509 |
|
if (p - fs_data != fsParsePathname) |
510 |
|
goto fsdat_error; |
511 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
514 |
|
WriteMacInt16(p, 0x701b); p+= 2; // UTParsePathname |
515 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
516 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
517 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
517 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
518 |
|
if (p - fs_data != fsDisposeVCB) |
519 |
|
goto fsdat_error; |
520 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
522 |
|
WriteMacInt16(p, 0x7008); p+= 2; // UTDisposeVCB |
523 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
524 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
525 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
525 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
526 |
|
if (p - fs_data != fsCheckWDRefNum) |
527 |
|
goto fsdat_error; |
528 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
530 |
|
WriteMacInt16(p, 0x7013); p+= 2; // UTCheckWDRefNum |
531 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
532 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
533 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
533 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
534 |
|
if (p - fs_data != fsSetDefaultVol) |
535 |
|
goto fsdat_error; |
536 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
540 |
|
WriteMacInt16(p, 0x7011); p+= 2; // UTSetDefaultVol |
541 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
542 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
543 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
543 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
544 |
|
if (p - fs_data != fsAllocateFCB) |
545 |
|
goto fsdat_error; |
546 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
549 |
|
WriteMacInt16(p, 0x7000); p+= 2; // UTAllocateFCB |
550 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
551 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
552 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
552 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
553 |
|
if (p - fs_data != fsReleaseFCB) |
554 |
|
goto fsdat_error; |
555 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
557 |
|
WriteMacInt16(p, 0x7001); p+= 2; // UTReleaseFCB |
558 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
559 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
560 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
560 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
561 |
|
if (p - fs_data != fsIndexFCB) |
562 |
|
goto fsdat_error; |
563 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
567 |
|
WriteMacInt16(p, 0x7004); p+= 2; // UTIndexFCB |
568 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
569 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
570 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
570 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
571 |
|
if (p - fs_data != fsResolveFCB) |
572 |
|
goto fsdat_error; |
573 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
576 |
|
WriteMacInt16(p, 0x7005); p+= 2; // UTResolveFCB |
577 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
578 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
579 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
579 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
580 |
|
if (p - fs_data != fsAdjustEOF) |
581 |
|
goto fsdat_error; |
582 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
584 |
|
WriteMacInt16(p, 0x7010); p+= 2; // UTAdjustEOF |
585 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
586 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
587 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
587 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
588 |
|
if (p - fs_data != fsAllocateWDCB) |
589 |
|
goto fsdat_error; |
590 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
592 |
|
WriteMacInt16(p, 0x700c); p+= 2; // UTAllocateWDCB |
593 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
594 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
595 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
595 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
596 |
|
if (p - fs_data != fsReleaseWDCB) |
597 |
|
goto fsdat_error; |
598 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
600 |
|
WriteMacInt16(p, 0x700d); p+= 2; // UTReleaseWDCB |
601 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
602 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
603 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
603 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
604 |
|
if (p - fs_data != SIZEOF_fsdat) |
605 |
|
goto fsdat_error; |
606 |
|
|
624 |
|
WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec); |
625 |
|
WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1); |
626 |
|
WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID); |
627 |
< |
memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32); |
627 |
> |
Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32); |
628 |
|
WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub); |
629 |
|
WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub); |
630 |
|
WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE); |
678 |
|
|
679 |
|
case ffsGetIconMessage: { // Get disk/drive icon |
680 |
|
if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) { |
681 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon)); |
681 |
> |
Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon)); |
682 |
|
WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon)); |
683 |
|
return noErr; |
684 |
|
} else |
686 |
|
} |
687 |
|
|
688 |
|
case ffsIDDiskMessage: { // Check if volume is handled by our FS |
689 |
< |
if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
689 |
> |
if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
690 |
|
return noErr; |
691 |
|
else |
692 |
|
return extFSErr; |
715 |
|
int16 result; |
716 |
|
|
717 |
|
// Determine volume |
718 |
< |
// D(bug(" determining volume\n")); |
718 |
> |
D(bug(" determining volume, dirID %d\n", dirID)); |
719 |
|
r.a[0] = pb; |
720 |
|
r.a[1] = fs_data + fsReturn; |
721 |
|
r.a[2] = fs_data + fsReturn + 2; |
733 |
|
int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); |
734 |
|
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
735 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
736 |
< |
// D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
737 |
< |
result = r.d[0] & 0xffff; |
736 |
> |
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
737 |
> |
result = (int16)(r.d[0] & 0xffff); |
738 |
|
|
739 |
|
if (result == noErr) { |
740 |
|
switch (status) { |
752 |
|
current_dir = dirID; |
753 |
|
else { |
754 |
|
D(bug(" resolving WDCB\n")); |
755 |
< |
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
755 |
> |
r.d[0] = 0; |
756 |
> |
r.d[1] = 0; |
757 |
> |
r.d[2] = ReadMacInt16(pb + ioVRefNum); |
758 |
|
r.a[0] = fs_data + fsReturn; |
759 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
760 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
761 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
762 |
< |
result = r.d[0] & 0xffff; |
762 |
> |
result = (int16)(r.d[0] & 0xffff); |
763 |
|
if (result == noErr) |
764 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
765 |
|
} |
775 |
|
r.a[0] = wdpb; |
776 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
777 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
778 |
< |
result = r.d[0] & 0xffff; |
778 |
> |
result = (int16)(r.d[0] & 0xffff); |
779 |
|
if (result == noErr) |
780 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
781 |
|
} |
801 |
|
r.a[0] = rec; |
802 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
803 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
804 |
< |
return r.d[0] & 0xffff; |
804 |
> |
return (int16)(r.d[0] & 0xffff); |
805 |
|
} |
806 |
|
|
807 |
|
|
818 |
|
uint32 current_dir; |
819 |
|
if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr) |
820 |
|
return result; |
821 |
+ |
D(bug(" current dir %08x\n", current_dir)); |
822 |
|
FSItem *p = find_fsitem_by_id(current_dir); |
823 |
|
if (p == NULL) |
824 |
|
return dirNFErr; |
832 |
|
WriteMacInt8(parseRec + ppFoundDelimiter, false); |
833 |
|
|
834 |
|
// Get length of volume name |
835 |
< |
// D(bug(" parsing pathname\n")); |
835 |
> |
D(bug(" parsing pathname\n")); |
836 |
|
r.a[0] = parseRec + ppStartOffset; |
837 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
838 |
|
Execute68k(fs_data + fsParsePathname, &r); |
839 |
< |
// D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
840 |
< |
result = r.d[0] & 0xffff; |
839 |
> |
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
840 |
> |
result = (int16)(r.d[0] & 0xffff); |
841 |
|
if (result == noErr) { |
842 |
|
|
843 |
|
// Check for leading delimiter of the partial pathname |
950 |
|
static int16 fs_mount_vol(uint32 pb) |
951 |
|
{ |
952 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
953 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
953 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
954 |
|
return noErr; |
955 |
|
else |
956 |
|
return extFSErr; |
971 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
972 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
973 |
|
if (r.d[0] & 0xffff) |
974 |
< |
return r.d[0]; |
974 |
> |
return (int16)r.d[0]; |
975 |
|
|
976 |
|
// Init VCB |
977 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
978 |
< |
#ifdef __BEOS__ |
978 |
> |
#if defined(__BEOS__) || defined(WIN32) |
979 |
|
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
980 |
|
#else |
981 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
985 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
986 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
987 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
988 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
989 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
988 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
989 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); |
990 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
991 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
992 |
< |
memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28); |
992 |
> |
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
993 |
|
WriteMacInt16(vcb + vcbFSID, MY_FSID); |
994 |
|
WriteMacInt32(vcb + vcbFilCnt, 1); //!! |
995 |
|
WriteMacInt32(vcb + vcbDirCnt, 1); //!! |
1000 |
|
r.a[0] = fs_data + fsReturn; |
1001 |
|
r.a[1] = vcb; |
1002 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1003 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1003 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1004 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1005 |
|
if (r.d[0] & 0xffff) |
1006 |
< |
return r.d[0]; |
1006 |
> |
return (int16)r.d[0]; |
1007 |
|
|
1008 |
|
// Post diskInsertEvent |
1009 |
|
D(bug(" posting diskInsertEvent\n")); |
1027 |
|
r.a[0] = vcb; |
1028 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1029 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1030 |
< |
return r.d[0]; |
1030 |
> |
return (int16)r.d[0]; |
1031 |
|
} |
1032 |
|
|
1033 |
|
// Get information about a volume (HVolumeParam) |
1038 |
|
// Fill in struct |
1039 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1040 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1041 |
< |
#ifdef __BEOS__ |
1041 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1042 |
|
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1043 |
|
#else |
1044 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1049 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1050 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1051 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1052 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1053 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1052 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1053 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1054 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1055 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1056 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1063 |
|
WriteMacInt32(pb + ioVWrCnt, 0); |
1064 |
|
WriteMacInt32(pb + ioVFilCnt, 1); //!! |
1065 |
|
WriteMacInt32(pb + ioVDirCnt, 1); //!! |
1066 |
< |
memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32); |
1066 |
> |
Mac_memset(pb + ioVFndrInfo, 0, 32); |
1067 |
|
} |
1068 |
|
return noErr; |
1069 |
|
} |
1083 |
|
// D(bug(" fs_get_vol_parms(%08lx)\n", pb)); |
1084 |
|
|
1085 |
|
// 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); |
1086 |
|
uint32 actual = ReadMacInt32(pb + ioReqCount); |
1087 |
< |
if (actual > sizeof(vol)) |
1088 |
< |
actual = sizeof(vol); |
1060 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual); |
1087 |
> |
if (actual > SIZEOF_GetVolParmsInfoBuffer) |
1088 |
> |
actual = SIZEOF_GetVolParmsInfoBuffer; |
1089 |
|
WriteMacInt32(pb + ioActCount, actual); |
1090 |
+ |
uint32 p = ReadMacInt32(pb + ioBuffer); |
1091 |
+ |
if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2); |
1092 |
+ |
if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol); |
1093 |
+ |
if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0); |
1094 |
+ |
if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0); |
1095 |
+ |
if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0); |
1096 |
+ |
if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0); |
1097 |
|
return noErr; |
1098 |
|
} |
1099 |
|
|
1108 |
|
r.a[0] = pb; |
1109 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1110 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1111 |
< |
return r.d[0]; |
1111 |
> |
return (int16)r.d[0]; |
1112 |
|
} |
1113 |
|
|
1114 |
|
// Set default volume (WDParam) |
1115 |
|
static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb) |
1116 |
|
{ |
1117 |
< |
D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
1117 |
> |
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))); |
1118 |
|
M68kRegisters r; |
1119 |
|
|
1120 |
|
// Determine parameters |
1164 |
|
r.d[2] = refNum; |
1165 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1166 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1167 |
< |
return r.d[0]; |
1167 |
> |
return (int16)r.d[0]; |
1168 |
|
} |
1169 |
|
|
1170 |
|
// Query file attributes (HFileParam) |
1171 |
|
static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID) |
1172 |
|
{ |
1173 |
< |
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)); |
1173 |
> |
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)); |
1174 |
|
|
1175 |
|
FSItem *fs_item; |
1176 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1177 |
< |
if (dir_index == 0) { // Query item specified by ioDirID and ioNamePtr |
1177 |
> |
if (dir_index <= 0) { // Query item specified by ioDirID and ioNamePtr |
1178 |
|
|
1179 |
|
// Find FSItem for given file |
1180 |
|
int16 result = get_item_and_path(pb, dirID, fs_item); |
1206 |
|
return fnfErr; |
1207 |
|
} |
1208 |
|
if (de->d_name[0] == '.') |
1209 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1209 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1210 |
|
//!! suppress directories |
1211 |
|
} |
1212 |
< |
add_path_component(de->d_name); |
1212 |
> |
add_path_comp(de->d_name); |
1213 |
|
|
1214 |
|
// Get FSItem for queried item |
1215 |
|
fs_item = find_fsitem(de->d_name, p); |
1230 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1231 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1232 |
|
|
1233 |
< |
#ifdef __BEOS__ |
1233 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1234 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1235 |
|
#else |
1236 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1237 |
|
#endif |
1238 |
|
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1239 |
|
|
1240 |
< |
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); |
1240 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1241 |
|
|
1242 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1243 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1244 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1244 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1245 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1246 |
|
uint32 rf_size = get_rfork_size(full_path); |
1247 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1248 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1248 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1249 |
|
|
1250 |
|
if (hfs) { |
1251 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1224 |
– |
memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); |
1252 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1253 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1254 |
|
} |
1258 |
|
// Set file attributes (HFileParam) |
1259 |
|
static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID) |
1260 |
|
{ |
1261 |
< |
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)); |
1261 |
> |
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)); |
1262 |
|
|
1263 |
|
// Find FSItem for given file/dir |
1264 |
|
FSItem *fs_item; |
1273 |
|
if (S_ISDIR(st.st_mode)) |
1274 |
|
return fnfErr; |
1275 |
|
|
1276 |
< |
// Set attributes |
1277 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1278 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1276 |
> |
// Set Finder info |
1277 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1278 |
> |
|
1279 |
|
//!! times |
1280 |
|
return noErr; |
1281 |
|
} |
1283 |
|
// Query file/directory attributes |
1284 |
|
static int16 fs_get_cat_info(uint32 pb) |
1285 |
|
{ |
1286 |
< |
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))); |
1286 |
> |
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))); |
1287 |
|
|
1288 |
|
FSItem *fs_item; |
1289 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1290 |
< |
if (dir_index == -1) { // Query directory specified by ioDirID |
1290 |
> |
if (dir_index < 0) { // Query directory specified by ioDirID |
1291 |
|
|
1292 |
|
// Find FSItem for directory |
1293 |
|
fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID)); |
1327 |
|
return fnfErr; |
1328 |
|
} |
1329 |
|
if (de->d_name[0] == '.') |
1330 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1330 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1331 |
|
} |
1332 |
< |
add_path_component(de->d_name); |
1332 |
> |
add_path_comp(de->d_name); |
1333 |
|
|
1334 |
|
// Get FSItem for queried item |
1335 |
|
fs_item = find_fsitem(de->d_name, p); |
1352 |
|
WriteMacInt8(pb + ioACUser, 0); |
1353 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1354 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1355 |
< |
#ifdef __BEOS__ |
1355 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1356 |
|
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1357 |
|
#else |
1358 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1363 |
|
fs_item->mtime = mtime; |
1364 |
|
cached = false; |
1365 |
|
} |
1366 |
< |
WriteMacInt32(pb + ioFlMdDat, mtime); |
1366 |
> |
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); |
1367 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1368 |
+ |
|
1369 |
+ |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1370 |
+ |
|
1371 |
|
if (S_ISDIR(st.st_mode)) { |
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); |
1372 |
|
|
1373 |
|
// Determine number of files in directory (cached) |
1374 |
|
int count; |
1383 |
|
de = readdir(d); |
1384 |
|
if (de == NULL) |
1385 |
|
break; |
1386 |
+ |
if (de->d_name[0] == '.') |
1387 |
+ |
continue; // Suppress names beginning with '.' |
1388 |
|
count++; |
1389 |
|
} |
1390 |
|
closedir(d); |
1393 |
|
} |
1394 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1395 |
|
} 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); |
1396 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1397 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1398 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1398 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1399 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1400 |
|
uint32 rf_size = get_rfork_size(full_path); |
1401 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1402 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1402 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1403 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1404 |
|
} |
1405 |
|
return noErr; |
1408 |
|
// Set file/directory attributes |
1409 |
|
static int16 fs_set_cat_info(uint32 pb) |
1410 |
|
{ |
1411 |
< |
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))); |
1411 |
> |
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))); |
1412 |
|
|
1413 |
|
// Find FSItem for given file/dir |
1414 |
|
FSItem *fs_item; |
1421 |
|
if (stat(full_path, &st) < 0) |
1422 |
|
return errno2oserr(); |
1423 |
|
|
1424 |
< |
// Set attributes |
1425 |
< |
if (S_ISDIR(st.st_mode)) |
1426 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags)); |
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 |
< |
} |
1424 |
> |
// Set Finder info |
1425 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1426 |
> |
|
1427 |
|
//!! times |
1428 |
|
return noErr; |
1429 |
|
} |
1431 |
|
// Open file |
1432 |
|
static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork) |
1433 |
|
{ |
1434 |
< |
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))); |
1434 |
> |
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))); |
1435 |
|
M68kRegisters r; |
1436 |
|
|
1437 |
|
// Find FSItem for given file |
1470 |
|
if (access(full_path, F_OK)) |
1471 |
|
return fnfErr; |
1472 |
|
fd = open_rfork(full_path, flag); |
1473 |
< |
if (fd > 0) { |
1474 |
< |
if (fstat(fd, &st) < 0) |
1473 |
> |
if (fd >= 0) { |
1474 |
> |
if (fstat(fd, &st) < 0) { |
1475 |
> |
close(fd); |
1476 |
|
return errno2oserr(); |
1477 |
+ |
} |
1478 |
|
} else { // Resource fork not supported, silently ignore it ("pseudo" resource fork) |
1479 |
|
st.st_size = 0; |
1480 |
|
st.st_mode = 0; |
1483 |
|
fd = open(full_path, flag); |
1484 |
|
if (fd < 0) |
1485 |
|
return errno2oserr(); |
1486 |
< |
if (fstat(fd, &st) < 0) |
1486 |
> |
if (fstat(fd, &st) < 0) { |
1487 |
> |
close(fd); |
1488 |
|
return errno2oserr(); |
1489 |
+ |
} |
1490 |
|
} |
1491 |
|
|
1492 |
|
// File open, allocate FCB |
1498 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1499 |
|
if (r.d[0] & 0xffff) { |
1500 |
|
close(fd); |
1501 |
< |
return r.d[0]; |
1501 |
> |
return (int16)r.d[0]; |
1502 |
|
} |
1503 |
|
|
1504 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1505 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1506 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1507 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1508 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1508 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1509 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1510 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1511 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1512 |
< |
uint32 type, creator; // fcb may point to kernel space, but stack is switched |
1513 |
< |
get_finder_type(full_path, type, creator); |
1514 |
< |
WriteMacInt32(fcb + fcbFType, type); |
1511 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1512 |
> |
|
1513 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1514 |
> |
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1515 |
> |
|
1516 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1517 |
|
WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); |
1518 |
|
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); |
1549 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1550 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1551 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1552 |
< |
return r.d[0]; |
1552 |
> |
return (int16)r.d[0]; |
1553 |
|
} |
1554 |
|
|
1555 |
|
// Query information about FCB (FCBPBRec) |
1568 |
|
|
1569 |
|
// Find FCB by index |
1570 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1571 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1571 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1572 |
|
D(bug(" indexing FCBs\n")); |
1573 |
|
r.a[0] = vcb; |
1574 |
|
r.a[1] = pb + ioRefNum; |
1577 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1578 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1579 |
|
if (r.d[0] & 0xffff) |
1580 |
< |
return r.d[0]; |
1580 |
> |
return (int16)r.d[0]; |
1581 |
|
} |
1582 |
|
} |
1583 |
|
if (fcb == 0) |
1625 |
|
|
1626 |
|
// Adjust FCBs |
1627 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1628 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1628 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1629 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1630 |
|
D(bug(" adjusting FCBs\n")); |
1631 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1660 |
|
|
1661 |
|
// Adjust FCBs |
1662 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1663 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1663 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1664 |
|
D(bug(" adjusting FCBs\n")); |
1665 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1666 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1723 |
|
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0) |
1724 |
|
return posErr; |
1725 |
|
break; |
1726 |
+ |
case fsFromLEOF: |
1727 |
+ |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0) |
1728 |
+ |
return posErr; |
1729 |
+ |
break; |
1730 |
|
case fsFromMark: |
1731 |
< |
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1731 |
> |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1732 |
|
return posErr; |
1733 |
+ |
break; |
1734 |
|
default: |
1735 |
|
break; |
1736 |
|
} |
1745 |
|
{ |
1746 |
|
D(bug(" fs_read(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset))); |
1747 |
|
|
1748 |
+ |
// Check parameters |
1749 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1750 |
+ |
return paramErr; |
1751 |
+ |
|
1752 |
|
// Find FCB and fd for file |
1753 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1754 |
|
if (fcb == 0) |
1780 |
|
} |
1781 |
|
|
1782 |
|
// Read |
1783 |
< |
size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1783 |
> |
ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1784 |
> |
int16 read_err = errno2oserr(); |
1785 |
|
D(bug(" actual %d\n", actual)); |
1786 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1786 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1787 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1788 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1789 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1790 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1791 |
< |
if (errno) |
1763 |
< |
return errno2oserr(); |
1764 |
< |
else |
1765 |
< |
return eofErr; |
1790 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1791 |
> |
return actual < 0 ? read_err : eofErr; |
1792 |
|
else |
1793 |
|
return noErr; |
1794 |
|
} |
1798 |
|
{ |
1799 |
|
D(bug(" fs_write(%08lx), refNum %d, buffer %p, count %d, posMode %d, posOffset %d\n", pb, ReadMacInt16(pb + ioRefNum), ReadMacInt32(pb + ioBuffer), ReadMacInt32(pb + ioReqCount), ReadMacInt16(pb + ioPosMode), ReadMacInt32(pb + ioPosOffset))); |
1800 |
|
|
1801 |
+ |
// Check parameters |
1802 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1803 |
+ |
return paramErr; |
1804 |
+ |
|
1805 |
|
// Find FCB and fd for file |
1806 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1807 |
|
if (fcb == 0) |
1833 |
|
} |
1834 |
|
|
1835 |
|
// Write |
1836 |
< |
size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1836 |
> |
ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1837 |
> |
int16 write_err = errno2oserr(); |
1838 |
|
D(bug(" actual %d\n", actual)); |
1839 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1839 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1840 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1841 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1842 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1843 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1844 |
< |
return errno2oserr(); |
1843 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1844 |
> |
return write_err; |
1845 |
|
else |
1846 |
|
return noErr; |
1847 |
|
} |
1849 |
|
// Create file |
1850 |
|
static int16 fs_create(uint32 pb, uint32 dirID) |
1851 |
|
{ |
1852 |
< |
D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1852 |
> |
D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID)); |
1853 |
|
|
1854 |
|
// Find FSItem for given file |
1855 |
|
FSItem *fs_item; |
1862 |
|
return dupFNErr; |
1863 |
|
|
1864 |
|
// Create file |
1865 |
< |
int fd = creat(full_path, 0664); |
1865 |
> |
int fd = creat(full_path, 0666); |
1866 |
|
if (fd < 0) |
1867 |
|
return errno2oserr(); |
1868 |
|
else { |
1874 |
|
// Create directory |
1875 |
|
static int16 fs_dir_create(uint32 pb) |
1876 |
|
{ |
1877 |
< |
D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID))); |
1877 |
> |
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))); |
1878 |
|
|
1879 |
|
// Find FSItem for given directory |
1880 |
|
FSItem *fs_item; |
1887 |
|
return dupFNErr; |
1888 |
|
|
1889 |
|
// Create directory |
1890 |
< |
if (mkdir(full_path, 0775) < 0) |
1890 |
> |
if (mkdir(full_path, 0777) < 0) |
1891 |
|
return errno2oserr(); |
1892 |
|
else { |
1893 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1898 |
|
// Delete file/directory |
1899 |
|
static int16 fs_delete(uint32 pb, uint32 dirID) |
1900 |
|
{ |
1901 |
< |
D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1901 |
> |
D(bug(" fs_delete(%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/dir |
1904 |
|
FSItem *fs_item; |
1907 |
|
return result; |
1908 |
|
|
1909 |
|
// Delete file |
1910 |
< |
if (remove(full_path) < 0) { |
1911 |
< |
int16 err = errno2oserr(); |
1912 |
< |
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 |
1910 |
> |
if (!extfs_remove(full_path)) |
1911 |
> |
return errno2oserr(); |
1912 |
> |
else |
1913 |
|
return noErr; |
1914 |
|
} |
1915 |
|
|
1916 |
|
// Rename file/directory |
1917 |
|
static int16 fs_rename(uint32 pb, uint32 dirID) |
1918 |
|
{ |
1919 |
< |
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)))); |
1919 |
> |
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))); |
1920 |
|
|
1921 |
|
// Find path of given file/dir |
1922 |
|
FSItem *fs_item; |
1929 |
|
strcpy(old_path, full_path); |
1930 |
|
|
1931 |
|
// Find path for new name |
1932 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
1933 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1910 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1932 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
1933 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1934 |
|
FSItem *new_item; |
1935 |
< |
result = get_item_and_path((uint32)new_pb, dirID, new_item); |
1935 |
> |
result = get_item_and_path(fs_data + fsPB, dirID, new_item); |
1936 |
|
if (result != noErr) |
1937 |
|
return result; |
1938 |
|
|
1942 |
|
|
1943 |
|
// Rename item |
1944 |
|
D(bug(" renaming %s -> %s\n", old_path, full_path)); |
1945 |
< |
if (rename(old_path, full_path) < 0) |
1945 |
> |
if (!extfs_rename(old_path, full_path)) |
1946 |
|
return errno2oserr(); |
1947 |
|
else { |
1948 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1949 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1950 |
|
uint32 t = fs_item->id; |
1951 |
|
fs_item->id = new_item->id; |
1952 |
|
new_item->id = t; |
1957 |
|
// Move file/directory (CMovePBRec) |
1958 |
|
static int16 fs_cat_move(uint32 pb) |
1959 |
|
{ |
1960 |
< |
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))); |
1960 |
> |
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))); |
1961 |
|
|
1962 |
|
// Find path of given file/dir |
1963 |
|
FSItem *fs_item; |
1970 |
|
strcpy(old_path, full_path); |
1971 |
|
|
1972 |
|
// Find path for new directory |
1973 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
1974 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1951 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
1973 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
1974 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
1975 |
|
FSItem *new_dir_item; |
1976 |
< |
result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
1976 |
> |
result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
1977 |
|
if (result != noErr) |
1978 |
|
return result; |
1979 |
|
|
1980 |
|
// Append old file/dir name |
1981 |
< |
add_path_component(fs_item->name); |
1981 |
> |
add_path_comp(fs_item->name); |
1982 |
|
|
1983 |
|
// Does the new name already exist? |
1984 |
|
if (access(full_path, F_OK) == 0) |
1986 |
|
|
1987 |
|
// Move item |
1988 |
|
D(bug(" moving %s -> %s\n", old_path, full_path)); |
1989 |
< |
if (rename(old_path, full_path) < 0) |
1989 |
> |
if (!extfs_rename(old_path, full_path)) |
1990 |
|
return errno2oserr(); |
1991 |
|
else { |
1992 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1993 |
|
FSItem *new_item = find_fsitem(fs_item->name, new_dir_item); |
1994 |
|
if (new_item) { |
1995 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1996 |
|
uint32 t = fs_item->id; |
1997 |
|
fs_item->id = new_item->id; |
1998 |
|
new_item->id = t; |
2004 |
|
// Open working directory (WDParam) |
2005 |
|
static int16 fs_open_wd(uint32 pb) |
2006 |
|
{ |
2007 |
< |
D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
2007 |
> |
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))); |
2008 |
|
M68kRegisters r; |
2009 |
|
|
2010 |
|
// Allocate WDCB |
2011 |
|
D(bug(" allocating WDCB\n")); |
2012 |
|
r.a[0] = pb; |
2013 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2014 |
< |
D(bug(" UTAllocateWDCB returned %d\n", r.d[0])); |
2015 |
< |
return r.d[0]; |
2014 |
> |
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2015 |
> |
return (int16)r.d[0]; |
2016 |
|
} |
2017 |
|
|
2018 |
|
// Close working directory (WDParam) |
2026 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2027 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2028 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2029 |
< |
return r.d[0]; |
2029 |
> |
return (int16)r.d[0]; |
2030 |
|
} |
2031 |
|
|
2032 |
|
// Query information about working directory (WDParam) |
2040 |
|
WriteMacInt32(pb + ioWDProcID, 0); |
2041 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum)); |
2042 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2043 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28); |
2043 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28); |
2044 |
|
WriteMacInt32(pb + ioWDDirID, ROOT_ID); |
2045 |
|
return noErr; |
2046 |
|
} |
2055 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2056 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2057 |
|
if (r.d[0] & 0xffff) |
2058 |
< |
return r.d[0]; |
2058 |
> |
return (int16)r.d[0]; |
2059 |
|
|
2060 |
|
// Return information |
2061 |
< |
WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2061 |
> |
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2062 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum)); |
2063 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2064 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28); |
2064 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28); |
2065 |
|
WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID)); |
2066 |
|
return noErr; |
2067 |
|
} |