2
* $Id: extfs_macosx.mm,v 1.2 2002/03/18 11:05:43 nigel Exp $
2
* $Id: extfs_macosx.mm,v 1.9 2007/01/24 02:37:06 asvitkine Exp $
4
4
* extfs_macosx.mm - Access Mac OS X Finder and resource information (using Carbon calls).
7
7
* extfs_unix.cpp - MacOS file system for access native file system access, Unix specific stuff
9
* Basilisk II (C) 1997-2002 Christian Bauer
9
* Basilisk II (C) 1997-2005 Christian Bauer
11
11
* This program is free software; you can redistribute it and/or modify
12
12
* it under the terms of the GNU General Public License as published by
103
103
* Resource forks on Mac OS X are kept on a UFS volume as /path/file/rsrc
105
105
* On HFS volumes, there is of course the data and rsrc fork, but the Darwin
106
* filesystem layer presents the resource fork using the above psuedo path
106
* filesystem layer presents the resource fork using the above pseudo path
109
109
static int open_rsrc(const char *path, int flag)
232
232
if ( status == noErr )
234
234
FSCatalogInfo cInfo;
235
uint32 AllFinderInfo = kFSCatInfoFinderInfo + kFSCatInfoFinderXInfo;
235
uint32 AllFinderInfo = kFSCatInfoFinderInfo;
238
AllFinderInfo |= kFSCatInfoFinderXInfo;
237
240
status = FSGetCatalogInfo(&fsRef, AllFinderInfo, &cInfo, NULL, NULL, NULL);
238
241
if ( status == noErr )
243
// byte-swap them to big endian (network order) if necessary
244
((FileInfo *)&cInfo.finderInfo)->fileType = htonl(((FileInfo *)&cInfo.finderInfo)->fileType);
245
((FileInfo *)&cInfo.finderInfo)->fileCreator = htonl(((FileInfo *)&cInfo.finderInfo)->fileCreator);
246
((FileInfo *)&cInfo.finderInfo)->finderFlags = htons(((FileInfo *)&cInfo.finderInfo)->finderFlags);
240
247
D(printf("get_finfo(%s,...) - Got info of '%16.16s'\n", path, cInfo.finderInfo));
241
Host2Mac_memcpy(finfo, cInfo.finderInfo, SIZEOF_FInfo);
248
Host2Mac_memcpy(finfo, &cInfo.finderInfo, SIZEOF_FInfo);
243
Host2Mac_memcpy(fxinfo, cInfo.extFinderInfo, SIZEOF_FXInfo);
250
Host2Mac_memcpy(fxinfo, &cInfo.extFinderInfo, SIZEOF_FXInfo);
286
293
status = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &cInfo, NULL, NULL, NULL);
287
294
if ( status == noErr )
289
Mac2Host_memcpy(cInfo.finderInfo, finfo, SIZEOF_FInfo);
290
Mac2Host_memcpy(cInfo.extFinderInfo, fxinfo, SIZEOF_FXInfo);
291
FSSetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &cInfo);
296
FSCatalogInfoBitmap whichInfo = kFSCatInfoNone;
298
whichInfo |= kFSCatInfoFinderInfo;
300
FIXME: Some users reported that directories could
301
mysteriously disappear from a MacOS X 10.4 Finder
304
An alternative is to use the ".finfo/" technique
305
on MacOS X provided that attributes are first
306
initialised from an FSGetCatalogInfo() call.
308
uint8 oldFlags1, oldFlags2;
310
oldFlags1 = cInfo.finderInfo[fdFlags];
311
oldFlags2 = cInfo.finderInfo[fdFlags + 1];
313
Mac2Host_memcpy(&cInfo.finderInfo, finfo, SIZEOF_FInfo);
315
cInfo.finderInfo[fdFlags] = oldFlags1;
316
cInfo.finderInfo[fdFlags + 1] = oldFlags2;
320
whichInfo |= kFSCatInfoFinderXInfo;
321
Mac2Host_memcpy(&cInfo.extFinderInfo, fxinfo, SIZEOF_FXInfo);
323
// byte-swap them to system byte order from big endian (network order) if necessary
324
((FileInfo *)&cInfo.finderInfo)->fileType = ntohl(((FileInfo *)&cInfo.finderInfo)->fileType);
325
((FileInfo *)&cInfo.finderInfo)->fileCreator = ntohl(((FileInfo *)&cInfo.finderInfo)->fileCreator);
326
((FileInfo *)&cInfo.finderInfo)->finderFlags = ntohs(((FileInfo *)&cInfo.finderInfo)->finderFlags);
327
FSSetCatalogInfo(&fsRef, whichInfo, &cInfo);
385
421
// Now rename file
386
422
return rename(old_path, new_path) == 0;
426
// Convert from the host OS filename encoding to MacRoman
427
const char *host_encoding_to_macroman(const char *filename)
429
static char filename_mr[64];
430
CFStringRef sref = CFStringCreateWithCString(0, filename, kCFStringEncodingUTF8);
432
memset(filename_mr, 0, sizeof(filename_mr));
433
if (CFStringGetCString(sref, filename_mr, sizeof(filename_mr), kCFStringEncodingMacRoman)) {
442
// Convert from MacRoman to the host OS filename encoding
443
const char *macroman_to_host_encoding(const char *filename)
445
static char filename_mr[64];
446
CFStringRef sref = CFStringCreateWithCString(0, filename, kCFStringEncodingMacRoman);
448
memset(filename_mr, 0, sizeof(filename_mr));
449
if (CFStringGetCString(sref, filename_mr, sizeof(filename_mr), kCFStringEncodingUTF8)) {