1 |
|
/* |
2 |
|
* extfs.cpp - MacOS file system for native file system access |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2005 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 |
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" |
56 |
|
#include "emul_op.h" |
57 |
|
#include "main.h" |
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 |
|
}; |
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 |
|
|
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 |
257 |
|
} |
258 |
|
|
259 |
|
// Not found, construct new FSItem |
260 |
< |
p = new FSItem; |
198 |
< |
last_fs_item->next = p; |
199 |
< |
p->next = NULL; |
200 |
< |
last_fs_item = p; |
201 |
< |
p->id = next_cnid++; |
202 |
< |
p->parent_id = parent->id; |
203 |
< |
p->parent = parent; |
204 |
< |
strncpy(p->name, name, 31); |
205 |
< |
p->name[31] = 0; |
206 |
< |
p->mtime = 0; |
207 |
< |
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 |
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; |
428 |
|
p->id = ROOT_ID; |
429 |
|
p->parent_id = ROOT_PARENT_ID; |
430 |
|
p->parent = first_fs_item; |
431 |
< |
strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32); |
432 |
< |
p->name[31] = 0; |
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) { |
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 |
|
} |
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 |
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 |
|
} |
1051 |
|
WriteMacInt16(vcb + vcbSigWord, 0x4244); |
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 |
1116 |
|
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME); |
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 |
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 |
|
#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 |
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); |
1434 |
|
WriteMacInt32(pb + ioFlParID, fs_item->parent_id); |
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 |
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 |
|
|