Chameleon

Chameleon Commit Details

Date:2012-08-05 00:38:41 (8 years 3 months ago)
Author:ErmaC
Commit:2037
Parents: 2036
Message:This revision is devoted to Samantha, AKA DHP or Revogirl in the OSx86 scene. A young talent we lost prematurely. Part of her work will now live on in the Chameleon source code. Changes: code cleaned, improvements taken from Revoboot. http://www.insanelymac.com/forum/index.php?showtopic=259090
Changes:
M/branches/ErmaC/Trunk/i386/libsaio/platform.h
M/branches/ErmaC/Trunk/i386/libsaio/disk.c
M/branches/ErmaC/Trunk/i386/libsaio/device_inject.c
M/branches/ErmaC/Trunk/i386/boot2/lzss.c
M/branches/ErmaC/Trunk/i386/boot2/options.c
M/branches/ErmaC/Trunk/i386/libsaio/device_inject.h
M/branches/ErmaC/Trunk/i386/libsaio/xml.c
M/branches/ErmaC/Trunk/i386/libsaio/bios.h
M/branches/ErmaC/Trunk/i386/libsaio/console.c
M/branches/ErmaC/Trunk/i386/libsaio/fdisk.h
M/branches/ErmaC/Trunk/i386/libsaio/xml.h
M/branches/ErmaC/Trunk/i386/libsaio/efi.h
M/branches/ErmaC/Trunk/i386/libsaio/vbe.c
M/branches/ErmaC/Trunk/CHANGES
M/branches/ErmaC/Trunk/i386/libsaio/sys.c
M/branches/ErmaC/Trunk/i386/libsaio/device_tree.c
M/branches/ErmaC/Trunk/i386/libsaio/hfs.c
M/branches/ErmaC/Trunk/i386/libsaio/biosfn.c
M/branches/ErmaC/Trunk/i386/boot2/drivers.c
M/branches/ErmaC/Trunk/i386/libsaio/device_tree.h
M/branches/ErmaC/Trunk/i386/libsaio/saio_types.h
M/branches/ErmaC/Trunk/i386/libsaio/memvendors.h
M/branches/ErmaC/Trunk/i386/boot2/prompt.c
M/branches/ErmaC/Trunk/i386/libsaio/hfs.h
M/branches/ErmaC/Trunk/i386/libsa/memory.h
M/branches/ErmaC/Trunk/i386/libsaio/spd.c
M/branches/ErmaC/Trunk/i386/libsaio/hfs_compare.c
M/branches/ErmaC/Trunk/i386/libsaio/cpu.c
M/branches/ErmaC/Trunk/i386/libsaio/md5c.c
M/branches/ErmaC/Trunk/i386/libsaio/fake_efi.c
M/branches/ErmaC/Trunk/i386/libsaio/spd.h
M/branches/ErmaC/Trunk/i386/libsa/zalloc.c
M/branches/ErmaC/Trunk/i386/libsaio/fake_efi.h
M/branches/ErmaC/Trunk/i386/libsa/prf.c
M/branches/ErmaC/Trunk/i386/libsaio/cache.c
M/branches/ErmaC/Trunk/i386/libsaio/gma.c
M/branches/ErmaC/Trunk/i386/libsa/efi_tables.c
M/branches/ErmaC/Trunk/i386/boot2/boot.c
M/branches/ErmaC/Trunk/i386/libsa/libsa.h
M/branches/ErmaC/Trunk/i386/boot2/boot2.s
M/branches/ErmaC/Trunk/i386/libsa/printf.c
M/branches/ErmaC/Trunk/i386/boot2/boot.h
M/branches/ErmaC/Trunk/i386/libsaio/pci.c
M/branches/ErmaC/Trunk/i386/libsaio/bootstruct.h
M/branches/ErmaC/Trunk/i386/libsa/string.c
M/branches/ErmaC/Trunk/i386/libsaio/stringTable.c
M/branches/ErmaC/Trunk/i386/libsaio/load.c
M/branches/ErmaC/Trunk/i386/libsaio/sl.h
M/branches/ErmaC/Trunk/i386/libsaio/allocate.c
M/branches/ErmaC/Trunk/Chameleon.xcodeproj/project.pbxproj

File differences

branches/ErmaC/Trunk/Chameleon.xcodeproj/project.pbxproj
12881288
12891289
12901290
1291
1292
1293
1294
1295
1296
1297
12981291
12991292
13001293
......
13771370
13781371
13791372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
13801434
13811435
13821436
......
32163270
32173271
32183272
3219
3220
3221
32223273
32233274
32243275
32253276
32263277
32273278
3279
3280
3281
32283282
32293283
32303284
......
34333487
34343488
34353489
3436
3437
3438
3490
3491
34393492
34403493
34413494
......
35523605
35533606
35543607
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
35833608
35843609
35853610
......
36993724
37003725
37013726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
37023802
37033803
37043804
B0056DD911F3868000754B65 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = text_scroll_next.png; sourceTree = "<group>"; };
B0056DDA11F3868000754B65 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = text_scroll_prev.png; sourceTree = "<group>"; };
B0056DDB11F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = "<group>"; };
B0056DFD11F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
B0056DFE11F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = "<group>"; };
B0056E0011F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
B0056E0111F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = "<group>"; };
B0056E0311F3868000754B65 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = font_small.png; sourceTree = "<group>"; };
B0056E0411F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
B0056E0511F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = "<group>"; };
B0056E0811F3868000754B65 /* Users_Guide0.4.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Users_Guide0.4.pdf; sourceTree = "<group>"; };
B0056E0911F3868000754B65 /* Users_Guide_v0.3.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Users_Guide_v0.3.pdf; sourceTree = "<group>"; };
B0056E0A11F3868000754B65 /* UsersGuide-v0.2.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "UsersGuide-v0.2.pdf"; sourceTree = "<group>"; };
B43E407714EE869800CD79F9 /* device_hfsplus_ml.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsplus_ml.png; sourceTree = "<group>"; };
B43E407814EE869A00CD79F9 /* device_hfsraid_ml_o.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsraid_ml_o.png; sourceTree = "<group>"; };
B43E407914EE869C00CD79F9 /* device_hfsraid_ml.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsraid_ml.png; sourceTree = "<group>"; };
B442D9F515C216C900985ED1 /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = embed/background.png; sourceTree = "<group>"; };
B442D9F615C216C900985ED1 /* boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boot.png; path = embed/boot.png; sourceTree = "<group>"; };
B442D9F715C216C900985ED1 /* device_cdrom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_cdrom.png; path = embed/device_cdrom.png; sourceTree = "<group>"; };
B442D9F815C216C900985ED1 /* device_ext3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ext3.png; path = embed/device_ext3.png; sourceTree = "<group>"; };
B442D9F915C216C900985ED1 /* device_fat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_fat.png; path = embed/device_fat.png; sourceTree = "<group>"; };
B442D9FA15C216C900985ED1 /* device_generic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_generic.png; path = embed/device_generic.png; sourceTree = "<group>"; };
B442D9FB15C216C900985ED1 /* device_hfsplus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsplus.png; path = embed/device_hfsplus.png; sourceTree = "<group>"; };
B442D9FC15C216C900985ED1 /* device_hfsraid.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsraid.png; path = embed/device_hfsraid.png; sourceTree = "<group>"; };
B442D9FD15C216C900985ED1 /* device_ntfs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ntfs.png; path = embed/device_ntfs.png; sourceTree = "<group>"; };
B442D9FE15C216C900985ED1 /* device_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_next.png; path = embed/device_scroll_next.png; sourceTree = "<group>"; };
B442D9FF15C216C900985ED1 /* device_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_prev.png; path = embed/device_scroll_prev.png; sourceTree = "<group>"; };
B442DA0015C216C900985ED1 /* device_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_selection.png; path = embed/device_selection.png; sourceTree = "<group>"; };
B442DA0115C216C900985ED1 /* font_console.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_console.png; path = embed/font_console.png; sourceTree = "<group>"; };
B442DA0215C216C900985ED1 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_small.png; path = embed/font_small.png; sourceTree = "<group>"; };
B442DA0315C216C900985ED1 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = embed/logo.png; sourceTree = "<group>"; };
B442DA0415C216C900985ED1 /* menu_boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_boot.png; path = embed/menu_boot.png; sourceTree = "<group>"; };
B442DA0515C216C900985ED1 /* menu_help.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_help.png; path = embed/menu_help.png; sourceTree = "<group>"; };
B442DA0615C216C900985ED1 /* menu_ignore_caches_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches_disabled.png; path = embed/menu_ignore_caches_disabled.png; sourceTree = "<group>"; };
B442DA0715C216C900985ED1 /* menu_ignore_caches.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches.png; path = embed/menu_ignore_caches.png; sourceTree = "<group>"; };
B442DA0815C216C900985ED1 /* menu_memory_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_memory_info.png; path = embed/menu_memory_info.png; sourceTree = "<group>"; };
B442DA0915C216C900985ED1 /* menu_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_selection.png; path = embed/menu_selection.png; sourceTree = "<group>"; };
B442DA0A15C216C900985ED1 /* menu_single_user_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user_disabled.png; path = embed/menu_single_user_disabled.png; sourceTree = "<group>"; };
B442DA0B15C216C900985ED1 /* menu_single_user.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user.png; path = embed/menu_single_user.png; sourceTree = "<group>"; };
B442DA0C15C216C900985ED1 /* menu_verbose_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose_disabled.png; path = embed/menu_verbose_disabled.png; sourceTree = "<group>"; };
B442DA0D15C216C900985ED1 /* menu_verbose.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose.png; path = embed/menu_verbose.png; sourceTree = "<group>"; };
B442DA0E15C216C900985ED1 /* menu_video_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_video_info.png; path = embed/menu_video_info.png; sourceTree = "<group>"; };
B442DA0F15C216C900985ED1 /* progress_bar_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar_background.png; path = embed/progress_bar_background.png; sourceTree = "<group>"; };
B442DA1015C216C900985ED1 /* progress_bar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar.png; path = embed/progress_bar.png; sourceTree = "<group>"; };
B442DA1115C216C900985ED1 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_next.png; path = embed/text_scroll_next.png; sourceTree = "<group>"; };
B442DA1215C216C900985ED1 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_prev.png; path = embed/text_scroll_prev.png; sourceTree = "<group>"; };
B442DA1315C216C900985ED1 /* theme.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = theme.plist; path = embed/theme.plist; sourceTree = "<group>"; };
B442DA1415C216E500985ED1 /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = legacy/background.png; sourceTree = "<group>"; };
B442DA1515C216E500985ED1 /* boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boot.png; path = legacy/boot.png; sourceTree = "<group>"; };
B442DA1615C216E500985ED1 /* device_cdrom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_cdrom.png; path = legacy/device_cdrom.png; sourceTree = "<group>"; };
B442DA1715C216E500985ED1 /* device_ext3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ext3.png; path = legacy/device_ext3.png; sourceTree = "<group>"; };
B442DA1815C216E500985ED1 /* device_fat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_fat.png; path = legacy/device_fat.png; sourceTree = "<group>"; };
B442DA1915C216E500985ED1 /* device_generic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_generic.png; path = legacy/device_generic.png; sourceTree = "<group>"; };
B442DA1A15C216E500985ED1 /* device_hfsplus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsplus.png; path = legacy/device_hfsplus.png; sourceTree = "<group>"; };
B442DA1B15C216E500985ED1 /* device_ntfs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ntfs.png; path = legacy/device_ntfs.png; sourceTree = "<group>"; };
B442DA1C15C216E500985ED1 /* device_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_next.png; path = legacy/device_scroll_next.png; sourceTree = "<group>"; };
B442DA1D15C216E500985ED1 /* device_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_prev.png; path = legacy/device_scroll_prev.png; sourceTree = "<group>"; };
B442DA1E15C216E500985ED1 /* device_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_selection.png; path = legacy/device_selection.png; sourceTree = "<group>"; };
B442DA1F15C216E500985ED1 /* font_console.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_console.png; path = legacy/font_console.png; sourceTree = "<group>"; };
B442DA2015C216E500985ED1 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_small.png; path = legacy/font_small.png; sourceTree = "<group>"; };
B442DA2115C216E500985ED1 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = legacy/logo.png; sourceTree = "<group>"; };
B442DA2215C216E500985ED1 /* menu_boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_boot.png; path = legacy/menu_boot.png; sourceTree = "<group>"; };
B442DA2315C216E500985ED1 /* menu_help.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_help.png; path = legacy/menu_help.png; sourceTree = "<group>"; };
B442DA2415C216E500985ED1 /* menu_ignore_caches_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches_disabled.png; path = legacy/menu_ignore_caches_disabled.png; sourceTree = "<group>"; };
B442DA2515C216E500985ED1 /* menu_ignore_caches.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches.png; path = legacy/menu_ignore_caches.png; sourceTree = "<group>"; };
B442DA2615C216E500985ED1 /* menu_memory_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_memory_info.png; path = legacy/menu_memory_info.png; sourceTree = "<group>"; };
B442DA2715C216E500985ED1 /* menu_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_selection.png; path = legacy/menu_selection.png; sourceTree = "<group>"; };
B442DA2815C216E500985ED1 /* menu_single_user_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user_disabled.png; path = legacy/menu_single_user_disabled.png; sourceTree = "<group>"; };
B442DA2915C216E500985ED1 /* menu_single_user.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user.png; path = legacy/menu_single_user.png; sourceTree = "<group>"; };
B442DA2A15C216E500985ED1 /* menu_verbose_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose_disabled.png; path = legacy/menu_verbose_disabled.png; sourceTree = "<group>"; };
B442DA2B15C216E500985ED1 /* menu_verbose.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose.png; path = legacy/menu_verbose.png; sourceTree = "<group>"; };
B442DA2C15C216E500985ED1 /* menu_video_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_video_info.png; path = legacy/menu_video_info.png; sourceTree = "<group>"; };
B442DA2D15C216E500985ED1 /* progress_bar_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar_background.png; path = legacy/progress_bar_background.png; sourceTree = "<group>"; };
B442DA2E15C216E500985ED1 /* progress_bar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar.png; path = legacy/progress_bar.png; sourceTree = "<group>"; };
B442DA2F15C216E500985ED1 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_next.png; path = legacy/text_scroll_next.png; sourceTree = "<group>"; };
B442DA3015C216E500985ED1 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_prev.png; path = legacy/text_scroll_prev.png; sourceTree = "<group>"; };
B442DA3115C216E500985ED1 /* theme.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = theme.plist; path = legacy/theme.plist; sourceTree = "<group>"; };
B4526097153EFCE90018E994 /* ar.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ar.po; sourceTree = "<group>"; };
B4526098153EFCE90018E994 /* bg.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bg.po; sourceTree = "<group>"; };
B4526099153EFCE90018E994 /* bs.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bs.po; sourceTree = "<group>"; };
B0056CFC11F3868000754B65 /* graphics.c */,
B0056CFD11F3868000754B65 /* graphics.h */,
B0056CFE11F3868000754B65 /* gui.c */,
6DBAFD1313B0D21E0047ED33 /* modules_support.s */,
6DBAFD1413B0D21E0047ED33 /* modules.c */,
6DBAFD1513B0D21E0047ED33 /* modules.h */,
B0056CFF11F3868000754B65 /* gui.h */,
B0056D0011F3868000754B65 /* IOHibernatePrivate.h */,
B0056D0111F3868000754B65 /* lzss.c */,
B0056D0211F3868000754B65 /* Makefile */,
B0056D0311F3868000754B65 /* mboot.c */,
B0056D0411F3868000754B65 /* mboot.h */,
6DBAFD1313B0D21E0047ED33 /* modules_support.s */,
6DBAFD1413B0D21E0047ED33 /* modules.c */,
6DBAFD1513B0D21E0047ED33 /* modules.h */,
B0056D0511F3868000754B65 /* multiboot.h */,
B0056D0611F3868000754B65 /* options.c */,
B0056D0711F3868000754B65 /* picopng.c */,
children = (
B0056DBC11F3868000754B65 /* bullet */,
B0056DDC11F3868000754B65 /* default */,
B0056DFC11F3868000754B65 /* msi_netbook */,
B0056DFF11F3868000754B65 /* pinktink */,
B0056E0211F3868000754B65 /* twilight */,
B442D9F315C2164800985ED1 /* embed */,
B442D9F415C2166000985ED1 /* legacy */,
);
path = themes;
sourceTree = "<group>";
path = default;
sourceTree = "<group>";
};
B0056DFC11F3868000754B65 /* msi_netbook */ = {
isa = PBXGroup;
children = (
B0056DFD11F3868000754B65 /* logo.png */,
B0056DFE11F3868000754B65 /* theme.plist */,
);
path = msi_netbook;
sourceTree = "<group>";
};
B0056DFF11F3868000754B65 /* pinktink */ = {
isa = PBXGroup;
children = (
B0056E0011F3868000754B65 /* logo.png */,
B0056E0111F3868000754B65 /* theme.plist */,
);
path = pinktink;
sourceTree = "<group>";
};
B0056E0211F3868000754B65 /* twilight */ = {
isa = PBXGroup;
children = (
B0056E0311F3868000754B65 /* font_small.png */,
B0056E0411F3868000754B65 /* logo.png */,
B0056E0511F3868000754B65 /* theme.plist */,
);
path = twilight;
sourceTree = "<group>";
};
B0056E0611F3868000754B65 /* doc */ = {
isa = PBXGroup;
children = (
name = lxdialog;
sourceTree = "<group>";
};
B442D9F315C2164800985ED1 /* embed */ = {
isa = PBXGroup;
children = (
B442D9F515C216C900985ED1 /* background.png */,
B442D9F615C216C900985ED1 /* boot.png */,
B442D9F715C216C900985ED1 /* device_cdrom.png */,
B442D9F815C216C900985ED1 /* device_ext3.png */,
B442D9F915C216C900985ED1 /* device_fat.png */,
B442D9FA15C216C900985ED1 /* device_generic.png */,
B442D9FB15C216C900985ED1 /* device_hfsplus.png */,
B442D9FC15C216C900985ED1 /* device_hfsraid.png */,
B442D9FD15C216C900985ED1 /* device_ntfs.png */,
B442D9FE15C216C900985ED1 /* device_scroll_next.png */,
B442D9FF15C216C900985ED1 /* device_scroll_prev.png */,
B442DA0015C216C900985ED1 /* device_selection.png */,
B442DA0115C216C900985ED1 /* font_console.png */,
B442DA0215C216C900985ED1 /* font_small.png */,
B442DA0315C216C900985ED1 /* logo.png */,
B442DA0415C216C900985ED1 /* menu_boot.png */,
B442DA0515C216C900985ED1 /* menu_help.png */,
B442DA0615C216C900985ED1 /* menu_ignore_caches_disabled.png */,
B442DA0715C216C900985ED1 /* menu_ignore_caches.png */,
B442DA0815C216C900985ED1 /* menu_memory_info.png */,
B442DA0915C216C900985ED1 /* menu_selection.png */,
B442DA0A15C216C900985ED1 /* menu_single_user_disabled.png */,
B442DA0B15C216C900985ED1 /* menu_single_user.png */,
B442DA0C15C216C900985ED1 /* menu_verbose_disabled.png */,
B442DA0D15C216C900985ED1 /* menu_verbose.png */,
B442DA0E15C216C900985ED1 /* menu_video_info.png */,
B442DA0F15C216C900985ED1 /* progress_bar_background.png */,
B442DA1015C216C900985ED1 /* progress_bar.png */,
B442DA1115C216C900985ED1 /* text_scroll_next.png */,
B442DA1215C216C900985ED1 /* text_scroll_prev.png */,
B442DA1315C216C900985ED1 /* theme.plist */,
);
name = embed;
sourceTree = "<group>";
};
B442D9F415C2166000985ED1 /* legacy */ = {
isa = PBXGroup;
children = (
B442DA1415C216E500985ED1 /* background.png */,
B442DA1515C216E500985ED1 /* boot.png */,
B442DA1615C216E500985ED1 /* device_cdrom.png */,
B442DA1715C216E500985ED1 /* device_ext3.png */,
B442DA1815C216E500985ED1 /* device_fat.png */,
B442DA1915C216E500985ED1 /* device_generic.png */,
B442DA1A15C216E500985ED1 /* device_hfsplus.png */,
B442DA1B15C216E500985ED1 /* device_ntfs.png */,
B442DA1C15C216E500985ED1 /* device_scroll_next.png */,
B442DA1D15C216E500985ED1 /* device_scroll_prev.png */,
B442DA1E15C216E500985ED1 /* device_selection.png */,
B442DA1F15C216E500985ED1 /* font_console.png */,
B442DA2015C216E500985ED1 /* font_small.png */,
B442DA2115C216E500985ED1 /* logo.png */,
B442DA2215C216E500985ED1 /* menu_boot.png */,
B442DA2315C216E500985ED1 /* menu_help.png */,
B442DA2415C216E500985ED1 /* menu_ignore_caches_disabled.png */,
B442DA2515C216E500985ED1 /* menu_ignore_caches.png */,
B442DA2615C216E500985ED1 /* menu_memory_info.png */,
B442DA2715C216E500985ED1 /* menu_selection.png */,
B442DA2815C216E500985ED1 /* menu_single_user_disabled.png */,
B442DA2915C216E500985ED1 /* menu_single_user.png */,
B442DA2A15C216E500985ED1 /* menu_verbose_disabled.png */,
B442DA2B15C216E500985ED1 /* menu_verbose.png */,
B442DA2C15C216E500985ED1 /* menu_video_info.png */,
B442DA2D15C216E500985ED1 /* progress_bar_background.png */,
B442DA2E15C216E500985ED1 /* progress_bar.png */,
B442DA2F15C216E500985ED1 /* text_scroll_next.png */,
B442DA3015C216E500985ED1 /* text_scroll_prev.png */,
B442DA3115C216E500985ED1 /* theme.plist */,
);
name = legacy;
sourceTree = "<group>";
};
B4526096153EFCE90018E994 /* po */ = {
isa = PBXGroup;
children = (
branches/ErmaC/Trunk/i386/libsaio/fake_efi.h
11
2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
326
427
528
......
932
1033
1134
12
35
1336
/*
* Copyright 2007 David F. Elliott. All rights reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* Copyright 2007 David F. Elliott.
* All rights reserved.
*
*/
#ifndef __LIBSAIO_FAKE_EFI_H
#define MAX_CONFIGURATION_TABLE_ENTRIES 10
extern void setupFakeEfi(void);
#endif /* !__LIBSAIO_FAKE_EFI_H */
branches/ErmaC/Trunk/i386/libsaio/xml.c
6767
6868
6969
70
71
72
73
74
75
76
70
71
72
73
74
75
76
77
7778
7879
7980
80
81
82
83
84
81
82
83
84
85
86
8587
8688
8789
8890
8991
9092
91
92
93
94
95
96
97
98
99
93
94
95
96
97
98
99
100
101
102
100103
101104
102105
103
104
105
106
107
108
109
106110
107111
108112
......
126130
127131
128132
129
130
133
131134
132
135
136
137
138
133139
134
135
136
137
138
139
140
141
140
141
142
143
144
145
146
142147
143
144
145
146
147
148
148
149
150
151
152
153
154
155
156
157
158
159
149160
150161
151162
return "";
}
struct Module {
struct Module *nextModule;
long willLoad;
TagPtr dict;
char *plistAddr;
long plistLength;
char *driverPath;
struct Module
{
struct Module *nextModule;
longwillLoad;
TagPtrdict;
char* plistAddr;
longplistLength;
char* driverPath;
};
typedef struct Module Module, *ModulePtr;
struct DriverInfo {
char *plistAddr;
long plistLength;
void *moduleAddr;
long moduleLength;
struct DriverInfo
{
char* plistAddr;
longplistLength;
void* moduleAddr;
longmoduleLength;
};
typedef struct DriverInfo DriverInfo, *DriverInfoPtr;
#define kDriverPackageSignature1 'MKXT'
#define kDriverPackageSignature2 'MOSX'
struct DriversPackage {
unsigned long signature1;
unsigned long signature2;
unsigned long length;
unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
unsigned long reserved2;
struct DriversPackage
{
unsigned long signature1;
unsigned long signature2;
unsigned long length;
unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
unsigned long reserved2;
};
typedef struct DriversPackage DriversPackage;
enum {
kCFBundleType2,
kCFBundleType3
enum
{
kCFBundleType2,
kCFBundleType3
};
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetProperty( TagPtr dict, const char * key )
TagPtr XMLGetProperty(TagPtr dict, const char * key)
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict)
{
return 0;
}
if (dict->type != kTagTypeDict) return 0;
tag = 0;
tagList = dict->tag;
while (tagList)
{
tag = tagList;
tagList = tag->tagNext;
TagPtr tag = 0;
TagPtr tagList = dict->tag;
while (tagList)
{
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue;
if (!strcmp(tag->string, key)) return tag->tag;
}
return 0;
if ((tag->type != kTagTypeKey) || (tag->string == 0))
{
continue;
}
if (!strcmp(tag->string, key))
{
return tag->tag;
}
}
return 0;
}
//==========================================================================
branches/ErmaC/Trunk/i386/libsaio/console.c
6969
7070
7171
72
73
72
73
7474
7575
7676
......
8383
8484
8585
86
86
8787
8888
8989
......
9191
9292
9393
94
94
9595
9696
9797
......
100100
101101
102102
103
103104
105
104106
105107
108
106109
110
107111
108112
109113
......
116120
117121
118122
123
119124
125
120126
121127
122128
......
136142
137143
138144
139
145
140146
141
147
142148
143149
144150
145
151
146152
147153
148154
149155
150
156
151157
152
153
154
155
158
159
160
161
162
163
164
165
156166
157167
158168
......
171181
172182
173183
174
184
175185
176186
187
177188
189
178190
191
179192
193
180194
181195
182196
......
194208
195209
196210
197
211
198212
199213
200214
......
202216
203217
204218
205
206
219
220
207221
208222
209223
210224
211
225
212226
213227
214228
215229
216230
217231
232
218233
234
219235
220236
237
221238
239
222240
223241
224242
225243
226244
227245
228
229
246
247
230248
231249
232250
233251
234
235
236
252
253
254
237255
256
238257
239
258
259
260
240261
262
241263
242
264
243265
244266
245267
......
248270
249271
250272
251
273
274
252275
253
276
277
278
254279
255280
256281
struct putc_info //Azi: exists on gui.c & printf.c
{
char * str;
char * last_str;
char * str;
char * last_str;
};
static int
return 0;
}
*(pi->str)++ = c;
return c;
return c;
}
void initBooterLog(void)
msgbuf = malloc(BOOTER_LOG_SIZE);
bzero(msgbuf, BOOTER_LOG_SIZE);
cursor = msgbuf;
msglog("%s\n", "Enoch by ErmaC (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
msglog("%s\n", "Enoch (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
}
void msglog(const char * fmt, ...)
struct putc_info pi;
if (!msgbuf)
{
return;
}
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
{
return;
}
va_start(ap, fmt);
pi.str = cursor;
void setupBooterLog(void)
{
if (!msgbuf)
{
return;
}
Node *node = DT__FindNode("/", false);
if (node)
}
if ( c == '\n' )
{
{
bios_putchar('\r');
}
}
bios_putchar(c);
return c;
return c;
}
int getc()
{
int c = bgetc();
int c = bgetc();
if ((c & 0xff) == 0)
return c;
else
return (c & 0xff);
if ((c & 0xff) == 0)
{
return c;
}
else
{
return (c & 0xff);
}
}
// Read and echo a character from console. This doesn't echo backspace
int printf(const char * fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
}
else
{
vprf(fmt, ap);
}
{
/* Kabyl: BooterLog */
}
va_end(ap);
return 0;
return 0;
}
int verbose(const char * fmt, ...)
va_list ap;
va_start(ap, fmt);
if (gVerboseMode)
{
if (gVerboseMode)
{
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
prf(fmt, ap, putchar, 0);
else
vprf(fmt, ap);
}
}
{
/* Kabyl: BooterLog */
struct putc_info pi;
if (!msgbuf)
{
return 0;
}
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
{
return 0;
}
pi.str = cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
}
va_end(ap);
return(0);
va_end(ap);
return(0);
}
int error(const char * fmt, ...)
{
va_list ap;
gErrors = true;
va_start(ap, fmt);
va_list ap;
gErrors = true;
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
else
}
else
{
vprf(fmt, ap);
}
va_end(ap);
return(0);
return(0);
}
void stop(const char * fmt, ...)
printf("\n");
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
} else {
}
else
{
vprf(fmt, ap);
}
va_end(ap);
branches/ErmaC/Trunk/i386/libsaio/xml.h
2525
2626
2727
28
29
30
31
32
33
34
35
36
37
38
28
29
30
31
32
33
34
35
36
37
38
39
3940
4041
4142
......
7071
7172
7273
73
74
75
76
77
74
75
76
77
78
79
7880
7981
8082
#ifndef __LIBSAIO_XML_H
#define __LIBSAIO_XML_H
enum xmltype {
kTagTypeNone = 0,
kTagTypeDict,
kTagTypeKey,
kTagTypeString,
kTagTypeInteger,
kTagTypeData,
kTagTypeDate,
kTagTypeFalse,
kTagTypeTrue,
kTagTypeArray
enum xmltype
{
kTagTypeNone = 0,
kTagTypeDict,
kTagTypeKey,
kTagTypeString,
kTagTypeInteger,
kTagTypeData,
kTagTypeDate,
kTagTypeFalse,
kTagTypeTrue,
kTagTypeArray
};
struct string_ref
#define kPropIONameMatch ("IONameMatch")
/*
struct Tag {
long type;
char *string;
struct Tag *tag;
struct Tag *tagNext;
struct Tag
{
long type;
char *string;
struct Tag *tag;
struct Tag *tagNext;
};
typedef struct Tag Tag, *TagPtr;
*/
branches/ErmaC/Trunk/i386/libsaio/efi.h
11
22
33
4
5
64
75
86
......
2321
2422
2523
26
2724
2825
2926
......
7168
7269
7370
74
7571
76
72
7773
7874
7975
......
8278
8379
8480
85
8681
87
8882
8983
9084
......
123117
124118
125119
126
127120
128121
129122
130123
131124
132125
133
126
127
134128
135129
136130
......
143137
144138
145139
146
140
141
147142
148143
149144
......
159154
160155
161156
162
157
158
163159
164160
165161
......
173169
174170
175171
176
172
177173
178
174
179175
180176
181177
182
178
183179
184
180
185181
186182
187183
......
202198
203199
204200
205
206
207
208
209
210
201
202
203
204
205
206
207
211208
212209
213
214210
215
211
216212
217213
218214
219215
220216
221217
222
218
223219
224
220
225221
226222
227223
228224
229
225
230226
231
227
232228
233229
234230
......
263259
264260
265261
266
262
267263
268
264
269265
270266
271267
......
302298
303299
304300
305
301
306302
307
308
303
304
305
309306
310307
311308
......
371368
372369
373370
374
375371
376
377
378
379
380
381
382
372
373
374
375
376
383377
384
385
378
386379
387380
388381
......
403396
404397
405398
406
407
399
400
401
408402
409
410
411
412
413
414
415
403
404
405
406
407
416408
417
418
419
420
421
409
422410
423
424
425
426
427
428
411
412
429413
430
431
432
433
434
435414
415
416
417
418
419
420
421
422
423
436424
437
438
439
440
441
442
425
426
427
428
429
430
443431
444432
445433
446434
447
448
435
436
437
449438
450
451
452
453
454
455
456
457439
458
459
460
461
462
440
463441
464
465
466
467
468
469
442
443
444
445
470446
471
472
473
474
475
447
476448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
477463
478
479
480
481
482
483
464
465
466
467
468
469
484470
485471
486472
......
488474
489475
490476
491
492
493
477
478
479
480
494481
495482
496
497
498
483
484
485
486
499487
500488
501
489
502490
503
491
504492
505493
506494
507495
508496
509497
510
511
498
499
500
512501
513
514
502
503
515504
516
517
505
506
518507
519
520
508
509
521510
522
523
511
512
524513
525
526
514
515
527516
528
529
517
518
530519
531520
532521
533
534
522
523
524
535525
536
537
526
527
538528
539
529
530
531
540532
541
542
533
534
543535
544
545
536
537
546538
547
548
539
540
549541
550
551
552
553
554
555
542
543
556544
557545
558546
/*
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#ifndef _PEXPERT_I386_EFI_H
*/
//
// Modifiers for EFI Runtime and Boot Services
//
#define EFI_RUNTIMESERVICE
#define EFIAPI
#define IN
#define EFI_MAX_BIT 0x80000000
//
// Set the upper bit to indicate EFI Error.
//
#define EFIERR(a) (EFI_MAX_BIT | (a))
#define EFIWARN(a) (a)
#define EFI_WARN_DELETE_FAILURE EFIWARN (2)
#define EFI_WARN_WRITE_FAILURE EFIWARN (3)
#define EFI_WARN_BUFFER_TOO_SMALL EFIWARN (4)
//
// EFI Specification Revision information
//
#define EFI_SPECIFICATION_MAJOR_REVISION 1
#define EFI_SPECIFICATION_MINOR_REVISION 10
typedef struct {
typedef struct
{
EFI_UINT32 Data1;
EFI_UINT16 Data2;
EFI_UINT16 Data3;
#define EFI_GLOBAL_VARIABLE_GUID \
{0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
typedef union {
typedef union
{
EFI_GUID Guid;
EFI_UINT8 Raw[16];
} EFI_GUID_UNION;
// Nanosecond: 0 - 999,999,999
// TimeZone: -1440 to 1440 or 2047
//
typedef struct {
typedef struct
{
EFI_UINT16 Year;
EFI_UINT8 Month;
EFI_UINT8 Day;
EFI_UINT8 Pad2;
} EFI_TIME;
//
// Bit definitions for EFI_TIME.Daylight
//
#define EFI_TIME_ADJUST_DAYLIGHT 0x01
#define EFI_TIME_IN_DAYLIGHT 0x02
//
// Value definition for EFI_TIME.TimeZone
//
#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
typedef enum {
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
typedef struct {
EFI_UINT64 Signature;
EFI_UINT32 Revision;
EFI_UINT32 HeaderSize;
EFI_UINT32 CRC32;
EFI_UINT32 Reserved;
typedef struct
{
EFI_UINT64Signature;
EFI_UINT32Revision;
EFI_UINT32HeaderSize;
EFI_UINT32CRC32;
EFI_UINT32Reserved;
} __attribute__((aligned(8))) EFI_TABLE_HEADER;
//
// possible caching types for the memory range
//
#define EFI_MEMORY_UC 0x0000000000000001ULL
#define EFI_MEMORY_WC 0x0000000000000002ULL
#define EFI_MEMORY_WT 0x0000000000000004ULL
#define EFI_MEMORY_WB 0x0000000000000008ULL
#define EFI_MEMORY_UCE 0x0000000000000010ULL
//
// physical memory protection on range
//
#define EFI_MEMORY_WP 0x0000000000001000ULL
#define EFI_MEMORY_RP 0x0000000000002000ULL
#define EFI_MEMORY_XP 0x0000000000004000ULL
//
// range requires a runtime mapping
//
#define EFI_MEMORY_RUNTIME 0x8000000000000000ULL
typedef EFI_UINT64 EFI_PHYSICAL_ADDRESS;
IN OUT VOID **Address
) __attribute__((regparm(0)));
//
// Variable attributes
//
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
IN VOID * Data
) __attribute__((regparm(0)));
//
// EFI Time
//
typedef struct {
typedef struct
{
EFI_UINT32 Resolution;
EFI_UINT32 Accuracy;
EFI_BOOLEAN SetsToZero;
OUT EFI_UINT32 * HighCount
) __attribute__((regparm(0)));
//
// Definition of Status Code extended data header
//
// HeaderSize The size of the architecture. This is specified to enable
// the future expansion
//
// Size The size of the data in bytes. This does not include the size
// of the header structure.
//
// HeaderSize The size of the architecture. This is specified to enable the future expansion
// Size The size of the data in bytes. This does not include the size of the header structure.
// Type A GUID defining the type of the data
//
//
#ifdef TIANO_EXTENSION_FLAG
typedef
#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552ULL
#define EFI_RUNTIME_SERVICES_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION))
typedef struct {
EFI_TABLE_HEADER Hdr;
typedef struct
{
EFI_TABLE_HEADERHdr;
//
// Time services
//
EFI_PTR32 GetTime;
EFI_PTR32 SetTime;
EFI_PTR32 GetWakeupTime;
EFI_PTR32 SetWakeupTime;
// Time Services
EFI_PTR32GetTime;
EFI_PTR32SetTime;
EFI_PTR32GetWakeupTime;
EFI_PTR32SetWakeupTime;
//
// Virtual memory services
//
EFI_PTR32 SetVirtualAddressMap;
EFI_PTR32 ConvertPointer;
// Virtual Memory Services
//
// Variable services
//
EFI_PTR32 GetVariable;
EFI_PTR32 GetNextVariableName;
EFI_PTR32 SetVariable;
EFI_PTR32 SetVirtualAddressMap;
EFI_PTR32 ConvertPointer;
//
// Misc
//
EFI_PTR32 GetNextHighMonotonicCount;
EFI_PTR32 ResetSystem;
// Variable Services
EFI_PTR32 GetVariable;
EFI_PTR32 GetNextVariableName;
EFI_PTR32 SetVariable;
// Miscellaneous Services
EFI_PTR32 GetNextHighMonotonicCount;
EFI_PTR32 ResetSystem;
#ifdef TIANO_EXTENSION_FLAG
//
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
//
EFI_PTR32 ReportStatusCode;
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
EFI_PTR32 ReportStatusCode;
#endif
} __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_32;
typedef struct {
EFI_TABLE_HEADER Hdr;
typedef struct
{
EFI_TABLE_HEADER Hdr;
//
// Time services
//
EFI_PTR64 GetTime;
EFI_PTR64 SetTime;
EFI_PTR64 GetWakeupTime;
EFI_PTR64 SetWakeupTime;
//
// Virtual memory services
//
EFI_PTR64 SetVirtualAddressMap;
EFI_PTR64 ConvertPointer;
// Time services
//
// Variable services
//
EFI_PTR64 GetVariable;
EFI_PTR64 GetNextVariableName;
EFI_PTR64 SetVariable;
EFI_PTR64 GetTime;
EFI_PTR64 SetTime;
EFI_PTR64 GetWakeupTime;
EFI_PTR64 SetWakeupTime;
//
// Misc
//
EFI_PTR64 GetNextHighMonotonicCount;
EFI_PTR64 ResetSystem;
// Virtual memory services
EFI_PTR64 SetVirtualAddressMap;
EFI_PTR64 ConvertPointer;
// Variable services
EFI_PTR64 GetVariable;
EFI_PTR64 GetNextVariableName;
EFI_PTR64 SetVariable;
// Misc
EFI_PTR64 GetNextHighMonotonicCount;
EFI_PTR64 ResetSystem;
#ifdef TIANO_EXTENSION_FLAG
//
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
//
EFI_PTR64 ReportStatusCode;
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
EFI_PTR64 ReportStatusCode;
#endif
} __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_64;
//
// EFI Configuration Table
//
typedef struct {
EFI_GUID VendorGuid;
EFI_PTR32 VendorTable;
typedef struct
{
EFI_GUID VendorGuid;
EFI_PTR32 VendorTable;
} EFI_CONFIGURATION_TABLE_32;
typedef struct {
EFI_GUID VendorGuid;
EFI_PTR64 VendorTable;
typedef struct
{
EFI_GUID VendorGuid;
EFI_PTR64 VendorTable;
} __attribute__((aligned(8))) EFI_CONFIGURATION_TABLE_64;
//
// EFI System Table
//
#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249ULL
#define EFI_SYSTEM_TABLE_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION))
#define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | 00)
#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | 02)
#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | 10)
typedef struct EFI_SYSTEM_TABLE_32 {
EFI_TABLE_HEADER Hdr;
typedef struct EFI_SYSTEM_TABLE_32
{
EFI_TABLE_HEADER Hdr;
EFI_PTR32 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_PTR32 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_HANDLE32 ConsoleInHandle;
EFI_PTR32 ConIn;
EFI_HANDLE32 ConsoleInHandle;
EFI_PTR32 ConIn;
EFI_HANDLE32 ConsoleOutHandle;
EFI_PTR32 ConOut;
EFI_HANDLE32 ConsoleOutHandle;
EFI_PTR32 ConOut;
EFI_HANDLE32 StandardErrorHandle;
EFI_PTR32 StdErr;
EFI_HANDLE32 StandardErrorHandle;
EFI_PTR32 StdErr;
EFI_PTR32 RuntimeServices;
EFI_PTR32 BootServices;
EFI_PTR32 RuntimeServices;
EFI_PTR32 BootServices;
EFI_UINT32 NumberOfTableEntries;
EFI_PTR32 ConfigurationTable;
EFI_UINT32 NumberOfTableEntries;
EFI_PTR32 ConfigurationTable;
} __attribute__((aligned(8))) EFI_SYSTEM_TABLE_32;
typedef struct EFI_SYSTEM_TABLE_64 {
EFI_TABLE_HEADER Hdr;
typedef struct EFI_SYSTEM_TABLE_64
{
EFI_TABLE_HEADER Hdr;
EFI_PTR64 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_PTR64 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_UINT32 __pad;
EFI_UINT32 __pad;
EFI_HANDLE64 ConsoleInHandle;
EFI_PTR64 ConIn;
EFI_HANDLE64 ConsoleInHandle;
EFI_PTR64 ConIn;
EFI_HANDLE64 ConsoleOutHandle;
EFI_PTR64 ConOut;
EFI_HANDLE64 ConsoleOutHandle;
EFI_PTR64 ConOut;
EFI_HANDLE64 StandardErrorHandle;
EFI_PTR64 StdErr;
EFI_HANDLE64 StandardErrorHandle;
EFI_PTR64 StdErr;
EFI_PTR64 RuntimeServices;
EFI_PTR64 BootServices;
EFI_PTR64 RuntimeServices;
EFI_PTR64 BootServices;
EFI_UINT64 NumberOfTableEntries;
EFI_PTR64 ConfigurationTable;
EFI_UINT64 NumberOfTableEntries;
EFI_PTR64 ConfigurationTable;
} __attribute__((aligned(8))) EFI_SYSTEM_TABLE_64;
#endif /* _PEXPERT_I386_EFI_H */
branches/ErmaC/Trunk/i386/libsaio/vbe.c
2929
3030
3131
32
33
34
35
36
32
33
34
35
36
37
38
39
3740
3841
3942
4043
41
42
44
45
46
4347
4448
4549
4650
4751
48
49
52
53
54
55
5056
5157
5258
5359
5460
55
56
61
62
63
64
5765
5866
5967
6068
6169
62
63
64
65
6670
67
71
72
73
6874
6975
7076
7177
7278
73
79
80
7481
7582
7683
77
84
85
86
87
7888
7989
8090
......
8292
8393
8494
95
8596
8697
8798
99
100
101
88102
89103
90104
......
95109
96110
97111
112
113
114
98115
99116
100117
......
102119
103120
104121
122
105123
106124
107125
126
108127
109128
110129
#include "libsaio.h"
#include "vbe.h"
/*
* Various inline routines for video I/O
*/
static inline void
outi (int port, int index, int val)
// Various inline routines for video I/O
static biosBuf_t bb;
//==============================================================================
static inline void outi(int port, int index, int val)
{
outw (port, (val << 8) | index);
}
static inline void
outib (int port, int index, int val)
//==============================================================================
static inline void outib(int port, int index, int val)
{
outb (port, index);
outb (port + 1, val);
}
static inline int
ini (int port, int index)
//==============================================================================
static inline int ini(int port, int index)
{
outb (port, index);
return inb (port + 1);
}
static inline void
rmwi (int port, int index, int clear, int set)
//==============================================================================
static inline void rmwi(int port, int index, int clear, int set)
{
outb (port, index);
outb (port + 1, (inb (port + 1) & ~clear) | set);
}
/*
* Globals
*/
static biosBuf_t bb;
int getVBEInfo( void * infoBlock )
//==============================================================================
int getVBEInfo(void * infoBlock)
{
bb.intno = 0x10;
bb.eax.rr = funcGetControllerInfo;
bb.es = SEG( infoBlock );
bb.edi.rr = OFF( infoBlock );
bios( &bb );
bios(&bb);
return(bb.eax.r.h);
}
int getVBEModeInfo( int mode, void * minfo_p )
//==============================================================================
int getVBEModeInfo(int mode, void * minfo_p)
{
bb.intno = 0x10;
bb.eax.rr = funcGetModeInfo;
bb.es = SEG(minfo_p);
bb.edi.rr = OFF(minfo_p);
bios(&bb);
return(bb.eax.r.h);
}
//==============================================================================
int getVBEDACFormat(unsigned char *format)
{
bb.intno = 0x10;
return(bb.eax.r.h);
}
//==============================================================================
int setVBEDACFormat(unsigned char format)
{
bb.intno = 0x10;
bb.ebx.r.l = subfuncSet;
bb.ebx.r.h = format;
bios(&bb);
return(bb.eax.r.h);
}
/*
* Default GTF parameter values.
*/
branches/ErmaC/Trunk/i386/libsaio/bootstruct.h
6262
6363
6464
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
8084
8185
82
83
84
85
86
87
88
89
90
91
8692
8793
8894
/*
* PCI bus information.
*/
typedef struct _PCI_bus_info_t {
union {
struct {
unsigned char configMethod1 :1;
unsigned char configMethod2 :1;
unsigned char :2;
unsigned char specialCycle1 :1;
unsigned char specialCycle2 :1;
} s;
unsigned char d;
} u_bus;
unsigned char maxBusNum;
unsigned char majorVersion;
unsigned char minorVersion;
unsigned char BIOSPresent;
typedef struct _PCI_bus_info_t
{
union
{
struct
{
unsigned char configMethod1 :1;
unsigned char configMethod2 :1;
unsigned char :2;
unsigned char specialCycle1 :1;
unsigned char specialCycle2 :1;
} s;
unsigned char d;
} u_bus;
unsigned char maxBusNum;
unsigned char majorVersion;
unsigned char minorVersion;
unsigned char BIOSPresent;
} PCI_bus_info_t;
typedef struct {
unsigned long address; // address where driver was loaded
unsigned long size; // number of bytes
unsigned long type; // driver type
typedef struct
{
unsigned long address; // address where driver was loaded
unsigned long size; // number of bytes
unsigned long type; // driver type
} driver_config_t;
/*
branches/ErmaC/Trunk/i386/libsaio/device_tree.c
11
2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
323
424
525
626
7
27
828
929
1030
1131
1232
13
14
15
33
34
35
36
1637
1738
1839
1940
20
21
22
41
42
43
44
2345
2446
2547
2648
2749
28
50
51
2952
3053
3154
......
4871
4972
5073
51
52
53
54
74
75
76
77
78
5579
5680
5781
5882
5983
6084
61
85
6286
6387
64
65
88
89
90
91
6692
67
93
6894
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
95
9196
92
93
94
97
98
99
100
95101
96
97
98
99
100
101
102
103
102
104103
105
106
107
108
104
105
106
107
109108
110
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
111152
112153
113
114
154
155
156
157
115158
116
159
117160
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
161
162
163
142164
143
144
145
146
147
148
149
150
151
152
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
153214
154215
155
156
216
217
218
219
157220
158
159
221
222
160223
161
162
224
225
226
227
228
163229
164
165
230
231
166232
167233
168
169
234
235
236
237
170238
171
172
173
174
175
176
177
178
179
180
181
182
183
239
240
241
242
243
244
245
246
247
248
249
250
251
184252
185253
254
186255
187
188
256
189257
190
191
258
192259
193
194
260
261
195262
196
197
198
199
200
201
263
202264
203
204
205
206
207
208
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
209281
210
211
212
213
214
282
283
284
285
215286
216287
217
218
288
289
290
291
219292
220
221
222
223
293
294
295
296
224297
225
298
299
300
301
226302
227
228
303
304
229305
230
231
232
233
234
235
236
237
238
306
307
308
309
310
311
312
313
314
239315
240
241
242
243
316
244317
245
318
319
320
321
322
323
324
325
246326
247327
248
249
250
328
329
330
251331
252332
253333
254334
255335
256
257
336
258337
259
260
338
339
261340
262
341
342
263343
264
344
345
346
347
265348
266349
267
268
269
350
270351
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
289383
290384
291
292
385
386
387
388
293389
294
390
295391
296
297
298
299
300
301
302
303
304
305
392
393
394
395
396
397
398
399
400
401
402
403
404
306405
307406
308
309
407
408
409
410
310411
311
312
313
314
412
413
414
415
315416
316
417
317418
318
319
320
419
420
321421
322
323
324
422
325423
326
327
424
425
426
427
428
429
430
328431
329
330
331
332
333
432
433
434
435
334436
335
336
337
338
339
340
341
342
343
344
345
437
346438
347
348
349
350
351
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
352472
353473
354474
355475
356
357
476
477
478
358479
359
360
480
481
361482
362
363
364
483
484
485
486
365487
366
367
368
369
370
371
372
373
374
375
376
377
378
379
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
380511
381512
382
383
513
514
515
516
384517
385
386
387
388
518
519
520
521
522
523
524
525
389526
390527
391
392
528
393529
394
395
530
531
396532
397533
398
399
534
400535
401
402
403
404
405
536
537
538
539
540
406541
407
408
409
542
543
544
410545
411
412
413
414
415
416
417
418
419
420
421
546
547
548
549
550
551
552
553
554
555
556
557
558
422559
423
560
424561
425562
426
427
563
428564
429
565
430566
431
567
432568
433
434
435
436
437
438
439
440
441
569
570
571
572
573
574
575
576
577
578
579
442580
443581
444
445
582
446583
447
584
448585
449586
450587
451588
452589
453590
454
455
456
457
458
459
460
461
591
592
593
594
595
596
597
598
462599
463
600
464601
465
466
467
468
602
603
604
605
469606
470
471
472
473
607
608
609
610
474611
475
476
477
478
612
613
614
615
479616
480
481
617
618
482619
483
620
484621
485
622
486623
487
624
488625
489
626
490627
491
628
492629
493
630
494631
495
632
496633
497
634
498635
499
500
501
502
636
637
638
639
640
641
642
643
644
645
646
503647
504
505
506
507
508
509
510
648
649
511650
512
513
514
515
516
517
651
652
653
654
655
656
657
658
518659
519
520
521
522
523
524
525
526
527
528
529
530
531
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
532675
533676
534
677
535678
536679
537680
/*
* Copyright (c) 2005 Apple Computer, Inc. All Rights Reserved.
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if 1
/*
Structures for a Flattened Device Tree
*/
#define kPropNameLength 32
typedef struct DeviceTreeNodeProperty {
char name[kPropNameLength]; // NUL terminated property name
unsigned long length; // Length (bytes) of folloing prop value
typedef struct DeviceTreeNodeProperty
{
char name[kPropNameLength]; // NUL terminated property name
unsigned long length; // Length (bytes) of folloing prop value
// unsigned long value[1]; // Variable length value of property
// Padded to a multiple of a longword?
} DeviceTreeNodeProperty;
typedef struct OpaqueDTEntry {
unsigned long nProperties; // Number of props[] elements (0 => end)
unsigned long nChildren; // Number of children[] elements
typedef struct OpaqueDTEntry
{
unsigned long nProperties; // Number of props[] elements (0 => end)
unsigned long nChildren; // Number of children[] elements
// DeviceTreeNodeProperty props[];// array size == nProperties
// DeviceTreeNode children[]; // array size == nChildren
} DeviceTreeNode;
typedef char DTPropertyNameBuf[32];
/* Entry Name Definitions (Entry Names are C-Strings)*/
// Entry Name Definitions (Entry Names are C-Strings).
enum {
kDTMaxEntryNameLength = 31 /* Max length of a C-String Entry Name (terminator not included) */
};
#define RoundToLong(x)(((x) + 3) & ~3)
static struct _DTSizeInfo {
uint32_t numNodes;
uint32_t numProperties;
uint32_t totalPropertySize;
static struct _DTSizeInfo
{
uint32_tnumNodes;
uint32_tnumProperties;
uint32_ttotalPropertySize;
} DTInfo;
#define kAllocSize 4096
static Node *rootNode;
static Node *freeNodes, *allocedNodes;
static Node * freeNodes, *allocedNodes;
static Property *freeProperties, *allocedProperties;
Property *
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
//==============================================================================
Property * DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
{
Property *prop;
Property *prop;
DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value);
if (freeProperties == NULL) {
void *buf = malloc(kAllocSize);
if (buf == 0) return 0;
int i;
DPRINTF("Allocating more free properties\n");
bzero(buf, kAllocSize);
// Use the first property to record the allocated buffer
// for later freeing.
prop = (Property *)buf;
prop->next = allocedProperties;
allocedProperties = prop;
prop->value = buf;
prop++;
for (i=1; i<(kAllocSize / sizeof(Property)); i++) {
prop->next = freeProperties;
freeProperties = prop;
prop++;
}
}
prop = freeProperties;
freeProperties = prop->next;
DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value);
prop->name = name;
prop->length = length;
prop->value = value;
if (freeProperties == NULL)
{
void *buf = malloc(kAllocSize);
int i;
// Always add to end of list
if (node->properties == 0) {
node->properties = prop;
} else {
node->last_prop->next = prop;
}
node->last_prop = prop;
prop->next = 0;
DPRINTF("Allocating more free properties\n");
DPRINTF("Done [0x%x]\n", prop);
DTInfo.numProperties++;
DTInfo.totalPropertySize += RoundToLong(length);
if (buf == 0)
{
return 0;
}
return prop;
bzero(buf, kAllocSize);
// Use the first property to record the allocated buffer
// for later freeing.
prop = (Property *)buf;
prop->next = allocedProperties;
allocedProperties = prop;
prop->value = buf;
prop++;
for (i = 1; i < (kAllocSize / sizeof(Property)); i++)
{
prop->next = freeProperties;
freeProperties = prop;
prop++;
}
}
prop = freeProperties;
freeProperties = prop->next;
prop->name = name;
prop->length = length;
prop->value = value;
// Always add to end of list
if (node->properties == 0)
{
node->properties = prop;
}
else
{
node->last_prop->next = prop;
}
node->last_prop = prop;
prop->next = 0;
DPRINTF("Done [0x%x]\n", prop);
DTInfo.numProperties++;
DTInfo.totalPropertySize += RoundToLong(length);
return prop;
}
Node *
DT__AddChild(Node *parent, const char *name)
//==============================================================================
Node * DT__AddChild(Node *parent, const char *name)
{
Node *node;
Node *node;
if (freeNodes == NULL) {
void *buf = malloc(kAllocSize);
if (buf == 0) return 0;
int i;
DPRINTF("Allocating more free nodes\n");
bzero(buf, kAllocSize);
node = (Node *)buf;
// Use the first node to record the allocated buffer
// for later freeing.
node->next = allocedNodes;
allocedNodes = node;
node->children = (Node *)buf;
node++;
for (i=1; i<(kAllocSize / sizeof(Node)); i++) {
node->next = freeNodes;
freeNodes = node;
node++;
}
}
DPRINTF("DT__AddChild(0x%x, '%s')\n", parent, name);
node = freeNodes;
freeNodes = node->next;
DPRINTF("Got free node 0x%x\n", node);
DPRINTF("prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next);
if (freeNodes == NULL)
{
void *buf = malloc(kAllocSize);
if (parent == NULL) {
rootNode = node;
node->next = 0;
} else {
node->next = parent->children;
parent->children = node;
}
DTInfo.numNodes++;
DT__AddProperty(node, "name", strlen(name) + 1, (void *) name);
return node;
if (buf == 0)
{
return 0;
}
int i;
DPRINTF("Allocating more free nodes\n");
bzero(buf, kAllocSize);
node = (Node *)buf;
// Use the first node to record the allocated buffer for later freeing.
node->next = allocedNodes;
allocedNodes = node;
node->children = (Node *)buf;
node++;
for (i = 1; i < (kAllocSize / sizeof(Node)); i++)
{
node->next = freeNodes;
freeNodes = node;
node++;
}
}
DPRINTF("DT__AddChild(0x%x, '%s')\n", parent, name);
node = freeNodes;
freeNodes = node->next;
DPRINTF("Got free node 0x%x\n", node);
DPRINTF("prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next);
if (parent == NULL)
{
rootNode = node;
node->next = 0;
}
else
{
node->next = parent->children;
parent->children = node;
}
DTInfo.numNodes++;
DT__AddProperty(node, "name", strlen(name) + 1, (void *) name);
return node;
}
void
DT__FreeProperty(Property *prop)
//==============================================================================
void DT__FreeProperty(Property *prop)
{
prop->next = freeProperties;
freeProperties = prop;
prop->next = freeProperties;
freeProperties = prop;
}
void
DT__FreeNode(Node *node)
//==============================================================================
void DT__FreeNode(Node *node)
{
node->next = freeNodes;
freeNodes = node;
node->next = freeNodes;
freeNodes = node;
}
void
DT__Initialize(void)
//==============================================================================
void DT__Initialize(void)
{
DPRINTF("DT__Initialize\n");
freeNodes = 0;
allocedNodes = 0;
freeProperties = 0;
allocedProperties = 0;
DTInfo.numNodes = 0;
DTInfo.numProperties = 0;
DTInfo.totalPropertySize = 0;
rootNode = DT__AddChild(NULL, "/");
DPRINTF("DT__Initialize done\n");
DPRINTF("DT__Initialize\n");
freeNodes = 0;
allocedNodes = 0;
freeProperties = 0;
allocedProperties = 0;
DTInfo.numNodes = 0;
DTInfo.numProperties = 0;
DTInfo.totalPropertySize = 0;
rootNode = DT__AddChild(NULL, "/");
DPRINTF("DT__Initialize done\n");
}
//==============================================================================
/*
* Free up memory used by in-memory representation
* of device tree.
* Free up memory used by in-memory representation of device tree.
*/
void
DT__Finalize(void)
void DT__Finalize(void)
{
Node *node;
Property *prop;
Node *node;
Property *prop;
DPRINTF("DT__Finalize\n");
for (prop = allocedProperties; prop != NULL; prop = prop->next) {
free(prop->value);
}
allocedProperties = NULL;
freeProperties = NULL;
DPRINTF("DT__Finalize\n");
for (node = allocedNodes; node != NULL; node = node->next) {
free((void *)node->children);
}
allocedNodes = NULL;
freeNodes = NULL;
rootNode = NULL;
for (prop = allocedProperties; prop != NULL; prop = prop->next)
{
free(prop->value);
}
allocedProperties = NULL;
freeProperties = NULL;
for (node = allocedNodes; node != NULL; node = node->next)
{
free((void *)node->children);
}
allocedNodes = NULL;
freeNodes = NULL;
rootNode = NULL;
// XXX leaks any created strings
DTInfo.numNodes = 0;
DTInfo.numProperties = 0;
DTInfo.totalPropertySize = 0;
// XXX leaks any created strings
DTInfo.numNodes = 0;
DTInfo.numProperties = 0;
DTInfo.totalPropertySize = 0;
}
static void *
FlattenNodes(Node *node, void *buffer)
//==============================================================================
static void * FlattenNodes(Node *node, void *buffer)
{
Property *prop;
DeviceTreeNode *flatNode;
DeviceTreeNodeProperty *flatProp;
int count;
Property *prop;
DeviceTreeNode *flatNode;
DeviceTreeNodeProperty *flatProp;
int count;
if (node == 0) return buffer;
if (node == 0)
{
return buffer;
}
flatNode = (DeviceTreeNode *)buffer;
buffer += sizeof(DeviceTreeNode);
flatNode = (DeviceTreeNode *)buffer;
buffer += sizeof(DeviceTreeNode);
for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next) {
flatProp = (DeviceTreeNodeProperty *)buffer;
strcpy(flatProp->name, prop->name);
flatProp->length = prop->length;
buffer += sizeof(DeviceTreeNodeProperty);
bcopy(prop->value, buffer, prop->length);
buffer += RoundToLong(prop->length);
}
flatNode->nProperties = count;
for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next)
{
flatProp = (DeviceTreeNodeProperty *)buffer;
strcpy(flatProp->name, prop->name);
flatProp->length = prop->length;
buffer += sizeof(DeviceTreeNodeProperty);
bcopy(prop->value, buffer, prop->length);
buffer += RoundToLong(prop->length);
}
for (count = 0, node = node->children; node != 0; count++, node = node->next) {
buffer = FlattenNodes(node, buffer);
}
flatNode->nChildren = count;
flatNode->nProperties = count;
return buffer;
for (count = 0, node = node->children; node != 0; count++, node = node->next)
{
buffer = FlattenNodes(node, buffer);
}
flatNode->nChildren = count;
return buffer;
}
/*
* Flatten the in-memory representation of the device tree
* into a binary DT block.
/*==============================================================================
* Flatten the in-memory representation of the device tree into a binary DT block.
* To get the buffer size needed, call with result = 0.
* To have a buffer allocated for you, call with *result = 0.
* To use your own buffer, call with *result = &buffer.
*/
void
DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
void DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
{
uint32_t totalSize;
void *buf;
uint32_t totalSize;
void * buf;
DPRINTF("DT__FlattenDeviceTree(0x%x, 0x%x)\n", buffer_p, length);
DPRINTF("DT__FlattenDeviceTree(0x%x, 0x%x)\n", buffer_p, length);
#if DEBUG
if (buffer_p) DT__PrintTree(rootNode);
if (buffer_p)
{
DT__PrintTree(rootNode);
}
#endif
totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) +
DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) +
DTInfo.totalPropertySize;
totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) + DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) + DTInfo.totalPropertySize;
DPRINTF("Total size 0x%x\n", totalSize);
if (buffer_p != 0) {
if (totalSize == 0) {
buf = 0;
} else {
if (*buffer_p == 0) {
buf = malloc(totalSize);
} else {
buf = *buffer_p;
}
bzero(buf, totalSize);
FlattenNodes(rootNode, buf);
}
*buffer_p = buf;
}
if (length)
*length = totalSize;
DPRINTF("Total size 0x%x\n", totalSize);
if (buffer_p != 0)
{
if (totalSize == 0)
{
buf = 0;
}
else
{
if (*buffer_p == 0)
{
buf = malloc(totalSize);
}
else
{
buf = *buffer_p;
}
bzero(buf, totalSize);
FlattenNodes(rootNode, buf);
}
*buffer_p = buf;
}
if (length)
{
*length = totalSize;
}
}
char *
DT__GetName(Node *node)
//==============================================================================
char * DT__GetName(Node *node)
{
Property *prop;
Property *prop;
//DPRINTF("DT__GetName(0x%x)\n", node);
//DPRINTF("Node properties = 0x%x\n", node->properties);
for (prop = node->properties; prop; prop = prop->next) {
//DPRINTF("Prop '%s'\n", prop->name);
if (strcmp(prop->name, "name") == 0) {
return prop->value;
}
}
//DPRINTF("DT__GetName returns 0\n");
return "(null)";
//DPRINTF("DT__GetName(0x%x)\n", node);
//DPRINTF("Node properties = 0x%x\n", node->properties);
for (prop = node->properties; prop; prop = prop->next)
{
//DPRINTF("Prop '%s'\n", prop->name);
if (strcmp(prop->name, "name") == 0)
{
return prop->value;
}
}
//DPRINTF("DT__GetName returns 0\n");
return "(null)";
}
Node *
DT__FindNode(const char *path, bool createIfMissing)
//==============================================================================
Node * DT__FindNode(const char *path, bool createIfMissing)
{
Node *node, *child;
DTPropertyNameBuf nameBuf;
char *bp;
int i;
Node *node, *child;
DTPropertyNameBuf nameBuf;
char *bp;
int i;
DPRINTF("DT__FindNode('%s', %d)\n", path, createIfMissing);
DPRINTF("DT__FindNode('%s', %d)\n", path, createIfMissing);
// Start at root
node = rootNode;
DPRINTF("root = 0x%x\n", rootNode);
// Start at root
node = rootNode;
while (node) {
// Skip leading slash
while (*path == '/') path++;
DPRINTF("root = 0x%x\n", rootNode);
for (i=0, bp = nameBuf; ++i < kDTMaxEntryNameLength && *path && *path != '/'; bp++, path++) *bp = *path;
*bp = '\0';
while (node)
{
// Skip leading slash
while (*path == '/')
{
path++;
}
if (nameBuf[0] == '\0') {
// last path entry
break;
}
DPRINTF("Node '%s'\n", nameBuf);
for (i = 0, bp = nameBuf; ++i < kDTMaxEntryNameLength && *path && *path != '/'; bp++, path++)
{
*bp = *path;
}
for (child = node->children; child != 0; child = child->next) {
DPRINTF("Child 0x%x\n", child);
if (strcmp(DT__GetName(child), nameBuf) == 0) {
break;
}
}
if (child == 0 && createIfMissing) {
DPRINTF("Creating node\n");
char *str = malloc(strlen(nameBuf) + 1);
// XXX this will leak
strcpy(str, nameBuf);
*bp = '\0';
child = DT__AddChild(node, str);
}
node = child;
}
return node;
if (nameBuf[0] == '\0')
{
// last path entry
break;
}
DPRINTF("Node '%s'\n", nameBuf);
for (child = node->children; child != 0; child = child->next)
{
DPRINTF("Child 0x%x\n", child);
if (strcmp(DT__GetName(child), nameBuf) == 0)
{
break;
}
}
if (child == 0 && createIfMissing)
{
DPRINTF("Creating node\n");
char *str = malloc(strlen(nameBuf) + 1);
// XXX this will leak
strcpy(str, nameBuf);
child = DT__AddChild(node, str);
}
node = child;
}
return node;
}
#if DEBUG
void
DT__PrintNode(Node *node, int level)
//==============================================================================
void DT__PrintNode(Node *node, int level)
{
char spaces[10], *cp = spaces;
Property *prop;
char spaces[10], *cp = spaces;
Property *prop;
if (level > 9) level = 9;
while (level--) *cp++ = ' ';
*cp = '\0';
if (level > 9)
{
level = 9;
}
printf("%s===Node===\n", spaces);
for (prop = node->properties; prop; prop = prop->next) {
char c = *((char *)prop->value);
if (prop->length < 64 && (
strcmp(prop->name, "name") == 0 ||
(c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') || c == '_')) {
printf("%s Property '%s' [%d] = '%s'\n", spaces, prop->name, prop->length, prop->value);
} else {
printf("%s Property '%s' [%d] = (data)\n", spaces, prop->name, prop->length);
}
}
printf("%s==========\n", spaces);
while (level--)
{
*cp++ = ' ';
}
*cp = '\0';
printf("%s===Node===\n", spaces);
for (prop = node->properties; prop; prop = prop->next)
{
char c = *((char *)prop->value);
if (prop->length < 64 && (strcmp(prop->name, "name") == 0 || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'))
{
printf("%s Property '%s' [%d] = '%s'\n", spaces, prop->name, prop->length, prop->value);
}
else
{
printf("%s Property '%s' [%d] = (data)\n", spaces, prop->name, prop->length);
}
}
printf("%s==========\n", spaces);
}
static void
_PrintTree(Node *node, int level)
//==============================================================================
static void _PrintTree(Node *node, int level)
{
DT__PrintNode(node, level);
level++;
for (node = node->children; node; node = node->next)
_PrintTree(node, level);
DT__PrintNode(node, level);
level++;
for (node = node->children; node; node = node->next)
{
_PrintTree(node, level);
}
}
void
DT__PrintTree(Node *node)
void DT__PrintTree(Node *node)
{
if (node == 0) node = rootNode;
_PrintTree(node, 0);
if (node == 0) node = rootNode;
_PrintTree(node, 0);
}
void
DT__PrintFlattenedNode(DTEntry entry, int level)
void DT__PrintFlattenedNode(DTEntry entry, int level)
{
char spaces[10], *cp = spaces;
DTPropertyIterator propIter;
char *name;
void *prop;
int propSize;
char spaces[10], *cp = spaces;
DTPropertyIterator propIter;
char *name;
void *prop;
int propSize;
if (level > 9) level = 9;
while (level--) *cp++ = ' ';
*cp = '\0';
if (level > 9) level = 9;
while (level--) *cp++ = ' ';
*cp = '\0';
printf("%s===Entry %p===\n", spaces, entry);
if (kSuccess != DTCreatePropertyIterator(entry, &propIter)) {
printf("Couldn't create property iterator\n");
return;
}
while( kSuccess == DTIterateProperties( propIter, &name)) {
if( kSuccess != DTGetProperty( entry, name, &prop, &propSize ))
continue;
printf("%s Property %s = %s\n", spaces, name, prop);
}
DTDisposePropertyIterator(propIter);
printf("%s===Entry %p===\n", spaces, entry);
if (kSuccess != DTCreatePropertyIterator(entry, &propIter))
{
printf("Couldn't create property iterator\n");
return;
}
while( kSuccess == DTIterateProperties( propIter, &name))
{
if( kSuccess != DTGetProperty( entry, name, &prop, &propSize ))
continue;
printf("%s Property %s = %s\n", spaces, name, prop);
}
DTDisposePropertyIterator(propIter);
printf("%s==========\n", spaces);
printf("%s==========\n", spaces);
}
static void
_PrintFlattenedTree(DTEntry entry, int level)
static void _PrintFlattenedTree(DTEntry entry, int level)
{
DTEntryIterator entryIter;
DTEntryIterator entryIter;
PrintFlattenedNode(entry, level);
PrintFlattenedNode(entry, level);
if (kSuccess != DTCreateEntryIterator(entry, &entryIter)) {
printf("Couldn't create entry iterator\n");
return;
}
level++;
while (kSuccess == DTIterateEntries( entryIter, &entry )) {
_PrintFlattenedTree(entry, level);
}
DTDisposeEntryIterator(entryIter);
if (kSuccess != DTCreateEntryIterator(entry, &entryIter))
{
printf("Couldn't create entry iterator\n");
return;
}
level++;
while (kSuccess == DTIterateEntries( entryIter, &entry ))
{
_PrintFlattenedTree(entry, level);
}
DTDisposeEntryIterator(entryIter);
}
void
DT__PrintFlattenedTree(DTEntry entry)
void DT__PrintFlattenedTree(DTEntry entry)
{
_PrintFlattenedTree(entry, 0);
_PrintFlattenedTree(entry, 0);
}
int
main(int argc, char **argv)
{
DTEntry dtEntry;
DTPropertyIterator propIter;
DTEntryIterator entryIter;
void*prop;
intpropSize;
char*name;
void *flatTree;
uint32_t flatSize;
DTEntrydtEntry;
DTPropertyIteratorpropIter;
DTEntryIteratorentryIter;
void*prop;
intpropSize;
char*name;
void*flatTree;
uint32_tflatSize;
Node *node;
Node *node;
node = AddChild(NULL, "device-tree");
AddProperty(node, "potato", 4, "foo");
AddProperty(node, "chemistry", 4, "bar");
AddProperty(node, "physics", 4, "baz");
node = AddChild(NULL, "device-tree");
AddProperty(node, "potato", 4, "foo");
AddProperty(node, "chemistry", 4, "bar");
AddProperty(node, "physics", 4, "baz");
node = AddChild(node, "dev");
AddProperty(node, "one", 4, "one");
AddProperty(node, "two", 4, "two");
AddProperty(node, "three", 6, "three");
node = AddChild(node, "dev");
AddProperty(node, "one", 4, "one");
AddProperty(node, "two", 4, "two");
AddProperty(node, "three", 6, "three");
node = AddChild(rootNode, "foo");
AddProperty(node, "aaa", 4, "aab");
AddProperty(node, "bbb", 4, "bbc");
AddProperty(node, "cccc", 6, "ccccd");
node = AddChild(rootNode, "foo");
AddProperty(node, "aaa", 4, "aab");
AddProperty(node, "bbb", 4, "bbc");
AddProperty(node, "cccc", 6, "ccccd");
node = FindNode("/this/is/a/test", 1);
AddProperty(node, "dddd", 12, "abcdefghijk");
node = FindNode("/this/is/a/test", 1);
AddProperty(node, "dddd", 12, "abcdefghijk");
printf("In-memory tree:\n\n");
printf("In-memory tree:\n\n");
PrintTree(rootNode);
PrintTree(rootNode);
FlattenDeviceTree(&flatTree, &flatSize);
FlattenDeviceTree(&flatTree, &flatSize);
printf("Flat tree = %p, size %d\n", flatTree, flatSize);
printf("Flat tree = %p, size %d\n", flatTree, flatSize);
dtEntry = (DTEntry)flatTree;
dtEntry = (DTEntry)flatTree;
printf("\n\nPrinting flat tree\n\n");
printf("\n\nPrinting flat tree\n\n");
DTInit(dtEntry);
DTInit(dtEntry);
PrintFlattenedTree((DTEntry)flatTree);
PrintFlattenedTree((DTEntry)flatTree);
#if 0
printf("=== Entry %p ===\n", dtEntry);
if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) {
printf("Couldn't create property iterator\n");
return 1;
printf("=== Entry %p ===\n", dtEntry);
if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter))
{
printf("Couldn't create property iterator\n");
return 1;
}
while( kSuccess == DTIterateProperties( propIter, &name))
{
if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize ))
continue;
printf(" Property %s = %s\n", name, prop);
}
while( kSuccess == DTIterateProperties( propIter, &name)) {
if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize ))
continue;
printf(" Property %s = %s\n", name, prop);
}
DTDisposePropertyIterator(propIter);
printf("========\n");
DTDisposePropertyIterator(propIter);
printf("========\n");
if (kSuccess != DTCreateEntryIterator(dtEntry, &entryIter)) {
printf("Couldn't create entry iterator\n");
return 1;
}
while (kSuccess == DTIterateEntries( entryIter, &dtEntry )) {
printf("=== Entry %p ===\n", dtEntry);
if (kSuccess != DTCreateEntryIterator(dtEntry, &entryIter))
{
printf("Couldn't create entry iterator\n");
return 1;
}
while (kSuccess == DTIterateEntries( entryIter, &dtEntry ))
{
printf("=== Entry %p ===\n", dtEntry);
if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) {
printf("Couldn't create property iterator\n");
return 1;
}
while( kSuccess == DTIterateProperties( propIter, &name)) {
if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize ))
continue;
printf(" Property %s = %s\n", name, prop);
}
DTDisposePropertyIterator(propIter);
printf("========\n");
}
DTDisposeEntryIterator(entryIter);
if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter))
{
printf("Couldn't create property iterator\n");
return 1;
}
while( kSuccess == DTIterateProperties( propIter, &name))
{
if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize ))
continue;
printf(" Property %s = %s\n", name, prop);
}
DTDisposePropertyIterator(propIter);
printf("========\n");
}
DTDisposeEntryIterator(entryIter);
#endif
return 0;
return 0;
}
#endif
branches/ErmaC/Trunk/i386/libsaio/hfs.c
7777
7878
7979
80
81
82
83
80
81
8482
85
86
87
88
89
83
84
9085
9186
9287
93
94
88
9589
96
97
90
9891
9992
10093
......
10598
10699
107100
108
109
101
110102
111103
104
105
112106
113107
114108
......
117111
118112
119113
114
115
116
120117
121118
122119
......
124121
125122
126123
124
125
126
127127
128128
129
130
131
132
129
130
131
132
133133
134134
135135
136
137
136
137
138138
139139
140140
141141
142
143
144
142145
143146
144
145
147
148
146149
147
150
151
148152
149
153
150154
151
152
155
156
153157
154158
155
156
157
158
159
160
161
162
163
159164
160165
161
162
163
164
165
166
167
166
167
168
169
170
171
172
168173
169174
170175
......
177182
178183
179184
180
181
185
186
187
182188
183
184
185
189
190
191
186192
187193
188194
......
194200
195201
196202
197
198
203
199204
200205
201206
202207
203208
204
205
206
207
209
210
211
212
213
208214
209
210
215
216
211217
212218
213219
......
219225
220226
221227
222
223
224
225
226
227
228
229
230
231
232
233
228234
229235
230236
......
248254
249255
250256
251
252
253
254
257
258
259
260
261
255262
256
263
257264
258265
266
267
268
259269
260270
261271
......
267277
268278
269279
270
271
280
281
282
283
284
272285
273286
274
275
276
277
278
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
279312
280
281
282
283
284
313
285314
286
287
288
289
290
291315
292316
293317
......
307331
308332
309333
310
311
312
334
313335
314
315
336
316337
317
338
318339
319
340
341
342
343
320344
321
322
323
324
325
326
327
328
329
330
331
345
346
347
348
332349
333
334
335
336
337
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
338365
339
340
341
366
367
368
369
342370
343
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
344405
345406
346
347
407
408
409
410
348411
349412
350413
......
353416
354417
355418
356
419
420
421
422
357423
358
359
360
424
425
426
361427
362
363
364
428
429
430
365431
366
432
367433
368
434
369435
370
371
436
437
372438
373439
374440
375
376
441
442
443
377444
378
379
380
381
382
445
446
447
448
449
383450
384
451
385452
386
387
388
389
390
391
392
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
393482
394
395
396
397
398
483
399484
400
401
402
403
404
485
486
487
488
489
490
491
492
405493
406
407
408
409
410
411
412494
413
414
415
495
496
497
416498
417
418
499
500
419501
420502
503
504
505
421506
422507
423
424
508
509
425510
511
512
513
426514
427515
428516
517
518
429519
430520
431521
432522
433
434
435
436
437
523
524
525
526
527
438528
439
440
441
442
443
444
445
446
447
529
530
531
532
533
534
535
536
537
538
539
540
448541
449
450
451
452
542
543
544
545
546
453547
454
455
456
548
549
550
551
457552
458
459
460
461
553
554
555
556
557
558
559
462560
463
464
561
465562
466
563
467564
468565
469
470
566
567
568
569
471570
472
473
571
572
474573
475
574
476575
477
478
479
480
481
482
576
577
578
579
580
581
483582
484
485
486
487
488
489
490
583
584
585
586
587
588
491589
492
493
494
495
496
497
498
499
590
591
592
593
594
595
596
597
598
500599
501
502
503
504
505
506
507
508
509
510
511
600
601
602
603
604
605
606
607
608
609
610
512611
513612
514613
......
519618
520619
521620
522
621
523622
524
525
526
527
528
623
624
625
626
627
529628
530
629
630
631
632
633
634
531635
532636
533
534
637
638
639
640
535641
536
537
538
539
642
643
644
645
540646
541
542
543
544
647
648
649
650
651
652
545653
546
547
548
654
549655
550
551
656
657
658
659
660
552661
553
554
555
556
662
557663
558
664
665
559666
560
561
562
563
564
565
667
566668
567
568
569
669
670
671
672
570673
571
572
573
574
575
576
577
578
579
580
674
581675
582
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
583706
584707
585
586
587
708
709
710
711
588712
589
590
591
592
713
714
715
716
593717
594
595
596
597
598
599
600
718
719
720
721
722
723
724
725
726
727
601728
602
603
604
729
730
731
605732
606733
607734
......
613740
614741
615742
616
617
618
743
744
745
746
619747
620748
621
622
623
624
625
626
749
750
751
752
753
754
755
756
627757
628758
629759
630760
631
632
633
761
762
763
764
765
634766
635767
636768
637
769
638770
639
771
640772
641773
642
643
774
775
776
777
644778
645
646
647
648
779
780
781
782
649783
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
784
785
786
787
788
665789
666
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
667812
668813
814
815
816
669817
670818
671
672
673
819
820
821
674822
675
676
677
678
679
680
681
682
683
684
823
824
825
826
827
828
829
830
831
832
833
834
835
685836
686
837
687838
688839
840
841
842
689843
690844
691
692
693
694
695
696
697
698
845
846
847
848
849
850
851
852
699853
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
720883
721
722
723
724
725
726
727
728
729
730
731
884
885
886
887
888
732889
733
734
735
736
890
891
892
893
894
737895
738
739
740
741
896
897
898
899
742900
743
744
745
746
747
901
902
903
904
748905
749
906
907
908
750909
751
752
753
754
755
756
757
758
759
760
761
762
763
910
911
912
764913
765
766
767
768
914
769915
770
771
772
773
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
774958
775
776
777
778
779
959
960
961
962
963
964
965
966
967
968
780969
781
782
970
971
972
973
974
975
783976
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
7991010
800
1011
8011012
802
803
804
805
806
807
808
809
810
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
8111024
812
1025
8131026
814
1027
8151028
8161029
817
818
1030
1031
1032
1033
8191034
820
821
1035
1036
8221037
823
824
825
826
827
828
829
830
831
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
8321050
8331051
834
835
836
1052
1053
1054
1055
8371056
8381057
8391058
......
8431062
8441063
8451064
846
1065
1066
1067
1068
8471069
8481070
8491071
......
8571079
8581080
8591081
1082
8601083
8611084
8621085
......
8791102
8801103
8811104
882
1105
1106
1107
1108
1109
8831110
8841111
8851112
1113
8861114
8871115
8881116
......
9001128
9011129
9021130
903
904
1131
9051132
9061133
9071134
908
1135
1136
1137
1138
9091139
9101140
9111141
912
913
1142
9141143
9151144
9161145
9171146
9181147
9191148
920
1149
1150
1151
1152
9211153
9221154
9231155
9241156
1157
1158
1159
9251160
9261161
927
928
929
1162
9301163
931
932
1164
1165
9331166
1167
1168
1169
1170
1171
1172
1173
1174
1175
9341176
9351177
9361178
1179
1180
1181
9371182
9381183
939
1184
9401185
9411186
9421187
943
944
1188
1189
1190
1191
1192
1193
1194
1195
9451196
9461197
9471198
9481199
1200
1201
1202
9491203
9501204
9511205
952
1206
9531207
9541208
9551209
......
9581212
9591213
9601214
961
962
1215
1216
1217
1218
1219
1220
1221
1222
9631223
9641224
9651225
......
9691229
9701230
9711231
1232
1233
1234
9721235
9731236
9741237
975
1238
9761239
9771240
9781241
......
9811244
9821245
9831246
984
985
1247
1248
1249
1250
1251
1252
1253
1254
9861255
9871256
9881257
9891258
990
991
992
9931259
1260
1261
1262
1263
9941264
9951265
9961266
......
10081278
10091279
10101280
1281
1282
1283
10111284
10121285
1013
1014
1286
1287
10151288
1016
1017
1289
1290
10181291
1019
1020
1292
1293
10211294
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
10431332
1044
1333
10451334
10461335
1336
1337
1338
10471339
10481340
1049
1050
1341
10511342
1052
1053
1343
10541344
1055
1056
1345
1346
10571347
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
10791385
1080
1386
10811387
10821388
#endif /* !__i386__ */
static long ReadFile(void *file, uint64_t *length, void *base, uint64_t offset);
static long GetCatalogEntryInfo(void *entry, long *flags, long *time,
FinderInfo *finderInfo, long *infoValid);
static long ResolvePathToCatalogEntry(char *filePath, long *flags,
void *entry, long dirID, long long *dirIndex);
static long GetCatalogEntryInfo(void *entry, long *flags, long *time, FinderInfo *finderInfo, long *infoValid);
static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry, long dirID, long long *dirIndex);
static long GetCatalogEntry(long long *dirIndex, char **name,
long *flags, long *time,
FinderInfo *finderInfo, long *infoValid);
static long ReadCatalogEntry(char *fileName, long dirID, void *entry,
long long *dirIndex);
static long GetCatalogEntry(long long *dirIndex, char **name, long *flags, long *time, FinderInfo *finderInfo, long *infoValid);
static long ReadCatalogEntry(char *fileName, long dirID, void *entry, long long *dirIndex);
static long ReadExtentsEntry(long fileID, long startBlock, void *entry);
static long ReadBTreeEntry(long btree, void *key, char *entry, long long *dirIndex);
static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize,
char **key, char **data);
static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize, char **key, char **data);
static long ReadExtent(char *extent, uint64_t extentSize, long extentFile,
uint64_t offset, uint64_t size, void *buffer, long cache);
static long ReadExtent(char *extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void *buffer, long cache);
static long GetExtentStart(void *extents, long index);
static long GetExtentSize(void *extents, long index);
static long CompareHFSPlusExtentsKeys(void *key, void *testKey);
extern long FastRelString(u_int8_t *str1, u_int8_t *str2);
extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1,
u_int16_t *uniStr2, u_int32_t len2);
extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1, u_int16_t *uniStr2, u_int32_t len2);
//==============================================================================
static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src)
{
dst->fdType = SWAP_BE32(src->fdType);
// Don't bother with location
}
//==============================================================================
void HFSFree(CICell ih)
{
if(gCurrentIH == ih)
free(ih);
}
//==============================================================================
bool HFSProbe (const void *buf)
{
const HFSMasterDirectoryBlock *mdb;
const HFSPlusVolumeHeader *header;
mdb=(const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset);
header=(const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);
const HFSMasterDirectoryBlock *mdb;
const HFSPlusVolumeHeader *header;
mdb = (const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset);
header = (const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);
if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord )
return true;
if (SWAP_BE16(header->signature) != kHFSPlusSigWord &&
SWAP_BE16(header->signature) != kHFSXSigWord)
if (SWAP_BE16(header->signature) != kHFSPlusSigWord && SWAP_BE16(header->signature) != kHFSXSigWord)
return false;
return true;
}
//==============================================================================
long HFSInitPartition(CICell ih)
{
long extentSize, extentFile, nodeSize;
void *extent;
long extentSize, extentFile, nodeSize;
void *extent;
if (ih == gCurrentIH) {
if (ih == gCurrentIH)
{
#ifdef __i386__
CacheInit(ih, gCacheBlockSize);
CacheInit(ih, gCacheBlockSize);
#endif
return 0;
}
return 0;
}
#ifdef __i386__
if (!gTempStr) gTempStr = (char *)malloc(4096);
if (!gLinkTemp) gLinkTemp = (char *)malloc(64);
if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)malloc(512);
if (!gHFSMdbVib) {
if (!gTempStr) gTempStr = (char *)malloc(4096);
if (!gLinkTemp) gLinkTemp = (char *)malloc(64);
if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)malloc(512);
if (!gHFSMdbVib)
{
gHFSMdbVib = (char *)malloc(kBlockSize);
gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib;
}
if (!gHFSPlusHeader) {
gHFSPlusHeader = (char *)malloc(kBlockSize);
gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader;
}
if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer ||
!gHFSMdbVib || !gHFSPlusHeader) return -1;
}
if (!gHFSPlusHeader)
{
gHFSPlusHeader = (char *)malloc(kBlockSize);
gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader;
}
if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || !gHFSMdbVib || !gHFSPlusHeader) return -1;
#endif /* __i386__ */
gAllocationOffset = 0;
Seek(ih, kMDBBaseOffset);
Read(ih, (long)gHFSMdbVib, kBlockSize);
if ( SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord ) {
gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize;
if (SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord)
{
gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize;
// See if it is HFSPlus
if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord) {
// Normal HFS;
// See if it is HFSPlus
if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord) {
// Normal HFS;
gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSMDB->drAlBlkSiz);
CacheInit(ih, gCacheBlockSize);
gCurrentIH = ih;
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
extentFile = kHFSCatalogFileID;
ReadExtent(extent, extentSize, extentFile, 0, 256,
gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);
ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);
nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 +
sizeof(BTNodeDescriptor)))->nodeSize);
// If the BTree node size is larger than the block size, reset the cache.
if (nodeSize > gBlockSize) {
gCacheBlockSize = nodeSize;
CacheInit(ih, gCacheBlockSize);
}
if (nodeSize > gBlockSize)
{
gCacheBlockSize = nodeSize;
CacheInit(ih, gCacheBlockSize);
}
return 0;
}
return 0;
}
// Calculate the offset to the embeded HFSPlus volume.
gAllocationOffset += (long long)SWAP_BE16(gHFSMDB->drEmbedExtent.startBlock) *
Read(ih, (long)gHFSPlusHeader, kBlockSize);
// Not a HFS+ or HFSX volume.
if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord &&
SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord) {
verbose("HFS signature was not present.\n");
gCurrentIH = 0;
return -1;
}
if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord && SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord)
{
verbose("HFS signature was not present.\n");
gCurrentIH = 0;
return -1;
}
gIsHFSPlus = 1;
gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSPlus->blockSize);
sizeof(BTNodeDescriptor)))->nodeSize);
// If the BTree node size is larger than the block size, reset the cache.
if (nodeSize > gBlockSize) {
gCacheBlockSize = nodeSize;
CacheInit(ih, gCacheBlockSize);
}
if (nodeSize > gBlockSize)
{
gCacheBlockSize = nodeSize;
CacheInit(ih, gCacheBlockSize);
}
return 0;
return 0;
}
//==============================================================================
long HFSLoadFile(CICell ih, char * filePath)
{
return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
char devStr[12];
long dirID, result, flags =0;
if (HFSInitPartition(ih) == -1) return -1;
if (HFSInitPartition(ih) == -1)
{
return -1;
}
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (filePath[0] == '/') {
if (filePath[1] == '/') {
if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);
else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
if (dirID == 0) {
if (filePath[0] == '/')
{
if (filePath[1] == '/')
{
if (gIsHFSPlus)
{
dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);
}
else
{
dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
}
if (dirID == 0)
{
return -1;
}
filePath++;
}
filePath++;
}
result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
return -1;
}
filePath++;
}
filePath++;
}
}
result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
return -1;
}
#if UNUSED
// Not yet for Intel. System.config/Default.table will fail this check.
// Check file owner and permissions.
return length;
}
long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name,
long * flags, long * time,
FinderInfo * finderInfo, long * infoValid)
long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)
{
char entry[512];
long dirID, dirFlags = 0;
char entry[512];
if (HFSInitPartition(ih) == -1) return -1;
long dirID, dirFlags = 0;
if (*dirIndex == -1) return -1;
if (HFSInitPartition(ih) == -1)
{
return -1;
}
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (dirPath[0] == '/') {
if (dirPath[1] == '/') {
if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);
else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
if (dirID == 0) return -1;
dirPath++;
}
dirPath++;
}
if (*dirIndex == -1)
{
return -1;
}
if (*dirIndex == 0) {
ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex);
if (*dirIndex == 0) *dirIndex = -1;
if ((dirFlags & kFileTypeMask) != kFileTypeUnknown) return -1;
}
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (dirPath[0] == '/')
{
if (dirPath[1] == '/')
{
if (gIsHFSPlus)
{
dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);
}
else
{
dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
}
GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid);
if (*dirIndex == 0) *dirIndex = -1;
if ((*flags & kFileTypeMask) == kFileTypeUnknown) return -1;
if (dirID == 0)
{
return -1;
}
return 0;
dirPath++;
}
dirPath++;
}
if (*dirIndex == 0)
{
ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex);
if (*dirIndex == 0)
{
*dirIndex = -1;
}
if ((dirFlags & kFileTypeMask) != kFileTypeUnknown)
{
return -1;
}
}
GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid);
if (*dirIndex == 0)
{
*dirIndex = -1;
}
if ((*flags & kFileTypeMask) == kFileTypeUnknown)
{
return -1;
}
return 0;
}
void
HFSGetDescription(CICell ih, char *str, long strMaxLen)
//==============================================================================
void HFSGetDescription(CICell ih, char *str, long strMaxLen)
{
UInt16 nodeSize;
char *name;
long flags =0, time;
if (HFSInitPartition(ih) == -1) { return; }
if (HFSInitPartition(ih) == -1)
{
return;
}
/* Fill some crucial data structures by side effect. */
dirIndex = 0;
HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0);
/* Fill some crucial data structures by side effect. */
dirIndex = 0;
HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0);
/* Now we can loook up the volume name node. */
nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);
firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode);
/* Now we can loook up the volume name node. */
nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);
firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode);
dirIndex = (long long) firstLeafNode * nodeSize;
dirIndex = (long long) firstLeafNode * nodeSize;
GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0);
GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0);
strncpy(str, name, strMaxLen);
str[strMaxLen] = '\0';
strncpy(str, name, strMaxLen);
str[strMaxLen] = '\0';
}
long
HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)
//==============================================================================
long HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)
{
char entry[512];
long dirID, result, flags =0;
void *extents;
HFSCatalogFile *hfsFile = (void *)entry;
HFSPlusCatalogFile *hfsPlusFile = (void *)entry;
char entry[512];
long dirID, result, flags =0;
void *extents;
HFSCatalogFile *hfsFile = (void *)entry;
HFSPlusCatalogFile *hfsPlusFile = (void *)entry;
if (HFSInitPartition(ih) == -1) return -1;
if (HFSInitPartition(ih) == -1) return -1;
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (filePath[0] == '/') {
if (filePath[1] == '/') {
if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);
else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
if (dirID == 0) {
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (filePath[0] == '/')
{
if (filePath[1] == '/')
{
if (gIsHFSPlus)
{
dirID = SWAP_BE32(((long *) gHFSPlus->finderInfo)[5]);
}
else
{
dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);
}
if (dirID == 0)
{
return -1;
}
filePath++;
}
filePath++;
}
result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
printf("HFS: Resolve path %s failed\n", filePath);
return -1;
}
filePath++;
}
filePath++;
}
}
result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
printf("HFS: Resolve path %s failed\n", filePath);
return -1;
}
if (gIsHFSPlus)
{
extents = &hfsPlusFile->dataFork.extents;
}
else
{
extents = &hfsFile->dataExtents;
}
if (gIsHFSPlus) {
extents = &hfsPlusFile->dataFork.extents;
} else {
extents = &hfsFile->dataExtents;
}
#if DEBUG
printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0));
printf("block size 0x%x\n", (unsigned long)gBlockSize);
printf("Allocation offset 0x%x\n", (unsigned long)gAllocationOffset);
printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0));
printf("block size 0x%x\n", (unsigned long)gBlockSize);
printf("Allocation offset 0x%x\n", (unsigned long)gAllocationOffset);
#endif
*firstBlock = ((unsigned long long)GetExtentStart(extents, 0) * (unsigned long long) gBlockSize + gAllocationOffset) / 512ULL;
return 0;
*firstBlock = ((unsigned long long)GetExtentStart(extents, 0) * (unsigned long long) gBlockSize + gAllocationOffset) / 512ULL;
return 0;
}
//==============================================================================
long HFSGetUUID(CICell ih, char *uuidStr)
{
if (HFSInitPartition(ih) == -1) return -1;
if (gVolID == 0LL) return -1;
if (HFSInitPartition(ih) == -1)
return -1;
if (gVolID == 0LL)
return -1;
return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr);
}
//==============================================================================
// Private Functions
static long ReadFile(void * file, uint64_t * length, void * base, uint64_t offset)
{
void *extents;
long fileID;
uint64_t fileLength;
HFSCatalogFile *hfsFile = file;
HFSPlusCatalogFile *hfsPlusFile = file;
void*extents;
longfileID;
uint64_tfileLength;
HFSCatalogFile*hfsFile = file;
HFSPlusCatalogFile*hfsPlusFile = file;
if (gIsHFSPlus) {
fileID = SWAP_BE32(hfsPlusFile->fileID);
fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize);
extents = &hfsPlusFile->dataFork.extents;
} else {
fileID = SWAP_BE32(hfsFile->fileID);
fileLength = SWAP_BE32(hfsFile->dataLogicalSize);
extents = &hfsFile->dataExtents;
}
if (gIsHFSPlus)
{
fileID = SWAP_BE32(hfsPlusFile->fileID);
fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize);
extents = &hfsPlusFile->dataFork.extents;
}
else
{
fileID = SWAP_BE32(hfsFile->fileID);
fileLength = SWAP_BE32(hfsFile->dataLogicalSize);
extents = &hfsFile->dataExtents;
}
if (offset > fileLength) {
printf("Offset is too large.\n");
return -1;
}
if (offset > fileLength)
{
printf("Offset is too large.\n");
return -1;
}
if ((*length == 0) || ((offset + *length) > fileLength)) {
*length = fileLength - offset;
}
if ((*length == 0) || ((offset + *length) > fileLength))
{
*length = fileLength - offset;
}
/* if (*length > kLoadSize) {
printf("File is too large.\n");
return -1;
}*/
/*
if (*length > kLoadSize)
{
printf("File is too large.\n");
return -1;
}
*/
*length = ReadExtent((char *)extents, fileLength, fileID,
offset, *length, (char *)base, 0);
*length = ReadExtent((char *)extents, fileLength, fileID, offset, *length, (char *)base, 0);
return 0;
return 0;
}
static long GetCatalogEntryInfo(void * entry, long * flags, long * time,
FinderInfo * finderInfo, long * infoValid)
//==============================================================================
static long GetCatalogEntryInfo(void * entry, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)
{
long tmpTime = 0;
long valid = 0;
long tmpTime = 0;
long valid = 0;
// Get information about the file.
// Get information about the file.
switch ( SWAP_BE16(*(short *)entry) )
{
case kHFSFolderRecord :
*flags = kFileTypeDirectory;
tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate);
break;
switch (SWAP_BE16(*(short *)entry))
{
case kHFSFolderRecord :
*flags = kFileTypeDirectory;
tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate);
break;
case kHFSPlusFolderRecord :
*flags = kFileTypeDirectory |
(SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask);
if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0)
*flags |= kOwnerNotRoot;
tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate);
break;
case kHFSPlusFolderRecord :
*flags = kFileTypeDirectory | (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask);
if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0)
*flags |= kOwnerNotRoot;
tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate);
break;
case kHFSFileRecord :
*flags = kFileTypeFlat;
tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate);
if (finderInfo) {
SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo);
valid = 1;
}
break;
case kHFSFileRecord :
*flags = kFileTypeFlat;
tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate);
if (finderInfo)
{
SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo);
valid = 1;
}
break;
case kHFSPlusFileRecord :
*flags = kFileTypeFlat |
(SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask);
if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0)
*flags |= kOwnerNotRoot;
tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate);
if (finderInfo) {
SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo);
valid = 1;
}
break;
case kHFSPlusFileRecord :
*flags = kFileTypeFlat | (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask);
if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0)
*flags |= kOwnerNotRoot;
tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate);
if (finderInfo)
{
SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo);
valid = 1;
}
break;
case kHFSFileThreadRecord :
case kHFSPlusFileThreadRecord :
break;
default:
break;
}
}
if (time != 0) {
// Convert base time from 1904 to 1970.
*time = tmpTime - 2082844800;
}
if (infoValid) *infoValid = valid;
if (time != 0)
{
// Convert base time from 1904 to 1970.
*time = tmpTime - 2082844800;
}
return 0;
if (infoValid)
{
*infoValid = valid;
}
return 0;
}
static long ResolvePathToCatalogEntry(char * filePath, long * flags,
void * entry, long dirID, long long * dirIndex)
//==============================================================================
static long ResolvePathToCatalogEntry(char * filePath, long * flags, void * entry, long dirID, long long * dirIndex)
{
char *restPath;
long result, cnt, subFolderID = 0;
long long tmpDirIndex;
HFSPlusCatalogFile *hfsPlusFile;
char*restPath;
longresult, cnt, subFolderID = 0;
long longtmpDirIndex;
HFSPlusCatalogFile*hfsPlusFile;
// Copy the file name to gTempStr
cnt = 0;
while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) cnt++;
strlcpy(gTempStr, filePath, cnt+1);
// Copy the file name to gTempStr
cnt = 0;
while ((filePath[cnt] != '/') && (filePath[cnt] != '\0'))
{
cnt++;
}
// Move restPath to the right place.
if (filePath[cnt] != '\0') cnt++;
restPath = filePath + cnt;
strlcpy(gTempStr, filePath, cnt+1);
// gTempStr is a name in the current Dir.
// restPath is the rest of the path if any.
// Move restPath to the right place.
if (filePath[cnt] != '\0')
{
cnt++;
}
result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex);
if (result == -1) {
return -1;
}
restPath = filePath + cnt;
GetCatalogEntryInfo(entry, flags, 0, 0, 0);
// gTempStr is a name in the current Dir.
// restPath is the rest of the path if any.
if ((*flags & kFileTypeMask) == kFileTypeDirectory) {
if (gIsHFSPlus)
subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID);
else
subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID);
}
result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex);
if ((*flags & kFileTypeMask) == kFileTypeDirectory)
result = ResolvePathToCatalogEntry(restPath, flags, entry,
subFolderID, dirIndex);
if (result == -1)
{
return -1;
}
if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat)) {
hfsPlusFile = (HFSPlusCatalogFile *)entry;
if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) &&
(SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator)) {
sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER,
HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum));
result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry,
kHFSRootFolderID, &tmpDirIndex);
}
}
GetCatalogEntryInfo(entry, flags, 0, 0, 0);
return result;
if ((*flags & kFileTypeMask) == kFileTypeDirectory)
{
if (gIsHFSPlus)
{
subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID);
}
else
{
subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID);
}
}
if ((*flags & kFileTypeMask) == kFileTypeDirectory)
{
result = ResolvePathToCatalogEntry(restPath, flags, entry, subFolderID, dirIndex);
}
if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat))
{
hfsPlusFile = (HFSPlusCatalogFile *)entry;
if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) &&
(SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator))
{
sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum));
result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, kHFSRootFolderID, &tmpDirIndex);
}
}
return result;
}
static long GetCatalogEntry(long long * dirIndex, char ** name,
long * flags, long * time,
FinderInfo * finderInfo, long * infoValid)
//==============================================================================
static long GetCatalogEntry(long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)
{
long extentSize, nodeSize, curNode, index;
void *extent;
char *nodeBuf, *testKey, *entry;
BTNodeDescriptor *node;
long extentSize, nodeSize, curNode, index;
void *extent;
char *nodeBuf, *testKey, *entry;
BTNodeDescriptor *node;
if (gIsHFSPlus) {
extent = &gHFSPlus->catalogFile.extents;
extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);
} else {
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
}
if (gIsHFSPlus)
{
extent = &gHFSPlus->catalogFile.extents;
extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);
}
else
{
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
}
nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
node = (BTNodeDescriptor *)nodeBuf;
nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
node = (BTNodeDescriptor *)nodeBuf;
index = (long) (*dirIndex % nodeSize);
curNode = (long) (*dirIndex / nodeSize);
GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid);
// Get the file name.
if (gIsHFSPlus) {
utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode,
// Get the file name.
if (gIsHFSPlus)
{
utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode,
SWAP_BE16(((HFSPlusCatalogKey *)testKey)->nodeName.length),
(u_int8_t *)gTempStr, 256, OSBigEndian);
} else {
strncpy(gTempStr,
(const char *)&((HFSCatalogKey *)testKey)->nodeName[1],
((HFSCatalogKey *)testKey)->nodeName[0]);
gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0';
}
}
else
{
strncpy(gTempStr, (const char *)&((HFSCatalogKey *)testKey)->nodeName[1],
((HFSCatalogKey *)testKey)->nodeName[0]);
gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0';
}
*name = gTempStr;
// Update dirIndex.
index++;
if (index == SWAP_BE16(node->numRecords)) {
index = 0;
curNode = SWAP_BE32(node->fLink);
if (index == SWAP_BE16(node->numRecords))
{
index = 0;
curNode = SWAP_BE32(node->fLink);
}
*dirIndex = (long long) curNode * nodeSize + index;
free(nodeBuf);
free(nodeBuf);
return 0;
return 0;
}
static long ReadCatalogEntry(char * fileName, long dirID,
void * entry, long long * dirIndex)
//==============================================================================
static long ReadCatalogEntry(char * fileName, long dirID, void * entry, long long * dirIndex)
{
long length;
char key[sizeof(HFSPlusCatalogKey)];
HFSCatalogKey *hfsKey = (HFSCatalogKey *)key;
HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key;
long length;
char key[sizeof(HFSPlusCatalogKey)];
HFSCatalogKey *hfsKey = (HFSCatalogKey *)key;
HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key;
// Make the catalog key.
if ( gIsHFSPlus )
{
hfsPlusKey->parentID = SWAP_BE32(dirID);
length = strlen(fileName);
if (length > 255) length = 255;
utf_decodestr((u_int8_t *)fileName, hfsPlusKey->nodeName.unicode,
&(hfsPlusKey->nodeName.length), 512, OSBigEndian);
} else {
hfsKey->parentID = SWAP_BE32(dirID);
length = strlen(fileName);
if (length > 31) length = 31;
hfsKey->nodeName[0] = length;
strncpy((char *)(hfsKey->nodeName + 1), fileName, length);
}
// Make the catalog key.
if (gIsHFSPlus)
{
hfsPlusKey->parentID = SWAP_BE32(dirID);
length = strlen(fileName);
return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex);
if (length > 255)
{
length = 255;
}
utf_decodestr((u_int8_t *)fileName, hfsPlusKey->nodeName.unicode, &(hfsPlusKey->nodeName.length), 512, OSBigEndian);
}
else
{
hfsKey->parentID = SWAP_BE32(dirID);
length = strlen(fileName);
if (length > 31)
{
length = 31;
}
hfsKey->nodeName[0] = length;
strncpy((char *)(hfsKey->nodeName + 1), fileName, length);
}
return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex);
}
//==============================================================================
static long ReadExtentsEntry(long fileID, long startBlock, void * entry)
{
char key[sizeof(HFSPlusExtentKey)];
HFSExtentKey *hfsKey = (HFSExtentKey *)key;
HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key;
char key[sizeof(HFSPlusExtentKey)];
HFSExtentKey *hfsKey = (HFSExtentKey *)key;
HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key;
// Make the extents key.
if (gIsHFSPlus) {
hfsPlusKey->forkType = 0;
hfsPlusKey->fileID = SWAP_BE32(fileID);
hfsPlusKey->startBlock = SWAP_BE32(startBlock);
} else {
hfsKey->forkType = 0;
hfsKey->fileID = SWAP_BE32(fileID);
hfsKey->startBlock = SWAP_BE16(startBlock);
}
// Make the extents key.
if (gIsHFSPlus)
{
hfsPlusKey->forkType = 0;
hfsPlusKey->fileID = SWAP_BE32(fileID);
hfsPlusKey->startBlock = SWAP_BE32(startBlock);
}
else
{
hfsKey->forkType = 0;
hfsKey->fileID = SWAP_BE32(fileID);
hfsKey->startBlock = SWAP_BE16(startBlock);
}
return ReadBTreeEntry(kBTreeExtents, &key, entry, 0);
return ReadBTreeEntry(kBTreeExtents, &key, entry, 0);
}
//==============================================================================
static long ReadBTreeEntry(long btree, void * key, char * entry, long long * dirIndex)
{
long extentSize;
void *extent;
short extentFile;
char *nodeBuf;
BTNodeDescriptor *node;
long nodeSize, result = 0, entrySize = 0;
long curNode, index = 0, lowerBound, upperBound;
char *testKey, *recordData =0;
long extentSize;
void *extent;
short extentFile;
char *nodeBuf;
BTNodeDescriptor *node;
long nodeSize, result = 0, entrySize = 0;
long curNode, index = 0, lowerBound, upperBound;
char *testKey, *recordData =0;
// Figure out which tree is being looked at.
if (btree == kBTreeCatalog) {
if (gIsHFSPlus) {
extent = &gHFSPlus->catalogFile.extents;
extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);
} else {
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
}
extentFile = kHFSCatalogFileID;
} else {
if (gIsHFSPlus) {
extent = &gHFSPlus->extentsFile.extents;
extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize);
} else {
extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drXTFlSize);
}
extentFile = kHFSExtentsFileID;
}
// Figure out which tree is being looked at.
if (btree == kBTreeCatalog)
{
if (gIsHFSPlus)
{
extent = &gHFSPlus->catalogFile.extents;
extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);
}
else
{
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
}
extentFile = kHFSCatalogFileID;
}
else
{
if (gIsHFSPlus)
{
extent = &gHFSPlus->extentsFile.extents;
extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize);
}
else
{
extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec;
extentSize = SWAP_BE32(gHFSMDB->drXTFlSize);
}
extentFile = kHFSExtentsFileID;
}
// Read the BTree Header if needed.
if (gBTHeaders[btree] == 0) {
ReadExtent(extent, extentSize, extentFile, 0, 256,
gBTreeHeaderBuffer + btree * 256, 0);
gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 +
sizeof(BTNodeDescriptor));
if ((gIsHFSPlus && btree == kBTreeCatalog) &&
(gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare)) {
gCaseSensitive = 1;
}
}
// Read the BTree Header if needed.
if (gBTHeaders[btree] == 0)
{
ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + btree * 256, 0);
gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + sizeof(BTNodeDescriptor));
curNode = SWAP_BE32(gBTHeaders[btree]->rootNode);
nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
node = (BTNodeDescriptor *)nodeBuf;
if ((gIsHFSPlus && btree == kBTreeCatalog) && (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare))
{
gCaseSensitive = 1;
}
}
while (1) {
// Read the current node.
ReadExtent(extent, extentSize, extentFile,
(long long) curNode * nodeSize, nodeSize, nodeBuf, 1);
curNode = SWAP_BE32(gBTHeaders[btree]->rootNode);
nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
node = (BTNodeDescriptor *)nodeBuf;
// Find the matching key.
lowerBound = 0;
upperBound = SWAP_BE16(node->numRecords) - 1;
while (lowerBound <= upperBound) {
index = (lowerBound + upperBound) / 2;
while (1)
{
// Read the current node.
ReadExtent(extent, extentSize, extentFile, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1);
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
// Find the matching key.
lowerBound = 0;
upperBound = SWAP_BE16(node->numRecords) - 1;
if (gIsHFSPlus) {
if (btree == kBTreeCatalog) {
result = CompareHFSPlusCatalogKeys(key, testKey);
} else {
result = CompareHFSPlusExtentsKeys(key, testKey);
}
} else {
if (btree == kBTreeCatalog) {
result = CompareHFSCatalogKeys(key, testKey);
} else {
result = CompareHFSExtentsKeys(key, testKey);
}
}
while (lowerBound <= upperBound)
{
index = (lowerBound + upperBound) / 2;
if (result < 0) upperBound = index - 1; // search < trial
else if (result > 0) lowerBound = index + 1; // search > trial
else break; // search = trial
}
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
if (result < 0) {
index = upperBound;
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
}
if (gIsHFSPlus)
{
if (btree == kBTreeCatalog)
{
result = CompareHFSPlusCatalogKeys(key, testKey);
}
else
{
result = CompareHFSPlusExtentsKeys(key, testKey);
}
}
else
{
if (btree == kBTreeCatalog)
{
result = CompareHFSCatalogKeys(key, testKey);
}
else
{
result = CompareHFSExtentsKeys(key, testKey);
}
}
if (result < 0)
{
upperBound = index - 1;// search < trial
}
else if (result > 0)
{
lowerBound = index + 1;// search > trial
}
else
{
break;// search = trial
}
}
if (result < 0)
{
index = upperBound;
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
}
// Found the closest key... Recurse on it if this is an index node.
if (node->kind == kBTIndexNode) {
curNode = SWAP_BE32( *((long *)recordData) );
} else break;
}
// Found the closest key... Recurse on it if this is an index node.
if (node->kind == kBTIndexNode)
{
curNode = SWAP_BE32( *((long *)recordData) );
}
else
{
break;
}
}
// Return error if the file was not found.
if (result != 0) { free(nodeBuf); return -1; }
// Return error if the file was not found.
if (result != 0)
{
free(nodeBuf);
return -1;
}
if (btree == kBTreeCatalog) {
switch (SWAP_BE16(*(short *)recordData)) {
case kHFSFolderRecord : entrySize = 70; break;
case kHFSFileRecord : entrySize = 102; break;
case kHFSFolderThreadRecord : entrySize = 46; break;
case kHFSFileThreadRecord : entrySize = 46; break;
case kHFSPlusFolderRecord : entrySize = 88; break;
case kHFSPlusFileRecord : entrySize = 248; break;
case kHFSPlusFolderThreadRecord : entrySize = 264; break;
case kHFSPlusFileThreadRecord : entrySize = 264; break;
}
} else {
if (gIsHFSPlus) entrySize = sizeof(HFSPlusExtentRecord);
else entrySize = sizeof(HFSExtentRecord);
}
if (btree == kBTreeCatalog)
{
switch (SWAP_BE16(*(short *)recordData))
{
case kHFSFolderRecord : entrySize = 70;
break;
case kHFSFileRecord : entrySize = 102;
break;
case kHFSFolderThreadRecord : entrySize = 46;
break;
case kHFSFileThreadRecord : entrySize = 46;
break;
case kHFSPlusFolderRecord : entrySize = 88;
break;
case kHFSPlusFileRecord : entrySize = 248;
break;
case kHFSPlusFolderThreadRecord : entrySize = 264;
break;
case kHFSPlusFileThreadRecord : entrySize = 264;
break;
}
}
else
{
if (gIsHFSPlus)
{
entrySize = sizeof(HFSPlusExtentRecord);
}
else
{
entrySize = sizeof(HFSExtentRecord);
}
}
bcopy(recordData, entry, entrySize);
bcopy(recordData, entry, entrySize);
// Update dirIndex.
if (dirIndex != 0) {
index++;
if (index == SWAP_BE16(node->numRecords)) {
index = 0;
curNode = SWAP_BE32(node->fLink);
}
*dirIndex = (long long) curNode * nodeSize + index;
}
// Update dirIndex.
if (dirIndex != 0)
{
index++;
if (index == SWAP_BE16(node->numRecords))
{
index = 0;
curNode = SWAP_BE32(node->fLink);
}
*dirIndex = (long long) curNode * nodeSize + index;
}
free(nodeBuf);
free(nodeBuf);
return 0;
return 0;
}
static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize,
char ** key, char ** data)
//==============================================================================
static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize, char ** key, char ** data)
{
long keySize;
long recordOffset;
long keySize;
long recordOffset;
recordOffset = SWAP_BE16(*((short *)(nodeBuffer + (nodeSize - 2 * index - 2))));
*key = nodeBuffer + recordOffset;
if (gIsHFSPlus) {
keySize = SWAP_BE16(*(short *)*key);
*data = *key + 2 + keySize;
} else {
keySize = **key;
*data = *key + 2 + keySize - (keySize & 1);
}
recordOffset = SWAP_BE16(*((short *)(nodeBuffer + (nodeSize - 2 * index - 2))));
*key = nodeBuffer + recordOffset;
if (gIsHFSPlus)
{
keySize = SWAP_BE16(*(short *)*key);
*data = *key + 2 + keySize;
}
else
{
keySize = **key;
*data = *key + 2 + keySize - (keySize & 1);
}
}
static long ReadExtent(char * extent, uint64_t extentSize,
long extentFile, uint64_t offset, uint64_t size,
void * buffer, long cache)
//==============================================================================
static long ReadExtent(char * extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void * buffer, long cache)
{
uint64_t lastOffset;
long long blockNumber, countedBlocks = 0;
long long extentDensity, sizeofExtent, currentExtentSize;
char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;
if (offset >= extentSize) return 0;
if (offset >= extentSize)
{
return 0;
}
if (gIsHFSPlus)
{
}
lastOffset = offset + size;
while (offset < lastOffset)
{
blockNumber = offset / gBlockSize;
if (extentBuffer == 0)
{
extentBuffer = malloc(sizeofExtent * extentDensity);
if (extentBuffer == 0) return -1;
if (extentBuffer == 0)
{
return -1;
}
}
nextExtentBlock = nextExtent / extentDensity;
if (currentExtentBlock != nextExtentBlock)
{
ReadExtentsEntry(extentFile, countedBlocks, extentBuffer);
countedBlocks += currentExtentSize;
}
readOffset = ((blockNumber - countedBlocks) * gBlockSize) +
(offset % gBlockSize);
readOffset = ((blockNumber - countedBlocks) * gBlockSize) + (offset % gBlockSize);
// MacWen: fix overflow in multiplication by forcing 64bit multiplication
readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;
if (readSize > (size - sizeRead)) readSize = size - sizeRead;
if (readSize > (size - sizeRead))
{
readSize = size - sizeRead;
}
readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize;
CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset,
readSize, cache);
CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, readSize, cache);
sizeRead += readSize;
offset += readSize;
bufferPos += readSize;
}
if (extentBuffer) free(extentBuffer);
if (extentBuffer)
{
free(extentBuffer);
}
return sizeRead;
}
//==============================================================================
static long GetExtentStart(void * extents, long index)
{
long start;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
long start;
if (gIsHFSPlus) start = SWAP_BE32(hfsPlusExtents[index].startBlock);
else start = SWAP_BE16(hfsExtents[index].startBlock);
HFSExtentDescriptor*hfsExtents= extents;
HFSPlusExtentDescriptor*hfsPlusExtents= extents;
if (gIsHFSPlus)
{
start = SWAP_BE32(hfsPlusExtents[index].startBlock);
}
else
{
start = SWAP_BE16(hfsExtents[index].startBlock);
}
return start;
}
//==============================================================================
static long GetExtentSize(void * extents, long index)
{
long size;
long size;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
if (gIsHFSPlus) size = SWAP_BE32(hfsPlusExtents[index].blockCount);
else size = SWAP_BE16(hfsExtents[index].blockCount);
if (gIsHFSPlus)
{
size = SWAP_BE32(hfsPlusExtents[index].blockCount);
}
else
{
size = SWAP_BE16(hfsExtents[index].blockCount);
}
return size;
}
//==============================================================================
static long CompareHFSCatalogKeys(void * key, void * testKey)
{
HFSCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
long result, searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;
trialParentID = SWAP_BE32(trialKey->parentID);
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
if (searchParentID > trialParentID)
{
result = 1;
}
else if (searchParentID < trialParentID)
{
result = -1;
}
else
{
// parent dirID's are equal, compare names
return result;
}
//==============================================================================
static long CompareHFSPlusCatalogKeys(void * key, void * testKey)
{
HFSPlusCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
long result, searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;
trialParentID = SWAP_BE32(trialKey->parentID);
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
if (searchParentID > trialParentID)
{
result = 1;
}
else if (searchParentID < trialParentID)
{
result = -1;
}
else
{
// parent dirID's are equal, compare names
if ((searchKey->nodeName.length == 0) || (trialKey->nodeName.length == 0))
result = searchKey->nodeName.length - trialKey->nodeName.length;
else
if (gCaseSensitive)
{
result = searchKey->nodeName.length - trialKey->nodeName.length;
}
else if (gCaseSensitive)
{
result = BinaryUnicodeCompare(&searchKey->nodeName.unicode[0],
SWAP_BE16(searchKey->nodeName.length),
&trialKey->nodeName.unicode[0],
return result;
}
//==============================================================================
static long CompareHFSExtentsKeys(void * key, void * testKey)
{
HFSExtentKey *searchKey, *trialKey;
long result;
HFSExtentKey *searchKey, *trialKey;
long result;
searchKey = key;
trialKey = testKey;
searchKey = key;
trialKey = testKey;
// assume searchKey < trialKey
result = -1;
// assume searchKey < trialKey
result = -1;
if (searchKey->fileID == trialKey->fileID) {
// FileNum's are equal; compare fork types
if (searchKey->forkType == trialKey->forkType) {
// Fork types are equal; compare allocation block number
if (searchKey->startBlock == trialKey->startBlock) {
// Everything is equal
result = 0;
} else {
// Allocation block numbers differ; determine sign
if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock))
result = 1;
}
} else {
// Fork types differ; determine sign
if (searchKey->forkType > trialKey->forkType) result = 1;
}
} else {
// FileNums differ; determine sign
if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))
result = 1;
}
if (searchKey->fileID == trialKey->fileID)
{
// FileNum's are equal; compare fork types
if (searchKey->forkType == trialKey->forkType)
{
// Fork types are equal; compare allocation block number
if (searchKey->startBlock == trialKey->startBlock)
{
// Everything is equal
result = 0;
}
else
{
// Allocation block numbers differ; determine sign
if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock))
{
result = 1;
}
}
}
else
{
// Fork types differ; determine sign
if (searchKey->forkType > trialKey->forkType)
{
result = 1;
}
}
}
else
{
// FileNums differ; determine sign
if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))
{
result = 1;
}
}
return result;
return result;
}
//==============================================================================
static long CompareHFSPlusExtentsKeys(void * key, void * testKey)
{
HFSPlusExtentKey *searchKey, *trialKey;
long result;
HFSPlusExtentKey *searchKey, *trialKey;
searchKey = key;
trialKey = testKey;
long result = -1; // assume searchKey < trialKey
// assume searchKey < trialKey
result = -1;
searchKey = key;
trialKey = testKey;
if (searchKey->fileID == trialKey->fileID) {
// FileNum's are equal; compare fork types
if (searchKey->forkType == trialKey->forkType) {
// Fork types are equal; compare allocation block number
if (searchKey->startBlock == trialKey->startBlock) {
// Everything is equal
result = 0;
} else {
// Allocation block numbers differ; determine sign
if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock))
result = 1;
}
} else {
// Fork types differ; determine sign
if (searchKey->forkType > trialKey->forkType) result = 1;
}
} else {
// FileNums differ; determine sign
if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))
result = 1;
}
if (searchKey->fileID == trialKey->fileID)
{
// FileNum's are equal; compare fork types
if (searchKey->forkType == trialKey->forkType)
{
// Fork types are equal; compare allocation block number
if (searchKey->startBlock == trialKey->startBlock)
{
// Everything is equal
result = 0;
}
else
{
// Allocation block numbers differ; determine sign
if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock))
{
result = 1;
}
}
}
else
{
// Fork types differ; determine sign
if (searchKey->forkType > trialKey->forkType)
{
result = 1;
}
}
}
else
{
// FileNums differ; determine sign
if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))
{
result = 1;
}
}
return result;
return result;
}
branches/ErmaC/Trunk/i386/libsaio/device_tree.h
11
2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
323
424
525
......
828
929
1030
11
12
13
14
1531
16
32
33
34
35
36
37
38
39
1740
1841
19
20
21
22
23
2442
25
43
44
45
46
47
48
49
50
2651
2752
28
29
3053
31
32
54
3355
34
35
56
3657
37
38
58
3959
40
41
60
4261
43
44
62
4563
46
47
64
4865
49
50
51
52
53
54
66
5567
56
57
68
69
5870
71
72
5973
/*
* Copyright (c) 2005 Apple Computer, Inc. All Rights Reserved.
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef __DEVICE_TREE_H
#include <stdbool.h>
#include <stdint.h>
typedef struct _Property {
const char * name;
uint32_t length;
void * value;
struct _Property * next;
//==============================================================================
typedef struct _Property
{
const char *name;
uint32_tlength;
void *value;
struct _Property *next;
} Property;
typedef struct _Node {
struct _Property * properties;
struct _Property * last_prop;
struct _Node * children;
struct _Node * next;
//==============================================================================
typedef struct _Node
{
struct _Property *properties;
struct _Property *last_prop;
struct _Node *children;
struct _Node *next;
} Node;
extern Property *
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);
extern Node *
DT__AddChild(Node *parent, const char *name);
extern Property * DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);
Node *
DT__FindNode(const char *path, bool createIfMissing);
extern Node * DT__AddChild(Node *parent, const char *name);
extern void
DT__FreeProperty(Property *prop);
Node * DT__FindNode(const char *path, bool createIfMissing);
extern void
DT__FreeNode(Node *node);
extern void DT__FreeProperty(Property *prop);
extern char *
DT__GetName(Node *node);
extern void DT__FreeNode(Node *node);
void
DT__Initialize(void);
extern char * DT__GetName(Node *node);
/*
* Free up memory used by in-memory representation
* of device tree.
*/
extern void
DT__Finalize(void);
void DT__Initialize(void);
void
DT__FlattenDeviceTree(void **result, uint32_t *length);
// Free up memory used by in-memory representation of device tree.
extern void DT__Finalize(void);
void DT__FlattenDeviceTree(void **result, uint32_t *length);
#endif /* __DEVICE_TREE_H */
branches/ErmaC/Trunk/i386/libsaio/allocate.c
3333
3434
3535
36
37
36
37
38
3839
39
40
40
41
4142
42
43
44
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
4563
46
47
48
49
50
51
52
53
54
64
5565
5666
57
58
67
68
69
70
5971
60
72
6173
62
74
6375
64
65
66
67
68
76
77
78
79
6980
70
81
7182
72
73
83
84
7485
75
86
7687
77
88
7889
#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1))
long
AllocateMemoryRange(char * rangeName, long start, long length, long type)
//==============================================================================
long AllocateMemoryRange(char * rangeName, long start, long length, long type)
{
char *nameBuf;
uint32_t *buffer;
char *nameBuf;
uint32_t *buffer;
nameBuf = malloc(strlen(rangeName) + 1);
if (nameBuf == 0) return -1;
strcpy(nameBuf, rangeName);
nameBuf = malloc(strlen(rangeName) + 1);
if (nameBuf == 0)
{
return -1;
}
strcpy(nameBuf, rangeName);
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0)
{
return -1;
}
buffer[0] = start;
buffer[1] = length;
DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0) return -1;
buffer[0] = start;
buffer[1] = length;
DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
return 0;
return 0;
}
long
AllocateKernelMemory( long inSize )
//==============================================================================
long AllocateKernelMemory(long inSize)
{
long addr;
long addr;
if (gImageLastKernelAddr == 0)
if (gImageLastKernelAddr == 0)
{
gImageLastKernelAddr = RoundPage( bootArgs->kaddr +
bootArgs->ksize );
}
addr = gImageLastKernelAddr;
gImageLastKernelAddr += RoundPage(inSize);
gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize);
}
addr = gImageLastKernelAddr;
gImageLastKernelAddr += RoundPage(inSize);
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) )
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) )
{
stop ("AllocateKernelMemory error");
}
stop ("AllocateKernelMemory error");
}
bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;
bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;
return addr;
return addr;
}
branches/ErmaC/Trunk/i386/libsaio/hfs.h
2323
2424
2525
26
27
28
26
2927
3028
3129
extern long HFSInitPartition(CICell ih);
extern long HFSLoadFile(CICell ih, char * filePath);
extern long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length);
extern long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex,
char ** name, long * flags, long * time,
FinderInfo * finderInfo, long * infoValid);
extern long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid);
extern void HFSGetDescription(CICell ih, char *str, long strMaxLen);
extern long HFSGetFileBlock(CICell ih, char *str, unsigned long long *firstBlock);
extern long HFSGetUUID(CICell ih, char *uuidStr);
branches/ErmaC/Trunk/i386/libsaio/hfs_compare.c
3232
3333
3434
35
36
35
3736
3837
3938
......
5857
5958
6059
61
62
60
6361
6462
6563
......
306304
307305
308306
309
310
307
311308
312309
313310
#if ! UNCOMPRESSED
static unsigned short *
UncompressStructure(struct compressed_block *bp, int count, int size)
static unsigned short * UncompressStructure(struct compressed_block *bp, int count, int size)
{
unsigned short *out = malloc(size);
unsigned short *op = out;
return out;
}
static void
InitCompareTables(void)
static void InitCompareTables(void)
{
if (gCompareTable == 0) {
gCompareTable = UncompressStructure(gCompareTableCompressed,
* ucslen is the number of UCS-2 input characters (not bytes)
* bufsize is the size of the output buffer in bytes
*/
void
utf_encodestr( const u_int16_t * ucsp, int ucslen,
void utf_encodestr( const u_int16_t * ucsp, int ucslen,
u_int8_t * utf8p, u_int32_t bufsize, int byte_order )
{
u_int8_t *bufend;
branches/ErmaC/Trunk/i386/libsaio/spd.c
6969
7070
7171
72
73
74
75
76
77
78
79
80
81
82
83
84
7285
7386
7487
......
107120
108121
109122
110
111
112
113
114
115
116
117
118
119
120
121
122123
123124
124125
......
134135
135136
136137
137
138
139
140
138
139
140
141
141142
142
143
144
145
146
147
148
149
150
151
152
153
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
154159
155160
156
157
158
159
160
161
162
163
164
161
162
163
164
165
166
167
168
169
170
171
165172
166173
167174
......
171178
172179
173180
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
201212
202213
203214
......
208219
209220
210221
211
212
213
214
215
216
217
218
222
223
224
225
226
227
228
229
219230
220231
221232
......
226237
227238
228239
229
240
241
230242
231243
232
244
245
233246
234247
235248
......
291304
292305
293306
294
307
295308
296309
297310
......
388401
389402
390403
391
404
405
392406
393407
394408
395409
396410
397411
398
399
400
412
401413
402
403
414
415
416
417
404418
405419
406420
407421
408422
409
423
410424
411425
412426
#define SMBHSTDAT 5
#define SBMBLKDAT 7
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */
unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd)
/* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */
#define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x)
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read from spd *used* values only*/
static void init_spd(char * spd, uint32_t base, int slot)
have different formats, always return a valid ptr.*/
const char * getVendorName(RamSlotInfo_t* slot, uint32_t base, int slot_num)
{
uint8_t bank = 0;
uint8_t code = 0;
int i = 0;
uint8_t * spd = (uint8_t *) slot->spd;
uint8_t bank = 0;
uint8_t code = 0;
int i = 0;
uint8_t * spd = (uint8_t *) slot->spd;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { // DDR3
bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1
code = spd[SPD_DDR3_MEMORY_CODE];
for (i=0; i < VEN_MAP_SIZE; i++)
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
return vendorMap[i].name;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) {
if(spd[64]==0x7f) {
for (i=64; i<72 && spd[i]==0x7f;i++) {
bank++;
READ_SPD(spd, base, slot_num,i+1); // prefetch next spd byte to read for next loop
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{ // DDR3
bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1
code = spd[SPD_DDR3_MEMORY_CODE];
for (i=0; i < VEN_MAP_SIZE; i++)
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
return vendorMap[i].name;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
if(spd[64]==0x7f)
{
for (i=64; i<72 && spd[i]==0x7f;i++)
{
bank++;
READ_SPD(spd, base, slot_num,i+1); // prefetch next spd byte to read for next loop
}
READ_SPD(spd, base, slot_num,i);
code = spd[i];
} else {
code = spd[64];
bank = 0;
}
for (i=0; i < VEN_MAP_SIZE; i++)
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
return vendorMap[i].name;
}
code = spd[i];
}
else
{
code = spd[64];
bank = 0;
}
for (i=0; i < VEN_MAP_SIZE; i++)
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
return vendorMap[i].name;
}
/* OK there is no vendor id here lets try to match the partnum if it exists */
if (strstr(slot->PartNo,"GU332") == slot->PartNo) // Unifosa fingerprint
return "Unifosa";
/** Get Default Memory Module Speed (no overclocking handled) */
int getDDRspeedMhz(const char * spd)
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
switch(spd[12]) {
case 0x0f:
return 1066;
case 0x0c:
return 1333;
case 0x0a:
return 1600;
case 0x14:
default:
return 800;
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) {
switch(spd[9]) {
case 0x50:
return 400;
case 0x3d:
return 533;
case 0x30:
return 667;
case 0x25:
default:
return 800;
}
}
return 800; // default freq for unknown types
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
switch(spd[12])
{
case 0x0f:
return 1066;
case 0x0c:
return 1333;
case 0x0a:
return 1600;
case 0x14:
default:
return 800;
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
switch(spd[9])
{
case 0x50:
return 400;
case 0x3d:
return 533;
case 0x30:
return 667;
case 0x25:
default:
return 800;
}
}
return 800; // default freq for unknown types
}
#define SMST(a) ((uint8_t)((spd[a] & 0xf0) >> 4))
{
static char asciiSerial[16];
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) // DDR2 or DDR
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
}
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) // DDR2 or DDR
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
}
return strdup(asciiSerial);
}
static char asciiPartNo[32];
int i, start=0, index = 0;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
start = 128;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) {
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
start = 73;
}
bzero(slot->spd, spd_size);
// Copy spd data into buffer
// Copy spd data into buffer
//for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x);
init_spd(slot->spd, base, i);
pci_dt_t*current = pci_dt;
int i;
while (current) {
while (current)
{
#if 0
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
#endif
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
{
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device)
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
{
smbus_controllers[i].read_smb(current); // read smb
return true;
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device)
{
smbus_controllers[i].read_smb(current); // read smb
return true;
}
}
find_and_read_smbus_controller(current->children);
current = current->next;
}
return false; // not found
return false; // not found
}
void scan_spd(PlatformInfo_t *p)
branches/ErmaC/Trunk/i386/libsaio/spd.h
1212
1313
1414
15
15
16
1617
1718
1819
19
20
2021
2122
2223
void scan_spd(PlatformInfo_t *p);
struct smbus_controllers_t {
struct smbus_controllers_t
{
uint32_tvendor;