72 |
|
fsAllocateVCB = 562, // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1}) |
73 |
|
fsAddNewVCB = 578, // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1}) |
74 |
|
fsDetermineVol = 594, // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4}) |
75 |
< |
fsResolveWDCB = 614, // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0}) |
75 |
> |
fsResolveWDCB = 614, // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0}) |
76 |
|
fsGetDefaultVol = 632, // UTGetDefaultVol(uint32 wdpb{a0}) |
77 |
|
fsGetPathComponentName = 644, // UTGetPathComponentName(uint32 rec{a0}) |
78 |
|
fsParsePathname = 656, // UTParsePathname(uint32 *start{a0}, uint32 name{a1}) |
201 |
|
* Get full path (->full_path) for given FSItem |
202 |
|
*/ |
203 |
|
|
204 |
– |
const int MAX_PATH_LENGTH = 1024; |
204 |
|
static char full_path[MAX_PATH_LENGTH]; |
205 |
|
|
206 |
< |
static void add_path_component(const char *s) |
206 |
> |
static void add_path_comp(const char *s) |
207 |
|
{ |
208 |
< |
int l = strlen(full_path); |
210 |
< |
if (l < MAX_PATH_LENGTH-1 && full_path[l-1] != '/') { |
211 |
< |
full_path[l] = '/'; |
212 |
< |
full_path[l+1] = 0; |
213 |
< |
} |
214 |
< |
strncat(full_path, s, MAX_PATH_LENGTH-1); |
208 |
> |
add_path_component(full_path, s); |
209 |
|
} |
210 |
|
|
211 |
|
static void get_path_for_fsitem(FSItem *p) |
212 |
|
{ |
213 |
< |
if (p->id == ROOT_ID) { |
213 |
> |
if (p->id == ROOT_PARENT_ID) { |
214 |
> |
full_path[0] = 0; |
215 |
> |
} else if (p->id == ROOT_ID) { |
216 |
|
strncpy(full_path, RootPath, MAX_PATH_LENGTH-1); |
217 |
|
full_path[MAX_PATH_LENGTH-1] = 0; |
218 |
|
} else { |
219 |
|
get_path_for_fsitem(p->parent); |
220 |
< |
add_path_component(p->name); |
220 |
> |
add_path_comp(p->name); |
221 |
|
} |
222 |
|
} |
223 |
|
|
436 |
|
WriteMacInt16(p, 0x7006); p+= 2; // UTAllocateVCB |
437 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
438 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
439 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
439 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
440 |
|
if (p - fs_data != fsAddNewVCB) |
441 |
|
goto fsdat_error; |
442 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
446 |
|
WriteMacInt16(p, 0x7007); p+= 2; // UTAddNewVCB |
447 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
448 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
449 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
449 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
450 |
|
if (p - fs_data != fsDetermineVol) |
451 |
|
goto fsdat_error; |
452 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
458 |
|
WriteMacInt16(p, 0x701d); p+= 2; // UTDetermineVol |
459 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
460 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
461 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
461 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
462 |
|
if (p - fs_data != fsResolveWDCB) |
463 |
|
goto fsdat_error; |
464 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
465 |
< |
WriteMacInt16(p, 0x42a7); p+= 2; // clr.l -(sp) |
466 |
< |
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
467 |
< |
WriteMacInt16(p, 0x3f00); p+= 2; // move.w d0,-(sp) |
465 |
> |
WriteMacInt16(p, 0x2f00); p+= 2; // move.l d0,-(sp) |
466 |
> |
WriteMacInt16(p, 0x3f01); p+= 2; // move.w d1,-(sp) |
467 |
> |
WriteMacInt16(p, 0x3f02); p+= 2; // move.w d2,-(sp) |
468 |
|
WriteMacInt16(p, 0x2f08); p+= 2; // move.l a0,-(sp) |
469 |
|
WriteMacInt16(p, 0x700e); p+= 2; // UTResolveWDCB |
470 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
471 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
472 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
472 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
473 |
|
if (p - fs_data != fsGetDefaultVol) |
474 |
|
goto fsdat_error; |
475 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
477 |
|
WriteMacInt16(p, 0x7012); p+= 2; // UTGetDefaultVol |
478 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
479 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
480 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
480 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
481 |
|
if (p - fs_data != fsGetPathComponentName) |
482 |
|
goto fsdat_error; |
483 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
485 |
|
WriteMacInt16(p, 0x701c); p+= 2; // UTGetPathComponentName |
486 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
487 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
488 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
488 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
489 |
|
if (p - fs_data != fsParsePathname) |
490 |
|
goto fsdat_error; |
491 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
494 |
|
WriteMacInt16(p, 0x701b); p+= 2; // UTParsePathname |
495 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
496 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
497 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
497 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
498 |
|
if (p - fs_data != fsDisposeVCB) |
499 |
|
goto fsdat_error; |
500 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
502 |
|
WriteMacInt16(p, 0x7008); p+= 2; // UTDisposeVCB |
503 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
504 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
505 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
505 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
506 |
|
if (p - fs_data != fsCheckWDRefNum) |
507 |
|
goto fsdat_error; |
508 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
510 |
|
WriteMacInt16(p, 0x7013); p+= 2; // UTCheckWDRefNum |
511 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
512 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
513 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
513 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
514 |
|
if (p - fs_data != fsSetDefaultVol) |
515 |
|
goto fsdat_error; |
516 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
520 |
|
WriteMacInt16(p, 0x7011); p+= 2; // UTSetDefaultVol |
521 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
522 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
523 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
523 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
524 |
|
if (p - fs_data != fsAllocateFCB) |
525 |
|
goto fsdat_error; |
526 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
529 |
|
WriteMacInt16(p, 0x7000); p+= 2; // UTAllocateFCB |
530 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
531 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
532 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
532 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
533 |
|
if (p - fs_data != fsReleaseFCB) |
534 |
|
goto fsdat_error; |
535 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
537 |
|
WriteMacInt16(p, 0x7001); p+= 2; // UTReleaseFCB |
538 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
539 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
540 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
540 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
541 |
|
if (p - fs_data != fsIndexFCB) |
542 |
|
goto fsdat_error; |
543 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
547 |
|
WriteMacInt16(p, 0x7004); p+= 2; // UTIndexFCB |
548 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
549 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
550 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
550 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
551 |
|
if (p - fs_data != fsResolveFCB) |
552 |
|
goto fsdat_error; |
553 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
556 |
|
WriteMacInt16(p, 0x7005); p+= 2; // UTResolveFCB |
557 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
558 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
559 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
559 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
560 |
|
if (p - fs_data != fsAdjustEOF) |
561 |
|
goto fsdat_error; |
562 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
564 |
|
WriteMacInt16(p, 0x7010); p+= 2; // UTAdjustEOF |
565 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
566 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
567 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
567 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
568 |
|
if (p - fs_data != fsAllocateWDCB) |
569 |
|
goto fsdat_error; |
570 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
572 |
|
WriteMacInt16(p, 0x700c); p+= 2; // UTAllocateWDCB |
573 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
574 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
575 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
575 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
576 |
|
if (p - fs_data != fsReleaseWDCB) |
577 |
|
goto fsdat_error; |
578 |
|
WriteMacInt16(p, 0x4267); p+= 2; // clr.w -(sp) |
580 |
|
WriteMacInt16(p, 0x700d); p+= 2; // UTReleaseWDCB |
581 |
|
WriteMacInt16(p, 0xa824); p+= 2; // FSMgr |
582 |
|
WriteMacInt16(p, 0x301f); p+= 2; // move.w (sp)+,d0 |
583 |
< |
WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2; |
583 |
> |
WriteMacInt16(p, M68K_RTS); p+= 2; |
584 |
|
if (p - fs_data != SIZEOF_fsdat) |
585 |
|
goto fsdat_error; |
586 |
|
|
732 |
|
current_dir = dirID; |
733 |
|
else { |
734 |
|
D(bug(" resolving WDCB\n")); |
735 |
< |
r.d[0] = ReadMacInt16(pb + ioVRefNum); |
735 |
> |
r.d[0] = 0; |
736 |
> |
r.d[1] = 0; |
737 |
> |
r.d[2] = ReadMacInt16(pb + ioVRefNum); |
738 |
|
r.a[0] = fs_data + fsReturn; |
739 |
|
Execute68k(fs_data + fsResolveWDCB, &r); |
740 |
|
uint32 wdcb = ReadMacInt32(fs_data + fsReturn); |
1154 |
|
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)); |
1155 |
|
|
1156 |
|
FSItem *fs_item; |
1157 |
< |
int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex); |
1157 |
> |
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1158 |
|
if (dir_index <= 0) { // Query item specified by ioDirID and ioNamePtr |
1159 |
|
|
1160 |
|
// Find FSItem for given file |
1190 |
|
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1191 |
|
//!! suppress directories |
1192 |
|
} |
1193 |
< |
add_path_component(de->d_name); |
1193 |
> |
add_path_comp(de->d_name); |
1194 |
|
|
1195 |
|
// Get FSItem for queried item |
1196 |
|
fs_item = find_fsitem(de->d_name, p); |
1275 |
|
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))); |
1276 |
|
|
1277 |
|
FSItem *fs_item; |
1278 |
< |
int16 dir_index = (int16)ReadMacInt16(pb + ioFDirIndex); |
1278 |
> |
int16 dir_index = ReadMacInt16(pb + ioFDirIndex); |
1279 |
|
if (dir_index < 0) { // Query directory specified by ioDirID |
1280 |
|
|
1281 |
|
// Find FSItem for directory |
1318 |
|
if (de->d_name[0] == '.') |
1319 |
|
goto read_next_de; // Suppress name beginning with '.' (MacOS could interpret these as driver names) |
1320 |
|
} |
1321 |
< |
add_path_component(de->d_name); |
1321 |
> |
add_path_comp(de->d_name); |
1322 |
|
|
1323 |
|
// Get FSItem for queried item |
1324 |
|
fs_item = find_fsitem(de->d_name, p); |
1852 |
|
return dupFNErr; |
1853 |
|
|
1854 |
|
// Create file |
1855 |
< |
int fd = creat(full_path, 0664); |
1855 |
> |
int fd = creat(full_path, 0666); |
1856 |
|
if (fd < 0) |
1857 |
|
return errno2oserr(); |
1858 |
|
else { |
1877 |
|
return dupFNErr; |
1878 |
|
|
1879 |
|
// Create directory |
1880 |
< |
if (mkdir(full_path, 0775) < 0) |
1880 |
> |
if (mkdir(full_path, 0777) < 0) |
1881 |
|
return errno2oserr(); |
1882 |
|
else { |
1883 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1976 |
|
return result; |
1977 |
|
|
1978 |
|
// Append old file/dir name |
1979 |
< |
add_path_component(fs_item->name); |
1979 |
> |
add_path_comp(fs_item->name); |
1980 |
|
|
1981 |
|
// Does the new name already exist? |
1982 |
|
if (access(full_path, F_OK) == 0) |
2008 |
|
D(bug(" allocating WDCB\n")); |
2009 |
|
r.a[0] = pb; |
2010 |
|
Execute68k(fs_data + fsAllocateWDCB, &r); |
2011 |
< |
D(bug(" UTAllocateWDCB returned %d\n", r.d[0])); |
2011 |
> |
D(bug(" UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum))); |
2012 |
|
return r.d[0]; |
2013 |
|
} |
2014 |
|
|