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.1 by cebix, 1999-10-19T17:41:14Z vs.
Revision 1.35 by gbeauche, 2008-01-01T09:40:31Z

# 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-2008 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  
38   #include <sys/types.h>
39   #include <sys/stat.h>
40 + #include <string.h>
41   #include <stdio.h>
42   #include <stdlib.h>
43 + #include <fcntl.h>
44 + #include <errno.h>
45 +
46 + #ifndef WIN32
47   #include <unistd.h>
48   #include <dirent.h>
49 < #include <errno.h>
49 > #endif
50 >
51 > #if defined __APPLE__ && defined __MACH__
52 > #include <sys/attr.h>
53 > #endif
54  
41 #include "sysdeps.h"
55   #include "cpu_emulation.h"
43 #include "macos_util.h"
56   #include "emul_op.h"
57   #include "main.h"
58   #include "disk.h"
# Line 49 | 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 59 | 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 95 | 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 105 | 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 137 | 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;                             // 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 148 | 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 162 | 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 +        p->name = new char[strlen(name) + 1];
239 +        strcpy(p->name, name);
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 177 | Line 257 | static FSItem *find_fsitem(const char *n
257          }
258  
259          // Not found, construct new FSItem
260 <        p = new FSItem;
181 <        last_fs_item->next = p;
182 <        p->next = NULL;
183 <        last_fs_item = p;
184 <        p->id = next_cnid++;
185 <        p->parent_id = parent->id;
186 <        p->parent = parent;
187 <        strncpy(p->name, name, 31);
188 <        p->name[31] = 0;
189 <        p->mtime = 0;
190 <        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(macroman_to_host_encoding(guest_name), guest_name, parent);
278 + }
279  
280   /*
281   *  Get full path (->full_path) for given FSItem
282   */
283  
198 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);
204 <        if (l < MAX_PATH_LENGTH-1 && full_path[l-1] != '/') {
205 <                full_path[l] = '/';
206 <                full_path[l+1] = 0;
207 <        }
208 <        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 238 | 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  
247 // Convert pascal string to C string
248 static void pstr2cstr(char *dst, const char *src)
249 {
250        int size = *src++;
251        while (size--) {
252                char c = *src++;
253                if (c == '/')
254                        c = ':';
255                *dst++ = c;
256        }
257        *dst = 0;
258 }
259
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 319 | 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 = new char[1];
420 +        p->name[0] = 0;
421 +        p->guest_name[0] = 0;
422 +
423 +        // Create root FSItem
424 +        p = new FSItem;
425 +        last_fs_item->next = p;
426 +        p->next = NULL;
427 +        last_fs_item = p;
428          p->id = ROOT_ID;
429          p->parent_id = ROOT_PARENT_ID;
430 <        p->parent = NULL;
431 <        strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
430 >        p->parent = first_fs_item;
431 >        const char *volume_name = GetString(STR_EXTFS_VOLUME_NAME);
432 >        p->name = new char[strlen(volume_name) + 1];
433 >        strcpy(p->name, volume_name);
434 >        strncpy(p->guest_name, host_encoding_to_macroman(p->name), 32);
435 >        p->guest_name[31] = 0;
436  
437          // Find path for root
438          if ((RootPath = PrefsFindString("extfs")) != NULL) {
# Line 349 | Line 455 | void ExtFSExit(void)
455          FSItem *p = first_fs_item, *next;
456          while (p) {
457                  next = p->next;
458 +                delete[] p->name;
459                  delete p;
460                  p = next;
461          }
# Line 375 | Line 482 | void InstallExtFS(void)
482          // FSM present?
483          r.d[0] = gestaltFSAttr;
484          Execute68kTrap(0xa1ad, &r);     // Gestalt()
485 <        D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0]));
486 <        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager)))
485 >        D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0]));
486 >        if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) {
487 >                printf("WARNING: No FSM present, disabling ExtFS\n");
488                  return;
489 +        }
490  
491          // Yes, version >=1.2?
492          r.d[0] = gestaltFSMVersion;
493          Execute68kTrap(0xa1ad, &r);     // Gestalt()
494 <        D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0]));
495 <        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120))
494 >        D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0]));
495 >        if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) {
496 >                printf("WARNING: FSM <1.2 found, disabling ExtFS\n");
497                  return;
498 +        }
499  
500          D(bug("FSM present\n"));
501  
# Line 420 | Line 531 | void InstallExtFS(void)
531          WriteMacInt16(p, 0x7006); p+= 2;        // UTAllocateVCB
532          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
533          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
534 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
534 >        WriteMacInt16(p, M68K_RTS); p+= 2;
535          if (p - fs_data != fsAddNewVCB)
536                  goto fsdat_error;
537          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 430 | Line 541 | void InstallExtFS(void)
541          WriteMacInt16(p, 0x7007); p+= 2;        // UTAddNewVCB
542          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
543          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
544 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
544 >        WriteMacInt16(p, M68K_RTS); p+= 2;
545          if (p - fs_data != fsDetermineVol)
546                  goto fsdat_error;
547          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 442 | Line 553 | void InstallExtFS(void)
553          WriteMacInt16(p, 0x701d); p+= 2;        // UTDetermineVol
554          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
555          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
556 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
556 >        WriteMacInt16(p, M68K_RTS); p+= 2;
557          if (p - fs_data != fsResolveWDCB)
558                  goto fsdat_error;
559          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
560 <        WriteMacInt16(p, 0x42a7); p+= 2;        // clr.l -(sp)
561 <        WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
562 <        WriteMacInt16(p, 0x3f00); p+= 2;        // move.w d0,-(sp)
560 >        WriteMacInt16(p, 0x2f00); p+= 2;        // move.l d0,-(sp)
561 >        WriteMacInt16(p, 0x3f01); p+= 2;        // move.w d1,-(sp)
562 >        WriteMacInt16(p, 0x3f02); p+= 2;        // move.w d2,-(sp)
563          WriteMacInt16(p, 0x2f08); p+= 2;        // move.l a0,-(sp)
564          WriteMacInt16(p, 0x700e); p+= 2;        // UTResolveWDCB
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 != fsGetDefaultVol)
569                  goto fsdat_error;
570          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 461 | Line 572 | void InstallExtFS(void)
572          WriteMacInt16(p, 0x7012); p+= 2;        // UTGetDefaultVol
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 != fsGetPathComponentName)
577                  goto fsdat_error;
578          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 469 | Line 580 | void InstallExtFS(void)
580          WriteMacInt16(p, 0x701c); p+= 2;        // UTGetPathComponentName
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 != fsParsePathname)
585                  goto fsdat_error;
586          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 478 | Line 589 | void InstallExtFS(void)
589          WriteMacInt16(p, 0x701b); p+= 2;        // UTParsePathname
590          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
591          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
592 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
592 >        WriteMacInt16(p, M68K_RTS); p+= 2;
593          if (p - fs_data != fsDisposeVCB)
594                  goto fsdat_error;
595          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 486 | Line 597 | void InstallExtFS(void)
597          WriteMacInt16(p, 0x7008); p+= 2;        // UTDisposeVCB
598          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
599          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
600 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
600 >        WriteMacInt16(p, M68K_RTS); p+= 2;
601          if (p - fs_data != fsCheckWDRefNum)
602                  goto fsdat_error;
603          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 494 | Line 605 | void InstallExtFS(void)
605          WriteMacInt16(p, 0x7013); p+= 2;        // UTCheckWDRefNum
606          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
607          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
608 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
608 >        WriteMacInt16(p, M68K_RTS); p+= 2;
609          if (p - fs_data != fsSetDefaultVol)
610                  goto fsdat_error;
611          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 504 | Line 615 | void InstallExtFS(void)
615          WriteMacInt16(p, 0x7011); p+= 2;        // UTSetDefaultVol
616          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
617          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
618 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
618 >        WriteMacInt16(p, M68K_RTS); p+= 2;
619          if (p - fs_data != fsAllocateFCB)
620                  goto fsdat_error;
621          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 513 | Line 624 | void InstallExtFS(void)
624          WriteMacInt16(p, 0x7000); p+= 2;        // UTAllocateFCB
625          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
626          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
627 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
627 >        WriteMacInt16(p, M68K_RTS); p+= 2;
628          if (p - fs_data != fsReleaseFCB)
629                  goto fsdat_error;
630          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 521 | Line 632 | void InstallExtFS(void)
632          WriteMacInt16(p, 0x7001); p+= 2;        // UTReleaseFCB
633          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
634          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
635 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
635 >        WriteMacInt16(p, M68K_RTS); p+= 2;
636          if (p - fs_data != fsIndexFCB)
637                  goto fsdat_error;
638          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 531 | Line 642 | void InstallExtFS(void)
642          WriteMacInt16(p, 0x7004); p+= 2;        // UTIndexFCB
643          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
644          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
645 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
645 >        WriteMacInt16(p, M68K_RTS); p+= 2;
646          if (p - fs_data != fsResolveFCB)
647                  goto fsdat_error;
648          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 540 | Line 651 | void InstallExtFS(void)
651          WriteMacInt16(p, 0x7005); p+= 2;        // UTResolveFCB
652          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
653          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
654 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
654 >        WriteMacInt16(p, M68K_RTS); p+= 2;
655          if (p - fs_data != fsAdjustEOF)
656                  goto fsdat_error;
657          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 548 | Line 659 | void InstallExtFS(void)
659          WriteMacInt16(p, 0x7010); p+= 2;        // UTAdjustEOF
660          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
661          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
662 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
662 >        WriteMacInt16(p, M68K_RTS); p+= 2;
663          if (p - fs_data != fsAllocateWDCB)
664                  goto fsdat_error;
665          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 556 | Line 667 | void InstallExtFS(void)
667          WriteMacInt16(p, 0x700c); p+= 2;        // UTAllocateWDCB
668          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
669          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
670 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
670 >        WriteMacInt16(p, M68K_RTS); p+= 2;
671          if (p - fs_data != fsReleaseWDCB)
672                  goto fsdat_error;
673          WriteMacInt16(p, 0x4267); p+= 2;        // clr.w -(sp)
# Line 564 | Line 675 | void InstallExtFS(void)
675          WriteMacInt16(p, 0x700d); p+= 2;        // UTReleaseWDCB
676          WriteMacInt16(p, 0xa824); p+= 2;        // FSMgr
677          WriteMacInt16(p, 0x301f); p+= 2;        // move.w (sp)+,d0
678 <        WriteMacInt16(p, M68K_EXEC_RETURN); p+= 2;
678 >        WriteMacInt16(p, M68K_RTS); p+= 2;
679          if (p - fs_data != SIZEOF_fsdat)
680                  goto fsdat_error;
681  
# Line 588 | Line 699 | void InstallExtFS(void)
699          WriteMacInt16(fs_data + fsFSD + fsdLength, SIZEOF_FSDRec);
700          WriteMacInt16(fs_data + fsFSD + fsdVersion, fsdVersion1);
701          WriteMacInt16(fs_data + fsFSD + fileSystemFSID, MY_FSID);
702 <        memcpy(Mac2HostAddr(fs_data + fsFSD + fileSystemName), FS_NAME, 32);
702 >        Host2Mac_memcpy(fs_data + fsFSD + fileSystemName, FS_NAME, 32);
703          WriteMacInt32(fs_data + fsFSD + fileSystemCommProc, fs_data + fsCommProcStub);
704          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + compInterfProc, fs_data + fsHFSProcStub);
705          WriteMacInt32(fs_data + fsFSD + fsdHFSCI + stackTop, fs_stack + STACK_SIZE);
# Line 642 | Line 753 | int16 ExtFSComm(uint16 message, uint32 p
753  
754                  case ffsGetIconMessage: {               // Get disk/drive icon
755                          if (ReadMacInt8(paramBlock + iconType) == kLargeIcon && ReadMacInt32(paramBlock + requestSize) >= sizeof(ExtFSIcon)) {
756 <                                memcpy(Mac2HostAddr(ReadMacInt32(paramBlock + iconBufferPtr)), ExtFSIcon, sizeof(ExtFSIcon));
756 >                                Host2Mac_memcpy(ReadMacInt32(paramBlock + iconBufferPtr), ExtFSIcon, sizeof(ExtFSIcon));
757                                  WriteMacInt32(paramBlock + actualSize, sizeof(ExtFSIcon));
758                                  return noErr;
759                          } else
# Line 650 | Line 761 | int16 ExtFSComm(uint16 message, uint32 p
761                  }
762  
763                  case ffsIDDiskMessage: {                // Check if volume is handled by our FS
764 <                        if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
764 >                        if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number)
765                                  return noErr;
766                          else
767                                  return extFSErr;
# Line 679 | Line 790 | static int16 get_current_dir(uint32 pb,
790          int16 result;
791  
792          // Determine volume
793 < //      D(bug("  determining volume\n"));
793 >        D(bug("  determining volume, dirID %d\n", dirID));
794          r.a[0] = pb;
795          r.a[1] = fs_data + fsReturn;
796          r.a[2] = fs_data + fsReturn + 2;
# Line 694 | Line 805 | static int16 get_current_dir(uint32 pb,
805          if (no_vol_name)
806                  WriteMacInt32(pb + ioNamePtr, name_ptr);
807          int16 status = ReadMacInt16(fs_data + fsReturn);
808 <        int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2);
809 <        int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4);
699 <        uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6);
700 < //      D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
701 <        result = r.d[0] & 0xffff;
808 >        D(bug("  UTDetermineVol() returned %d, status %d\n", r.d[0], status));
809 >        result = (int16)(r.d[0] & 0xffff);
810  
811          if (result == noErr) {
812                  switch (status) {
# Line 716 | Line 824 | static int16 get_current_dir(uint32 pb,
824                                          current_dir = dirID;
825                                  else {
826                                          D(bug("  resolving WDCB\n"));
827 <                                        r.d[0] = ReadMacInt16(pb + ioVRefNum);
827 >                                        r.d[0] = 0;
828 >                                        r.d[1] = 0;
829 >                                        r.d[2] = ReadMacInt16(pb + ioVRefNum);
830                                          r.a[0] = fs_data + fsReturn;
831                                          Execute68k(fs_data + fsResolveWDCB, &r);
832                                          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
833                                          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
834 <                                        result = r.d[0] & 0xffff;
834 >                                        result = (int16)(r.d[0] & 0xffff);
835                                          if (result == noErr)
836                                                  current_dir = ReadMacInt32(wdcb + wdDirID);
837                                  }
# Line 737 | Line 847 | static int16 get_current_dir(uint32 pb,
847                                          r.a[0] = wdpb;
848                                          Execute68k(fs_data + fsGetDefaultVol, &r);
849                                          D(bug("  UTGetDefaultVol() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdpb + ioWDDirID)));
850 <                                        result = r.d[0] & 0xffff;
850 >                                        result = (int16)(r.d[0] & 0xffff);
851                                          if (result == noErr)
852                                                  current_dir = ReadMacInt32(wdpb + ioWDDirID);
853                                  }
# Line 763 | Line 873 | static int16 get_path_component_name(uin
873          r.a[0] = rec;
874          Execute68k(fs_data + fsGetPathComponentName, &r);
875   //      D(bug("  UTGetPathComponentName returned %d\n", r.d[0]));
876 <        return r.d[0] & 0xffff;
876 >        return (int16)(r.d[0] & 0xffff);
877   }
878  
879  
# Line 780 | Line 890 | static int16 get_item_and_path(uint32 pb
890          uint32 current_dir;
891          if ((result = get_current_dir(pb, dirID, current_dir, no_vol_name)) != noErr)
892                  return result;
893 +        D(bug("  current dir %08x\n", current_dir));
894          FSItem *p = find_fsitem_by_id(current_dir);
895          if (p == NULL)
896                  return dirNFErr;
# Line 793 | Line 904 | static int16 get_item_and_path(uint32 pb
904          WriteMacInt8(parseRec + ppFoundDelimiter, false);
905  
906          // Get length of volume name
907 < //      D(bug("  parsing pathname\n"));
907 >        D(bug("  parsing pathname\n"));
908          r.a[0] = parseRec + ppStartOffset;
909          r.a[1] = ReadMacInt32(parseRec + ppNamePtr);
910          Execute68k(fs_data + fsParsePathname, &r);
911 < //      D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
912 <        result = r.d[0] & 0xffff;
911 >        D(bug("  UTParsePathname() returned %d, startOffset %d\n", r.d[0], ReadMacInt16(parseRec + ppStartOffset)));
912 >        result = (int16)(r.d[0] & 0xffff);
913          if (result == noErr) {
914  
915                  // Check for leading delimiter of the partial pathname
# Line 833 | Line 944 | static int16 get_item_and_path(uint32 pb
944                                                  char name[32];
945                                                  strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
946                                                  D(bug("  entering %s\n", name));
947 <                                                p = find_fsitem(name, p);
947 >                                                p = find_fsitem_guest(name, p);
948                                                  current_dir = p->id;
949  
950                                                  // startOffset = start of next component
# Line 856 | Line 967 | static int16 get_item_and_path(uint32 pb
967                                          char name[32];
968                                          strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
969                                          D(bug("  object is %s\n", name));
970 <                                        item = find_fsitem(name, p);
970 >                                        item = find_fsitem_guest(name, p);
971                                  }
972                          }
973                  }
# Line 911 | Line 1022 | static uint32 find_fcb(int16 refNum)
1022   static int16 fs_mount_vol(uint32 pb)
1023   {
1024          D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum)));
1025 <        if (ReadMacInt16(pb + ioVRefNum) == drive_number)
1025 >        if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number)
1026                  return noErr;
1027          else
1028                  return extFSErr;
# Line 928 | Line 1039 | static int16 fs_volume_mount(uint32 pb)
1039          r.a[0] = fs_data + fsReturn;
1040          r.a[1] = fs_data + fsReturn + 2;
1041          Execute68k(fs_data + fsAllocateVCB, &r);
1042 + #if DEBUG
1043          uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn);
1044 + #endif
1045          uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2);
1046          D(bug("  UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength));
1047          if (r.d[0] & 0xffff)
1048 <                return r.d[0];
1048 >                return (int16)r.d[0];
1049  
1050          // Init VCB
1051          WriteMacInt16(vcb + vcbSigWord, 0x4244);
1052 < #ifdef __BEOS__
1053 <        WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
1052 > #if defined(__BEOS__) || defined(WIN32)
1053 >        WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
1054 > #elif defined __APPLE__ && defined __MACH__
1055 >        WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath));
1056   #else
1057          WriteMacInt32(vcb + vcbCrDate, 0);
1058   #endif
1059 <        WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET);
1059 >        WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime));
1060          WriteMacInt32(vcb + vcbVolBkUp, 0);
1061          WriteMacInt16(vcb + vcbNmFls, 1);                       //!!
1062          WriteMacInt16(vcb + vcbNmRtDirs, 1);            //!!
1063          WriteMacInt16(vcb + vcbNmAlBlks, 0xffff);       //!!
1064 <        WriteMacInt32(vcb + vcbAlBlkSiz, 1024);
1065 <        WriteMacInt32(vcb + vcbClpSiz, 1024);
1064 >        WriteMacInt32(vcb + vcbAlBlkSiz, AL_BLK_SIZE);
1065 >        WriteMacInt32(vcb + vcbClpSiz, CLUMP_SIZE);
1066          WriteMacInt32(vcb + vcbNxtCNID, next_cnid);
1067          WriteMacInt16(vcb + vcbFreeBks, 0xffff);        //!!
1068 <        memcpy(Mac2HostAddr(vcb + vcbVN), VOLUME_NAME, 28);
1068 >        Host2Mac_memcpy(vcb + vcbVN, VOLUME_NAME, 28);
1069          WriteMacInt16(vcb + vcbFSID, MY_FSID);
1070          WriteMacInt32(vcb + vcbFilCnt, 1);                      //!!
1071          WriteMacInt32(vcb + vcbDirCnt, 1);                      //!!
# Line 961 | Line 1076 | static int16 fs_volume_mount(uint32 pb)
1076          r.a[0] = fs_data + fsReturn;
1077          r.a[1] = vcb;
1078          Execute68k(fs_data + fsAddNewVCB, &r);
1079 <        int16 vRefNum = ReadMacInt32(fs_data + fsReturn);
1079 >        int16 vRefNum = (int16)ReadMacInt32(fs_data + fsReturn);
1080          D(bug("  UTAddNewVCB() returned %d, vRefNum %d\n", r.d[0], vRefNum));
1081          if (r.d[0] & 0xffff)
1082 <                return r.d[0];
1082 >                return (int16)r.d[0];
1083  
1084          // Post diskInsertEvent
1085          D(bug("  posting diskInsertEvent\n"));
# Line 988 | Line 1103 | static int16 fs_unmount_vol(uint32 vcb)
1103          r.a[0] = vcb;
1104          Execute68k(fs_data + fsDisposeVCB, &r);
1105          D(bug("  UTDisposeVCB() returned %d\n", r.d[0]));
1106 <        return r.d[0];
1106 >        return (int16)r.d[0];
1107   }
1108  
1109   // Get information about a volume (HVolumeParam)
# Line 999 | Line 1114 | static int16 fs_get_vol_info(uint32 pb,
1114          // Fill in struct
1115          if (ReadMacInt32(pb + ioNamePtr))
1116                  pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1117 < #ifdef __BEOS__
1118 <        WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
1117 > #if defined(__BEOS__) || defined(WIN32)
1118 >        WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
1119 > #elif defined __APPLE__ && defined __MACH__
1120 >        WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath));
1121   #else
1122          WriteMacInt32(pb + ioVCrDate, 0);
1123   #endif
1124 <        WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET);
1124 >        WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime));
1125          WriteMacInt16(pb + ioVAtrb, 0);
1126          WriteMacInt16(pb + ioVNmFls, 1);                        //!!
1127          WriteMacInt16(pb + ioVBitMap, 0);
1128          WriteMacInt16(pb + ioAllocPtr, 0);
1129          WriteMacInt16(pb + ioVNmAlBlks, 0xffff);        //!!
1130 <        WriteMacInt32(pb + ioVAlBlkSiz, 1024);
1131 <        WriteMacInt32(pb + ioVClpSiz, 1024);
1130 >        WriteMacInt32(pb + ioVAlBlkSiz, AL_BLK_SIZE);
1131 >        WriteMacInt32(pb + ioVClpSiz, CLUMP_SIZE);
1132          WriteMacInt16(pb + ioAlBlSt, 0);
1133          WriteMacInt32(pb + ioVNxtCNID, next_cnid);
1134          WriteMacInt16(pb + ioVFrBlk, 0xffff);           //!!
# Line 1024 | Line 1141 | static int16 fs_get_vol_info(uint32 pb,
1141                  WriteMacInt32(pb + ioVWrCnt, 0);
1142                  WriteMacInt32(pb + ioVFilCnt, 1);                       //!!
1143                  WriteMacInt32(pb + ioVDirCnt, 1);                       //!!
1144 <                memset(Mac2HostAddr(pb + ioVFndrInfo), 0, 32);
1144 >                Mac_memset(pb + ioVFndrInfo, 0, 32);
1145          }
1146          return noErr;
1147   }
# Line 1044 | Line 1161 | static int16 fs_get_vol_parms(uint32 pb)
1161   //      D(bug(" fs_get_vol_parms(%08lx)\n", pb));
1162  
1163          // Return parameter block
1047        uint8 vol[SIZEOF_GetVolParmsInfoBuffer];
1048        WriteMacInt16((uint32)vol + vMVersion, 2);
1049        WriteMacInt32((uint32)vol + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1050        WriteMacInt32((uint32)vol + vMLocalHand, 0);
1051        WriteMacInt32((uint32)vol + vMServerAdr, 0);
1052        WriteMacInt32((uint32)vol + vMVolumeGrade, 0);
1053        WriteMacInt16((uint32)vol + vMForeignPrivID, 0);
1164          uint32 actual = ReadMacInt32(pb + ioReqCount);
1165 <        if (actual > sizeof(vol))
1166 <                actual = sizeof(vol);
1057 <        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), vol, actual);
1165 >        if (actual > SIZEOF_GetVolParmsInfoBuffer)
1166 >                actual = SIZEOF_GetVolParmsInfoBuffer;
1167          WriteMacInt32(pb + ioActCount, actual);
1168 +        uint32 p = ReadMacInt32(pb + ioBuffer);
1169 +        if (actual > vMVersion) WriteMacInt16(p + vMVersion, 2);
1170 +        if (actual > vMAttrib) WriteMacInt32(p + vMAttrib, kNoMiniFndr | kNoVNEdit | kNoLclSync | kTrshOffLine | kNoSwitchTo | kNoBootBlks | kNoSysDir | kHasExtFSVol);
1171 +        if (actual > vMLocalHand) WriteMacInt32(p + vMLocalHand, 0);
1172 +        if (actual > vMServerAdr) WriteMacInt32(p + vMServerAdr, 0);
1173 +        if (actual > vMVolumeGrade) WriteMacInt32(p + vMVolumeGrade, 0);
1174 +        if (actual > vMForeignPrivID) WriteMacInt16(p + vMForeignPrivID, 0);
1175          return noErr;
1176   }
1177  
# Line 1070 | Line 1186 | static int16 fs_get_vol(uint32 pb)
1186          r.a[0] = pb;
1187          Execute68k(fs_data + fsGetDefaultVol, &r);
1188          D(bug("  UTGetDefaultVol() returned %d\n", r.d[0]));
1189 <        return r.d[0];
1189 >        return (int16)r.d[0];
1190   }
1191  
1192   // Set default volume (WDParam)
1193   static int16 fs_set_vol(uint32 pb, bool hfs, uint32 vcb)
1194   {
1195 <        D(bug(" fs_set_vol(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
1195 >        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)));
1196          M68kRegisters r;
1197  
1198          // Determine parameters
# Line 1126 | Line 1242 | static int16 fs_set_vol(uint32 pb, bool
1242          r.d[2] = refNum;
1243          Execute68k(fs_data + fsSetDefaultVol, &r);
1244          D(bug("  UTSetDefaultVol() returned %d\n", r.d[0]));
1245 <        return r.d[0];
1245 >        return (int16)r.d[0];
1246   }
1247  
1248   // Query file attributes (HFileParam)
1249   static int16 fs_get_file_info(uint32 pb, bool hfs, uint32 dirID)
1250   {
1251 <        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));
1251 >        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));
1252  
1253          FSItem *fs_item;
1254          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1255 <        if (dir_index == 0) {   // Query item specified by ioDirID and ioNamePtr
1255 >        if (dir_index <= 0) {           // Query item specified by ioDirID and ioNamePtr
1256  
1257                  // Find FSItem for given file
1258                  int16 result = get_item_and_path(pb, dirID, fs_item);
# Line 1168 | Line 1284 | read_next_de:
1284                                  return fnfErr;
1285                          }
1286                          if (de->d_name[0] == '.')
1287 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1287 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1288                          //!! suppress directories
1289                  }
1290 <                add_path_component(de->d_name);
1290 >                add_path_comp(de->d_name);
1291  
1292                  // Get FSItem for queried item
1293                  fs_item = find_fsitem(de->d_name, p);
# Line 1187 | Line 1303 | read_next_de:
1303  
1304          // Fill in struct from fs_item and stats
1305          if (ReadMacInt32(pb + ioNamePtr))
1306 <                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
1306 >                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1307          WriteMacInt16(pb + ioFRefNum, 0);
1308          WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1309          WriteMacInt32(pb + ioDirID, fs_item->id);
1310  
1311 < #ifdef __BEOS__
1312 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1311 > #if defined(__BEOS__) || defined(WIN32)
1312 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1313 > #elif defined __APPLE__ && defined __MACH__
1314 >        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1315   #else
1316          WriteMacInt32(pb + ioFlCrDat, 0);
1317   #endif
1318 <        WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
1318 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime));
1319  
1320 <        memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1203 <        uint32 type, creator;   // pb may point to kernel space, but stack is switched
1204 <        get_finder_type(full_path, type, creator);
1205 <        WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1206 <        WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1207 <        uint16 fflags;
1208 <        get_finder_flags(full_path, fflags);
1209 <        WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1320 >        get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1321  
1322          WriteMacInt16(pb + ioFlStBlk, 0);
1323          WriteMacInt32(pb + ioFlLgLen, st.st_size);
1324 <        WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1324 >        WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1325          WriteMacInt16(pb + ioFlRStBlk, 0);
1326          uint32 rf_size = get_rfork_size(full_path);
1327          WriteMacInt32(pb + ioFlRLgLen, rf_size);
1328 <        WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1328 >        WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1329  
1330          if (hfs) {
1331                  WriteMacInt32(pb + ioFlBkDat, 0);
1221                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1332                  WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1333                  WriteMacInt32(pb + ioFlClpSiz, 0);
1334          }
# Line 1228 | Line 1338 | read_next_de:
1338   // Set file attributes (HFileParam)
1339   static int16 fs_set_file_info(uint32 pb, bool hfs, uint32 dirID)
1340   {
1341 <        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));
1341 >        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));
1342  
1343          // Find FSItem for given file/dir
1344          FSItem *fs_item;
# Line 1243 | Line 1353 | static int16 fs_set_file_info(uint32 pb,
1353          if (S_ISDIR(st.st_mode))
1354                  return fnfErr;
1355  
1356 <        // Set attributes
1357 <        set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1358 <        set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1356 >        // Set Finder info
1357 >        set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
1358 >
1359          //!! times
1360          return noErr;
1361   }
# Line 1253 | Line 1363 | static int16 fs_set_file_info(uint32 pb,
1363   // Query file/directory attributes
1364   static int16 fs_get_cat_info(uint32 pb)
1365   {
1366 <        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)));
1366 >        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)));
1367  
1368          FSItem *fs_item;
1369          int16 dir_index = ReadMacInt16(pb + ioFDirIndex);
1370 <        if (dir_index == -1) {          // Query directory specified by ioDirID
1370 >        if (dir_index < 0) {                    // Query directory specified by ioDirID
1371  
1372                  // Find FSItem for directory
1373                  fs_item = find_fsitem_by_id(ReadMacInt32(pb + ioDrDirID));
# Line 1297 | Line 1407 | read_next_de:
1407                                  return fnfErr;
1408                          }
1409                          if (de->d_name[0] == '.')
1410 <                                goto read_next_de;      // Suppress name beginning with '.' (MacOS could interpret these as driver names)
1410 >                                goto read_next_de;      // Suppress names beginning with '.' (MacOS could interpret these as driver names)
1411                  }
1412 <                add_path_component(de->d_name);
1412 >                add_path_comp(de->d_name);
1413  
1414                  // Get FSItem for queried item
1415                  fs_item = find_fsitem(de->d_name, p);
# Line 1316 | Line 1426 | read_next_de:
1426  
1427          // Fill in struct from fs_item and stats
1428          if (ReadMacInt32(pb + ioNamePtr))
1429 <                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
1429 >                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1430          WriteMacInt16(pb + ioFRefNum, 0);
1431          WriteMacInt8(pb + ioFlAttrib, (S_ISDIR(st.st_mode) ? faIsDir : 0) | (access(full_path, W_OK) == 0 ? 0 : faLocked));
1432          WriteMacInt8(pb + ioACUser, 0);
1433          WriteMacInt32(pb + ioDirID, fs_item->id);
1434          WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1435 < #ifdef __BEOS__
1436 <        WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
1435 > #if defined(__BEOS__) || defined(WIN32)
1436 >        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
1437 > #elif defined __APPLE__ && defined __MACH__
1438 >        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1439   #else
1440          WriteMacInt32(pb + ioFlCrDat, 0);
1441   #endif
# Line 1333 | Line 1445 | read_next_de:
1445                  fs_item->mtime = mtime;
1446                  cached = false;
1447          }
1448 <        WriteMacInt32(pb + ioFlMdDat, mtime);
1448 >        WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime));
1449          WriteMacInt32(pb + ioFlBkDat, 0);
1450 +
1451 +        get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1452 +
1453          if (S_ISDIR(st.st_mode)) {
1339                memset(Mac2HostAddr(pb + ioDrUsrWds), 0, SIZEOF_DInfo);
1340                memset(Mac2HostAddr(pb + ioDrFndrInfo), 0, SIZEOF_DXInfo);
1341                uint16 fflags;  // pb may point to kernel space, but stack is switched
1342                get_finder_flags(full_path, fflags);
1343                WriteMacInt16(pb + ioDrUsrWds + frFlags, fflags);
1454  
1455                  // Determine number of files in directory (cached)
1456                  int count;
# Line 1355 | Line 1465 | read_next_de:
1465                                          de = readdir(d);
1466                                          if (de == NULL)
1467                                                  break;
1468 +                                        if (de->d_name[0] == '.')
1469 +                                                continue;       // Suppress names beginning with '.'
1470                                          count++;
1471                                  }
1472                                  closedir(d);
# Line 1363 | Line 1475 | read_next_de:
1475                  }
1476                  WriteMacInt16(pb + ioDrNmFls, count);
1477          } else {
1366                memset(Mac2HostAddr(pb + ioFlFndrInfo), 0, SIZEOF_FInfo);
1367                memset(Mac2HostAddr(pb + ioFlXFndrInfo), 0, SIZEOF_FXInfo);
1368                uint32 type, creator;   // pb may point to kernel space, but stack is switched
1369                get_finder_type(full_path, type, creator);
1370                WriteMacInt32(pb + ioFlFndrInfo + fdType, type);
1371                WriteMacInt32(pb + ioFlFndrInfo + fdCreator, creator);
1372                uint16 fflags;
1373                get_finder_flags(full_path, fflags);
1374                WriteMacInt16(pb + ioFlFndrInfo + fdFlags, fflags);
1478                  WriteMacInt16(pb + ioFlStBlk, 0);
1479                  WriteMacInt32(pb + ioFlLgLen, st.st_size);
1480 <                WriteMacInt32(pb + ioFlPyLen, (st.st_size + 1023) & ~1023);
1480 >                WriteMacInt32(pb + ioFlPyLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1481                  WriteMacInt16(pb + ioFlRStBlk, 0);
1482                  uint32 rf_size = get_rfork_size(full_path);
1483                  WriteMacInt32(pb + ioFlRLgLen, rf_size);
1484 <                WriteMacInt32(pb + ioFlRPyLen, (rf_size + 1023) & ~1023);
1484 >                WriteMacInt32(pb + ioFlRPyLen, (rf_size | (AL_BLK_SIZE - 1)) + 1);
1485                  WriteMacInt32(pb + ioFlClpSiz, 0);
1486          }
1487          return noErr;
# Line 1387 | Line 1490 | read_next_de:
1490   // Set file/directory attributes
1491   static int16 fs_set_cat_info(uint32 pb)
1492   {
1493 <        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)));
1493 >        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)));
1494  
1495          // Find FSItem for given file/dir
1496          FSItem *fs_item;
# Line 1400 | Line 1503 | static int16 fs_set_cat_info(uint32 pb)
1503          if (stat(full_path, &st) < 0)
1504                  return errno2oserr();
1505  
1506 <        // Set attributes
1507 <        if (S_ISDIR(st.st_mode))
1508 <                set_finder_flags(full_path, ReadMacInt16(pb + ioDrUsrWds + frFlags));
1406 <        else {
1407 <                set_finder_type(full_path, ReadMacInt32(pb + ioFlFndrInfo + fdType), ReadMacInt32(pb + ioFlFndrInfo + fdCreator));
1408 <                set_finder_flags(full_path, ReadMacInt16(pb + ioFlFndrInfo + fdFlags));
1409 <        }
1506 >        // Set Finder info
1507 >        set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));
1508 >
1509          //!! times
1510          return noErr;
1511   }
# Line 1414 | Line 1513 | static int16 fs_set_cat_info(uint32 pb)
1513   // Open file
1514   static int16 fs_open(uint32 pb, uint32 dirID, uint32 vcb, bool resource_fork)
1515   {
1516 <        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)));
1516 >        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)));
1517          M68kRegisters r;
1518  
1519          // Find FSItem for given file
# Line 1453 | Line 1552 | static int16 fs_open(uint32 pb, uint32 d
1552                  if (access(full_path, F_OK))
1553                          return fnfErr;
1554                  fd = open_rfork(full_path, flag);
1555 <                if (fd > 0) {
1556 <                        if (fstat(fd, &st) < 0)
1555 >                if (fd >= 0) {
1556 >                        if (fstat(fd, &st) < 0) {
1557 >                                close(fd);
1558                                  return errno2oserr();
1559 +                        }
1560                  } else {        // Resource fork not supported, silently ignore it ("pseudo" resource fork)
1561                          st.st_size = 0;
1562                          st.st_mode = 0;
# Line 1464 | Line 1565 | static int16 fs_open(uint32 pb, uint32 d
1565                  fd = open(full_path, flag);
1566                  if (fd < 0)
1567                          return errno2oserr();
1568 <                if (fstat(fd, &st) < 0)
1568 >                if (fstat(fd, &st) < 0) {
1569 >                        close(fd);
1570                          return errno2oserr();
1571 +                }
1572          }
1573  
1574          // File open, allocate FCB
# Line 1477 | Line 1580 | static int16 fs_open(uint32 pb, uint32 d
1580          D(bug("  UTAllocateFCB() returned %d, fRefNum %d, fcb %08lx\n", r.d[0], ReadMacInt16(pb + ioRefNum), fcb));
1581          if (r.d[0] & 0xffff) {
1582                  close(fd);
1583 <                return r.d[0];
1583 >                return (int16)r.d[0];
1584          }
1585  
1586          // Initialize FCB, fd is stored in fcbCatPos
1587          WriteMacInt32(fcb + fcbFlNm, fs_item->id);
1588          WriteMacInt8(fcb + fcbFlags, ((flag == O_WRONLY || flag == O_RDWR) ? fcbWriteMask : 0) | (resource_fork ? fcbResourceMask : 0) | (write_ok ? 0 : fcbFileLockedMask));
1589          WriteMacInt32(fcb + fcbEOF, st.st_size);
1590 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1590 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1591          WriteMacInt32(fcb + fcbCrPs, 0);
1592          WriteMacInt32(fcb + fcbVPtr, vcb);
1593 <        WriteMacInt32(fcb + fcbClmpSize, 1024);
1594 <        uint32 type, creator;   // fcb may point to kernel space, but stack is switched
1595 <        get_finder_type(full_path, type, creator);
1596 <        WriteMacInt32(fcb + fcbFType, type);
1593 >        WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE);
1594 >
1595 >        get_finfo(full_path, fs_data + fsPB, 0, false);
1596 >        WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType));
1597 >
1598          WriteMacInt32(fcb + fcbCatPos, fd);
1599          WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1600 <        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
1600 >        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->guest_name);
1601          return noErr;
1602   }
1603  
# Line 1527 | Line 1631 | static int16 fs_close(uint32 pb)
1631          r.d[0] = ReadMacInt16(pb + ioRefNum);
1632          Execute68k(fs_data + fsReleaseFCB, &r);
1633          D(bug("  UTReleaseFCB() returned %d\n", r.d[0]));
1634 <        return r.d[0];
1634 >        return (int16)r.d[0];
1635   }
1636  
1637   // Query information about FCB (FCBPBRec)
# Line 1546 | Line 1650 | static int16 fs_get_fcb_info(uint32 pb,
1650  
1651                  // Find FCB by index
1652                  WriteMacInt16(pb + ioRefNum, 0);
1653 <                for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) {
1653 >                for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) {
1654                          D(bug("  indexing FCBs\n"));
1655                          r.a[0] = vcb;
1656                          r.a[1] = pb + ioRefNum;
# Line 1555 | Line 1659 | static int16 fs_get_fcb_info(uint32 pb,
1659                          fcb = ReadMacInt32(fs_data + fsReturn);
1660                          D(bug("  UTIndexFCB() returned %d, fcb %p\n", r.d[0], fcb));
1661                          if (r.d[0] & 0xffff)
1662 <                                return r.d[0];
1662 >                                return (int16)r.d[0];
1663                  }
1664          }
1665          if (fcb == 0)
# Line 1603 | Line 1707 | static int16 fs_get_eof(uint32 pb)
1707  
1708          // Adjust FCBs
1709          WriteMacInt32(fcb + fcbEOF, st.st_size);
1710 <        WriteMacInt32(fcb + fcbPLen, (st.st_size + 1023) & ~1023);
1710 >        WriteMacInt32(fcb + fcbPLen, (st.st_size | (AL_BLK_SIZE - 1)) + 1);
1711          WriteMacInt32(pb + ioMisc, st.st_size);
1712          D(bug("  adjusting FCBs\n"));
1713          r.d[0] = ReadMacInt16(pb + ioRefNum);
# Line 1638 | Line 1742 | static int16 fs_set_eof(uint32 pb)
1742  
1743          // Adjust FCBs
1744          WriteMacInt32(fcb + fcbEOF, size);
1745 <        WriteMacInt32(fcb + fcbPLen, (size + 1023) & ~1023);
1745 >        WriteMacInt32(fcb + fcbPLen, (size | (AL_BLK_SIZE - 1)) + 1);
1746          D(bug("  adjusting FCBs\n"));
1747          r.d[0] = ReadMacInt16(pb + ioRefNum);
1748          Execute68k(fs_data + fsAdjustEOF, &r);
# Line 1701 | Line 1805 | static int16 fs_set_fpos(uint32 pb)
1805                          if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_SET) < 0)
1806                                  return posErr;
1807                          break;
1808 +                case fsFromLEOF:
1809 +                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_END) < 0)
1810 +                                return posErr;
1811 +                        break;
1812                  case fsFromMark:
1813 <                        if (lseek(fd, ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1813 >                        if (lseek(fd, (int32)ReadMacInt32(pb + ioPosOffset), SEEK_CUR) < 0)
1814                                  return posErr;
1815 +                        break;
1816                  default:
1817                          break;
1818          }
# Line 1718 | Line 1827 | static int16 fs_read(uint32 pb)
1827   {
1828          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)));
1829  
1830 +        // Check parameters
1831 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1832 +                return paramErr;
1833 +
1834          // Find FCB and fd for file
1835          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1836          if (fcb == 0)
# Line 1749 | Line 1862 | static int16 fs_read(uint32 pb)
1862          }
1863  
1864          // Read
1865 <        size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1865 >        ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1866 >        int16 read_err = errno2oserr();
1867          D(bug("  actual %d\n", actual));
1868 <        WriteMacInt32(pb + ioActCount, actual);
1868 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1869          uint32 pos = lseek(fd, 0, SEEK_CUR);
1870          WriteMacInt32(fcb + fcbCrPs, pos);
1871          WriteMacInt32(pb + ioPosOffset, pos);
1872 <        if (actual != ReadMacInt32(pb + ioReqCount))
1873 <                if (errno)
1760 <                        return errno2oserr();
1761 <                else
1762 <                        return eofErr;
1872 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1873 >                return actual < 0 ? read_err : eofErr;
1874          else
1875                  return noErr;
1876   }
# Line 1769 | Line 1880 | static int16 fs_write(uint32 pb)
1880   {
1881          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)));
1882  
1883 +        // Check parameters
1884 +        if ((int32)ReadMacInt32(pb + ioReqCount) < 0)
1885 +                return paramErr;
1886 +
1887          // Find FCB and fd for file
1888          uint32 fcb = find_fcb(ReadMacInt16(pb + ioRefNum));
1889          if (fcb == 0)
# Line 1800 | Line 1915 | static int16 fs_write(uint32 pb)
1915          }
1916  
1917          // Write
1918 <        size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1918 >        ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
1919 >        int16 write_err = errno2oserr();
1920          D(bug("  actual %d\n", actual));
1921 <        WriteMacInt32(pb + ioActCount, actual);
1921 >        WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
1922          uint32 pos = lseek(fd, 0, SEEK_CUR);
1923          WriteMacInt32(fcb + fcbCrPs, pos);
1924          WriteMacInt32(pb + ioPosOffset, pos);
1925 <        if (actual != ReadMacInt32(pb + ioReqCount))
1926 <                return errno2oserr();
1925 >        if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount))
1926 >                return write_err;
1927          else
1928                  return noErr;
1929   }
# Line 1815 | Line 1931 | static int16 fs_write(uint32 pb)
1931   // Create file
1932   static int16 fs_create(uint32 pb, uint32 dirID)
1933   {
1934 <        D(bug(" fs_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1934 >        D(bug(" fs_create(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1935  
1936          // Find FSItem for given file
1937          FSItem *fs_item;
# Line 1828 | Line 1944 | static int16 fs_create(uint32 pb, uint32
1944                  return dupFNErr;
1945  
1946          // Create file
1947 <        int fd = creat(full_path, 0664);
1947 >        int fd = creat(full_path, 0666);
1948          if (fd < 0)
1949                  return errno2oserr();
1950          else {
# Line 1840 | Line 1956 | static int16 fs_create(uint32 pb, uint32
1956   // Create directory
1957   static int16 fs_dir_create(uint32 pb)
1958   {
1959 <        D(bug(" fs_dir_create(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioDirID)));
1959 >        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)));
1960  
1961          // Find FSItem for given directory
1962          FSItem *fs_item;
# Line 1853 | Line 1969 | static int16 fs_dir_create(uint32 pb)
1969                  return dupFNErr;
1970  
1971          // Create directory
1972 <        if (mkdir(full_path, 0775) < 0)
1972 >        if (mkdir(full_path, 0777) < 0)
1973                  return errno2oserr();
1974          else {
1975                  WriteMacInt32(pb + ioDirID, fs_item->id);
# Line 1864 | Line 1980 | static int16 fs_dir_create(uint32 pb)
1980   // Delete file/directory
1981   static int16 fs_delete(uint32 pb, uint32 dirID)
1982   {
1983 <        D(bug(" fs_delete(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), dirID));
1983 >        D(bug(" fs_delete(%08lx), vRefNum %d, name %.31s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr) + 1), dirID));
1984  
1985          // Find FSItem for given file/dir
1986          FSItem *fs_item;
# Line 1873 | Line 1989 | static int16 fs_delete(uint32 pb, uint32
1989                  return result;
1990  
1991          // Delete file
1992 <        if (remove(full_path) < 0) {
1993 <                int16 err = errno2oserr();
1994 <                if (errno == EISDIR) {  // Workaround for BeOS bug
1879 <                        if (rmdir(full_path) < 0)
1880 <                                return errno2oserr();
1881 <                        else
1882 <                                return noErr;
1883 <                } else
1884 <                        return err;
1885 <        } else
1992 >        if (!extfs_remove(full_path))
1993 >                return errno2oserr();
1994 >        else
1995                  return noErr;
1996   }
1997  
1998   // Rename file/directory
1999   static int16 fs_rename(uint32 pb, uint32 dirID)
2000   {
2001 <        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))));
2001 >        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)));
2002  
2003          // Find path of given file/dir
2004          FSItem *fs_item;
# Line 1902 | Line 2011 | static int16 fs_rename(uint32 pb, uint32
2011          strcpy(old_path, full_path);
2012  
2013          // Find path for new name
2014 <        uint8 new_pb[SIZEOF_IOParam];
2015 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1907 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioMisc));
2014 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2015 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioMisc));
2016          FSItem *new_item;
2017 <        result = get_item_and_path((uint32)new_pb, dirID, new_item);
2017 >        result = get_item_and_path(fs_data + fsPB, dirID, new_item);
2018          if (result != noErr)
2019                  return result;
2020  
# Line 1916 | Line 2024 | static int16 fs_rename(uint32 pb, uint32
2024  
2025          // Rename item
2026          D(bug("  renaming %s -> %s\n", old_path, full_path));
2027 <        if (rename(old_path, full_path) < 0)
2027 >        if (!extfs_rename(old_path, full_path))
2028                  return errno2oserr();
2029          else {
2030                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2031 +                swap_parent_ids(fs_item->id, new_item->id);
2032                  uint32 t = fs_item->id;
2033                  fs_item->id = new_item->id;
2034                  new_item->id = t;
# Line 1930 | Line 2039 | static int16 fs_rename(uint32 pb, uint32
2039   // Move file/directory (CMovePBRec)
2040   static int16 fs_cat_move(uint32 pb)
2041   {
2042 <        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)));
2042 >        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)));
2043  
2044          // Find path of given file/dir
2045          FSItem *fs_item;
# Line 1943 | Line 2052 | static int16 fs_cat_move(uint32 pb)
2052          strcpy(old_path, full_path);
2053  
2054          // Find path for new directory
2055 <        uint8 new_pb[SIZEOF_IOParam];
2056 <        memcpy(new_pb, Mac2HostAddr(pb), SIZEOF_IOParam);
1948 <        WriteMacInt32((uint32)new_pb + ioNamePtr, ReadMacInt32(pb + ioNewName));
2055 >        Mac2Mac_memcpy(fs_data + fsPB, pb, SIZEOF_IOParam);
2056 >        WriteMacInt32(fs_data + fsPB + ioNamePtr, ReadMacInt32(pb + ioNewName));
2057          FSItem *new_dir_item;
2058 <        result = get_item_and_path((uint32)new_pb, ReadMacInt32(pb + ioNewDirID), new_dir_item);
2058 >        result = get_item_and_path(fs_data + fsPB, ReadMacInt32(pb + ioNewDirID), new_dir_item);
2059          if (result != noErr)
2060                  return result;
2061  
2062          // Append old file/dir name
2063 <        add_path_component(fs_item->name);
2063 >        add_path_comp(fs_item->name);
2064  
2065          // Does the new name already exist?
2066          if (access(full_path, F_OK) == 0)
# Line 1960 | Line 2068 | static int16 fs_cat_move(uint32 pb)
2068  
2069          // Move item
2070          D(bug("  moving %s -> %s\n", old_path, full_path));
2071 <        if (rename(old_path, full_path) < 0)
2071 >        if (!extfs_rename(old_path, full_path))
2072                  return errno2oserr();
2073          else {
2074                  // The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
2075                  FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
2076                  if (new_item) {
2077 +                        swap_parent_ids(fs_item->id, new_item->id);
2078                          uint32 t = fs_item->id;
2079                          fs_item->id = new_item->id;
2080                          new_item->id = t;
# Line 1977 | Line 2086 | static int16 fs_cat_move(uint32 pb)
2086   // Open working directory (WDParam)
2087   static int16 fs_open_wd(uint32 pb)
2088   {
2089 <        D(bug(" fs_open_wd(%08lx), vRefNum %d, name %#s, dirID %d\n", pb, ReadMacInt16(pb + ioVRefNum), Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), ReadMacInt32(pb + ioWDDirID)));
2089 >        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)));
2090          M68kRegisters r;
2091  
2092          // Allocate WDCB
2093          D(bug("  allocating WDCB\n"));
2094          r.a[0] = pb;
2095          Execute68k(fs_data + fsAllocateWDCB, &r);
2096 <        D(bug("  UTAllocateWDCB returned %d\n", r.d[0]));
2097 <        return r.d[0];
2096 >        D(bug("  UTAllocateWDCB returned %d, refNum is %d\n", r.d[0], ReadMacInt16(pb + ioVRefNum)));
2097 >        return (int16)r.d[0];
2098   }
2099  
2100   // Close working directory (WDParam)
# Line 1999 | Line 2108 | static int16 fs_close_wd(uint32 pb)
2108          r.d[0] = ReadMacInt16(pb + ioVRefNum);
2109          Execute68k(fs_data + fsReleaseWDCB, &r);
2110          D(bug("  UTReleaseWDCB returned %d\n", r.d[0]));
2111 <        return r.d[0];
2111 >        return (int16)r.d[0];
2112   }
2113  
2114   // Query information about working directory (WDParam)
# Line 2013 | Line 2122 | static int16 fs_get_wd_info(uint32 pb, u
2122                  WriteMacInt32(pb + ioWDProcID, 0);
2123                  WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(vcb + vcbVRefNum));
2124                  if (ReadMacInt32(pb + ioNamePtr))
2125 <                        memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(vcb + vcbVN), 28);
2125 >                        Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), vcb + vcbVN, 28);
2126                  WriteMacInt32(pb + ioWDDirID, ROOT_ID);
2127                  return noErr;
2128          }
# Line 2028 | Line 2137 | static int16 fs_get_wd_info(uint32 pb, u
2137          uint32 wdcb = ReadMacInt32(fs_data + fsReturn);
2138          D(bug("  UTResolveWDCB() returned %d, dirID %d\n", r.d[0], ReadMacInt32(wdcb + wdDirID)));
2139          if (r.d[0] & 0xffff)
2140 <                return r.d[0];
2140 >                return (int16)r.d[0];
2141  
2142          // Return information
2143 <        WriteMacInt16(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2143 >        WriteMacInt32(pb + ioWDProcID, ReadMacInt32(wdcb + wdProcID));
2144          WriteMacInt16(pb + ioWDVRefNum, ReadMacInt16(ReadMacInt32(wdcb + wdVCBPtr) + vcbVRefNum));
2145          if (ReadMacInt32(pb + ioNamePtr))
2146 <                memcpy(Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), Mac2HostAddr(ReadMacInt32(wdcb + wdVCBPtr) + vcbVN), 28);
2146 >                Mac2Mac_memcpy(ReadMacInt32(pb + ioNamePtr), ReadMacInt32(wdcb + wdVCBPtr) + vcbVN, 28);
2147          WriteMacInt32(pb + ioWDDirID, ReadMacInt32(wdcb + wdDirID));
2148          return noErr;
2149   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines