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-2004 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; |
730 |
|
if (no_vol_name) |
731 |
|
WriteMacInt32(pb + ioNamePtr, name_ptr); |
732 |
|
int16 status = ReadMacInt16(fs_data + fsReturn); |
733 |
< |
int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); |
734 |
< |
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; |
733 |
> |
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
734 |
> |
result = (int16)(r.d[0] & 0xffff); |
735 |
|
|
736 |
|
if (result == noErr) { |
737 |
|
switch (status) { |
749 |
|
current_dir = dirID; |
750 |
|
else { |
751 |
|
D(bug(" resolving WDCB\n")); |
752 |
< |
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
752 |
> |
r.d[0] = 0; |
753 |
> |
r.d[1] = 0; |
754 |
> |
r.d[2] = ReadMacInt16(pb + ioVRefNum); |
755 |
|
r.a[0] = fs_data + fsReturn; |
756 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
757 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
758 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
759 |
< |
result = r.d[0] & 0xffff; |
759 |
> |
result = (int16)(r.d[0] & 0xffff); |
760 |
|
if (result == noErr) |
761 |
|
current_dir = ReadMacInt32(wdcb + wdDirID); |
762 |
|
} |
772 |
|
r.a[0] = wdpb; |
773 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
774 |
|
D(bug(" UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID))); |
775 |
< |
result = r.d[0] & 0xffff; |
775 |
> |
result = (int16)(r.d[0] & 0xffff); |
776 |
|
if (result == noErr) |
777 |
|
current_dir = ReadMacInt32(wdpb + ioWDDirID); |
778 |
|
} |
798 |
|
r.a[0] = rec; |
799 |
|
Execute68k(fs_data + fsGetPathComponentName, &r); |
800 |
|
// D(bug(" UTGetPathComponentName returned %d\n", r.d[0])); |
801 |
< |
return r.d[0] & 0xffff; |
801 |
> |
return (int16)(r.d[0] & 0xffff); |
802 |
|
} |
803 |
|
|
804 |
|
|
815 |
|
uint32 current_dir; |
816 |
|
if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr) |
817 |
|
return result; |
818 |
+ |
D(bug(" current dir %08x\n", current_dir)); |
819 |
|
FSItem *p = find_fsitem_by_id(current_dir); |
820 |
|
if (p == NULL) |
821 |
|
return dirNFErr; |
829 |
|
WriteMacInt8(parseRec + ppFoundDelimiter, false); |
830 |
|
|
831 |
|
// Get length of volume name |
832 |
< |
// D(bug(" parsing pathname\n")); |
832 |
> |
D(bug(" parsing pathname\n")); |
833 |
|
r.a[0] = parseRec + ppStartOffset; |
834 |
|
r.a[1] = ReadMacInt32(parseRec + ppNamePtr); |
835 |
|
Execute68k(fs_data + fsParsePathname, &r); |
836 |
< |
// D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
837 |
< |
result = r.d[0] & 0xffff; |
836 |
> |
D(bug(" UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset))); |
837 |
> |
result = (int16)(r.d[0] & 0xffff); |
838 |
|
if (result == noErr) { |
839 |
|
|
840 |
|
// Check for leading delimiter of the partial pathname |
947 |
|
static int16 fs_mount_vol(uint32 pb) |
948 |
|
{ |
949 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
950 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
950 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
951 |
|
return noErr; |
952 |
|
else |
953 |
|
return extFSErr; |
964 |
|
r.a[0] = fs_data + fsReturn; |
965 |
|
r.a[1] = fs_data + fsReturn + 2; |
966 |
|
Execute68k(fs_data + fsAllocateVCB, &r); |
967 |
+ |
#if DEBUG |
968 |
|
uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn); |
969 |
+ |
#endif |
970 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
971 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
972 |
|
if (r.d[0] & 0xffff) |
973 |
< |
return r.d[0]; |
973 |
> |
return (int16)r.d[0]; |
974 |
|
|
975 |
|
// Init VCB |
976 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
977 |
< |
#ifdef __BEOS__ |
978 |
< |
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
977 |
> |
#if defined(__BEOS__) || defined(WIN32) |
978 |
> |
WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime)); |
979 |
|
#else |
980 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
981 |
|
#endif |
982 |
< |
WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET); |
982 |
> |
WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime)); |
983 |
|
WriteMacInt32(vcb + vcbVolBkUp, 0); |
984 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
985 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
986 |
|
WriteMacInt16(vcb + vcbNmAlBlks, 0xffff); //!! |
987 |
< |
WriteMacInt32(vcb + vcbAlBlkSiz, 1024); |
988 |
< |
WriteMacInt32(vcb + vcbClpSiz, 1024); |
987 |
> |
WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE); |
988 |
> |
WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE); |
989 |
|
WriteMacInt32(vcb + vcbNxtCNID, next_cnid); |
990 |
|
WriteMacInt16(vcb + vcbFreeBks, 0xffff); //!! |
991 |
< |
memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28); |
991 |
> |
Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28); |
992 |
|
WriteMacInt16(vcb + vcbFSID, MY_FSID); |
993 |
|
WriteMacInt32(vcb + vcbFilCnt, 1); //!! |
994 |
|
WriteMacInt32(vcb + vcbDirCnt, 1); //!! |
999 |
|
r.a[0] = fs_data + fsReturn; |
1000 |
|
r.a[1] = vcb; |
1001 |
|
Execute68k(fs_data + fsAddNewVCB, &r); |
1002 |
< |
int16 vRefNum = ReadMacInt32(fs_data + fsReturn); |
1002 |
> |
int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn); |
1003 |
|
D(bug(" UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum)); |
1004 |
|
if (r.d[0] & 0xffff) |
1005 |
< |
return r.d[0]; |
1005 |
> |
return (int16)r.d[0]; |
1006 |
|
|
1007 |
|
// Post diskInsertEvent |
1008 |
|
D(bug(" posting diskInsertEvent\n")); |
1026 |
|
r.a[0] = vcb; |
1027 |
|
Execute68k(fs_data + fsDisposeVCB, &r); |
1028 |
|
D(bug(" UTDisposeVCB() returned %d\n", r.d[0])); |
1029 |
< |
return r.d[0]; |
1029 |
> |
return (int16)r.d[0]; |
1030 |
|
} |
1031 |
|
|
1032 |
|
// Get information about a volume (HVolumeParam) |
1037 |
|
// Fill in struct |
1038 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1039 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1040 |
< |
#ifdef __BEOS__ |
1041 |
< |
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1040 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1041 |
> |
WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime)); |
1042 |
|
#else |
1043 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1044 |
|
#endif |
1045 |
< |
WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET); |
1045 |
> |
WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime)); |
1046 |
|
WriteMacInt16(pb + ioVAtrb, 0); |
1047 |
|
WriteMacInt16(pb + ioVNmFls, 1); //!! |
1048 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1049 |
|
WriteMacInt16(pb + ioAllocPtr, 0); |
1050 |
|
WriteMacInt16(pb + ioVNmAlBlks, 0xffff); //!! |
1051 |
< |
WriteMacInt32(pb + ioVAlBlkSiz, 1024); |
1052 |
< |
WriteMacInt32(pb + ioVClpSiz, 1024); |
1051 |
> |
WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE); |
1052 |
> |
WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE); |
1053 |
|
WriteMacInt16(pb + ioAlBlSt, 0); |
1054 |
|
WriteMacInt32(pb + ioVNxtCNID, next_cnid); |
1055 |
|
WriteMacInt16(pb + ioVFrBlk, 0xffff); //!! |
1062 |
|
WriteMacInt32(pb + ioVWrCnt, 0); |
1063 |
|
WriteMacInt32(pb + ioVFilCnt, 1); //!! |
1064 |
|
WriteMacInt32(pb + ioVDirCnt, 1); //!! |
1065 |
< |
memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32); |
1065 |
> |
Mac_memset(pb + ioVFndrInfo, 0, 32); |
1066 |
|
} |
1067 |
|
return noErr; |
1068 |
|
} |
1082 |
|
// D(bug(" fs_get_vol_parms(%08lx)\n", pb)); |
1083 |
|
|
1084 |
|
// 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); |
1085 |
|
uint32 actual = ReadMacInt32(pb + ioReqCount); |
1086 |
< |
if (actual > sizeof(vol)) |
1087 |
< |
actual = sizeof(vol); |
1060 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual); |
1086 |
> |
if (actual > SIZEOF_GetVolParmsInfoBuffer) |
1087 |
> |
actual = SIZEOF_GetVolParmsInfoBuffer; |
1088 |
|
WriteMacInt32(pb + ioActCount, actual); |
1089 |
+ |
uint32 p = ReadMacInt32(pb + ioBuffer); |
1090 |
+ |
if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2); |
1091 |
+ |
if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol); |
1092 |
+ |
if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0); |
1093 |
+ |
if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0); |
1094 |
+ |
if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0); |
1095 |
+ |
if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0); |
1096 |
|
return noErr; |
1097 |
|
} |
1098 |
|
|
1107 |
|
r.a[0] = pb; |
1108 |
|
Execute68k(fs_data + fsGetDefaultVol, &r); |
1109 |
|
D(bug(" UTGetDefaultVol() returned %d\n", r.d[0])); |
1110 |
< |
return r.d[0]; |
1110 |
> |
return (int16)r.d[0]; |
1111 |
|
} |
1112 |
|
|
1113 |
|
// Set default volume (WDParam) |
1114 |
|
static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb) |
1115 |
|
{ |
1116 |
< |
D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
1116 |
> |
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))); |
1117 |
|
M68kRegisters r; |
1118 |
|
|
1119 |
|
// Determine parameters |
1163 |
|
r.d[2] = refNum; |
1164 |
|
Execute68k(fs_data + fsSetDefaultVol, &r); |
1165 |
|
D(bug(" UTSetDefaultVol() returned %d\n", r.d[0])); |
1166 |
< |
return r.d[0]; |
1166 |
> |
return (int16)r.d[0]; |
1167 |
|
} |
1168 |
|
|
1169 |
|
// Query file attributes (HFileParam) |
1170 |
|
static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID) |
1171 |
|
{ |
1172 |
< |
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)); |
1172 |
> |
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)); |
1173 |
|
|
1174 |
|
FSItem *fs_item; |
1175 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1176 |
< |
if (dir_index == 0) { // Query item specified by ioDirID and ioNamePtr |
1176 |
> |
if (dir_index <= 0) { // Query item specified by ioDirID and ioNamePtr |
1177 |
|
|
1178 |
|
// Find FSItem for given file |
1179 |
|
int16 result = get_item_and_path(pb, dirID, fs_item); |
1205 |
|
return fnfErr; |
1206 |
|
} |
1207 |
|
if (de->d_name[0] == '.') |
1208 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1208 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1209 |
|
//!! suppress directories |
1210 |
|
} |
1211 |
< |
add_path_component(de->d_name); |
1211 |
> |
add_path_comp(de->d_name); |
1212 |
|
|
1213 |
|
// Get FSItem for queried item |
1214 |
|
fs_item = find_fsitem(de->d_name, p); |
1229 |
|
WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked); |
1230 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1231 |
|
|
1232 |
< |
#ifdef __BEOS__ |
1233 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1232 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1233 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1234 |
|
#else |
1235 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1236 |
|
#endif |
1237 |
< |
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1237 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime)); |
1238 |
|
|
1239 |
< |
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); |
1239 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1240 |
|
|
1241 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1242 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1243 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1243 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1244 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1245 |
|
uint32 rf_size = get_rfork_size(full_path); |
1246 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1247 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1247 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1248 |
|
|
1249 |
|
if (hfs) { |
1250 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1224 |
– |
memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo); |
1251 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1252 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1253 |
|
} |
1257 |
|
// Set file attributes (HFileParam) |
1258 |
|
static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID) |
1259 |
|
{ |
1260 |
< |
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)); |
1260 |
> |
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)); |
1261 |
|
|
1262 |
|
// Find FSItem for given file/dir |
1263 |
|
FSItem *fs_item; |
1272 |
|
if (S_ISDIR(st.st_mode)) |
1273 |
|
return fnfErr; |
1274 |
|
|
1275 |
< |
// Set attributes |
1276 |
< |
set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator)); |
1277 |
< |
set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags)); |
1275 |
> |
// Set Finder info |
1276 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1277 |
> |
|
1278 |
|
//!! times |
1279 |
|
return noErr; |
1280 |
|
} |
1282 |
|
// Query file/directory attributes |
1283 |
|
static int16 fs_get_cat_info(uint32 pb) |
1284 |
|
{ |
1285 |
< |
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))); |
1285 |
> |
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))); |
1286 |
|
|
1287 |
|
FSItem *fs_item; |
1288 |
|
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1289 |
< |
if (dir_index == -1) { // Query directory specified by ioDirID |
1289 |
> |
if (dir_index < 0) { // Query directory specified by ioDirID |
1290 |
|
|
1291 |
|
// Find FSItem for directory |
1292 |
|
fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID)); |
1326 |
|
return fnfErr; |
1327 |
|
} |
1328 |
|
if (de->d_name[0] == '.') |
1329 |
< |
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1329 |
> |
goto read_next_de; // Suppress names beginning with '.' (MacOS could interpret these as driver names) |
1330 |
|
} |
1331 |
< |
add_path_component(de->d_name); |
1331 |
> |
add_path_comp(de->d_name); |
1332 |
|
|
1333 |
|
// Get FSItem for queried item |
1334 |
|
fs_item = find_fsitem(de->d_name, p); |
1351 |
|
WriteMacInt8(pb + ioACUser, 0); |
1352 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1353 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1354 |
< |
#ifdef __BEOS__ |
1355 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1354 |
> |
#if defined(__BEOS__) || defined(WIN32) |
1355 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1356 |
|
#else |
1357 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1358 |
|
#endif |
1362 |
|
fs_item->mtime = mtime; |
1363 |
|
cached = false; |
1364 |
|
} |
1365 |
< |
WriteMacInt32(pb + ioFlMdDat, mtime); |
1365 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime)); |
1366 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1367 |
+ |
|
1368 |
+ |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1369 |
+ |
|
1370 |
|
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); |
1371 |
|
|
1372 |
|
// Determine number of files in directory (cached) |
1373 |
|
int count; |
1382 |
|
de = readdir(d); |
1383 |
|
if (de == NULL) |
1384 |
|
break; |
1385 |
+ |
if (de->d_name[0] == '.') |
1386 |
+ |
continue; // Suppress names beginning with '.' |
1387 |
|
count++; |
1388 |
|
} |
1389 |
|
closedir(d); |
1392 |
|
} |
1393 |
|
WriteMacInt16(pb + ioDrNmFls, count); |
1394 |
|
} 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); |
1395 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1396 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1397 |
< |
WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023); |
1397 |
> |
WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1398 |
|
WriteMacInt16(pb + ioFlRStBlk, 0); |
1399 |
|
uint32 rf_size = get_rfork_size(full_path); |
1400 |
|
WriteMacInt32(pb + ioFlRLgLen, rf_size); |
1401 |
< |
WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023); |
1401 |
> |
WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1); |
1402 |
|
WriteMacInt32(pb + ioFlClpSiz, 0); |
1403 |
|
} |
1404 |
|
return noErr; |
1407 |
|
// Set file/directory attributes |
1408 |
|
static int16 fs_set_cat_info(uint32 pb) |
1409 |
|
{ |
1410 |
< |
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))); |
1410 |
> |
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))); |
1411 |
|
|
1412 |
|
// Find FSItem for given file/dir |
1413 |
|
FSItem *fs_item; |
1420 |
|
if (stat(full_path, &st) < 0) |
1421 |
|
return errno2oserr(); |
1422 |
|
|
1423 |
< |
// Set attributes |
1424 |
< |
if (S_ISDIR(st.st_mode)) |
1425 |
< |
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 |
< |
} |
1423 |
> |
// Set Finder info |
1424 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1425 |
> |
|
1426 |
|
//!! times |
1427 |
|
return noErr; |
1428 |
|
} |
1430 |
|
// Open file |
1431 |
|
static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork) |
1432 |
|
{ |
1433 |
< |
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))); |
1433 |
> |
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))); |
1434 |
|
M68kRegisters r; |
1435 |
|
|
1436 |
|
// Find FSItem for given file |
1469 |
|
if (access(full_path, F_OK)) |
1470 |
|
return fnfErr; |
1471 |
|
fd = open_rfork(full_path, flag); |
1472 |
< |
if (fd > 0) { |
1473 |
< |
if (fstat(fd, &st) < 0) |
1472 |
> |
if (fd >= 0) { |
1473 |
> |
if (fstat(fd, &st) < 0) { |
1474 |
> |
close(fd); |
1475 |
|
return errno2oserr(); |
1476 |
+ |
} |
1477 |
|
} else { // Resource fork not supported, silently ignore it ("pseudo" resource fork) |
1478 |
|
st.st_size = 0; |
1479 |
|
st.st_mode = 0; |
1482 |
|
fd = open(full_path, flag); |
1483 |
|
if (fd < 0) |
1484 |
|
return errno2oserr(); |
1485 |
< |
if (fstat(fd, &st) < 0) |
1485 |
> |
if (fstat(fd, &st) < 0) { |
1486 |
> |
close(fd); |
1487 |
|
return errno2oserr(); |
1488 |
+ |
} |
1489 |
|
} |
1490 |
|
|
1491 |
|
// File open, allocate FCB |
1497 |
|
D(bug(" UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb)); |
1498 |
|
if (r.d[0] & 0xffff) { |
1499 |
|
close(fd); |
1500 |
< |
return r.d[0]; |
1500 |
> |
return (int16)r.d[0]; |
1501 |
|
} |
1502 |
|
|
1503 |
|
// Initialize FCB, fd is stored in fcbCatPos |
1504 |
|
WriteMacInt32(fcb + fcbFlNm, fs_item->id); |
1505 |
|
WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask)); |
1506 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1507 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1507 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1508 |
|
WriteMacInt32(fcb + fcbCrPs, 0); |
1509 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1510 |
< |
WriteMacInt32(fcb + fcbClmpSize, 1024); |
1511 |
< |
uint32 type, creator; // fcb may point to kernel space, but stack is switched |
1512 |
< |
get_finder_type(full_path, type, creator); |
1513 |
< |
WriteMacInt32(fcb + fcbFType, type); |
1510 |
> |
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1511 |
> |
|
1512 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1513 |
> |
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1514 |
> |
|
1515 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1516 |
|
WriteMacInt32(fcb + fcbDirID, fs_item->parent_id); |
1517 |
|
cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name); |
1548 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1549 |
|
Execute68k(fs_data + fsReleaseFCB, &r); |
1550 |
|
D(bug(" UTReleaseFCB() returned %d\n", r.d[0])); |
1551 |
< |
return r.d[0]; |
1551 |
> |
return (int16)r.d[0]; |
1552 |
|
} |
1553 |
|
|
1554 |
|
// Query information about FCB (FCBPBRec) |
1567 |
|
|
1568 |
|
// Find FCB by index |
1569 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1570 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1570 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1571 |
|
D(bug(" indexing FCBs\n")); |
1572 |
|
r.a[0] = vcb; |
1573 |
|
r.a[1] = pb + ioRefNum; |
1576 |
|
fcb = ReadMacInt32(fs_data + fsReturn); |
1577 |
|
D(bug(" UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb)); |
1578 |
|
if (r.d[0] & 0xffff) |
1579 |
< |
return r.d[0]; |
1579 |
> |
return (int16)r.d[0]; |
1580 |
|
} |
1581 |
|
} |
1582 |
|
if (fcb == 0) |
1624 |
|
|
1625 |
|
// Adjust FCBs |
1626 |
|
WriteMacInt32(fcb + fcbEOF, st.st_size); |
1627 |
< |
WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023); |
1627 |
> |
WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1); |
1628 |
|
WriteMacInt32(pb + ioMisc, st.st_size); |
1629 |
|
D(bug(" adjusting FCBs\n")); |
1630 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1659 |
|
|
1660 |
|
// Adjust FCBs |
1661 |
|
WriteMacInt32(fcb + fcbEOF, size); |
1662 |
< |
WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023); |
1662 |
> |
WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1); |
1663 |
|
D(bug(" adjusting FCBs\n")); |
1664 |
|
r.d[0] = ReadMacInt16(pb + ioRefNum); |
1665 |
|
Execute68k(fs_data + fsAdjustEOF, &r); |
1722 |
|
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0) |
1723 |
|
return posErr; |
1724 |
|
break; |
1725 |
+ |
case fsFromLEOF: |
1726 |
+ |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0) |
1727 |
+ |
return posErr; |
1728 |
+ |
break; |
1729 |
|
case fsFromMark: |
1730 |
< |
if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1730 |
> |
if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0) |
1731 |
|
return posErr; |
1732 |
+ |
break; |
1733 |
|
default: |
1734 |
|
break; |
1735 |
|
} |
1744 |
|
{ |
1745 |
|
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))); |
1746 |
|
|
1747 |
+ |
// Check parameters |
1748 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1749 |
+ |
return paramErr; |
1750 |
+ |
|
1751 |
|
// Find FCB and fd for file |
1752 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1753 |
|
if (fcb == 0) |
1779 |
|
} |
1780 |
|
|
1781 |
|
// Read |
1782 |
< |
size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1782 |
> |
ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1783 |
> |
int16 read_err = errno2oserr(); |
1784 |
|
D(bug(" actual %d\n", actual)); |
1785 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1785 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1786 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1787 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1788 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1789 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1790 |
< |
if (errno) |
1763 |
< |
return errno2oserr(); |
1764 |
< |
else |
1765 |
< |
return eofErr; |
1789 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1790 |
> |
return actual < 0 ? read_err : eofErr; |
1791 |
|
else |
1792 |
|
return noErr; |
1793 |
|
} |
1797 |
|
{ |
1798 |
|
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))); |
1799 |
|
|
1800 |
+ |
// Check parameters |
1801 |
+ |
if ((int32)ReadMacInt32(pb + ioReqCount) < 0) |
1802 |
+ |
return paramErr; |
1803 |
+ |
|
1804 |
|
// Find FCB and fd for file |
1805 |
|
uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum)); |
1806 |
|
if (fcb == 0) |
1832 |
|
} |
1833 |
|
|
1834 |
|
// Write |
1835 |
< |
size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1835 |
> |
ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount)); |
1836 |
> |
int16 write_err = errno2oserr(); |
1837 |
|
D(bug(" actual %d\n", actual)); |
1838 |
< |
WriteMacInt32(pb + ioActCount, actual); |
1838 |
> |
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0); |
1839 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1840 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1841 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1842 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1843 |
< |
return errno2oserr(); |
1842 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1843 |
> |
return write_err; |
1844 |
|
else |
1845 |
|
return noErr; |
1846 |
|
} |
1848 |
|
// Create file |
1849 |
|
static int16 fs_create(uint32 pb, uint32 dirID) |
1850 |
|
{ |
1851 |
< |
D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1851 |
> |
D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID)); |
1852 |
|
|
1853 |
|
// Find FSItem for given file |
1854 |
|
FSItem *fs_item; |
1861 |
|
return dupFNErr; |
1862 |
|
|
1863 |
|
// Create file |
1864 |
< |
int fd = creat(full_path, 0664); |
1864 |
> |
int fd = creat(full_path, 0666); |
1865 |
|
if (fd < 0) |
1866 |
|
return errno2oserr(); |
1867 |
|
else { |
1873 |
|
// Create directory |
1874 |
|
static int16 fs_dir_create(uint32 pb) |
1875 |
|
{ |
1876 |
< |
D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID))); |
1876 |
> |
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))); |
1877 |
|
|
1878 |
|
// Find FSItem for given directory |
1879 |
|
FSItem *fs_item; |
1886 |
|
return dupFNErr; |
1887 |
|
|
1888 |
|
// Create directory |
1889 |
< |
if (mkdir(full_path, 0775) < 0) |
1889 |
> |
if (mkdir(full_path, 0777) < 0) |
1890 |
|
return errno2oserr(); |
1891 |
|
else { |
1892 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1897 |
|
// Delete file/directory |
1898 |
|
static int16 fs_delete(uint32 pb, uint32 dirID) |
1899 |
|
{ |
1900 |
< |
D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID)); |
1900 |
> |
D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID)); |
1901 |
|
|
1902 |
|
// Find FSItem for given file/dir |
1903 |
|
FSItem *fs_item; |
1906 |
|
return result; |
1907 |
|
|
1908 |
|
// Delete file |
1909 |
< |
if (remove(full_path) < 0) { |
1910 |
< |
int16 err = errno2oserr(); |
1911 |
< |
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 |
1909 |
> |
if (!extfs_remove(full_path)) |
1910 |
> |
return errno2oserr(); |
1911 |
> |
else |
1912 |
|
return noErr; |
1913 |
|
} |
1914 |
|
|
1915 |
|
// Rename file/directory |
1916 |
|
static int16 fs_rename(uint32 pb, uint32 dirID) |
1917 |
|
{ |
1918 |
< |
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)))); |
1918 |
> |
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))); |
1919 |
|
|
1920 |
|
// Find path of given file/dir |
1921 |
|
FSItem *fs_item; |
1928 |
|
strcpy(old_path, full_path); |
1929 |
|
|
1930 |
|
// Find path for new name |
1931 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
1932 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1910 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1931 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
1932 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc)); |
1933 |
|
FSItem *new_item; |
1934 |
< |
result = get_item_and_path((uint32)new_pb, dirID, new_item); |
1934 |
> |
result = get_item_and_path(fs_data + fsPB, dirID, new_item); |
1935 |
|
if (result != noErr) |
1936 |
|
return result; |
1937 |
|
|
1941 |
|
|
1942 |
|
// Rename item |
1943 |
|
D(bug(" renaming %s -> %s\n", old_path, full_path)); |
1944 |
< |
if (rename(old_path, full_path) < 0) |
1944 |
> |
if (!extfs_rename(old_path, full_path)) |
1945 |
|
return errno2oserr(); |
1946 |
|
else { |
1947 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1948 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1949 |
|
uint32 t = fs_item->id; |
1950 |
|
fs_item->id = new_item->id; |
1951 |
|
new_item->id = t; |
1956 |
|
// Move file/directory (CMovePBRec) |
1957 |
|
static int16 fs_cat_move(uint32 pb) |
1958 |
|
{ |
1959 |
< |
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))); |
1959 |
> |
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))); |
1960 |
|
|
1961 |
|
// Find path of given file/dir |
1962 |
|
FSItem *fs_item; |
1969 |
|
strcpy(old_path, full_path); |
1970 |
|
|
1971 |
|
// Find path for new directory |
1972 |
< |
uint8 new_pb[SIZEOF_IOParam]; |
1973 |
< |
memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam); |
1951 |
< |
WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
1972 |
> |
Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam); |
1973 |
> |
WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName)); |
1974 |
|
FSItem *new_dir_item; |
1975 |
< |
result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
1975 |
> |
result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item); |
1976 |
|
if (result != noErr) |
1977 |
|
return result; |
1978 |
|
|
1979 |
|
// Append old file/dir name |
1980 |
< |
add_path_component(fs_item->name); |
1980 |
> |
add_path_comp(fs_item->name); |
1981 |
|
|
1982 |
|
// Does the new name already exist? |
1983 |
|
if (access(full_path, F_OK) == 0) |
1985 |
|
|
1986 |
|
// Move item |
1987 |
|
D(bug(" moving %s -> %s\n", old_path, full_path)); |
1988 |
< |
if (rename(old_path, full_path) < 0) |
1988 |
> |
if (!extfs_rename(old_path, full_path)) |
1989 |
|
return errno2oserr(); |
1990 |
|
else { |
1991 |
|
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems |
1992 |
|
FSItem *new_item = find_fsitem(fs_item->name, new_dir_item); |
1993 |
|
if (new_item) { |
1994 |
+ |
swap_parent_ids(fs_item->id, new_item->id); |
1995 |
|
uint32 t = fs_item->id; |
1996 |
|
fs_item->id = new_item->id; |
1997 |
|
new_item->id = t; |
2003 |
|
// Open working directory (WDParam) |
2004 |
|
static int16 fs_open_wd(uint32 pb) |
2005 |
|
{ |
2006 |
< |
D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID))); |
2006 |
> |
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))); |
2007 |
|
M68kRegisters r; |
2008 |
|
|
2009 |
|
// Allocate WDCB |
2010 |
|
D(bug(" allocating WDCB\n")); |
2011 |
|
r.a[0] = pb; |
2012 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2013 |
< |
D(bug(" UTAllocateWDCB returned %d\n", r.d[0])); |
2014 |
< |
return r.d[0]; |
2013 |
> |
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2014 |
> |
return (int16)r.d[0]; |
2015 |
|
} |
2016 |
|
|
2017 |
|
// Close working directory (WDParam) |
2025 |
|
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
2026 |
|
Execute68k(fs_data + fsReleaseWDCB, &r); |
2027 |
|
D(bug(" UTReleaseWDCB returned %d\n", r.d[0])); |
2028 |
< |
return r.d[0]; |
2028 |
> |
return (int16)r.d[0]; |
2029 |
|
} |
2030 |
|
|
2031 |
|
// Query information about working directory (WDParam) |
2039 |
|
WriteMacInt32(pb + ioWDProcID, 0); |
2040 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum)); |
2041 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2042 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28); |
2042 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28); |
2043 |
|
WriteMacInt32(pb + ioWDDirID, ROOT_ID); |
2044 |
|
return noErr; |
2045 |
|
} |
2054 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
2055 |
|
D(bug(" UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID))); |
2056 |
|
if (r.d[0] & 0xffff) |
2057 |
< |
return r.d[0]; |
2057 |
> |
return (int16)r.d[0]; |
2058 |
|
|
2059 |
|
// Return information |
2060 |
< |
WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2060 |
> |
WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID)); |
2061 |
|
WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum)); |
2062 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
2063 |
< |
memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28); |
2063 |
> |
Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28); |
2064 |
|
WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID)); |
2065 |
|
return noErr; |
2066 |
|
} |