1 |
|
/* |
2 |
|
* extfs.cpp - MacOS file system for native file system access |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 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 |
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" |
52 |
– |
#include "macos_util.h" |
56 |
|
#include "emul_op.h" |
57 |
|
#include "main.h" |
58 |
|
#include "disk.h" |
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; |
169 |
|
|
170 |
|
|
171 |
|
/* |
172 |
+ |
* Get object creation time |
173 |
+ |
*/ |
174 |
+ |
|
175 |
+ |
#if defined __APPLE__ && defined __MACH__ |
176 |
+ |
struct crtimebuf { |
177 |
+ |
unsigned long length; |
178 |
+ |
struct timespec crtime; |
179 |
+ |
}; |
180 |
+ |
|
181 |
+ |
static uint32 do_get_creation_time(const char *path) |
182 |
+ |
{ |
183 |
+ |
struct attrlist attr; |
184 |
+ |
memset(&attr, 0, sizeof(attr)); |
185 |
+ |
attr.bitmapcount = ATTR_BIT_MAP_COUNT; |
186 |
+ |
attr.commonattr = ATTR_CMN_CRTIME; |
187 |
+ |
|
188 |
+ |
crtimebuf buf; |
189 |
+ |
if (getattrlist(path, &attr, &buf, sizeof(buf), FSOPT_NOFOLLOW) < 0) |
190 |
+ |
return 0; |
191 |
+ |
return TimeToMacTime(buf.crtime.tv_sec); |
192 |
+ |
} |
193 |
+ |
|
194 |
+ |
static uint32 get_creation_time(const char *path) |
195 |
+ |
{ |
196 |
+ |
if (path == NULL) |
197 |
+ |
return 0; |
198 |
+ |
if (path == RootPath) { |
199 |
+ |
static uint32 root_crtime = UINT_MAX; |
200 |
+ |
if (root_crtime == UINT_MAX) |
201 |
+ |
root_crtime = do_get_creation_time(path); |
202 |
+ |
return root_crtime; |
203 |
+ |
} |
204 |
+ |
return do_get_creation_time(path); |
205 |
+ |
} |
206 |
+ |
#endif |
207 |
+ |
|
208 |
+ |
|
209 |
+ |
/* |
210 |
|
* Find FSItem for given CNID |
211 |
|
*/ |
212 |
|
|
318 |
|
} |
319 |
|
} |
320 |
|
|
280 |
– |
// Convert pascal string to C string |
281 |
– |
static void pstr2cstr(char *dst, const char *src) |
282 |
– |
{ |
283 |
– |
int size = *src++; |
284 |
– |
while (size--) { |
285 |
– |
char c = *src++; |
286 |
– |
// Note: we are converting Mac '/' characters to host ':' characters here |
287 |
– |
// '/' is not a path separator as this function is only used on object names |
288 |
– |
if (c == '/') |
289 |
– |
c = ':'; |
290 |
– |
*dst++ = c; |
291 |
– |
} |
292 |
– |
*dst = 0; |
293 |
– |
} |
294 |
– |
|
321 |
|
// Convert string (no length byte) to C string, length given separately |
322 |
|
static void strn2cstr(char *dst, const char *src, int size) |
323 |
|
{ |
449 |
|
// FSM present? |
450 |
|
r.d[0] = gestaltFSAttr; |
451 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
452 |
< |
D(bug("FSAttr %ld, %08lx\n", r.d[0], r.a[0])); |
452 |
> |
D(bug("FSAttr %d, %08x\n", r.d[0], r.a[0])); |
453 |
|
if ((r.d[0] & 0xffff) || !(r.a[0] & (1 << gestaltHasFileSystemManager))) { |
454 |
|
printf("WARNING: No FSM present, disabling ExtFS\n"); |
455 |
|
return; |
458 |
|
// Yes, version >=1.2? |
459 |
|
r.d[0] = gestaltFSMVersion; |
460 |
|
Execute68kTrap(0xa1ad, &r); // Gestalt() |
461 |
< |
D(bug("FSMVersion %ld, %08lx\n", r.d[0], r.a[0])); |
461 |
> |
D(bug("FSMVersion %d, %08x\n", r.d[0], r.a[0])); |
462 |
|
if ((r.d[0] & 0xffff) || (r.a[0] < 0x0120)) { |
463 |
|
printf("WARNING: FSM <1.2 found, disabling ExtFS\n"); |
464 |
|
return; |
728 |
|
} |
729 |
|
|
730 |
|
case ffsIDDiskMessage: { // Check if volume is handled by our FS |
731 |
< |
if (ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
731 |
> |
if ((int16)ReadMacInt16(paramBlock + ioVRefNum) == drive_number) |
732 |
|
return noErr; |
733 |
|
else |
734 |
|
return extFSErr; |
772 |
|
if (no_vol_name) |
773 |
|
WriteMacInt32(pb + ioNamePtr, name_ptr); |
774 |
|
int16 status = ReadMacInt16(fs_data + fsReturn); |
749 |
– |
int16 more_matches = ReadMacInt16(fs_data + fsReturn + 2); |
750 |
– |
int16 vRefNum = ReadMacInt16(fs_data + fsReturn + 4); |
751 |
– |
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 6); |
775 |
|
D(bug(" UTDetermineVol() returned %d, status %d\n", r.d[0], status)); |
776 |
|
result = (int16)(r.d[0] & 0xffff); |
777 |
|
|
989 |
|
static int16 fs_mount_vol(uint32 pb) |
990 |
|
{ |
991 |
|
D(bug(" fs_mount_vol(%08lx), vRefNum %d\n", pb, ReadMacInt16(pb + ioVRefNum))); |
992 |
< |
if (ReadMacInt16(pb + ioVRefNum) == drive_number) |
992 |
> |
if ((int16)ReadMacInt16(pb + ioVRefNum) == drive_number) |
993 |
|
return noErr; |
994 |
|
else |
995 |
|
return extFSErr; |
1006 |
|
r.a[0] = fs_data + fsReturn; |
1007 |
|
r.a[1] = fs_data + fsReturn + 2; |
1008 |
|
Execute68k(fs_data + fsAllocateVCB, &r); |
1009 |
+ |
#if DEBUG |
1010 |
|
uint16 sysVCBLength = ReadMacInt16(fs_data + fsReturn); |
1011 |
+ |
#endif |
1012 |
|
uint32 vcb = ReadMacInt32(fs_data + fsReturn + 2); |
1013 |
|
D(bug(" UTAllocateVCB() returned %d, vcb %08lx, size %d\n", r.d[0], vcb, sysVCBLength)); |
1014 |
|
if (r.d[0] & 0xffff) |
1017 |
|
// Init VCB |
1018 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
1019 |
|
#if defined(__BEOS__) || defined(WIN32) |
1020 |
< |
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET); |
1020 |
> |
WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime)); |
1021 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1022 |
> |
WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath)); |
1023 |
|
#else |
1024 |
|
WriteMacInt32(vcb + vcbCrDate, 0); |
1025 |
|
#endif |
1026 |
< |
WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET); |
1026 |
> |
WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime)); |
1027 |
|
WriteMacInt32(vcb + vcbVolBkUp, 0); |
1028 |
|
WriteMacInt16(vcb + vcbNmFls, 1); //!! |
1029 |
|
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!! |
1082 |
|
if (ReadMacInt32(pb + ioNamePtr)) |
1083 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
1084 |
|
#if defined(__BEOS__) || defined(WIN32) |
1085 |
< |
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET); |
1085 |
> |
WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime)); |
1086 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1087 |
> |
WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath)); |
1088 |
|
#else |
1089 |
|
WriteMacInt32(pb + ioVCrDate, 0); |
1090 |
|
#endif |
1091 |
< |
WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET); |
1091 |
> |
WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime)); |
1092 |
|
WriteMacInt16(pb + ioVAtrb, 0); |
1093 |
|
WriteMacInt16(pb + ioVNmFls, 1); //!! |
1094 |
|
WriteMacInt16(pb + ioVBitMap, 0); |
1276 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1277 |
|
|
1278 |
|
#if defined(__BEOS__) || defined(WIN32) |
1279 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1279 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1280 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1281 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1282 |
|
#else |
1283 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1284 |
|
#endif |
1285 |
< |
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET); |
1285 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime)); |
1286 |
|
|
1287 |
< |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0); |
1287 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1288 |
|
|
1289 |
|
WriteMacInt16(pb + ioFlStBlk, 0); |
1290 |
|
WriteMacInt32(pb + ioFlLgLen, st.st_size); |
1321 |
|
return fnfErr; |
1322 |
|
|
1323 |
|
// Set Finder info |
1324 |
< |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0); |
1324 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false); |
1325 |
|
|
1326 |
|
//!! times |
1327 |
|
return noErr; |
1400 |
|
WriteMacInt32(pb + ioDirID, fs_item->id); |
1401 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
1402 |
|
#if defined(__BEOS__) || defined(WIN32) |
1403 |
< |
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET); |
1403 |
> |
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime)); |
1404 |
> |
#elif defined __APPLE__ && defined __MACH__ |
1405 |
> |
WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path)); |
1406 |
|
#else |
1407 |
|
WriteMacInt32(pb + ioFlCrDat, 0); |
1408 |
|
#endif |
1412 |
|
fs_item->mtime = mtime; |
1413 |
|
cached = false; |
1414 |
|
} |
1415 |
< |
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET); |
1415 |
> |
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime)); |
1416 |
|
WriteMacInt32(pb + ioFlBkDat, 0); |
1417 |
|
|
1418 |
< |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo); |
1418 |
> |
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1419 |
|
|
1420 |
|
if (S_ISDIR(st.st_mode)) { |
1421 |
|
|
1471 |
|
return errno2oserr(); |
1472 |
|
|
1473 |
|
// Set Finder info |
1474 |
< |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo); |
1474 |
> |
set_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode)); |
1475 |
|
|
1476 |
|
//!! times |
1477 |
|
return noErr; |
1559 |
|
WriteMacInt32(fcb + fcbVPtr, vcb); |
1560 |
|
WriteMacInt32(fcb + fcbClmpSize, CLUMP_SIZE); |
1561 |
|
|
1562 |
< |
get_finfo(full_path, fs_data + fsPB, 0); |
1562 |
> |
get_finfo(full_path, fs_data + fsPB, 0, false); |
1563 |
|
WriteMacInt32(fcb + fcbFType, ReadMacInt32(fs_data + fsPB + fdType)); |
1564 |
|
|
1565 |
|
WriteMacInt32(fcb + fcbCatPos, fd); |
1617 |
|
|
1618 |
|
// Find FCB by index |
1619 |
|
WriteMacInt16(pb + ioRefNum, 0); |
1620 |
< |
for (int i=0; i<ReadMacInt16(pb + ioFCBIndx); i++) { |
1620 |
> |
for (int i=0; i<(int)ReadMacInt16(pb + ioFCBIndx); i++) { |
1621 |
|
D(bug(" indexing FCBs\n")); |
1622 |
|
r.a[0] = vcb; |
1623 |
|
r.a[1] = pb + ioRefNum; |
1836 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1837 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1838 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1839 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1839 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1840 |
|
return actual < 0 ? read_err : eofErr; |
1841 |
|
else |
1842 |
|
return noErr; |
1889 |
|
uint32 pos = lseek(fd, 0, SEEK_CUR); |
1890 |
|
WriteMacInt32(fcb + fcbCrPs, pos); |
1891 |
|
WriteMacInt32(pb + ioPosOffset, pos); |
1892 |
< |
if (actual != ReadMacInt32(pb + ioReqCount)) |
1892 |
> |
if (actual != (ssize_t)ReadMacInt32(pb + ioReqCount)) |
1893 |
|
return write_err; |
1894 |
|
else |
1895 |
|
return noErr; |