Chameleon

Chameleon Commit Details

Date:2010-09-21 20:48:41 (9 years 23 days ago)
Author:Evan Lojewski
Commit:536
Parents: 535
Message:#ifdef to #ifndef. Various other changes
Changes:
M/branches/meklort/i386/modules/Memory/Memory.c
M/branches/meklort/i386/libsaio/disk.c
M/branches/meklort/i386/libsaio/ntfs.c
M/branches/meklort/i386/boot2/modules.c
M/branches/meklort/i386/libsaio/ext2fs.c
M/branches/meklort/i386/boot2/options.c

File differences

branches/meklort/i386/libsaio/ext2fs.c
66
77
88
9
9
1010
1111
1212
......
4040
4141
4242
43
* Copyright 2009 __MyCompanyName__. All rights reserved.
*
*/
#ifndef OPTION_ROM
#include "libsaio.h"
#include "sl.h"
#include "ext2fs.h"
strncpy (str, buf+0x478, min (strMaxLen, 16));
free (buf);
}
#endif
branches/meklort/i386/libsaio/ntfs.c
2222
2323
2424
25
25
2626
2727
2828
......
342342
343343
344344
345
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef OPTION_ROM
#include "libsaio.h"
#include "sl.h"
return result;
}
#endif
branches/meklort/i386/libsaio/disk.c
4545
4646
4747
48
49
48
49
5050
5151
5252
......
9292
9393
9494
95
95
9696
9797
98
98
9999
100100
101101
......
122122
123123
124124
125
126
125
126
127127
128128
129129
......
153153
154154
155155
156
156
157157
158158
159
159
160160
161
161
162162
163
164
163
164
165165
166
166
167167
168
168
169169
170170
171171
......
178178
179179
180180
181
181
182182
183183
184
184
185185
186186
187187
188
188
189189
190190
191191
......
205205
206206
207207
208
208
209209
210210
211
211
212212
213213
214214
......
228228
229229
230230
231
231
232232
233233
234234
235235
236
236
237237
238
238
239239
240240
241
242
241
242
243243
244
244
245245
246246
247247
248248
249249
250
250
251251
252
252
253253
254254
255
255
256256
257257
258258
......
264264
265265
266266
267
267
268268
269269
270270
271
271
272272
273273
274274
......
283283
284284
285285
286
287
286
287
288288
289289
290290
291
291
292292
293293
294294
......
300300
301301
302302
303
303
304304
305305
306
306
307307
308308
309309
310310
311311
312
312
313313
314314
315315
......
324324
325325
326326
327
327
328328
329
329
330330
331331
332332
......
334334
335335
336336
337
337
338338
339339
340340
......
348348
349349
350350
351
352
351
352
353353
354354
355355
356356
357
357
358358
359359
360360
361
361
362362
363363
364
364
365365
366366
367367
......
370370
371371
372372
373
373
374374
375375
376376
377377
378378
379
379
380380
381
381
382382
383383
384384
......
392392
393393
394394
395
395
396396
397
397
398398
399399
400400
......
405405
406406
407407
408
408
409409
410410
411411
......
414414
415415
416416
417
417
418418
419419
420420
421421
422
422
423423
424424
425425
......
427427
428428
429429
430
430
431431
432432
433433
434
434
435435
436436
437437
......
439439
440440
441441
442
442
443443
444
444
445445
446446
447447
448448
449
449
450450
451
451
452452
453453
454454
......
458458
459459
460460
461
461
462462
463
463
464464
465
465
466466
467
467
468468
469469
470470
471471
472472
473
473
474474
475
475
476476
477477
478478
479479
480
480
481481
482482
483
483
484484
485485
486
486
487487
488488
489
489
490490
491491
492492
493493
494494
495495
496
497
498
499
500
501
502
503
504
496
497
498
499
500
501
502
503
504
505505
506506
507507
508508
509509
510
510
511511
512512
513513
......
520520
521521
522522
523
523
524524
525525
526
526
527527
528
528
529529
530530
531531
532
532
533533
534534
535535
536
536
537537
538538
539
539
540540
541541
542542
......
562562
563563
564564
565
566
567
568
569
570
571
572
573
565
566
567
568
569
570
571
572
573
574574
575575
576576
577577
578578
579
579
580580
581581
582582
......
590590
591591
592592
593
593
594594
595
596
597
598
595
596
597
598
599599
600
600
601601
602602
603603
604
604
605605
606606
607607
608
608
609609
610610
611
611
612612
613613
614614
615615
616616
617
618
619
620
621
617
618
619
620
621
622622
623623
624624
......
643643
644644
645645
646
647
648
649
650
651
652
653
654
646
647
648
649
650
651
652
653
654
655655
656656
657657
658658
659659
660
660
661661
662662
663663
......
672672
673673
674674
675
676
675
676
677677
678
679
678
679
680680
681
682
683
684
681
682
683
684
685685
686
686
687687
688688
689689
690
690
691691
692692
693693
694
694
695695
696696
697
697
698698
699699
700700
......
738738
739739
740740
741
741
742742
743743
744
744
745745
746746
747747
748748
749
750
749
750
751751
752
752
753753
754754
755
755
756756
757757
758758
......
761761
762762
763763
764
764
765765
766
766
767767
768768
769769
770770
771771
772
772
773773
774774
775775
776776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791791
792792
793
793
794794
795795
796
797
798
799
800
801
802
803
804
805
806
807
808
796
797
798
799
800
801
802
803
804
805
806
807
808
809809
810
811
810
811
812812
813813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828828
829
829
830830
831831
832832
833
834
835
836
837
838
839
840
841
842
843
844
845
833
834
835
836
837
838
839
840
841
842
843
844
845
846846
847847
848
848
849849
850850
851851
852852
853853
854854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
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
870882
871
872
873
874
875
876
877
878
879
880
881
882
883883
884
885
886
887
888
889
890
891
892
893
884
885
886
887
888
889
890
891
892
893
894894
895895
896
897
898
899
900
901
902
903
896
897
898
899
900
901
902
903
904904
905
905
906906
907907
908908
......
910910
911911
912912
913
913
914914
915915
916916
917
917
918918
919919
920920
......
927927
928928
929929
930
930
931931
932932
933933
934934
935935
936936
937
938
939
940
941
942
943
944
945
946
937
938
939
940
941
942
943
944
945
946
947947
948
948
949949
950950
951
952
953
954
955
951
952
953
954
955
956956
957957
958958
......
966966
967967
968968
969
969
970970
971
971
972972
973973
974974
......
981981
982982
983983
984
984
985985
986986
987987
......
10011001
10021002
10031003
1004
1004
10051005
10061006
10071007
......
10091009
10101010
10111011
1012
1012
10131013
10141014
10151015
10161016
10171017
1018
1018
10191019
10201020
1021
1021
10221022
10231023
10241024
1025
1025
10261026
10271027
10281028
10291029
1030
1031
1032
1033
1034
1035
1036
1030
1031
1032
1033
1034
1035
1036
10371037
10381038
10391039
......
10561056
10571057
10581058
1059
1059
10601060
1061
1061
10621062
1063
1063
10641064
10651065
10661066
......
10731073
10741074
10751075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
11161118
1117
1118
1119
1120
11191121
11201122
11211123
......
11231125
11241126
11251127
1126
1128
11271129
11281130
11291131
......
11441146
11451147
11461148
1147
1149
11481150
11491151
11501152
......
11561158
11571159
11581160
1159
1161
11601162
11611163
11621164
11631165
1164
1166
11651167
11661168
1167
1169
11681170
11691171
11701172
11711173
1172
1174
11731175
1174
1176
11751177
11761178
11771179
11781180
1179
1181
11801182
1181
1183
11821184
11831185
1184
1186
11851187
11861188
11871189
11881190
1189
1191
11901192
11911193
11921194
11931195
1194
1196
11951197
1196
1198
11971199
1198
1200
11991201
12001202
12011203
12021204
1203
1205
12041206
1205
1207
12061208
12071209
12081210
12091211
12101212
12111213
1212
1214
12131215
12141216
12151217
12161218
1217
1219
12181220
12191221
12201222
12211223
1222
1224
12231225
12241226
12251227
1226
1228
12271229
12281230
12291231
12301232
1231
1233
12321234
12331235
1234
1236
12351237
1236
1238
12371239
12381240
12391241
......
12411243
12421244
12431245
1244
1246
12451247
12461248
12471249
12481250
12491251
1250
1251
1252
1252
1253
1254
12531255
12541256
1255
1257
12561258
12571259
1258
1260
12591261
12601262
12611263
12621264
12631265
1264
1266
12651267
12661268
1267
1269
12681270
1269
1271
12701272
12711273
12721274
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
12861288
1287
1288
1289
1290
12891291
1290
1292
12911293
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
13071311
1308
1312
13091313
13101314
13111315
13121316
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1317
1318
1319
1320
13531321
1354
1355
1356
1357
1358
1359
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
13601332
1361
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
13621366
13631367
1364
1368
13651369
13661370
1367
1371
13681372
13691373
13701374
......
13811385
13821386
13831387
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
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
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
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
14471451
14481452
14491453
......
15011505
15021506
15031507
1504
1508
15051509
1506
1510
15071511
15081512
15091513
15101514
15111515
15121516
1513
1517
15141518
15151519
15161520
1517
1521
15181522
15191523
1520
1524
15211525
15221526
15231527
1524
1528
15251529
15261530
15271531
......
15321536
15331537
15341538
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
15481552
15491553
15501554
15511555
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
15631567
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
16341638
1635
1636
1637
1638
1639
1640
1639
1640
1641
1642
1643
1644
16411645
1642
1643
1644
1645
1646
1646
1647
1648
1649
1650
16471651
16481652
16491653
16501654
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
16731677
16741678
16751679
16761680
16771681
16781682
1683
16791684
1685
16801686
16811687
16821688
16831689
16841690
16851691
1692
16861693
1694
16871695
16881696
16891697
......
16961704
16971705
16981706
1699
1707
17001708
17011709
17021710
......
17431751
17441752
17451753
1746
1747
1754
1755
17481756
17491757
17501758
......
17691777
17701778
17711779
1772
1780
17731781
17741782
17751783
......
17871795
17881796
17891797
1790
1798
17911799
17921800
17931801
......
18051813
18061814
18071815
1808
1816
18091817
18101818
18111819
......
18141822
18151823
18161824
1817
1825
18181826
18191827
18201828
......
18361844
18371845
18381846
1839
1847
18401848
18411849
18421850
......
18461854
18471855
18481856
1849
1857
18501858
18511859
18521860
1853
1861
18541862
18551863
18561864
18571865
18581866
18591867
1860
1868
18611869
18621870
18631871
......
18731881
18741882
18751883
1876
1884
18771885
18781886
18791887
......
18831891
18841892
18851893
1886
1894
18871895
18881896
1889
1890
1891
1897
1898
1899
18921900
18931901
18941902
......
19071915
19081916
19091917
1910
1911
1912
1913
1918
1919
1920
1921
19141922
19151923
19161924
......
19191927
19201928
19211929
1922
1930
19231931
19241932
19251933
19261934
19271935
1928
1936
19291937
1930
1938
19311939
19321940
19331941
19341942
1935
1943
19361944
19371945
19381946
......
19481956
19491957
19501958
1951
1959
19521960
19531961
19541962
......
19581966
19591967
19601968
1961
1969
19621970
19631971
19641972
19651973
19661974
1967
1975
19681976
1969
1977
19701978
19711979
19721980
19731981
1974
1982
19751983
19761984
19771985
......
19841992
19851993
19861994
1987
1995
19881996
19891997
19901998
......
19922000
19932001
19942002
1995
2003
19962004
1997
2005
19982006
19992007
20002008
......
20022010
20032011
20042012
2005
2013
20062014
20072015
20082016
*/
/* Copyright 2007 VMware Inc.
"Preboot" ramdisk support added by David Elliott
GPT support added by David Elliott. Based on IOGUIDPartitionScheme.cpp.
"Preboot" ramdisk support added by David Elliott
GPT support added by David Elliott. Based on IOGUIDPartitionScheme.cpp.
*/
// Allow UFS_SUPPORT to be overridden with preprocessor option.
* of vm's round_page() and trunc_page().
*/
#define IORound(value,multiple) \
((((value) + (multiple) - 1) / (multiple)) * (multiple))
((((value) + (multiple) - 1) / (multiple)) * (multiple))
#define IOTrunc(value,multiple) \
(((value) / (multiple)) * (multiple));
(((value) / (multiple)) * (multiple));
/*
* trackbuf points to the start of the track cache. Biosread()
// Function pointers to be filled in if ramdisks are available:
int (*p_ramdiskReadBytes)( int biosdev, unsigned int blkno,
unsigned int byteoff,
unsigned int byteCount, void * buffer ) = NULL;
unsigned int byteoff,
unsigned int byteCount, void * buffer ) = NULL;
int (*p_get_ramdisk_info)(int biosdev, struct driveInfo *dip) = NULL;
else
return 0;
}
if ( !cached_di.valid || biosdev != cached_di.biosdev )
{
cc = get_drive_info(biosdev, &cached_di);
cc = get_drive_info(biosdev, &cached_di);
if (cc < 0) {
cached_di.valid = 0;
cached_di.valid = 0;
DEBUG_DISK(("get_drive_info returned error\n"));
return (-1); // BIOS call error
}
return (-1); // BIOS call error
}
}
bcopy(&cached_di, dip, sizeof(cached_di));
return 0;
}
};
static const char * getNameForValue( const struct NamedValue * nameTable,
unsigned char value )
unsigned char value )
{
const struct NamedValue * np;
for ( np = nameTable; np->value; np++)
if (np->value == value)
return np->name;
return NULL;
}
{
static char errorstr[] = "Error 0x00";
const char * errname;
errname = getNameForValue( bios_errors, errnum );
if ( errname ) return errname;
sprintf(errorstr, "Error 0x%02x", errnum);
return errorstr; // No string, print error code only
}
static int xbiosdev, xcyl, xhead;
static unsigned int xsec, xnsecs;
struct driveInfo di;
int rc = -1;
int cyl, head, sec;
int tries = 0;
int bps, divisor;
if (getDriveInfo(biosdev, &di) < 0) {
return -1;
return -1;
}
if (di.no_emulation) {
/* Always assume 2k block size; BIOS may lie about geometry */
bps = 2048;
/* Always assume 2k block size; BIOS may lie about geometry */
bps = 2048;
} else {
bps = di.di.params.phys_nbps;
bps = di.di.params.phys_nbps;
if (bps == 0) {
return -1;
}
}
divisor = bps / BPS;
DEBUG_DISK(("Biosread dev %x sec %d bps %d\n", biosdev, secno, bps));
// To read the disk sectors, use EBIOS if we can. Otherwise,
// revert to the standard BIOS calls.
if ((biosdev >= kBIOSDevTypeHardDrive) &&
(di.uses_ebios & EBIOS_FIXED_DISK_ACCESS))
{
biosbuf = trackbuf + (BPS * (secno - xsec));
return 0;
}
xnsecs = N_CACHE_SECS;
xsec = (secno / divisor) * divisor;
cache_valid = false;
while ((rc = ebiosread(biosdev, secno / divisor, xnsecs / divisor)) && (++tries < 5))
{
if (rc == ECC_CORRECTED_ERR) {
}
else
{
/* spc = spt * heads */
int spc = (di.di.params.phys_spt * di.di.params.phys_heads);
/* spc = spt * heads */
int spc = (di.di.params.phys_spt * di.di.params.phys_heads);
cyl = secno / spc;
head = (secno % spc) / di.di.params.phys_spt;
sec = secno % di.di.params.phys_spt;
if (cache_valid &&
(biosdev == xbiosdev) &&
(cyl == xcyl) &&
biosbuf = trackbuf + (BPS * (sec - xsec));
return 0;
}
// Cache up to a track worth of sectors, but do not cross a
// track boundary.
xcyl = cyl;
xhead = head;
xsec = sec;
xnsecs = ((unsigned int)(sec + N_CACHE_SECS) > di.di.params.phys_spt) ? (di.di.params.phys_spt - sec) : N_CACHE_SECS;
cache_valid = false;
while ((rc = biosread(biosdev, cyl, head, sec, xnsecs)) &&
(++tries < 5))
{
sleep(1);
}
}
// If the BIOS reported success, mark the sector cache as valid.
if (rc == 0) {
cache_valid = true;
}
xbiosdev = biosdev;
spinActivityIndicator(xnsecs);
return rc;
}
//==========================================================================
static int readBytes( int biosdev, unsigned long long blkno,
unsigned int byteoff,
unsigned int byteCount, void * buffer )
unsigned int byteoff,
unsigned int byteCount, void * buffer )
{
// ramdisks require completely different code for reading.
if(p_ramdiskReadBytes != NULL && biosdev >= 0x100)
return (*p_ramdiskReadBytes)(biosdev, blkno, byteoff, byteCount, buffer);
char * cbuf = (char *) buffer;
int error;
int copy_len;
DEBUG_DISK(("%s: dev %x block %x [%d] -> 0x%x...", __FUNCTION__,
biosdev, blkno, byteCount, (unsigned)cbuf));
for ( ; byteCount; cbuf += copy_len, blkno++ )
{
error = Biosread( biosdev, blkno );
DEBUG_DISK(("error\n"));
return (-1);
}
copy_len = ((byteCount + byteoff) > BPS) ? (BPS - byteoff) : byteCount;
bcopy( biosbuf + byteoff, cbuf, copy_len );
byteCount -= copy_len;
byteoff = 0;
}
DEBUG_DISK(("done\n"));
return 0;
}
0x0f, /* Win95 extended */
0x85, /* Linux extended */
};
unsigned int i;
for (i = 0; i < sizeof(extParts)/sizeof(extParts[0]); i++)
{
if (extParts[i] == part->systid) return 1;
//==========================================================================
static int getNextFDiskPartition( int biosdev, int * partno,
const struct fdisk_part ** outPart )
const struct fdisk_part ** outPart )
{
static int sBiosdev = -1;
static int sNextPartNo;
static unsigned int sExtDepth;
static struct fdisk_part * sExtPart;
struct fdisk_part * part;
if ( sBiosdev != biosdev || *partno < 0 )
{
// Fetch MBR.
if ( readBootSector( biosdev, DISK_BLK0, 0 ) ) return 0;
sBiosdev = biosdev;
sNextPartNo = 0;
sFirstBase = 0;
sExtDepth = 0;
sExtPart = NULL;
}
while (1)
{
part = NULL;
if ( sNextPartNo < FDISK_NPART )
{
part = (struct fdisk_part *) gBootSector->parts[sNextPartNo];
else if ( sExtPart )
{
unsigned int blkno = sExtPart->relsect + sFirstBase;
// Save the block offset of the first extended partition.
if (sExtDepth == 0) {
sFirstBase = blkno;
}
sExtBase = blkno;
// Load extended partition table.
if ( readBootSector( biosdev, blkno, 0 ) == 0 )
{
sNextPartNo = 0;
}
// Fall through to part == NULL
}
if ( part == NULL ) break; // Reached end of partition chain.
// Advance to next partition number.
sNextPartNo++;
if ( isExtendedFDiskPartition(part) )
{
sExtPart = part;
continue;
}
// Skip empty slots.
if ( part->systid == 0x00 )
{
continue;
}
// Change relative offset to an absolute offset.
part->relsect += sExtBase;
*outPart = part;
*partno = sExtDepth ? (int)(sExtDepth + FDISK_NPART) : sNextPartNo;
break;
}
return (part != NULL);
}
//==========================================================================
static BVRef newFDiskBVRef( int biosdev, int partno, unsigned int blkoff,
const struct fdisk_part * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
const struct fdisk_part * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
bvr->biosdev = biosdev;
bvr->part_no = partno;
bvr->part_boff = blkoff;
bvr->description = getDescriptionFunc;
bvr->type = type;
bvr->bv_free = bvFreeFunc;
if ((part->bootid & FDISK_ACTIVE) && (part->systid == FDISK_HFS))
bvr->flags |= kBVFlagPrimary;
// Probe the filesystem.
if ( initFunc )
{
bvr->flags |= kBVFlagNativeBoot;
if ( probe && initFunc( bvr ) != 0 )
{
// filesystem probe failed.
DEBUG_DISK(("%s: failed probe on dev %x part %d\n",
__FUNCTION__, biosdev, partno));
(*bvr->bv_free)(bvr);
bvr = NULL;
}
//==========================================================================
BVRef newAPMBVRef( int biosdev, int partno, unsigned int blkoff,
const DPME * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
const DPME * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
bvr->biosdev = biosdev;
bvr->part_no = partno;
bvr->part_boff = blkoff;
bvr->bv_free = bvFreeFunc;
strlcpy(bvr->name, part->dpme_name, DPISTRLEN);
strlcpy(bvr->type_name, part->dpme_type, DPISTRLEN);
/*
if ( part->bootid & FDISK_ACTIVE )
bvr->flags |= kBVFlagPrimary;
*/
if ( part->bootid & FDISK_ACTIVE )
bvr->flags |= kBVFlagPrimary;
*/
// Probe the filesystem.
if ( initFunc )
{
bvr->flags |= kBVFlagNativeBoot | kBVFlagBootable | kBVFlagSystemVolume;
if ( probe && initFunc( bvr ) != 0 )
{
// filesystem probe failed.
DEBUG_DISK(("%s: failed probe on dev %x part %d\n",
__FUNCTION__, biosdev, partno));
(*bvr->bv_free)(bvr);
bvr = NULL;
}
}
/*
else if ( readBootSector( biosdev, blkoff, (void *)0x7e00 ) == 0 )
{
bvr->flags |= kBVFlagForeignBoot;
}
*/
else if ( readBootSector( biosdev, blkoff, (void *)0x7e00 ) == 0 )
{
bvr->flags |= kBVFlagForeignBoot;
}
*/
else
{
(*bvr->bv_free)(bvr);
BVRef newGPTBVRef( int biosdev, int partno, unsigned int blkoff,
const gpt_ent * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
const gpt_ent * part,
FSInit initFunc, FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
bvr->biosdev = biosdev;
bvr->part_no = partno;
bvr->part_boff = blkoff;
// FIXME: UCS-2 -> UTF-8 the name
strlcpy(bvr->name, "----", DPISTRLEN);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)part->ent_type) == 0) ||
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)part->ent_type) == 0) )
strlcpy(bvr->type_name, "GPT HFS+", DPISTRLEN);
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)part->ent_type) == 0) )
strlcpy(bvr->type_name, "GPT HFS+", DPISTRLEN);
else
strlcpy(bvr->type_name, "GPT Unknown", DPISTRLEN);
strlcpy(bvr->type_name, "GPT Unknown", DPISTRLEN);
/*
if ( part->bootid & FDISK_ACTIVE )
bvr->flags |= kBVFlagPrimary;
*/
if ( part->bootid & FDISK_ACTIVE )
bvr->flags |= kBVFlagPrimary;
*/
// Probe the filesystem.
if ( initFunc )
{
bvr->flags |= kBVFlagNativeBoot;
if ( probe && initFunc( bvr ) != 0 )
{
// filesystem probe failed.
DEBUG_DISK(("%s: failed probe on dev %x part %d\n",
__FUNCTION__, biosdev, partno));
(*bvr->bv_free)(bvr);
bvr = NULL;
}
int spc;
struct driveInfo di;
boot_drive_info_t *dp;
/* Initialize disk info */
if (getDriveInfo(biosdev, &di) != 0) {
return NULL;
return NULL;
}
dp = &di.di;
spc = (dp->params.phys_spt * dp->params.phys_heads);
if (spc == 0) {
/* This is probably a CD-ROM; punt on the geometry. */
spc = 1;
/* This is probably a CD-ROM; punt on the geometry. */
spc = 1;
}
do {
// Create a new mapping.
map = (struct DiskBVMap *) malloc( sizeof(*map) );
if ( map )
{
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
// Create a record for each partition found on the disk.
while ( getNextFDiskPartition( biosdev, &partno, &part ) )
{
DEBUG_DISK(("%s: part %d [%x]\n", __FUNCTION__,
partno, part->systid));
bvr = 0;
switch ( part->systid )
{
#if UFS_SUPPORT
case FDISK_UFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect + UFS_FRONT_PORCH/BPS,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect + UFS_FRONT_PORCH/BPS,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
#endif
case FDISK_HFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
// turbo - we want the booter type scanned also
// turbo - we want the booter type scanned also
case FDISK_BOOTER:
if (part->bootid & FDISK_ACTIVE)
gBIOSBootVolume = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
gBIOSBootVolume = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
#if UFS_SUPPORT
case FDISK_BOOTER:
booterUFS = newFDiskBVRef(
biosdev, partno,
((part->relsect + spc - 1) / spc) * spc,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
biosdev, partno,
((part->relsect + spc - 1) / spc) * spc,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
#endif
case FDISK_FAT32:
case FDISK_DOS12:
case FDISK_DOS16S:
case FDISK_DOS16B:
case FDISK_SMALLFAT32:
case FDISK_DOS16SLBA:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
#ifndef OPTION_ROM
case FDISK_NTFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
NTFSGetUUID,
NTFSGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_NTFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
NTFSGetUUID,
NTFSGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_LINUX:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
EX2GetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
EX2GetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
#endif
default:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
}
if ( bvr )
{
bvr->next = map->bvr;
map->bvrcnt++;
}
}
#if UFS_SUPPORT
// Booting from a CD with an UFS filesystem embedded
// in a booter partition.
if ( booterUFS )
{
if ( map->bvrcnt == 0 )
#endif
}
} while (0);
/*
* If no FDisk partition, then we will check for
* an Apple partition map elsewhere.
*/
#if UNUSED
if (map->bvrcnt == 0) {
static struct fdisk_part cdpart;
cdpart.systid = 0xCD;
/* Let's try assuming we are on a hybrid HFS/ISO9660 CD. */
bvr = newFDiskBVRef(
biosdev, 0,
0,
&cdpart,
HFSInitPartition,
HFSLoadFile,
static struct fdisk_part cdpart;
cdpart.systid = 0xCD;
/* Let's try assuming we are on a hybrid HFS/ISO9660 CD. */
bvr = newFDiskBVRef(
biosdev, 0,
0,
&cdpart,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
0,
kBIOSDevTypeHardDrive);
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
0,
kBIOSDevTypeHardDrive);
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
}
#endif
// Actually this should always be true given the above code
map = NULL;
}
}
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
}
unsigned int blksize;
unsigned int factor;
void *buffer = malloc(BPS);
/* Check for alternate block size */
if (readBytes( biosdev, 0, 0, BPS, buffer ) != 0) {
return NULL;
do {
// Create a new mapping.
map = (struct DiskBVMap *) malloc( sizeof(*map) );
if ( map )
{
DPME *dpme_p = (DPME *)buffer;
UInt32 i, npart = UINT_MAX;
BVRef bvr;
map->biosdev = biosdev;
map->bvr = NULL;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
for (i=0; i<npart; i++) {
error = readBytes( biosdev, (kAPMSector + i) * factor, 0, blksize, buffer );
if (error || OSSwapBigToHostInt16(dpme_p->dpme_signature) != DPME_SIGNATURE) {
break;
}
if (i==0) {
npart = OSSwapBigToHostInt32(dpme_p->dpme_map_entries);
}
/*
printf("name = %s, %s%s %d -> %d [%d -> %d] {%d}\n",
dpme.dpme_name, dpme.dpme_type, (dpme.dpme_flags & DPME_FLAGS_BOOTABLE) ? "(bootable)" : "",
dpme.dpme_pblock_start, dpme.dpme_pblocks,
dpme.dpme_lblock_start, dpme.dpme_lblocks,
dpme.dpme_boot_block);
*/
printf("name = %s, %s%s %d -> %d [%d -> %d] {%d}\n",
dpme.dpme_name, dpme.dpme_type, (dpme.dpme_flags & DPME_FLAGS_BOOTABLE) ? "(bootable)" : "",
dpme.dpme_pblock_start, dpme.dpme_pblocks,
dpme.dpme_lblock_start, dpme.dpme_lblocks,
dpme.dpme_boot_block);
*/
if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0) {
bvr = newAPMBVRef(biosdev,
i,
}
}
} while (0);
free(buffer);
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
}
*/
static int probeFileSystem(int biosdev, unsigned int blkoff)
{
// detected filesystem type;
int result = -1;
int fatbits;
// Allocating buffer for 4 sectors.
const void * probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
goto exit;
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (error)
goto exit;
if (HFSProbe(probeBuffer))
result = FDISK_HFS;
else if (EX2Probe(probeBuffer))
result = FDISK_LINUX;
else if (NTFSProbe(probeBuffer))
result = FDISK_NTFS;
else if (fatbits=MSDOSProbe(probeBuffer))
{
switch (fatbits)
{
case 32:
default:
result = FDISK_FAT32;
break;
case 16:
result = FDISK_DOS16B;
break;
case 12:
result = FDISK_DOS12;
break;
}
}
else
// Couldn't detect filesystem type
result = 0;
// detected filesystem type;
int result = -1;
int fatbits;
// Allocating buffer for 4 sectors.
const void * probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
goto exit;
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (error)
goto exit;
if (HFSProbe(probeBuffer))
result = FDISK_HFS;
#ifndef OPTION_ROM
else if (EX2Probe(probeBuffer))
result = FDISK_LINUX;
else if (NTFSProbe(probeBuffer))
result = FDISK_NTFS;
#endif
else if (fatbits=MSDOSProbe(probeBuffer))
{
switch (fatbits)
{
case 32:
default:
result = FDISK_FAT32;
break;
case 16:
result = FDISK_DOS16B;
break;
case 12:
result = FDISK_DOS12;
break;
}
}
else
// Couldn't detect filesystem type
result = 0;
exit:
if (probeBuffer != NULL) free((void *)probeBuffer);
return result;
if (probeBuffer != NULL) free((void *)probeBuffer);
return result;
}
static bool isPartitionUsed(gpt_ent * partition)
//
// Ask whether the given partition is used.
//
return efi_guid_is_null((EFI_GUID const*)partition->ent_type) ? false : true;
}
verbose("Failed to find boot signature on BIOS device %02xh\n", biosdev);
goto scanErr;
}
int fdiskID = 0;
unsigned index;
for ( index = 0; index < FDISK_NPART; index++ )
// Fail if two 0xEE partitions are present which
// means the FDISK code will wind up parsing it.
if ( fdiskID ) goto scanErr;
fdiskID = index + 1;
}
}
}
if ( fdiskID == 0 ) goto scanErr;
verbose("Attempting to read GPT\n");
if(readBytes(biosdev, 1, 0, BPS, buffer) != 0)
goto scanErr;
gpt_hdr *headerMap = buffer;
// Determine whether the partition header signature is present.
if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) )
{
goto scanErr;
}
// Determine whether the partition header size is valid.
UInt32 headerCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_self);
UInt32 headerSize = OSSwapLittleToHostInt32(headerMap->hdr_size);
if ( headerSize < offsetof(gpt_hdr, padding) )
{
goto scanErr;
}
if ( headerSize > BPS )
{
goto scanErr;
}
// Determine whether the partition header checksum is valid.
headerMap->hdr_crc_self = 0;
if ( crc32(0, headerMap, headerSize) != headerCheck )
{
goto scanErr;
}
// Determine whether the partition entry size is valid.
UInt64 gptBlock = 0;
UInt32 gptCheck = 0;
UInt32 gptCount = 0;
UInt32 gptID = 0;
gpt_ent * gptMap = 0;
UInt32 gptSize = 0;
gptBlock = OSSwapLittleToHostInt64(headerMap->hdr_lba_table);
gptCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_table);
gptCount = OSSwapLittleToHostInt32(headerMap->hdr_entries);
gptSize = OSSwapLittleToHostInt32(headerMap->hdr_entsz);
if ( gptSize < sizeof(gpt_ent) )
{
goto scanErr;
}
// Allocate a buffer large enough to hold one map, rounded to a media block.
free(buffer);
buffer = NULL;
UInt32 bufferSize = IORound(gptCount * gptSize, BPS);
if(bufferSize == 0)
goto scanErr;
buffer = malloc(bufferSize);
if(readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0)
goto scanErr;
verbose("Read GPT\n");
// Allocate a new map for this BIOS device and insert it into the chain
map = malloc(sizeof(*map));
map->biosdev = biosdev;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
// fdisk like partition type id.
int fsType = 0;
for(gptID = 1; gptID <= gptCount; ++gptID)
{
BVRef bvr = NULL;
unsigned int bvrFlags = 0;
BVRef bvr = NULL;
unsigned int bvrFlags = 0;
// size on disk can be larger than sizeof(gpt_ent)
gptMap = (gpt_ent *) ( buffer + ( (gptID - 1) * gptSize) );
// NOTE: EFI_GUID's are in LE and we know we're on an x86.
// The IOGUIDPartitionScheme.cpp code uses byte-based UUIDs, we don't.
if(isPartitionUsed(gptMap))
{
char stringuuid[100];
efi_guid_unparse_upper((EFI_GUID*)gptMap->ent_type, stringuuid);
verbose("Reading GPT partition %d, type %s\n", gptID, stringuuid);
// Getting fdisk like partition type.
fsType = probeFileSystem(biosdev, gptMap->ent_lba_start);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
bvrFlags = (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ? kBVFlagBooter : 0;
bvr = newGPTBVRef(biosdev,
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
}
// zef - foreign OS support
// zef - foreign OS support
if ( (efi_guid_compare(&GPT_BASICDATA_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_NTFS:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, NTFSGetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
default:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
}
switch (fsType)
{
#ifndef OPTION_ROM
case FDISK_NTFS:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, NTFSGetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
#endif
default:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
}
}
// turbo - save our booter partition
// zef - only on original boot device
if ( (efi_guid_compare(&GPT_EFISYS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_HFS:
if (readBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
case FDISK_FAT32:
if (testFAT32EFIBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
if (biosdev == gBIOSDev)
gBIOSBootVolume = bvr;
}
}
if (bvr)
switch (fsType)
{
case FDISK_HFS:
if (readBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
// Fixup bvr with the fake fdisk partition type.
if (fsType > 0) bvr->part_type = fsType;
bvr->next = map->bvr;
map->bvr = bvr;
++map->bvrcnt;
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
case FDISK_FAT32:
if (testFAT32EFIBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
if (biosdev == gBIOSDev)
gBIOSBootVolume = bvr;
}
}
if (bvr)
{
// Fixup bvr with the fake fdisk partition type.
if (fsType > 0) bvr->part_type = fsType;
bvr->next = map->bvr;
map->bvr = bvr;
++map->bvrcnt;
}
}
}
scanErr:
free(buffer);
if(map)
{
if(countPtr) *countPtr = map->bvrcnt;
static void scanFSLevelBVRSettings(BVRef chain)
{
BVRef bvr;
char dirSpec[512], fileSpec[512];
char label[BVSTRLEN];
int ret;
long flags, time;
int fh, fileSize, error;
for (bvr = chain; bvr; bvr = bvr->next)
{
ret = -1;
error = 0;
//
// Check for alternate volume label on boot helper partitions.
//
if (bvr->flags & kBVFlagBooter)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, ".disk_label.contentDetails");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (!ret)
{
fh = open(strcat(dirSpec, fileSpec), 0);
fileSize = file_size(fh);
if (fileSize > 0 && fileSize < BVSTRLEN)
{
if (read(fh, label, fileSize) != fileSize)
error = -1;
}
else
error = -1;
close(fh);
if (!error)
{
label[fileSize] = '\0';
strcpy(bvr->altlabel, label);
}
}
}
//
// Check for SystemVersion.plist or ServerVersion.plist
// to determine if a volume hosts an installed system.
//
if (bvr->flags & kBVFlagNativeBoot)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, "SystemVersion.plist");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (ret == -1)
{
strcpy(fileSpec, "ServerVersion.plist");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
}
if (!ret)
bvr->flags |= kBVFlagSystemVolume;
}
}
BVRef bvr;
char dirSpec[512], fileSpec[512];
char label[BVSTRLEN];
int ret;
long flags, time;
int fh, fileSize, error;
for (bvr = chain; bvr; bvr = bvr->next)
{
ret = -1;
error = 0;
//
// Check for alternate volume label on boot helper partitions.
//
if (bvr->flags & kBVFlagBooter)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, ".disk_label.contentDetails");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (!ret)
{
fh = open(strcat(dirSpec, fileSpec), 0);
fileSize = file_size(fh);
if (fileSize > 0 && fileSize < BVSTRLEN)
{
if (read(fh, label, fileSize) != fileSize)
error = -1;
}
else
error = -1;
close(fh);
if (!error)
{
label[fileSize] = '\0';
strcpy(bvr->altlabel, label);
}
}
}
//
// Check for SystemVersion.plist or ServerVersion.plist
// to determine if a volume hosts an installed system.
//
if (bvr->flags & kBVFlagNativeBoot)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, "SystemVersion.plist");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (ret == -1)
{
strcpy(fileSpec, "ServerVersion.plist");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
}
if (!ret)
bvr->flags |= kBVFlagSystemVolume;
}
}
}
#ifndef OPTION_ROM
void rescanBIOSDevice(int biosdev)
struct DiskBVMap * map;
BVRef bvr;
int count = 0;
// Find an existing mapping for this device.
for ( map = gDiskBVMap; map; map = map->next ) {
if ( biosdev == map->biosdev ) {
count = map->bvrcnt;
break;
}
}
if (map == NULL) {
bvr = diskScanGPTBootVolumes(biosdev, &count);
if (bvr == NULL) {
bvr = diskScanFDiskBootVolumes(biosdev, &count);
bvr = diskScanFDiskBootVolumes(biosdev, &count);
}
if (bvr == NULL) {
bvr = diskScanAPMBootVolumes(biosdev, &count);
bvr = diskScanAPMBootVolumes(biosdev, &count);
}
if (bvr)
{
scanFSLevelBVRSettings(bvr);
scanFSLevelBVRSettings(bvr);
}
} else {
bvr = map->bvr;
BVRef getBVChainForBIOSDev(int biosdev)
{
BVRef chain = NULL;
struct DiskBVMap * map = NULL;
for (map = gDiskBVMap; map; map = map->next)
{
if (map->biosdev == biosdev)
{
chain = map->bvr;
break;
}
}
return chain;
BVRef chain = NULL;
struct DiskBVMap * map = NULL;
for (map = gDiskBVMap; map; map = map->next)
{
if (map->biosdev == biosdev)
{
chain = map->bvr;
break;
}
}
return chain;
}
BVRef newFilteredBVChain(int minBIOSDev, int maxBIOSDev, unsigned int allowFlags, unsigned int denyFlags, int *count)
{
BVRef chain = NULL;
BVRef bvr = NULL;
BVRef newBVR = NULL;
BVRef prevBVR = NULL;
struct DiskBVMap * map = NULL;
int bvCount = 0;
const char *raw = 0;
char* val = 0;
int len;
BVRef chain = NULL;
BVRef bvr = NULL;
BVRef newBVR = NULL;
BVRef prevBVR = NULL;
struct DiskBVMap * map = NULL;
int bvCount = 0;
const char *raw = 0;
char* val = 0;
int len;
getValueForKey(kHidePartition, &raw, &len, &bootInfo->bootConfig);
if(raw)
{
val = XMLDecode(raw);
}
/*
* Traverse gDISKBVmap to get references for
* individual bvr chains of each drive.
*/
for (map = gDiskBVMap; map; map = map->next)
{
for (bvr = map->bvr; bvr; bvr = bvr->next)
{
/*
* Save the last bvr.
*/
if (newBVR) prevBVR = newBVR;
/*
* Allocate and copy the matched bvr entry into a new one.
*/
newBVR = (BVRef) malloc(sizeof(*newBVR));
bcopy(bvr, newBVR, sizeof(*newBVR));
/*
* Adjust the new bvr's fields.
*/
newBVR->next = NULL;
newBVR->filtered = true;
if ( (!allowFlags || newBVR->flags & allowFlags)
&& (!denyFlags || !(newBVR->flags & denyFlags) )
&& (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev)
)
newBVR->visible = true;
/* Looking for "Hide Partition" entries in 'hd(x,y)|uuid|"label" hd(m,n)|uuid|"label"' format
* to be able to hide foreign partitions from the boot menu.
*/
if ( (newBVR->flags & kBVFlagForeignBoot) )
{
char *start, *next = val;
long len = 0;
do
{
start = strbreak(next, &next, &len);
if(len && matchVolumeToString(newBVR, start, len) )
newBVR->visible = false;
}
while ( next && *next );
}
/*
* Use the first bvr entry as the starting chain pointer.
*/
if (!chain)
chain = newBVR;
/*
* Update the previous bvr's link pointer to use the new memory area.
*/
if (prevBVR)
prevBVR->next = newBVR;
if (newBVR->visible)
bvCount++;
}
}
getValueForKey(kHidePartition, &raw, &len, &bootInfo->bootConfig);
if(raw)
{
val = XMLDecode(raw);
}
/*
* Traverse gDISKBVmap to get references for
* individual bvr chains of each drive.
*/
for (map = gDiskBVMap; map; map = map->next)
{
for (bvr = map->bvr; bvr; bvr = bvr->next)
{
/*
* Save the last bvr.
*/
if (newBVR) prevBVR = newBVR;
/*
* Allocate and copy the matched bvr entry into a new one.
*/
newBVR = (BVRef) malloc(sizeof(*newBVR));
bcopy(bvr, newBVR, sizeof(*newBVR));
/*
* Adjust the new bvr's fields.
*/
newBVR->next = NULL;
newBVR->filtered = true;
if ( (!allowFlags || newBVR->flags & allowFlags)
&& (!denyFlags || !(newBVR->flags & denyFlags) )
&& (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev)
)
newBVR->visible = true;
/* Looking for "Hide Partition" entries in 'hd(x,y)|uuid|"label" hd(m,n)|uuid|"label"' format
* to be able to hide foreign partitions from the boot menu.
*/
if ( (newBVR->flags & kBVFlagForeignBoot) )
{
char *start, *next = val;
long len = 0;
do
{
start = strbreak(next, &next, &len);
if(len && matchVolumeToString(newBVR, start, len) )
newBVR->visible = false;
}
while ( next && *next );
}
/*
* Use the first bvr entry as the starting chain pointer.
*/
if (!chain)
chain = newBVR;
/*
* Update the previous bvr's link pointer to use the new memory area.
*/
if (prevBVR)
prevBVR->next = newBVR;
if (newBVR->visible)
bvCount++;
}
}
#if DEBUG
for (bvr = chain; bvr; bvr = bvr->next)
{
printf(" bvr: %d, dev: %d, part: %d, flags: %d, vis: %d\n", bvr, bvr->biosdev, bvr->part_no, bvr->flags, bvr->visible);
}
printf("count: %d\n", bvCount);
getc();
for (bvr = chain; bvr; bvr = bvr->next)
{
printf(" bvr: %d, dev: %d, part: %d, flags: %d, vis: %d\n", bvr, bvr->biosdev, bvr->part_no, bvr->flags, bvr->visible);
}
printf("count: %d\n", bvCount);
getc();
#endif
*count = bvCount;
free(val);
return chain;
*count = bvCount;
free(val);
return chain;
}
int freeFilteredBVChain(const BVRef chain)
{
int ret = 1;
BVRef bvr = chain;
BVRef nextBVR = NULL;
while (bvr)
{
nextBVR = bvr->next;
if (bvr->filtered)
{
free(bvr);
}
else
{
ret = 0;
break;
}
bvr = nextBVR;
}
return ret;
int ret = 1;
BVRef bvr = chain;
BVRef nextBVR = NULL;
while (bvr)
{
nextBVR = bvr->next;
if (bvr->filtered)
{
free(bvr);
}
else
{
ret = 0;
break;
}
bvr = nextBVR;
}
return ret;
}
//==========================================================================
static const struct NamedValue fdiskTypes[] =
{
#ifndef OPTION_ROM
{ FDISK_NTFS, "Windows NTFS" },
#endif
{ FDISK_DOS12, "Windows FAT12" },
{ FDISK_DOS16B, "Windows FAT16" },
{ FDISK_DOS16S, "Windows FAT16" },
{ FDISK_DOS16SLBA, "Windows FAT16" },
{ FDISK_SMALLFAT32, "Windows FAT32" },
{ FDISK_FAT32, "Windows FAT32" },
#ifndef OPTION_ROM
{ FDISK_LINUX, "Linux" },
#endif
{ FDISK_UFS, "Apple UFS" },
{ FDISK_HFS, "Apple HFS" },
{ FDISK_BOOTER, "Apple Boot/UFS" },
bool matchVolumeToString( BVRef bvr, const char* match, long matchLen)
{
char testStr[128];
if ( !bvr || !match || !*match)
return 0;
return false;
for ( entryStart = entryNext = aliasList;
entryNext && *entryNext;
entryStart = entryNext )
entryNext && *entryNext;
entryStart = entryNext )
{
char *volStart, *volEnd, *aliasStart;
long volLen, aliasLen;
{
strncat(str, aliasStart, min(strMaxLen, aliasLen));
free(aliasList);
return true;
}
}
return;
type = (unsigned char) bvr->part_type;
if (useDeviceDescription)
{
int len = getDeviceDescription(bvr, str);
strncpy(bvr->label, p, strMaxLen);
return; // we're done here no need to seek for real name
}
//
// Get the volume label using filesystem specific functions
// or use the alternate volume label if available.
strncpy(p, bvr->altlabel, strMaxLen);
else if (bvr->description)
bvr->description(bvr, p, strMaxLen);
if (*p == '\0') {
const char * name = getNameForValue( fdiskTypes, type );
if (name == NULL) {
{
struct disk_blk0 * bootSector = (struct disk_blk0 *) buffer;
int error;
if ( bootSector == NULL )
{
if ( gBootSector == NULL )
}
bootSector = gBootSector;
}
error = readBytes( biosdev, secno, 0, BPS, bootSector );
if ( error || bootSector->signature != DISK_SIGNATURE )
return -1;
return 0;
}
/*
* Format of boot1f32 block.
*/
#define BOOT1F32_MAGIC "BOOT "
#define BOOT1F32_MAGICLEN 11
{
struct disk_boot1f32_blk * bootSector = (struct disk_boot1f32_blk *) buffer;
int error;
if ( bootSector == NULL )
{
if ( gBootSector == NULL )
}
bootSector = (struct disk_boot1f32_blk *) gBootSector;
}
error = readBytes( biosdev, secno, 0, BPS, bootSector );
if ( error || bootSector->signature != DISK_SIGNATURE
|| strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
return -1;
|| strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
return -1;
return 0;
}
int diskRead( BVRef bvr, long addr, long length )
{
return readBytes( bvr->biosdev,
bvr->fs_boff + bvr->part_boff,
bvr->fs_byteoff,
length,
(void *) addr );
bvr->fs_boff + bvr->part_boff,
bvr->fs_byteoff,
length,
(void *) addr );
}
int rawDiskRead( BVRef bvr, unsigned int secno, void *buffer, unsigned int len )
unsigned char *cbuf = (unsigned char *)buffer;
unsigned int copy_len;
int rc;
if ((len & (BPS-1)) != 0) {
error("raw disk read not sector aligned");
return -1;
}
secno += bvr->part_boff;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
//printf("rdr: ebiosread(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebiosread(bvr->biosdev, secno, secs)) != 0) {
/* Ignore corrected ECC errors */
secno += secs;
spinActivityIndicator(secs);
}
return 0;
}
unsigned char *cbuf = (unsigned char *)buffer;
unsigned int copy_len;
int rc;
if ((len & (BPS-1)) != 0) {
error("raw disk write not sector aligned");
return -1;
}
secno += bvr->part_boff;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
bcopy( cbuf, trackbuf, copy_len );
//printf("rdr: ebioswrite(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebioswrite(bvr->biosdev, secno, secs)) != 0) {
secno += secs;
spinActivityIndicator(secs);
}
return 0;
}
int diskIsCDROM(BVRef bvr)
{
struct driveInfo di;
if (getDriveInfo(bvr->biosdev, &di) == 0 && di.no_emulation) {
return 1;
return 1;
}
return 0;
}
int biosDevIsCDROM(int biosdev)
{
struct driveInfo di;
if (getDriveInfo(biosdev, &di) == 0 && di.no_emulation)
{
return 1;
branches/meklort/i386/boot2/modules.c
12221222
12231223
12241224
1225
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
return 0;
}
}
}
/* Nedded to devide 64bit numbers correctly. TODO: look into why modules need this
* And why it isn't needed when compiled into boot2
*/
uint64_t __udivdi3(uint64_t numerator, uint64_t denominator)
{
uint64_t quotient = 0, qbit = 1;
if (denominator)
{
while ((int64_t) denominator >= 0)
{
denominator <<= 1;
qbit <<= 1;
}
while (denominator)
{
if (denominator <= numerator)
{
numerator -= denominator;
quotient += qbit;
}
denominator >>= 1;
qbit >>= 1;
}
return quotient;
}
else {
stop("Divide by 0");
return 0;
}
}
branches/meklort/i386/boot2/options.c
12811281
12821282
12831283
1284
1284
12851285
12861286
12871287
}
#endif
#ifdef OPTION_ROM
#ifndef OPTION_ROM
bool promptForRescanOption(void)
{
printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");
branches/meklort/i386/modules/Memory/Memory.c
4343
4444
4545
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
46
}
scan_memory(&Platform); // unfortunately still necesary for some comp where spd cant read correct speed
scan_spd(&Platform);
}
/* Nedded to devide 64bit numbers correctly. TODO: look into why the module needs this
* And why it isn't needed when compiled into boot2
*/
uint64_t __udivdi3(uint64_t numerator, uint64_t denominator)
{
uint64_t quotient = 0, qbit = 1;
if (denominator)
{
while ((int64_t) denominator >= 0)
{
denominator <<= 1;
qbit <<= 1;
}
while (denominator)
{
if (denominator <= numerator)
{
numerator -= denominator;
quotient += qbit;
}
denominator >>= 1;
qbit >>= 1;
}
return quotient;
}
else {
stop("Divide by 0");
return 0;
}
}
}

Archive Download the corresponding diff file

Revision: 536