ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/extfs.cpp
(Generate patch)

Comparing BasiliskII/src/extfs.cpp (file contents):
Revision 1.2 by cebix, 1999-10-19T21:33:56Z vs.
Revision 1.32 by asvitkine, 2007-01-22T17:14:06Z

# Line 1 | Line 1
1   /*
2 < *  extfs.cpp - MacOS file system for access native file system access
2 > *  extfs.cpp - MacOS file system for native file system access
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 19 | Line 19
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  
# Line 37 | Line 40 | UnlockRng
40   #include <string.h>
41   #include <stdio.h>
42   #include <stdlib.h>
40 #include <unistd.h>
43   #include <fcntl.h>
42 #include <dirent.h>
44   #include <errno.h>
45  
46 + #ifndef WIN32
47 + #include <unistd.h>
48 + #include <dirent.h>
49 + #endif
50 +
51 + #if defined __APPLE__ && defined __MACH__
52 + #include <sys/attr.h>
53 + #endif
54 +
55   #include "cpu_emulation.h"
46 #include "macos_util.h"
56   #include "emul_op.h"
57   #include "main.h"
58   #include "disk.h"
# Line 52 | Line 61 | UnlockRng
61   #include "extfs.h"
62   #include "extfs_defs.h"
63  
64 + #ifdef WIN32
65 + # include "posix_emu.h"
66 + #endif
67 +
68   #define DEBUG 0
69   #include "debug.h"
70  
# Line 62 | Line 75 | enum {
75          fsHFSProcStub = 6,
76          fsDrvStatus = 12,                               // Drive Status record
77          fsFSD = 42,                                             // File system descriptor
78 <        fsPB = 238,                                             // IOParam (for mounting)
78 >        fsPB = 238,                                             // IOParam (for mounting and renaming), also used for temporary storage
79          fsVMI = 288,                                    // VoumeMountInfoHeader (for mounting)
80          fsParseRec = 296,                               // ParsePathRec struct
81          fsReturn = 306,                                 // Area for return data of 68k routines
82          fsAllocateVCB = 562,                    // UTAllocateVCB(uint16 *sysVCBLength{a0}, uint32 *vcb{a1})
83          fsAddNewVCB = 578,                              // UTAddNewVCB(int drive_number{d0}, int16 *vRefNum{a1}, uint32 vcb{a1})
84          fsDetermineVol = 594,                   // UTDetermineVol(uint32 pb{a0}, int16 *status{a1}, int16 *more_matches{a2}, int16 *vRefNum{a3}, uint32 *vcb{a4})
85 <        fsResolveWDCB = 614,                    // UTResolveWDCB(int16 vRefNum{d0}, uint32 *wdcb{a0})
85 >        fsResolveWDCB = 614,                    // UTResolveWDCB(uint32 procID{d0}, int16 index{d1}, int16 vRefNum{d0}, uint32 *wdcb{a0})
86          fsGetDefaultVol = 632,                  // UTGetDefaultVol(uint32 wdpb{a0})
87          fsGetPathComponentName = 644,   // UTGetPathComponentName(uint32 rec{a0})
88          fsParsePathname = 656,                  // UTParsePathname(uint32 *start{a0}, uint32 name{a1})
# Line 98 | Line 111 | static bool ready = false;
111   static struct stat root_stat;
112  
113   // File system ID/media type
114 < const int16 MY_FSID = 'ba';
115 < const uint32 MY_MEDIA_TYPE = 'basi';
114 > const int16 MY_FSID = EMULATOR_ID_2;
115 > const uint32 MY_MEDIA_TYPE = EMULATOR_ID_4;
116  
117   // CNID of root and root's parent
118   const uint32 ROOT_ID = 2;
# Line 108 | Line 121 | const uint32 ROOT_PARENT_ID = 1;
121   // File system stack size
122   const int STACK_SIZE = 0x10000;
123  
124 + // Allocation block and clump size as reported to MacOS (these are of course
125 + // not the real values and have no meaning on the host OS)
126 + const int AL_BLK_SIZE = 0x4000;
127 + const int CLUMP_SIZE = 0x4000;
128 +
129   // Drive number of our pseudo-drive
130   static int drive_number;
131  
# Line 140 | Line 158 | struct FSItem {
158          uint32 id;                              // CNID of this file/dir
159          uint32 parent_id;               // CNID of parent file/dir
160          FSItem *parent;                 // Pointer to parent
161 <        char name[32];                  // Object name (C string)
161 >        char name[32];                  // Object name (C string) - Host OS
162 >        char guest_name[32];                    // Object name (C string) - Guest OS
163          time_t mtime;                   // Modification time for get_cat_info caching
164          int cache_dircount;             // Cached number of files in directory
165   };
# Line 151 | Line 170 | static uint32 next_cnid = fsUsrCNID;   //
170  
171  
172   /*
173 + *  Get object creation time
174 + */
175 +
176 + #if defined __APPLE__ && defined __MACH__
177 + struct crtimebuf {
178 +        unsigned long length;
179 +        struct timespec crtime;
180 + };
181 +
182 + static uint32 do_get_creation_time(const char *path)
183 + {
184 +        struct attrlist attr;
185 +        memset(&attr, 0, sizeof(attr));
186 +        attr.bitmapcount = ATTR_BIT_MAP_COUNT;
187 +        attr.commonattr = ATTR_CMN_CRTIME;
188 +
189 +        crtimebuf buf;
190 +        if (getattrlist(path, &attr, &buf, sizeof(buf), FSOPT_NOFOLLOW) < 0)
191 +                return 0;
192 +        return TimeToMacTime(buf.crtime.tv_sec);
193 + }
194 +
195 + static uint32 get_creation_time(const char *path)
196 + {
197 +        if (path == NULL)
198 +                return 0;
199 +        if (path == RootPath) {
200 +                static uint32 root_crtime = UINT_MAX;
201 +                if (root_crtime == UINT_MAX)
202 +                        root_crtime = do_get_creation_time(path);
203 +                return root_crtime;
204 +        }
205 +        return do_get_creation_time(path);
206 + }
207 + #endif
208 +
209 +
210 + /*
211   *  Find FSItem for given CNID
212   */
213  
# Line 165 | Line 222 | static FSItem *find_fsitem_by_id(uint32
222          return NULL;
223   }
224  
225 + /*
226 + *  Create FSItem with the given parameters
227 + */
228 +
229 + static FSItem *create_fsitem(const char *name, const char *guest_name, FSItem *parent)
230 + {
231 +        FSItem *p = new FSItem;
232 +        last_fs_item->next = p;
233 +        p->next = NULL;
234 +        last_fs_item = p;
235 +        p->id = next_cnid++;
236 +        p->parent_id = parent->id;
237 +        p->parent = parent;
238 +        strncpy(p->name, name, 31);
239 +        p->name[31] = 0;
240 +        strncpy(p->guest_name, guest_name, 31);
241 +        p->guest_name[31] = 0;
242 +        p->mtime = 0;
243 +        return p;
244 + }
245  
246   /*
247   *  Find FSItem for given name and parent, construct new FSItem if not found
# Line 180 | Line 257 | static FSItem *find_fsitem(const char *n
257          }
258  
259          // Not found, construct new FSItem
260 <        p = new FSItem;
184 <        last_fs_item->next = p;
185 <        p->next = NULL;
186 <        last_fs_item = p;
187 <        p->id = next_cnid++;
188 <        p->parent_id = parent->id;
189 <        p->parent = parent;
190 <        strncpy(p->name, name, 31);
191 <        p->name[31] = 0;
192 <        p->mtime = 0;
193 <        return p;
260 >        return create_fsitem(name, host_encoding_to_macroman(name), parent);
261   }
262  
263 + /*
264 + *  Find FSItem for given guest_name and parent, construct new FSItem if not found
265 + */
266 +
267 + static FSItem *find_fsitem_guest(const char *guest_name, FSItem *parent)
268 + {
269 +        FSItem *p = first_fs_item;
270 +        while (p) {
271 +                if (p->parent == parent && !strcmp(p->guest_name, guest_name))
272 +                        return p;
273 +                p = p->next;
274 +        }
275 +
276 +        // Not found, construct new FSItem
277 +        return create_fsitem(guest_name, guest_name, parent);
278 + }
279  
280   /*
281   *  Get full path (->full_path) for given FSItem
282   */
283  
201 const int MAX_PATH_LENGTH = 1024;
284   static char full_path[MAX_PATH_LENGTH];
285  
286 < static void add_path_component(const char *s)
286 > static void add_path_comp(const char *s)
287   {
288 <        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);
288 >        add_path_component(full_path, s);
289   }
290  
291   static void get_path_for_fsitem(FSItem *p)
292   {
293 <        if (p->id == ROOT_ID) {
293 >        if (p->id == ROOT_PARENT_ID) {
294 >                full_path[0] = 0;
295 >        } else if (p->id == ROOT_ID) {
296                  strncpy(full_path, RootPath, MAX_PATH_LENGTH-1);
297                  full_path[MAX_PATH_LENGTH-1] = 0;
298          } else {
299                  get_path_for_fsitem(p->parent);
300 <                add_path_component(p->name);
300 >                add_path_comp(p->name);
301 >        }
302 > }
303 >
304 >
305 > /*
306 > *  Exchange parent CNIDs in all FSItems
307 > */
308 >
309 > static void swap_parent_ids(uint32 parent1, uint32 parent2)
310 > {
311 >        FSItem *p = first_fs_item;
312 >        while (p) {
313 >                if (p->parent_id == parent1)
314 >                        p->parent_id = parent2;
315 >                else if (p->parent_id == parent2)
316 >                        p->parent_id = parent1;
317 >                p = p->next;
318          }
319   }
320  
# Line 241 | Line 337 | static void cstr2pstr(char *dst, const c
337          *dst++ = strlen(src);
338          char c;
339          while ((c = *src++) != 0) {
340 +                // Note: we are converting host ':' characters to Mac '/' characters here
341 +                // '/' is not a path separator as this function is only used on object names
342                  if (c == ':')
343                          c = '/';
344                  *dst++ = c;
345          }
346   }
347  
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
348   // Convert string (no length byte) to C string, length given separately
349   static void strn2cstr(char *dst, const char *src, int size)
350   {
351          while (size--) {
352                  char c = *src++;
353 +                // Note: we are converting Mac '/' characters to host ':' characters here
354 +                // '/' is not a path separator as this function is only used on object names
355                  if (c == '/')
356                          c = ':';
357                  *dst++ = c;
# Line 322 | Line 409 | void ExtFSInit(void)
409          cstr2pstr(FS_NAME, GetString(STR_EXTFS_NAME));
410          cstr2pstr(VOLUME_NAME, GetString(STR_EXTFS_VOLUME_NAME));
411  
412 <        // Create root FSItem
412 >        // Create root's parent FSItem
413          FSItem *p = new FSItem;
414          first_fs_item = last_fs_item = p;
415          p->next = NULL;
416 +        p->id = ROOT_PARENT_ID;
417 +        p->parent_id = 0;
418 +        p->parent = NULL;
419 +        p->name[0] = 0;
420 +        p->guest_name[0] = 0;
421 +
422 +        // Create root FSItem
423 +        p = new FSItem;
424 +        last_fs_item->next = p;
425 +        p->next = NULL;
426 +        last_fs_item = p;
427          p->id = ROOT_ID;
428          p->parent_id = ROOT_PARENT_ID;
429 <        p->parent = NULL;
429 >        p->parent = first_fs_item;
430          strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
431 +        p->name[31] = 0;
432 +        strncpy(p->guest_name, host_encoding_to_macroman(p->name), 32);
433 +        p->guest_name[31] = 0;
434  
435          // Find path for root
436          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 378 | Line 479 | void InstallExtFS(void)
479          // FSM present?
480          r.d[0] = gestaltFSAttr;
481          Execute68kTrap(0xa1ad, &r);     // Gestalt()
482 <        D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
483 <        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager)))
482 >        D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0]));
483 >        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
484 >                printf("WARNING: No FSM present, disabling ExtFS\n");
485                  return;
486 +        }
487  
488          // Yes, version >=1.2?
489          r.d[0] = gestaltFSMVersion;
490          Execute68kTrap(0xa1ad, &r);     // Gestalt()
491 <        D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
492 <        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120))
491 >        D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0]));
492 >        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
493 >                printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
494                  return;
495 +        }
496  
497          D(bug("FSM present\n"));
498  
# Line 423 | Line 528 | void InstallExtFS(void)
528          WriteMacInt16(p, 0x7006); p+= 2;        // UTAllocateVCB
529          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
530          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
531 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
531 >        WriteMacInt16(p, M68K_RTS); p+= 2;
532          if (p - fs_data != fsAddNewVCB)
533                  goto fsdat_error;
534          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 433 | Line 538 | void InstallExtFS(void)
538          WriteMacInt16(p, 0x7007); p+= 2;        // UTAddNewVCB
539          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
540          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
541 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
541 >        WriteMacInt16(p, M68K_RTS); p+= 2;
542          if (p - fs_data != fsDetermineVol)
543                  goto fsdat_error;
544          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 445 | Line 550 | void InstallExtFS(void)
550          WriteMacInt16(p, 0x701d); p+= 2;        // UTDetermineVol
551          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
552          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
553 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
553 >        WriteMacInt16(p, M68K_RTS); p+= 2;
554          if (p - fs_data != fsResolveWDCB)
555                  goto fsdat_error;
556          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
557 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
558 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
559 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
557 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
558 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
559 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
560          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
561          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
562          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
563          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
564 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
564 >        WriteMacInt16(p, M68K_RTS); p+= 2;
565          if (p - fs_data != fsGetDefaultVol)
566                  goto fsdat_error;
567          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 464 | Line 569 | void InstallExtFS(void)
569          WriteMacInt16(p, 0x7012); p+= 2;        // UTGetDefaultVol
570          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
571          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
572 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
572 >        WriteMacInt16(p, M68K_RTS); p+= 2;
573          if (p - fs_data != fsGetPathComponentName)
574                  goto fsdat_error;
575          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 472 | Line 577 | void InstallExtFS(void)
577          WriteMacInt16(p, 0x701c); p+= 2;        // UTGetPathComponentName
578          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
579          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
580 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
580 >        WriteMacInt16(p, M68K_RTS); p+= 2;
581          if (p - fs_data != fsParsePathname)
582                  goto fsdat_error;
583          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 481 | Line 586 | void InstallExtFS(void)
586          WriteMacInt16(p, 0x701b); p+= 2;        // UTParsePathname
587          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
588          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
589 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
589 >        WriteMacInt16(p, M68K_RTS); p+= 2;
590          if (p - fs_data != fsDisposeVCB)
591                  goto fsdat_error;
592          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 489 | Line 594 | void InstallExtFS(void)
594          WriteMacInt16(p, 0x7008); p+= 2;        // UTDisposeVCB
595          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
596          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
597 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
597 >        WriteMacInt16(p, M68K_RTS); p+= 2;
598          if (p - fs_data != fsCheckWDRefNum)
599                  goto fsdat_error;
600          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 497 | Line 602 | void InstallExtFS(void)
602          WriteMacInt16(p, 0x7013); p+= 2;        // UTCheckWDRefNum
603          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
604          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
605 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
605 >        WriteMacInt16(p, M68K_RTS); p+= 2;
606          if (p - fs_data != fsSetDefaultVol)
607                  goto fsdat_error;
608          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 507 | Line 612 | void InstallExtFS(void)
612          WriteMacInt16(p, 0x7011); p+= 2;        // UTSetDefaultVol
613          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
614          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
615 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
615 >        WriteMacInt16(p, M68K_RTS); p+= 2;
616          if (p - fs_data != fsAllocateFCB)
617                  goto fsdat_error;
618          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 516 | Line 621 | void InstallExtFS(void)
621          WriteMacInt16(p, 0x7000); p+= 2;        // UTAllocateFCB
622          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
623          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
624 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
624 >        WriteMacInt16(p, M68K_RTS); p+= 2;
625          if (p - fs_data != fsReleaseFCB)
626                  goto fsdat_error;
627          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 524 | Line 629 | void InstallExtFS(void)
629          WriteMacInt16(p, 0x7001); p+= 2;        // UTReleaseFCB
630          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
631          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
632 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
632 >        WriteMacInt16(p, M68K_RTS); p+= 2;
633          if (p - fs_data != fsIndexFCB)
634                  goto fsdat_error;
635          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 534 | Line 639 | void InstallExtFS(void)
639          WriteMacInt16(p, 0x7004); p+= 2;        // UTIndexFCB
640          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
641          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
642 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
642 >        WriteMacInt16(p, M68K_RTS); p+= 2;
643          if (p - fs_data != fsResolveFCB)
644                  goto fsdat_error;
645          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 543 | Line 648 | void InstallExtFS(void)
648          WriteMacInt16(p, 0x7005); p+= 2;        // UTResolveFCB
649          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
650          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
651 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
651 >        WriteMacInt16(p, M68K_RTS); p+= 2;
652          if (p - fs_data != fsAdjustEOF)
653                  goto fsdat_error;
654          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 551 | Line 656 | void InstallExtFS(void)
656          WriteMacInt16(p, 0x7010); p+= 2;        // UTAdjustEOF
657          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
658          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
659 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
659 >        WriteMacInt16(p, M68K_RTS); p+= 2;
660          if (p - fs_data != fsAllocateWDCB)
661                  goto fsdat_error;
662          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 559 | Line 664 | void InstallExtFS(void)
664          WriteMacInt16(p, 0x700c); p+= 2;        // UTAllocateWDCB
665          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
666          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
667 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
667 >        WriteMacInt16(p, M68K_RTS); p+= 2;
668          if (p - fs_data != fsReleaseWDCB)
669                  goto fsdat_error;
670          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 567 | Line 672 | void InstallExtFS(void)
672          WriteMacInt16(p, 0x700d); p+= 2;        // UTReleaseWDCB
673          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
674          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
675 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
675 >        WriteMacInt16(p, M68K_RTS); p+= 2;
676          if (p - fs_data != SIZEOF_fsdat)
677                  goto fsdat_error;
678  
# Line 591 | Line 696 | void InstallExtFS(void)
696          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
697          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
698          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
699 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
699 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
700          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
701          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
702          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 645 | Line 750 | int16 ExtFSComm(uint16 message, uint32 p
750  
751                  case ffsGetIconMessage: {               // Get disk/drive icon
752                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
753 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
753 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
754                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
755                                  return noErr;
756                          } else
# Line 653 | Line 758 | int16 ExtFSComm(uint16 message, uint32 p
758                  }
759  
760                  case ffsIDDiskMessage: {                // Check if volume is handled by our FS
761 <                        if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
761 >                        if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
762                                  return noErr;
763                          else
764                                  return extFSErr;
# Line 682 | Line 787 | static int16 get_current_dir(uint32 pb,
787          int16 result;
788  
789          // Determine volume
790 < //      D(bug("  determining volume\n"));
790 >        D(bug("  determining volume, dirID %d\n", dirID));
791          r.a[0] = pb;
792          r.a[1] = fs_data + fsReturn;
793          r.a[2] = fs_data + fsReturn + 2;
# Line 697 | Line 802 | static int16 get_current_dir(uint32 pb,
802          if (no_vol_name)
803                  WriteMacInt32(pb + ioNamePtr, name_ptr);
804          int16 status = ReadMacInt16(fs_data + fsReturn);
805 <        int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
806 <        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;
805 >        D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
806 >        result = (int16)(r.d[0] & 0xffff);
807  
808          if (result == noErr) {
809                  switch (status) {
# Line 719 | Line 821 | static int16 get_current_dir(uint32 pb,
821                                          current_dir = dirID;
822                                  else {
823                                          D(bug("  resolving WDCB\n"));
824 <                                        r.d[0] = ReadMacInt16(pb + ioVRefNum);
824 >                                        r.d[0] = 0;
825 >                                        r.d[1] = 0;
826 >                                        r.d[2] = ReadMacInt16(pb + ioVRefNum);
827                                          r.a[0] = fs_data + fsReturn;
828                                          Execute68k(fs_data + fsResolveWDCB, &r);
829                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
830                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
831 <                                        result = r.d[0] & 0xffff;
831 >                                        result = (int16)(r.d[0] & 0xffff);
832                                          if (result == noErr)
833                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
834                                  }
# Line 740 | Line 844 | static int16 get_current_dir(uint32 pb,
844                                          r.a[0] = wdpb;
845                                          Execute68k(fs_data + fsGetDefaultVol, &r);
846                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
847 <                                        result = r.d[0] & 0xffff;
847 >                                        result = (int16)(r.d[0] & 0xffff);
848                                          if (result == noErr)
849                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
850                                  }
# Line 766 | Line 870 | static int16 get_path_component_name(uin
870          r.a[0] = rec;
871          Execute68k(fs_data + fsGetPathComponentName, &r);
872   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
873 <        return r.d[0] & 0xffff;
873 >        return (int16)(r.d[0] & 0xffff);
874   }
875  
876  
# Line 783 | Line 887 | static int16 get_item_and_path(uint32 pb
887          uint32 current_dir;
888          if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr)
889                  return result;
890 +        D(bug("  current dir %08x\n", current_dir));
891          FSItem *p = find_fsitem_by_id(current_dir);
892          if (p == NULL)
893                  return dirNFErr;
# Line 796 | Line 901 | static int16 get_item_and_path(uint32 pb
901          WriteMacInt8(parseRec + ppFoundDelimiter, false);
902  
903          // Get length of volume name
904 < //      D(bug("  parsing pathname\n"));
904 >        D(bug("  parsing pathname\n"));
905          r.a[0] = parseRec + ppStartOffset;
906          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
907          Execute68k(fs_data + fsParsePathname, &r);
908 < //      D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
909 <        result = r.d[0] & 0xffff;
908 >        D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
909 >        result = (int16)(r.d[0] & 0xffff);
910          if (result == noErr) {
911  
912                  // Check for leading delimiter of the partial pathname
# Line 836 | Line 941 | static int16 get_item_and_path(uint32 pb
941                                                  char name[32];
942                                                  strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
943                                                  D(bug("  entering %s\n", name));
944 <                                                p = find_fsitem(name, p);
944 >                                                p = find_fsitem_guest(name, p);
945                                                  current_dir = p->id;
946  
947                                                  // startOffset = start of next component
# Line 859 | Line 964 | static int16 get_item_and_path(uint32 pb
964                                          char name[32];
965                                          strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
966                                          D(bug("  object is %s\n", name));
967 <                                        item = find_fsitem(name, p);
967 >                                        item = find_fsitem_guest(name, p);
968                                  }
969                          }
970                  }
# Line 914 | Line 1019 | static uint32 find_fcb(int16 refNum)
1019   static int16 fs_mount_vol(uint32 pb)
1020   {
1021          D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum)));
1022 <        if (ReadMacInt16(pb + ioVRefNum) == drive_number)
1022 >        if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number)
1023                  return noErr;
1024          else
1025                  return extFSErr;
# Line 931 | Line 1036 | static int16 fs_volume_mount(uint32 pb)
1036          r.a[0] = fs_data + fsReturn;
1037          r.a[1] = fs_data + fsReturn + 2;
1038          Execute68k(fs_data + fsAllocateVCB, &r);
1039 + #if DEBUG
1040          uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn);
1041 + #endif
1042          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
1043          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
1044          if (r.d[0] & 0xffff)
1045 <                return r.d[0];
1045 >                return (int16)r.d[0];
1046  
1047          // Init VCB
1048          WriteMacInt16(vcb + vcbSigWord, 0x4244);
1049 < #ifdef __BEOS__
1050 <        WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
1049 > #if defined(__BEOS__) || defined(WIN32)
1050 >        WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
1051 > #elif defined __APPLE__ && defined __MACH__
1052 >        WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath));
1053   #else
1054          WriteMacInt32(vcb + vcbCrDate, 0);
1055   #endif
1056 <        WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET);
1056 >        WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime));
1057          WriteMacInt32(vcb + vcbVolBkUp, 0);
1058          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
1059          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
1060          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
1061 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
1062 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
1061 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
1062 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
1063          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
1064          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
1065 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
1065 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
1066          WriteMacInt16(vcb + vcbFSID, MY_FSID);
1067          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
1068          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 964 | Line 1073 | static int16 fs_volume_mount(uint32 pb)
1073          r.a[0] = fs_data + fsReturn;
1074          r.a[1] = vcb;
1075          Execute68k(fs_data + fsAddNewVCB, &r);
1076 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1076 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1077          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1078          if (r.d[0] & 0xffff)
1079 <                return r.d[0];
1079 >                return (int16)r.d[0];
1080  
1081          // Post diskInsertEvent
1082          D(bug("  posting diskInsertEvent\n"));
# Line 991 | Line 1100 | static int16 fs_unmount_vol(uint32 vcb)
1100          r.a[0] = vcb;
1101          Execute68k(fs_data + fsDisposeVCB, &r);
1102          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1103 <        return r.d[0];
1103 >        return (int16)r.d[0];
1104   }
1105  
1106   // Get information about a volume (HVolumeParam)
# Line 1002 | Line 1111 | static int16 fs_get_vol_info(uint32 pb,
1111          // Fill in struct
1112          if (ReadMacInt32(pb + ioNamePtr))
1113                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1114 < #ifdef __BEOS__
1115 <        WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1114 > #if defined(__BEOS__) || defined(WIN32)
1115 >        WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
1116 > #elif defined __APPLE__ && defined __MACH__
1117 >        WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath));
1118   #else
1119          WriteMacInt32(pb + ioVCrDate, 0);
1120   #endif
1121 <        WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET);
1121 >        WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime));
1122          WriteMacInt16(pb + ioVAtrb, 0);
1123          WriteMacInt16(pb + ioVNmFls, 1);                        //!!
1124          WriteMacInt16(pb + ioVBitMap, 0);
1125          WriteMacInt16(pb + ioAllocPtr, 0);
1126          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1127 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1128 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1127 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1128 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1129          WriteMacInt16(pb + ioAlBlSt, 0);
1130          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1131          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1027 | Line 1138 | static int16 fs_get_vol_info(uint32 pb,
1138                  WriteMacInt32(pb + ioVWrCnt, 0);
1139                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1140                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1141 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1141 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1142          }
1143          return noErr;
1144   }
# Line 1047 | Line 1158 | static int16 fs_get_vol_parms(uint32 pb)
1158   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1159  
1160          // 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);
1161          uint32 actual = ReadMacInt32(pb + ioReqCount);
1162 <        if (actual > sizeof(vol))
1163 <                actual = sizeof(vol);
1060 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1162 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1163 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1164          WriteMacInt32(pb + ioActCount, actual);
1165 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1166 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1167 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1168 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1169 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1170 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1171 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1172          return noErr;
1173   }
1174  
# Line 1073 | Line 1183 | static int16 fs_get_vol(uint32 pb)
1183          r.a[0] = pb;
1184          Execute68k(fs_data + fsGetDefaultVol, &r);
1185          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1186 <        return r.d[0];
1186 >        return (int16)r.d[0];
1187   }
1188  
1189   // Set default volume (WDParam)
1190   static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb)
1191   {
1192 <        D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
1192 >        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)));
1193          M68kRegisters r;
1194  
1195          // Determine parameters
# Line 1129 | Line 1239 | static int16 fs_set_vol(uint32 pb, bool
1239          r.d[2] = refNum;
1240          Execute68k(fs_data + fsSetDefaultVol, &r);
1241          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1242 <        return r.d[0];
1242 >        return (int16)r.d[0];
1243   }
1244  
1245   // Query file attributes (HFileParam)
1246   static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID)
1247   {
1248 <        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));
1248 >        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));
1249  
1250          FSItem *fs_item;
1251          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1252 <        if (dir_index == 0) {   // Query item specified by ioDirID and ioNamePtr
1252 >        if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1253  
1254                  // Find FSItem for given file
1255                  int16 result = get_item_and_path(pb, dirID, fs_item);
# Line 1171 | Line 1281 | read_next_de:
1281                                  return fnfErr;
1282                          }
1283                          if (de->d_name[0] == '.')
1284 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1284 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1285                          //!! suppress directories
1286                  }
1287 <                add_path_component(de->d_name);
1287 >                add_path_comp(de->d_name);
1288  
1289                  // Get FSItem for queried item
1290                  fs_item = find_fsitem(de->d_name, p);
# Line 1190 | Line 1300 | read_next_de:
1300  
1301          // Fill in struct from fs_item and stats
1302          if (ReadMacInt32(pb + ioNamePtr))
1303 <                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
1303 >                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1304          WriteMacInt16(pb + ioFRefNum, 0);
1305          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1306          WriteMacInt32(pb + ioDirID, fs_item->id);
1307  
1308 < #ifdef __BEOS__
1309 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1308 > #if defined(__BEOS__) || defined(WIN32)
1309 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1310 > #elif defined __APPLE__ && defined __MACH__
1311 >        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1312   #else
1313          WriteMacInt32(pb + ioFlCrDat, 0);
1314   #endif
1315 <        WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1315 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime));
1316  
1317 <        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);
1317 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1318  
1319          WriteMacInt16(pb + ioFlStBlk, 0);
1320          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1321 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1321 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1322          WriteMacInt16(pb + ioFlRStBlk, 0);
1323          uint32 rf_size = get_rfork_size(full_path);
1324          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1325 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1325 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1326  
1327          if (hfs) {
1328                  WriteMacInt32(pb + ioFlBkDat, 0);
1224                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1329                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1330                  WriteMacInt32(pb + ioFlClpSiz, 0);
1331          }
# Line 1231 | Line 1335 | read_next_de:
1335   // Set file attributes (HFileParam)
1336   static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID)
1337   {
1338 <        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));
1338 >        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));
1339  
1340          // Find FSItem for given file/dir
1341          FSItem *fs_item;
# Line 1246 | Line 1350 | static int16 fs_set_file_info(uint32 pb,
1350          if (S_ISDIR(st.st_mode))
1351                  return fnfErr;
1352  
1353 <        // Set attributes
1354 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1355 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1353 >        // Set Finder info
1354 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1355 >
1356          //!! times
1357          return noErr;
1358   }
# Line 1256 | Line 1360 | static int16 fs_set_file_info(uint32 pb,
1360   // Query file/directory attributes
1361   static int16 fs_get_cat_info(uint32 pb)
1362   {
1363 <        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)));
1363 >        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)));
1364  
1365          FSItem *fs_item;
1366          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1367 <        if (dir_index == -1) {          // Query directory specified by ioDirID
1367 >        if (dir_index < 0) {                    // Query directory specified by ioDirID
1368  
1369                  // Find FSItem for directory
1370                  fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID));
# Line 1300 | Line 1404 | read_next_de:
1404                                  return fnfErr;
1405                          }
1406                          if (de->d_name[0] == '.')
1407 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1407 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1408                  }
1409 <                add_path_component(de->d_name);
1409 >                add_path_comp(de->d_name);
1410  
1411                  // Get FSItem for queried item
1412                  fs_item = find_fsitem(de->d_name, p);
# Line 1319 | Line 1423 | read_next_de:
1423  
1424          // Fill in struct from fs_item and stats
1425          if (ReadMacInt32(pb + ioNamePtr))
1426 <                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
1426 >                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1427          WriteMacInt16(pb + ioFRefNum, 0);
1428          WriteMacInt8(pb + ioFlAttrib, (S_ISDIR(st.st_mode) ? faIsDir : 0) | (access(full_path, W_OK) == 0 ? 0 : faLocked));
1429          WriteMacInt8(pb + ioACUser, 0);
1430          WriteMacInt32(pb + ioDirID, fs_item->id);
1431          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1432 < #ifdef __BEOS__
1433 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1432 > #if defined(__BEOS__) || defined(WIN32)
1433 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1434 > #elif defined __APPLE__ && defined __MACH__
1435 >        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1436   #else
1437          WriteMacInt32(pb + ioFlCrDat, 0);
1438   #endif
# Line 1336 | Line 1442 | read_next_de:
1442                  fs_item->mtime = mtime;
1443                  cached = false;
1444          }
1445 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1445 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime));
1446          WriteMacInt32(pb + ioFlBkDat, 0);
1447 +
1448 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1449 +
1450          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);
1451  
1452                  // Determine number of files in directory (cached)
1453                  int count;
# Line 1358 | Line 1462 | read_next_de:
1462                                          de = readdir(d);
1463                                          if (de == NULL)
1464                                                  break;
1465 +                                        if (de->d_name[0] == '.')
1466 +                                                continue;       // Suppress names beginning with '.'
1467                                          count++;
1468                                  }
1469                                  closedir(d);
# Line 1366 | Line 1472 | read_next_de:
1472                  }
1473                  WriteMacInt16(pb + ioDrNmFls, count);
1474          } 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);
1475                  WriteMacInt16(pb + ioFlStBlk, 0);
1476                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1477 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1477 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1478                  WriteMacInt16(pb + ioFlRStBlk, 0);
1479                  uint32 rf_size = get_rfork_size(full_path);
1480                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1481 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1481 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1482                  WriteMacInt32(pb + ioFlClpSiz, 0);
1483          }
1484          return noErr;
# Line 1390 | Line 1487 | read_next_de:
1487   // Set file/directory attributes
1488   static int16 fs_set_cat_info(uint32 pb)
1489   {
1490 <        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)));
1490 >        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)));
1491  
1492          // Find FSItem for given file/dir
1493          FSItem *fs_item;
# Line 1403 | Line 1500 | static int16 fs_set_cat_info(uint32 pb)
1500          if (stat(full_path, &st) < 0)
1501                  return errno2oserr();
1502  
1503 <        // Set attributes
1504 <        if (S_ISDIR(st.st_mode))
1505 <                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 <        }
1503 >        // Set Finder info
1504 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1505 >
1506          //!! times
1507          return noErr;
1508   }
# Line 1417 | Line 1510 | static int16 fs_set_cat_info(uint32 pb)
1510   // Open file
1511   static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork)
1512   {
1513 <        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)));
1513 >        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)));
1514          M68kRegisters r;
1515  
1516          // Find FSItem for given file
# Line 1456 | Line 1549 | static int16 fs_open(uint32 pb, uint32 d
1549                  if (access(full_path, F_OK))
1550                          return fnfErr;
1551                  fd = open_rfork(full_path, flag);
1552 <                if (fd > 0) {
1553 <                        if (fstat(fd, &st) < 0)
1552 >                if (fd >= 0) {
1553 >                        if (fstat(fd, &st) < 0) {
1554 >                                close(fd);
1555                                  return errno2oserr();
1556 +                        }
1557                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1558                          st.st_size = 0;
1559                          st.st_mode = 0;
# Line 1467 | Line 1562 | static int16 fs_open(uint32 pb, uint32 d
1562                  fd = open(full_path, flag);
1563                  if (fd < 0)
1564                          return errno2oserr();
1565 <                if (fstat(fd, &st) < 0)
1565 >                if (fstat(fd, &st) < 0) {
1566 >                        close(fd);
1567                          return errno2oserr();
1568 +                }
1569          }
1570  
1571          // File open, allocate FCB
# Line 1480 | Line 1577 | static int16 fs_open(uint32 pb, uint32 d
1577          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1578          if (r.d[0] & 0xffff) {
1579                  close(fd);
1580 <                return r.d[0];
1580 >                return (int16)r.d[0];
1581          }
1582  
1583          // Initialize FCB, fd is stored in fcbCatPos
1584          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1585          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1586          WriteMacInt32(fcb + fcbEOF, st.st_size);
1587 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1587 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1588          WriteMacInt32(fcb + fcbCrPs, 0);
1589          WriteMacInt32(fcb + fcbVPtr, vcb);
1590 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1591 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1592 <        get_finder_type(full_path, type, creator);
1593 <        WriteMacInt32(fcb + fcbFType, type);
1590 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1591 >
1592 >        get_finfo(full_path, fs_data + fsPB, 0, false);
1593 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1594 >
1595          WriteMacInt32(fcb + fcbCatPos, fd);
1596          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1597 <        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
1597 >        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->guest_name);
1598          return noErr;
1599   }
1600  
# Line 1530 | Line 1628 | static int16 fs_close(uint32 pb)
1628          r.d[0] = ReadMacInt16(pb + ioRefNum);
1629          Execute68k(fs_data + fsReleaseFCB, &r);
1630          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1631 <        return r.d[0];
1631 >        return (int16)r.d[0];
1632   }
1633  
1634   // Query information about FCB (FCBPBRec)
# Line 1549 | Line 1647 | static int16 fs_get_fcb_info(uint32 pb,
1647  
1648                  // Find FCB by index
1649                  WriteMacInt16(pb + ioRefNum, 0);
1650 <                for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) {
1650 >                for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) {
1651                          D(bug("  indexing FCBs\n"));
1652                          r.a[0] = vcb;
1653                          r.a[1] = pb + ioRefNum;
# Line 1558 | Line 1656 | static int16 fs_get_fcb_info(uint32 pb,
1656                          fcb = ReadMacInt32(fs_data + fsReturn);
1657                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1658                          if (r.d[0] & 0xffff)
1659 <                                return r.d[0];
1659 >                                return (int16)r.d[0];
1660                  }
1661          }
1662          if (fcb == 0)
# Line 1606 | Line 1704 | static int16 fs_get_eof(uint32 pb)
1704  
1705          // Adjust FCBs
1706          WriteMacInt32(fcb + fcbEOF, st.st_size);
1707 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1707 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1708          WriteMacInt32(pb + ioMisc, st.st_size);
1709          D(bug("  adjusting FCBs\n"));
1710          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1641 | Line 1739 | static int16 fs_set_eof(uint32 pb)
1739  
1740          // Adjust FCBs
1741          WriteMacInt32(fcb + fcbEOF, size);
1742 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1742 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1743          D(bug("  adjusting FCBs\n"));
1744          r.d[0] = ReadMacInt16(pb + ioRefNum);
1745          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1704 | Line 1802 | static int16 fs_set_fpos(uint32 pb)
1802                          if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0)
1803                                  return posErr;
1804                          break;
1805 +                case fsFromLEOF:
1806 +                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0)
1807 +                                return posErr;
1808 +                        break;
1809                  case fsFromMark:
1810 <                        if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1810 >                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1811                                  return posErr;
1812 +                        break;
1813                  default:
1814                          break;
1815          }
# Line 1721 | Line 1824 | static int16 fs_read(uint32 pb)
1824   {
1825          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)));
1826  
1827 +        // Check parameters
1828 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1829 +                return paramErr;
1830 +
1831          // Find FCB and fd for file
1832          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1833          if (fcb == 0)
# Line 1752 | Line 1859 | static int16 fs_read(uint32 pb)
1859          }
1860  
1861          // Read
1862 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1862 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1863 >        int16 read_err = errno2oserr();
1864          D(bug("  actual %d\n", actual));
1865 <        WriteMacInt32(pb + ioActCount, actual);
1865 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1866          uint32 pos = lseek(fd, 0, SEEK_CUR);
1867          WriteMacInt32(fcb + fcbCrPs, pos);
1868          WriteMacInt32(pb + ioPosOffset, pos);
1869 <        if (actual != ReadMacInt32(pb + ioReqCount))
1870 <                if (errno)
1763 <                        return errno2oserr();
1764 <                else
1765 <                        return eofErr;
1869 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1870 >                return actual < 0 ? read_err : eofErr;
1871          else
1872                  return noErr;
1873   }
# Line 1772 | Line 1877 | static int16 fs_write(uint32 pb)
1877   {
1878          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)));
1879  
1880 +        // Check parameters
1881 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1882 +                return paramErr;
1883 +
1884          // Find FCB and fd for file
1885          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1886          if (fcb == 0)
# Line 1803 | Line 1912 | static int16 fs_write(uint32 pb)
1912          }
1913  
1914          // Write
1915 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1915 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1916 >        int16 write_err = errno2oserr();
1917          D(bug("  actual %d\n", actual));
1918 <        WriteMacInt32(pb + ioActCount, actual);
1918 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1919          uint32 pos = lseek(fd, 0, SEEK_CUR);
1920          WriteMacInt32(fcb + fcbCrPs, pos);
1921          WriteMacInt32(pb + ioPosOffset, pos);
1922 <        if (actual != ReadMacInt32(pb + ioReqCount))
1923 <                return errno2oserr();
1922 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1923 >                return write_err;
1924          else
1925                  return noErr;
1926   }
# Line 1818 | Line 1928 | static int16 fs_write(uint32 pb)
1928   // Create file
1929   static int16 fs_create(uint32 pb, uint32 dirID)
1930   {
1931 <        D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1931 >        D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1932  
1933          // Find FSItem for given file
1934          FSItem *fs_item;
# Line 1831 | Line 1941 | static int16 fs_create(uint32 pb, uint32
1941                  return dupFNErr;
1942  
1943          // Create file
1944 <        int fd = creat(full_path, 0664);
1944 >        int fd = creat(full_path, 0666);
1945          if (fd < 0)
1946                  return errno2oserr();
1947          else {
# Line 1843 | Line 1953 | static int16 fs_create(uint32 pb, uint32
1953   // Create directory
1954   static int16 fs_dir_create(uint32 pb)
1955   {
1956 <        D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID)));
1956 >        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)));
1957  
1958          // Find FSItem for given directory
1959          FSItem *fs_item;
# Line 1856 | Line 1966 | static int16 fs_dir_create(uint32 pb)
1966                  return dupFNErr;
1967  
1968          // Create directory
1969 <        if (mkdir(full_path, 0775) < 0)
1969 >        if (mkdir(full_path, 0777) < 0)
1970                  return errno2oserr();
1971          else {
1972                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1867 | Line 1977 | static int16 fs_dir_create(uint32 pb)
1977   // Delete file/directory
1978   static int16 fs_delete(uint32 pb, uint32 dirID)
1979   {
1980 <        D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1980 >        D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1981  
1982          // Find FSItem for given file/dir
1983          FSItem *fs_item;
# Line 1876 | Line 1986 | static int16 fs_delete(uint32 pb, uint32
1986                  return result;
1987  
1988          // Delete file
1989 <        if (remove(full_path) < 0) {
1990 <                int16 err = errno2oserr();
1991 <                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
1989 >        if (!extfs_remove(full_path))
1990 >                return errno2oserr();
1991 >        else
1992                  return noErr;
1993   }
1994  
1995   // Rename file/directory
1996   static int16 fs_rename(uint32 pb, uint32 dirID)
1997   {
1998 <        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))));
1998 >        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)));
1999  
2000          // Find path of given file/dir
2001          FSItem *fs_item;
# Line 1905 | Line 2008 | static int16 fs_rename(uint32 pb, uint32
2008          strcpy(old_path, full_path);
2009  
2010          // Find path for new name
2011 <        uint8 new_pb[SIZEOF_IOParam];
2012 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1910 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
2011 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2012 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
2013          FSItem *new_item;
2014 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
2014 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
2015          if (result != noErr)
2016                  return result;
2017  
# Line 1919 | Line 2021 | static int16 fs_rename(uint32 pb, uint32
2021  
2022          // Rename item
2023          D(bug("  renaming %s -> %s\n", old_path, full_path));
2024 <        if (rename(old_path, full_path) < 0)
2024 >        if (!extfs_rename(old_path, full_path))
2025                  return errno2oserr();
2026          else {
2027                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2028 +                swap_parent_ids(fs_item->id, new_item->id);
2029                  uint32 t = fs_item->id;
2030                  fs_item->id = new_item->id;
2031                  new_item->id = t;
# Line 1933 | Line 2036 | static int16 fs_rename(uint32 pb, uint32
2036   // Move file/directory (CMovePBRec)
2037   static int16 fs_cat_move(uint32 pb)
2038   {
2039 <        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)));
2039 >        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)));
2040  
2041          // Find path of given file/dir
2042          FSItem *fs_item;
# Line 1946 | Line 2049 | static int16 fs_cat_move(uint32 pb)
2049          strcpy(old_path, full_path);
2050  
2051          // Find path for new directory
2052 <        uint8 new_pb[SIZEOF_IOParam];
2053 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1951 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
2052 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2053 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
2054          FSItem *new_dir_item;
2055 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
2055 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
2056          if (result != noErr)
2057                  return result;
2058  
2059          // Append old file/dir name
2060 <        add_path_component(fs_item->name);
2060 >        add_path_comp(fs_item->name);
2061  
2062          // Does the new name already exist?
2063          if (access(full_path, F_OK) == 0)
# Line 1963 | Line 2065 | static int16 fs_cat_move(uint32 pb)
2065  
2066          // Move item
2067          D(bug("  moving %s -> %s\n", old_path, full_path));
2068 <        if (rename(old_path, full_path) < 0)
2068 >        if (!extfs_rename(old_path, full_path))
2069                  return errno2oserr();
2070          else {
2071                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2072                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2073                  if (new_item) {
2074 +                        swap_parent_ids(fs_item->id, new_item->id);
2075                          uint32 t = fs_item->id;
2076                          fs_item->id = new_item->id;
2077                          new_item->id = t;
# Line 1980 | Line 2083 | static int16 fs_cat_move(uint32 pb)
2083   // Open working directory (WDParam)
2084   static int16 fs_open_wd(uint32 pb)
2085   {
2086 <        D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
2086 >        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)));
2087          M68kRegisters r;
2088  
2089          // Allocate WDCB
2090          D(bug("  allocating WDCB\n"));
2091          r.a[0] = pb;
2092          Execute68k(fs_data + fsAllocateWDCB, &r);
2093 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2094 <        return r.d[0];
2093 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2094 >        return (int16)r.d[0];
2095   }
2096  
2097   // Close working directory (WDParam)
# Line 2002 | Line 2105 | static int16 fs_close_wd(uint32 pb)
2105          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2106          Execute68k(fs_data + fsReleaseWDCB, &r);
2107          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2108 <        return r.d[0];
2108 >        return (int16)r.d[0];
2109   }
2110  
2111   // Query information about working directory (WDParam)
# Line 2016 | Line 2119 | static int16 fs_get_wd_info(uint32 pb, u
2119                  WriteMacInt32(pb + ioWDProcID, 0);
2120                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2121                  if (ReadMacInt32(pb + ioNamePtr))
2122 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2122 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2123                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2124                  return noErr;
2125          }
# Line 2031 | Line 2134 | static int16 fs_get_wd_info(uint32 pb, u
2134          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2135          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2136          if (r.d[0] & 0xffff)
2137 <                return r.d[0];
2137 >                return (int16)r.d[0];
2138  
2139          // Return information
2140 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2140 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2141          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2142          if (ReadMacInt32(pb + ioNamePtr))
2143 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2143 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2144          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2145          return noErr;
2146   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines