~ubuntu-branches/ubuntu/vivid/basilisk2/vivid

« back to all changes in this revision

Viewing changes to src/MacOSX/extfs_macosx.mm

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-03-06 19:33:01 UTC
  • mfrom: (2.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080306193301-cc2ofn705nfsq3y0
Tags: 0.9.20070407-4
* Update copyright-check cdbs snippet to parse licensecheck using perl:
  + No longer randomly drops newlines
  + More compact hint file (and ordered more like wiki-proposed new copyright
    syntax).
  + No longer ignore files without copyright.
* Update copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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 $
3
3
 *
4
4
 *      extfs_macosx.mm - Access Mac OS X Finder and resource information (using Carbon calls).
5
5
 *                    Based on:
6
6
 *
7
7
 *  extfs_unix.cpp - MacOS file system for access native file system access, Unix specific stuff
8
8
 *
9
 
 *  Basilisk II (C) 1997-2002 Christian Bauer
 
9
 *  Basilisk II (C) 1997-2005 Christian Bauer
10
10
 *
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
104
104
 *
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
107
107
 */
108
108
 
109
109
static int open_rsrc(const char *path, int flag)
114
114
        return open(path_rsrc, flag);
115
115
}
116
116
 
 
117
 
117
118
/*
118
119
 * Finder info is a little bit harder. We need to use Carbon library calls to access them
119
120
 */
220
221
{
221
222
    FSRef       fsRef;
222
223
    int32       status;
223
 
 
224
224
        // Set default finder info
225
225
        Mac_memset(finfo, 0, SIZEOF_FInfo);
226
226
        if (fxinfo)
232
232
        if ( status == noErr )
233
233
        {
234
234
                FSCatalogInfo   cInfo;
235
 
                uint32                  AllFinderInfo = kFSCatInfoFinderInfo + kFSCatInfoFinderXInfo;
 
235
                uint32                  AllFinderInfo = kFSCatInfoFinderInfo;
 
236
 
 
237
                if (fxinfo)
 
238
                        AllFinderInfo |= kFSCatInfoFinderXInfo;
236
239
 
237
240
                status = FSGetCatalogInfo(&fsRef, AllFinderInfo, &cInfo, NULL, NULL, NULL);
238
241
                if ( status == noErr )
239
242
                {
 
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);
242
249
                        if (fxinfo)
243
 
                                Host2Mac_memcpy(fxinfo, cInfo.extFinderInfo, SIZEOF_FXInfo);
 
250
                                Host2Mac_memcpy(fxinfo, &cInfo.extFinderInfo, SIZEOF_FXInfo);
244
251
                        return;
245
252
                }
246
253
                else
286
293
                status = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &cInfo, NULL, NULL, NULL);
287
294
                if ( status == noErr )
288
295
                {
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;
 
297
                        if (finfo) {
 
298
                                whichInfo |= kFSCatInfoFinderInfo;
 
299
                                /*
 
300
                                  FIXME: Some users reported that directories could
 
301
                                  mysteriously disappear from a MacOS X 10.4 Finder
 
302
                                  point of view.
 
303
 
 
304
                                  An alternative is to use the ".finfo/" technique
 
305
                                  on MacOS X provided that attributes are first
 
306
                                  initialised from an FSGetCatalogInfo() call.
 
307
                                */
 
308
                                uint8 oldFlags1, oldFlags2;
 
309
                                if (is_dir) {
 
310
                                        oldFlags1 = cInfo.finderInfo[fdFlags];
 
311
                                        oldFlags2 = cInfo.finderInfo[fdFlags + 1];
 
312
                                }
 
313
                                Mac2Host_memcpy(&cInfo.finderInfo,    finfo,  SIZEOF_FInfo);
 
314
                                if (is_dir) {
 
315
                                        cInfo.finderInfo[fdFlags] = oldFlags1;
 
316
                                        cInfo.finderInfo[fdFlags + 1] = oldFlags2;
 
317
                                }
 
318
                        }
 
319
                        if (fxinfo) {
 
320
                                whichInfo |= kFSCatInfoFinderXInfo;
 
321
                                Mac2Host_memcpy(&cInfo.extFinderInfo, fxinfo, SIZEOF_FXInfo);
 
322
                        }
 
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);
292
328
                }
293
329
    }
294
330
}
385
421
        // Now rename file
386
422
        return rename(old_path, new_path) == 0;
387
423
}
 
424
 
 
425
 
 
426
// Convert from the host OS filename encoding to MacRoman
 
427
const char *host_encoding_to_macroman(const char *filename)
 
428
{
 
429
        static char filename_mr[64];
 
430
        CFStringRef sref = CFStringCreateWithCString(0, filename, kCFStringEncodingUTF8);
 
431
        if (sref) {
 
432
                memset(filename_mr, 0, sizeof(filename_mr));
 
433
                if (CFStringGetCString(sref, filename_mr, sizeof(filename_mr), kCFStringEncodingMacRoman)) {
 
434
                        return filename_mr;
 
435
                }
 
436
                CFRelease(sref);
 
437
        }
 
438
        return filename;
 
439
}
 
440
 
 
441
 
 
442
// Convert from MacRoman to the host OS filename encoding
 
443
const char *macroman_to_host_encoding(const char *filename)
 
444
{
 
445
        static char filename_mr[64];
 
446
        CFStringRef sref = CFStringCreateWithCString(0, filename, kCFStringEncodingMacRoman);
 
447
        if (sref) {
 
448
                memset(filename_mr, 0, sizeof(filename_mr));
 
449
                if (CFStringGetCString(sref, filename_mr, sizeof(filename_mr), kCFStringEncodingUTF8)) {
 
450
                        return filename_mr;
 
451
                }
 
452
                CFRelease(sref);
 
453
        }
 
454
        return filename;
 
455
}
 
456