~ubuntu-branches/ubuntu/wily/basilisk2/wily-proposed

« back to all changes in this revision

Viewing changes to src/extfs.cpp

  • 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
2
 *  extfs.cpp - MacOS file system for native file system access
3
3
 *
4
 
 *  Basilisk II (C) 1997-2002 Christian Bauer
 
4
 *  Basilisk II (C) 1997-2005 Christian Bauer
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
48
48
#include <dirent.h>
49
49
#endif
50
50
 
 
51
#if defined __APPLE__ && defined __MACH__
 
52
#include <sys/attr.h>
 
53
#endif
 
54
 
51
55
#include "cpu_emulation.h"
52
56
#include "emul_op.h"
53
57
#include "main.h"
154
158
        uint32 id;                              // CNID of this file/dir
155
159
        uint32 parent_id;               // CNID of parent file/dir
156
160
        FSItem *parent;                 // Pointer to parent
157
 
        char name[32];                  // Object name (C string)
 
161
        char name[32];                  // Object name (C string) - Host OS
 
162
        char guest_name[32];                    // Object name (C string) - Guest OS
158
163
        time_t mtime;                   // Modification time for get_cat_info caching
159
164
        int cache_dircount;             // Cached number of files in directory
160
165
};
165
170
 
166
171
 
167
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
/*
168
211
 *  Find FSItem for given CNID
169
212
 */
170
213
 
179
222
        return NULL;
180
223
}
181
224
 
182
 
 
183
225
/*
184
 
 *  Find FSItem for given name and parent, construct new FSItem if not found
 
226
 *  Create FSItem with the given parameters
185
227
 */
186
228
 
187
 
static FSItem *find_fsitem(const char *name, FSItem *parent)
 
229
static FSItem *create_fsitem(const char *name, const char *guest_name, FSItem *parent)
188
230
{
189
 
        FSItem *p = first_fs_item;
190
 
        while (p) {
191
 
                if (p->parent == parent && !strcmp(p->name, name))
192
 
                        return p;
193
 
                p = p->next;
194
 
        }
195
 
 
196
 
        // Not found, construct new FSItem
197
 
        p = new FSItem;
 
231
        FSItem *p = new FSItem;
198
232
        last_fs_item->next = p;
199
233
        p->next = NULL;
200
234
        last_fs_item = p;
203
237
        p->parent = parent;
204
238
        strncpy(p->name, name, 31);
205
239
        p->name[31] = 0;
 
240
        strncpy(p->guest_name, guest_name, 31);
 
241
        p->guest_name[31] = 0;
206
242
        p->mtime = 0;
207
243
        return p;
208
244
}
209
245
 
 
246
/*
 
247
 *  Find FSItem for given name and parent, construct new FSItem if not found
 
248
 */
 
249
 
 
250
static FSItem *find_fsitem(const char *name, FSItem *parent)
 
251
{
 
252
        FSItem *p = first_fs_item;
 
253
        while (p) {
 
254
                if (p->parent == parent && !strcmp(p->name, name))
 
255
                        return p;
 
256
                p = p->next;
 
257
        }
 
258
 
 
259
        // Not found, construct new FSItem
 
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
}
210
279
 
211
280
/*
212
281
 *  Get full path (->full_path) for given FSItem
348
417
        p->parent_id = 0;
349
418
        p->parent = NULL;
350
419
        p->name[0] = 0;
 
420
        p->guest_name[0] = 0;
351
421
 
352
422
        // Create root FSItem
353
423
        p = new FSItem;
359
429
        p->parent = first_fs_item;
360
430
        strncpy(p->name, GetString(STR_EXTFS_VOLUME_NAME), 32);
361
431
        p->name[31] = 0;
 
432
        strncpy(p->guest_name, host_encoding_to_macroman(p->name), 32);
 
433
        p->guest_name[31] = 0;
362
434
 
363
435
        // Find path for root
364
436
        if ((RootPath = PrefsFindString("extfs")) != NULL) {
869
941
                                                char name[32];
870
942
                                                strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
871
943
                                                D(bug("  entering %s\n", name));
872
 
                                                p = find_fsitem(name, p);
 
944
                                                p = find_fsitem_guest(name, p);
873
945
                                                current_dir = p->id;
874
946
 
875
947
                                                // startOffset = start of next component
892
964
                                        char name[32];
893
965
                                        strn2cstr(name, (char *)Mac2HostAddr(ReadMacInt32(parseRec + ppNamePtr)) + ReadMacInt16(parseRec + ppStartOffset) + 1, ReadMacInt16(parseRec + ppComponentLength));
894
966
                                        D(bug("  object is %s\n", name));
895
 
                                        item = find_fsitem(name, p);
 
967
                                        item = find_fsitem_guest(name, p);
896
968
                                }
897
969
                        }
898
970
                }
976
1048
        WriteMacInt16(vcb + vcbSigWord, 0x4244);
977
1049
#if defined(__BEOS__) || defined(WIN32)
978
1050
        WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
 
1051
#elif defined __APPLE__ && defined __MACH__
 
1052
        WriteMacInt32(vcb + vcbCrDate, get_creation_time(RootPath));
979
1053
#else
980
1054
        WriteMacInt32(vcb + vcbCrDate, 0);
981
1055
#endif
1039
1113
                pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
1040
1114
#if defined(__BEOS__) || defined(WIN32)
1041
1115
        WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
 
1116
#elif defined __APPLE__ && defined __MACH__
 
1117
        WriteMacInt32(pb + ioVCrDate, get_creation_time(RootPath));
1042
1118
#else
1043
1119
        WriteMacInt32(pb + ioVCrDate, 0);
1044
1120
#endif
1224
1300
 
1225
1301
        // Fill in struct from fs_item and stats
1226
1302
        if (ReadMacInt32(pb + ioNamePtr))
1227
 
                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
 
1303
                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1228
1304
        WriteMacInt16(pb + ioFRefNum, 0);
1229
1305
        WriteMacInt8(pb + ioFlAttrib, access(full_path, W_OK) == 0 ? 0 : faLocked);
1230
1306
        WriteMacInt32(pb + ioDirID, fs_item->id);
1231
1307
 
1232
1308
#if defined(__BEOS__) || defined(WIN32)
1233
1309
        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
 
1310
#elif defined __APPLE__ && defined __MACH__
 
1311
        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1234
1312
#else
1235
1313
        WriteMacInt32(pb + ioFlCrDat, 0);
1236
1314
#endif
1345
1423
 
1346
1424
        // Fill in struct from fs_item and stats
1347
1425
        if (ReadMacInt32(pb + ioNamePtr))
1348
 
                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->name);
 
1426
                cstr2pstr((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), fs_item->guest_name);
1349
1427
        WriteMacInt16(pb + ioFRefNum, 0);
1350
1428
        WriteMacInt8(pb + ioFlAttrib, (S_ISDIR(st.st_mode) ? faIsDir : 0) | (access(full_path, W_OK) == 0 ? 0 : faLocked));
1351
1429
        WriteMacInt8(pb + ioACUser, 0);
1353
1431
        WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
1354
1432
#if defined(__BEOS__) || defined(WIN32)
1355
1433
        WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
 
1434
#elif defined __APPLE__ && defined __MACH__
 
1435
        WriteMacInt32(pb + ioFlCrDat, get_creation_time(full_path));
1356
1436
#else
1357
1437
        WriteMacInt32(pb + ioFlCrDat, 0);
1358
1438
#endif
1514
1594
 
1515
1595
        WriteMacInt32(fcb + fcbCatPos, fd);
1516
1596
        WriteMacInt32(fcb + fcbDirID, fs_item->parent_id);
1517
 
        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->name);
 
1597
        cstr2pstr((char *)Mac2HostAddr(fcb + fcbCName), fs_item->guest_name);
1518
1598
        return noErr;
1519
1599
}
1520
1600