File: raid_dev.cpp

package info (click to toggle)
raidutils 0.0.6-23
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,840 kB
  • sloc: cpp: 39,794; ansic: 22,774; sh: 8,306; makefile: 19
file content (2021 lines) | stat: -rw-r--r-- 53,196 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
152
153
154
155
156
157
158
159
160
161
162
163
164
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
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
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
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
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
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
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
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
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
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
1332
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
1366
1367
1368
1369
1370
1371
1372
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
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
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
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
/* Copyright (c) 1996-2004, Adaptec Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name of the Adaptec Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

//File - RAID_DEV.CPP
//***************************************************************************
//
//Description:
//
//    This file contains the function definitions for the dptRAIDdev_C
//class.
//
//Author:	Doug Anderson
//Date:		3/25/93
//
//Editors:
//
//Remarks:
//
//
//***************************************************************************

//Include Files -------------------------------------------------------------

#include	"allfiles.hpp"	// All engine include files

//Function - dptRAIDdev_C::dptRAIDdev_C() - start
//===========================================================================
//
//Description:
//
//    This function is the constructor for the dptRAIDdev_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptRAIDdev_C::dptRAIDdev_C()
{

raidFlags = 0;
raidType = RAID_NONE;
redundants = 0;

scheduledDiag = 0;
newPhyStatus = 0;

compCount = 0;
maxRaidLBA = 0;

osVisible = 0;

udmaModeSupported = 0;
udmaModeSelected = 0;

minReservedSpace = RESERVED_SPACE_RAID;

segment_P = NULL;
maxSegments = 0;

}
//dptRAIDdev_C::dptRAIDdev_C() - end


//Function - dptRAIDdev_C::okRAIDdevice() - start
//===========================================================================
//
//Description:
//
//    This function verifies this RAID device against the specified
//RAID definition.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::okRAIDdevice(raidHeader_S *&header_P,
					   raidDef_S *&def_P
					  )
{

   DPT_RTN_T	retVal;

  // Save the optimization flags
if (header_P->control & FLG_RCTL_SS_MULTIPLE)
   raidFlags |= FLG_RDEV_SS_MULTIPLE;
if (header_P->control & FLG_RCTL_CAPACITY_OPT)
   raidFlags |= FLG_RDEV_CAPACITY_OPT;

  // Compute the component data (stripe size, # stripes...)
computeComps(header_P,def_P);

  // Determine if all RAID requirements are met
retVal = okRequired(def_P);
if (retVal == MSG_RTN_COMPLETED)
     // Determine if any permissions are violated
   retVal = okPermission(def_P);

return (retVal);

}
//dptSCSImgr_C::okRAIDparams() - end


//Function - dptRAIDdev_C::okRequired() - start
//===========================================================================
//
//Description:
//
//    This function determines if this RAID device meets the criteria
//in the specified RAID definition's "required" flags.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::okRequired(raidDef_S *&def_P)
{

   uSHORT	minChan,maxChan,chanCount,chan;
   uSHORT	dataDrives;
   dptRAIDdev_C	*comp_P;
   uLONG	stripeSize,numStripes;
   uCHAR	bitCount;

  // Verify the component drive count
if (compList.size()<def_P->minDrives)
     // Not enough component drives specified
   return (MSG_RTN_FAILED | ERR_RAID_TOO_FEW);

if (compList.size()>def_P->maxDrives)
     // Too many component drives specified
   return (MSG_RTN_FAILED | ERR_RAID_TOO_MANY);

if ((def_P->required & FLG_REQ_EVEN_DRIVES) && (compList.size() & 0x1))
     // An even number of components are required
   return (MSG_RTN_FAILED | ERR_RAID_EVEN);

if ((def_P->required & FLG_REQ_ODD_DRIVES) && !(compList.size() & 0x0001))
     // An odd number of components are required
   return (MSG_RTN_FAILED | ERR_RAID_ODD);

if (def_P->required & FLG_REQ_POWER_2_PLUS) {
   bitCount	= 0;
     // Get the number of drives minus the number of redundant drives
   dataDrives = compList.size() - def_P->redundants;
     // Bit #0 cannot be the only bit set
   if (dataDrives>1) {
	// There should only be 1 bit set if the number is a power of 2
      while ( (dataDrives!=0) && (bitCount<=1) ) {
	 if (dataDrives & 0x0001)
	    bitCount++;
	 dataDrives >>= 1;
      }
   }
   if (bitCount!=1)
	// The number of component drives must be a power of 2 plus
	// the number of parity drives
      return (MSG_RTN_FAILED | ERR_RAID_POWER_2_PLUS);
}

  // If there is a limit to the number of times a single
  // channel can appear in the component list...
minChan = myMgr_P()->getMinAddr().chan;
if (def_P->required & FLG_REQ_CHAN_COUNT) {
   maxChan = myMgr_P()->getMaxAddr().chan;
   for (chan=minChan;chan<=maxChan;chan++) {
      chanCount = 0;
      comp_P = (dptRAIDdev_C *) compList.reset();
      while (comp_P!=NULL) {
	 if (comp_P->getChan()==chan)
	    chanCount++;
	 comp_P = (dptRAIDdev_C *) compList.next();
      }
      if (chanCount>def_P->chanCount)
	 return (MSG_RTN_FAILED | ERR_RAID_CHAN_COUNT);
   }
}

  // Check stripe size/capacity limits
comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
   if (comp_P->parent.stripeSize<def_P->minStripe)
	// The component's stripe size is below the minimum
      return (MSG_RTN_FAILED | ERR_RAID_MIN_STRIPE);
   if (comp_P->parent.stripeSize>def_P->maxStripe)
	// The component's stripe size is above the maximum
      return (MSG_RTN_FAILED | ERR_RAID_MAX_STRIPE);
   if (comp_P->parent.numStripes==0)
	// There must be at least 1 stripe
      return (MSG_RTN_FAILED | ERR_RAID_ZERO_STRIPES);
   if (comp_P->getLastParentLBA() > comp_P->capacity.maxLBA) // use maxRaidLBA here?
	// The component capacity can not exceed the device capacity
      return (MSG_RTN_FAILED | ERR_RAID_TOO_LARGE);
   if ((comp_P->getLevel()==2) &&
	    ((comp_P->getMaxPhyLBA()-comp_P->getLastLBA())<0x11))
	// There isn't enough room for a RAID table
      return (MSG_RTN_FAILED | ERR_RAID_TABLE_REQUIRED);
     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

comp_P = (dptRAIDdev_C *) compList.reset();
if (comp_P!=NULL) {
     // Initialize test data with the first component's data
   stripeSize = comp_P->parent.stripeSize;
   numStripes = comp_P->parent.numStripes;
   chanCount = comp_P->getChan();
   if ((def_P->required & FLG_REQ_MIN_CHAN) && (chanCount!=minChan))
	// The first component does not appear on the first channel
      return (MSG_RTN_FAILED | ERR_RAID_START_CHAN);
}

while (comp_P!=NULL) {
   if (def_P->required & FLG_REQ_SEQ_CHAN)
      if (comp_P->getChan()!=chanCount)
	   // The components do not appear on sequential channels
	 return (MSG_RTN_FAILED | ERR_RAID_SEQ_CHAN);

   if (def_P->required & FLG_REQ_SAME_STRIPE_SZ)
      if (comp_P->parent.stripeSize!=stripeSize)
	   // The components have different stripe sizes
	 return (MSG_RTN_FAILED | ERR_RAID_DIFF_STRIPES);

   if (def_P->required & FLG_REQ_SAME_NUM_STRIPE)
      if (comp_P->parent.numStripes!=numStripes)
	   // The components have different # of stripes
	 return (MSG_RTN_FAILED | ERR_RAID_DIFF_NUM_STR);

   if (def_P->required & FLG_REQ_UNDER_MULTIPLE)
      if ((comp_P->parent.stripeSize % comp_P->getMaxCompStripe())!=0)
	   // The stripe size is not a multiple of the underlying
	   // stripe size.
	 return (MSG_RTN_FAILED | ERR_RAID_OVER_STRIPE);

   comp_P = (dptRAIDdev_C *) compList.next();
   chanCount++;

} // end while (comp_P!=NULL)

return (MSG_RTN_COMPLETED);

}
//dptRAIDdev_C::okRequired() - end


//Function - dptRAIDdev_C::okPermission() - start
//===========================================================================
//
//Description:
//
//    This function determines if this RAID device meets the criteria
//in the specified RAID definition's "permit" flags.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::okPermission(raidDef_S *&def_P)
{

   DPT_RTN_T		retVal = MSG_RTN_COMPLETED;
   dptRAIDdev_C		*comp_P,*comp1_P;

comp_P = comp1_P = (dptRAIDdev_C *) compList.reset();

while ((comp_P!=NULL) && (retVal==MSG_RTN_COMPLETED)) {
   if (!(def_P->permit & FLG_COMP_REMOVABLE))
      if (comp_P->isRemovable())
	   // Removable media devices not permitted
	 retVal = MSG_RTN_FAILED | ERR_RAID_COMP_REMOVE;
   if (!(def_P->permit & FLG_COMP_EMULATED))
      if (comp_P->isEmulated())
	   // Removable media devices not permitted
	 retVal = MSG_RTN_FAILED | ERR_RAID_COMP_EMULATED;
   if (!(def_P->permit & FLG_COMP_ANY_TYPE))
      if (comp_P->getObjType()!=def_P->devType)
	   // Invalid device type
	 retVal = MSG_RTN_FAILED | ERR_RAID_COMP_DEVTYPE;
   if (!(def_P->permit & FLG_COMP_NON_512))
      if (comp_P->capacity.blockSize!=512)
	   // Non-512 byte block size
	 retVal = MSG_RTN_FAILED | ERR_RAID_COMP_NON_512;
   if (!(def_P->permit & FLG_COMP_DIFF_BLOCKS))
      if (comp_P->capacity.blockSize!=comp1_P->capacity.blockSize)
	   // Components have different block sizes
	 retVal = MSG_RTN_FAILED | ERR_RAID_COMP_NON_512;
   if (def_P->permit & FLG_COMP_SAME_CAPACITY)
      if (comp_P->capacity.maxLBA!=comp1_P->capacity.maxLBA)
	   // Components have different capacities
	 retVal = MSG_RTN_FAILED | ERR_RAID_DIFF_CAPACITY;
   if (def_P->permit & FLG_COMP_SAME_VENDOR)
      if (!findSubString((uCHAR *)comp_P->descr.vendorID,
			 (uCHAR *)comp1_P->descr.vendorID,8,8,0))
	   // Components have different vendor IDs
	 retVal = MSG_RTN_FAILED | ERR_RAID_DIFF_VENDOR;
   if (def_P->permit & FLG_COMP_SAME_PRODUCT)
      if (!findSubString((uCHAR *)comp_P->descr.productID,
			 (uCHAR *)comp1_P->descr.productID,16,16,0))
	   // Components have different product IDs
	 retVal = MSG_RTN_FAILED | ERR_RAID_DIFF_PRODUCT;
   if (def_P->permit & FLG_COMP_SAME_REVISION)
      if (!findSubString((uCHAR *)comp_P->descr.revision,
			 (uCHAR *)comp1_P->descr.revision,4,4,0))
	   // Components have different revisions
	 retVal = MSG_RTN_FAILED | ERR_RAID_DIFF_REVISION;

     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

return (retVal);

}
//dptRAIDdev_C::okPermission() - end


//Function - dptRAIDdev_C::freeComponents() - start
//===========================================================================
//
//Description:
//
//    This function frees all component device's from any association
//with this device as a parent RAID device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::freeComponents()
{

DEBUG_BEGIN(1, dptRAIDdev_C::freeComponents());

dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Clear the RAID parent structure
   comp_P->parent.reset();
     // Clear the suppression desired status
   comp_P->supNotDesired();
     // If space has been temporarily reserved...
   if (comp_P->prevMaxLBA!=0) {
	// Restore the logical capacity
      comp_P->capacity.maxLBA = comp_P->prevMaxLBA;
      comp_P->prevMaxLBA = 0;
   }
     // If a physical device...
   if (comp_P->isPhysical()) {
#ifdef _SINIX_ADDON
	// If this array exists in hardware...
      if (isReal()) {
	 DEBUG(1, PRT_DADDR(comp_P) << \
	       " RESTORE: newlba=" << comp_P->getMaxPhyLBA() - 1 << " oldlba=" << \
	       comp_P->getLastLBA());
	 comp_P->capacity.maxLBA = comp_P->getMaxPhyLBA() - 1;
	   // Indicate that the component is in a hardware mismatch state
	 comp_P->setHWmismatch1();
      }
#else
	// If this array exists in hardware...
      if (isReal())
	   // Indicate that the component is in a hardware mismatch state
	 comp_P->setHWmismatch1();
#endif
	// Allow PAP status if previously not a component
      comp_P->clrHWmismatch2();
	// Set the physical component's status to unconfigured
      comp_P->status.display = DSPLY_STAT_OPTIMAL;
      comp_P->status.main = PAPM_UNCONFIGURED;
      comp_P->status.sub = PAPS_UNCONFIGURED;
   }
   comp_P = (dptRAIDdev_C *) compList.next();
}

}
//dptRAIDdev_C::freeComponents() - end


//Function - dptRAIDdev_C::enterParent() - start
//===========================================================================
//
//Description:
//
//    This function sets this device's RAID parent.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::enterParent(dptRAIDdev_C *parent_P,
				  raidCompList_S *list_P,
				  uSHORT flags
				 )
{

  // Enter the parent device
enterParent(parent_P,list_P->numStripes,list_P->stripeSize,flags);

}
//dptRAIDdev_C::enterParent() - end


//Function - dptRAIDdev_C::enterParent() - start
//===========================================================================
//
//Description:
//
//    This function sets this device's RAID parent.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::enterParent(dptRAIDdev_C *parent_P,
				  uLONG inNumStripes,
				  uLONG inStripeSize,
				  uSHORT flags
				 )
{

  // Initialize the RAID parent structure
parent.dev_P		= parent_P;
parent.startLBA		= 0;
parent.stripeSize	= inStripeSize;
parent.numStripes	= inNumStripes;
parent.flags		= flags;

if (parent_P->myHBA_P()) {
	parent_P->myHBA_P()->incRaidEntries(); // Increment the RAID entry count for the component device
	// If this is the first component entered...
	if (parent_P->getCompCount() == 0) {
		parent_P->myHBA_P()->incRaidEntries(); // Increment the RAID entry count for the array itself
	}
}
parent_P->incCompCount();

if (myMgr_P()->isBubbler())
     // Suppress this device
   myConn_P()->suppress(this);

}
//dptRAIDdev_C::enterParent() - end


//Function - dptRAIDdev_C::computeComps() - start
//===========================================================================
//
//Description:
//
//    This function computes the stripe size size and number of stripes
//for each component device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::computeComps(raidHeader_S *&header_P,
				   raidDef_S *&def_P
				  )
{

   dptRAIDdev_C		*comp_P;
   uLONG		numStripes,size;
   uLONG		maxStripeSize = 0;
   uLONG		minNumStripes = 0xffffffffL;

if (getRAIDtype() == RAID_1) {
	// Determine if either component has a Solaris partition...
	int foundSolarisPartition = 0;
	comp_P = (dptRAIDdev_C *) compList.reset();
	while (comp_P!=NULL) {
		if (comp_P->isSolarisPartition()) {
			foundSolarisPartition++;
		}
		comp_P = (dptRAIDdev_C *) compList.next();
	}
	// If one of the drives has a Solaris partition
	if (foundSolarisPartition) {
		// Ensure all components are flagged as having a Solaris partition
		// to prevent allocating additional space at the end of the drives
		comp_P = (dptRAIDdev_C *) compList.reset();
		while (comp_P!=NULL) {
			comp_P->setSolarisPartition();
			comp_P = (dptRAIDdev_C *) compList.next();
		}
	}
}

  // Reserve space at the end of all HBA physical components
  // and get the max. RAID LBA using this manager's drive size table
comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Ensure sufficient space is reserved
   comp_P->reserveTempSpace();
     // Update the max RAID LBA based on the manager's drive size table
   comp_P->updateMaxRaidLBA();
   comp_P = (dptRAIDdev_C *) compList.next();
}

  // If use global stripe size...
if (!(header_P->control & FLG_RCTL_STRIPE)) {
   comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P!=NULL) {
	// Set individual stripe sizes to the global stripe size
      comp_P->parent.stripeSize = header_P->stripeSize;
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

  // Compute all zero size stripes
comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // If stripe size can vary & optimize for performance...
   if (!(def_P->required & FLG_REQ_SAME_STRIPE_SZ) &&
       !(header_P->control & FLG_RCTL_CAPACITY_OPT))
      size = comp_P->calcStripeSize(def_P->minStripe,1);
   else
	// Compute the stripe size for this component
	// (Original method)
      size = comp_P->calcStripeSize(def_P->minStripe);
     // Get the maximum stripe size
   if (size>maxStripeSize)
      maxStripeSize = size;
   comp_P = (dptRAIDdev_C *) compList.next();
}

  // If all stripe sizes must be the same...
if ( (def_P->required & FLG_REQ_SAME_STRIPE_SZ) ||
     (!(header_P->control & FLG_RCTL_SIZE) && (header_P->size!=0)) ) {
   comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P!=NULL) {
	// Set the stripe size to the largest stripe size
      comp_P->parent.stripeSize = maxStripeSize;
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

  // If use global device size...
if (!(header_P->control & FLG_RCTL_SIZE)) {
   size = compList.size() - redundants;
   if (size!=0)
      numStripes = header_P->size / size;
   else
      numStripes = 0;
   if (maxStripeSize!=0)
      numStripes /= maxStripeSize;
   comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P!=NULL) {
	// Set individual # stripes to the computed value
      comp_P->parent.numStripes = numStripes;
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

  // Compute all zero value # stripes
comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Compute the number of stripes for this component
   size = comp_P->calcNumStripes();
     // Get the minimum # of stripes
   if (size<minNumStripes)
      minNumStripes = size;
   comp_P = (dptRAIDdev_C *) compList.next();
}

  // If all number of stripes must be the same...
if (def_P->required & FLG_REQ_SAME_NUM_STRIPE) {
   comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P!=NULL) {
	// Set the # of stripes to the minimum
      comp_P->parent.numStripes = minNumStripes;
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

  // If the stripe sizes can vary...
if (!(def_P->required & FLG_REQ_SAME_STRIPE_SZ) &&
     (header_P->control & FLG_RCTL_CAPACITY_OPT)) {
   comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P!=NULL) {
	// Try multiples of the current stripe size to access
	// the devices full capacity
      comp_P->calcVaryStripe(def_P,header_P);
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

  // Compute the size of this RAID device
size = 0;
comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Compute the number of stripes for this component
   if (!(comp_P->parent.flags & FLG_PAR_REDUNDANT))
      size += comp_P->parent.numStripes * comp_P->parent.stripeSize;
   if (comp_P->capacity.blockSize > capacity.blockSize)
      capacity.blockSize = comp_P->capacity.blockSize;
   comp_P = (dptRAIDdev_C *) compList.next();
}

capacity.maxLBA = capacity.maxPhysLBA = size - 1;

}
//dptRAIDdev_C::computeComps() - end


//Function - dptRAIDdev_C::reserveTempSpace() - start
//===========================================================================
//
//Description:
//
//    This function insures that all HBA physical components have blocks
//reserved at the end of the disk for use by DPT.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::reserveTempSpace()
{

	uLONG	spaceReserved = 0;

	DEBUG_BEGIN(1, dptRAIDdev_C::reserveTempSpace());

	uSHORT parentRaidType = (parent.dev_P != NULL) ? parent.dev_P->getRAIDtype() : RAID_NONE;

	uLONG spaceToReserve = ((parentRaidType == RAID_0) || (parentRaidType == RAID_5) || (parentRaidType == RAID_3)) ? minReservedSpace : RESERVED_SPACE_DISK;

	// Clear for safety
	prevMaxLBA = 0;
	// If an HBA physical DASD device...
	if ((getObjType()==DPT_SCSI_DASD) && (getLevel()==2) &&
	(getMaxPhyLBA()>=spaceToReserve)) {
		#ifdef _SINIX_ADDON
			uLONG used_by_sdi = 0;
			dptHBA_C *hba_P = myHBA_P();

			// Save the last logical block #
			prevMaxLBA = getLastLBA();

			// Determine how much space is currently reserved by SDI
			int ret = osdGetLBA(hba_P->getDrvrNum(), getChan(), getID(), &used_by_sdi, userBuff, prevMaxLBA);
			DEBUG(1, PRT_ADDR << "MaxLBA/LBA/SDI= " << getMaxPhyLBA() << " / " << getLastLBA() << " / " << used_by_sdi << " Driver# " << hba_P->getDrvrNum());

			if ((parent.dev_P->getRAIDtype() < RAID_HOT_SPARE) && ret && (used_by_sdi <= getMaxPhyLBA()))
				// Temporarily reserve for Raid 0,1,5 all by SDI not used blocks + 33 blocks.
				capacity.maxLBA = used_by_sdi - 33;
			else
				// For unknown disks or if SDI query failed, reserve only 33 blocks.
				// For compatibility with old version reserve only 33 blocks for HS & REDIR
				capacity.maxLBA = getMaxPhyLBA() - 33;

			DEBUG(1, PRT_ADDR << "RAID-0x" << parent.dev_P->getRAIDtype() << " new spaceReserved=" << \
			getMaxPhyLBA() - getLastLBA() << " old=" << getMaxPhyLBA() - prevMaxLBA);
		#else
			// Determine how much space is currently reserved
			spaceReserved = getMaxPhyLBA() - getLastLBA();
			// If insufficient blocks have been reserved...
			if (spaceReserved != spaceToReserve) {
				// Save the last logical block #
				prevMaxLBA = getLastLBA();
				// Temporarily reserve the desired space
				capacity.maxLBA = getMaxPhyLBA() - spaceToReserve;
			}
		#endif
	}

}
//dptRAIDdev_C::reserveTempSpace() - end


//Function - dptRAIDdev_C::calcVaryStripe() - start
//===========================================================================
//
//Description:
//
//    This function attempts to increase the stripe size in even multiples
//of the current stripe size.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::calcVaryStripe(raidDef_S *&def_P,
				     raidHeader_S *&header_P
				    )
{

   uLONG	maxCompStripe,idealStripe;

if (parent.numStripes!=0)
     // Compute the ideal stripe size to gain maximum capacity
   idealStripe = (maxRaidLBA+1) / parent.numStripes;
else
   idealStripe = parent.stripeSize;

  // Limit the stripe size
if (idealStripe<def_P->minStripe)
   idealStripe = def_P->minStripe;
else if (idealStripe > def_P->maxStripe)
   idealStripe = def_P->maxStripe;

  // Get the largest component stripe size;
maxCompStripe = getMaxCompStripe();

if (header_P->control & FLG_RCTL_SS_MULTIPLE)
     // Force the stripe size to be a multiple of the underlying
     // stripe size
   idealStripe = (idealStripe/maxCompStripe)*maxCompStripe;
else {
   if (maxCompStripe<8)
	// Force the stripe size to be a multiple of the underlying
	// stripe size
      idealStripe = (idealStripe/maxCompStripe)*maxCompStripe;
   else
	// Force the stripe size to be a multiple of 4K
      idealStripe = (idealStripe/8)*8;
}

  // Set the new stripe size
if (idealStripe > 0)
   parent.stripeSize = idealStripe;

return (parent.stripeSize);

}
//dptRAIDdev_C::calcVaryStripe() - end


//Function - dptRAIDdev_C::calcStripeSize() - start
//===========================================================================
//
//Description:
//
//    This function computes the stripe size for this device if the
//current stripe size is zero.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::calcStripeSize(uLONG minStripe,uSHORT method)
{

  // If the stripe size needs to be computed...
if (parent.stripeSize==0) {
   if (method && compList.size())
	// SS = underlying stripe size * # data drives
      parent.stripeSize = getMaxCompStripe() * (compList.size()-redundants);
   else
	// Get the largest component stripe size
      parent.stripeSize = getMaxCompStripe();
     // If the minimum stripe size is greater than the underlying...
   if (minStripe > parent.stripeSize)
	// Set the stripe size to the minimum
      parent.stripeSize = minStripe;
     // Allow no zero size stripe (Safety for bad RAID definition)
   if (parent.stripeSize==0)
      parent.stripeSize = 1;
}

return (parent.stripeSize);

}
//dptRAIDdev_C::calcStripeSize() - end


//Function - dptRAIDdev_C::calcNumStripes() - start
//===========================================================================
//
//Description:
//
//    This function computes the number of stripes for this device
//if current number of stripes is zero.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::calcNumStripes()
{

  // If the # of stripes should be computed...
if (parent.numStripes==0) {
   if (parent.stripeSize!=0)
	// Compute the # of stripes
      parent.numStripes = (maxRaidLBA+1 - parent.startLBA)
			     / parent.stripeSize;
   else
      parent.numStripes = 1;
}

return (parent.numStripes);

}
//dptRAIDdev_C::calcNumStripes() - end


//Function - dptRAIDdev_C::getMaxCompStripe() - start
//===========================================================================
//
//Description:
//
//    This function gets the largest component stripe size.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::getMaxCompStripe()
{

uLONG	maxStripe = 1;

dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Get the largest component stripe size
   if (comp_P->parent.stripeSize > maxStripe)
      maxStripe = comp_P->parent.stripeSize;
     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

return (maxStripe);

}
//dptRAIDdev_C::getMaxCompStripe() - end


//Function - dptRAIDdev_C::getMinCompStripe() - start
//===========================================================================
//
//Description:
//
//    This function gets the smallest component stripe size.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::getMinCompStripe()
{

uLONG	minStripe = 0xffffffff;

dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Get the smallest component stripe size
   if (comp_P->parent.stripeSize < minStripe)
      minStripe = comp_P->parent.stripeSize;
     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

return (minStripe);

}
//dptRAIDdev_C::getMinCompStripe() - end


//Function - dptRAIDdev_C::getUnderCount() - start
//===========================================================================
//
//Description:
//
//    This function gets the underlying number of stripes for this device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
/*
uLONG	dptRAIDdev_C::getUnderCount()
{

uLONG	underCount = 0;

dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // Get the largest component stripe size
   if (comp_P->parent.numStripes > underCount)
      underCount = comp_P->parent.numStripes;
     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

return (underCount);

}
//dptRAIDdev_C::getUnderCount() - end
*/

//Function - dptRAIDdev_C::getMasterStripe() - start
//===========================================================================
//
//Description:
//
//    This function gets the master stripe size for this device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::getMasterStripe()
{

uLONG	masterStripe = 0;

dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
while (comp_P!=NULL) {
     // If this is not a redundant drive...
   if (!(comp_P->parent.flags & FLG_PAR_REDUNDANT))
        // Add the stripe size of all component devices
      masterStripe += comp_P->parent.stripeSize;
     // Get the next component
   comp_P = (dptRAIDdev_C *) compList.next();
}

return (masterStripe);

}
//dptRAIDdev_C::getMasterStripe() - end


//Function - dptRAIDdev_C::getLastParentLBA() - start
//===========================================================================
//
//Description:
//
//    This function computes the last LBA used by the parent device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uLONG	dptRAIDdev_C::getLastParentLBA()
{

   uLONG	lastBlock = 0;

if (isComponent())
   lastBlock = parent.startLBA + (parent.numStripes * parent.stripeSize - 1);

return (lastBlock);

}
//dptRAIDdev_C::getLastParentLBA() - end


//Function - dptRAIDdev_C::setInfo() - start
//===========================================================================
//
//Description:
//
//    This function sets SCSI device information from the specified
//input buffer.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::setInfo(dptBuffer_S *toEng_P,uSHORT setAll)
{

   DPT_RTN_T	retVal = MSG_RTN_DATA_UNDERFLOW;

  // Set base class information
dptSCSIdev_C::setInfo(toEng_P,setAll);

  // If loading a configuration...
if (setAll>=2)
     // Set the RAID type
   toEng_P->extract(raidType);
else
     // Skip the RAID type
   toEng_P->skip(sizeof(uSHORT));

#if defined (_DPT_STRICT_ALIGN)
toEng_P->skip(2);
#endif

  // Skip the rest of the RAID information
toEng_P->skip(sizeof(uLONG));
toEng_P->skip(sizeof(uLONG));
toEng_P->skip(sizeof(uLONG));
toEng_P->skip(sizeof(DPT_TAG_T));
toEng_P->skip(sizeof(DPT_TAG_T));
toEng_P->skip(sizeof(uLONG));
toEng_P->skip(sizeof(uLONG));

  // Get the supplemental device flags
toEng_P->extract(scsiFlags2);
  // Skip the HBA slot #
toEng_P->skip(sizeof(uSHORT));
  // Skip the HBA flags
toEng_P->skip(sizeof(uSHORT));
#if defined (_DPT_STRICT_ALIGN)
toEng_P->skip(2);
#endif

if (setAll)
     // Set the RAID magic number
   toEng_P->extract(magicNum);
else
   toEng_P->skip(sizeof(uLONG));

  // Skip the HBA tag
toEng_P->skip(sizeof(uLONG));

  // Get the flags3 word
toEng_P->extract(scsiFlags3);

  // Get the negotiated bus speed
toEng_P->extract(busSpeed);

  // Get the path2 flags
toEng_P->extract(p2Flags);

  // Skip reserved fields
toEng_P->skip(1);
toEng_P->skip(4);

toEng_P->extract(udmaModeSupported);
toEng_P->extract(udmaModeSelected);

toEng_P->skip(1);

  // Get the diagnostic test type
toEng_P->extract(scheduledDiag);

  // Get the device's physical sector size
toEng_P->extract(phyBlockSize);

  // Skip the extra bytes
#if defined (_DPT_STRICT_ALIGN)
if (toEng_P->skip(10))
#else
if (toEng_P->skip(8))
#endif
   retVal = MSG_RTN_COMPLETED;

return (retVal);

}
//dptRAIDdev_C::setInfo() - end


//Function - dptRAIDdev_C::rtnInfo() - start
//===========================================================================
//
//Description:
//
//    This function returns RAID device information to the specified
//output buffer.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::rtnInfo(dptBuffer_S *fromEng_P)
{

   DPT_RTN_T		retVal = MSG_RTN_DATA_OVERFLOW;
   dptSCSImgr_C		*nextMgr_P;
   uLONG		tempLong = 0;
   uSHORT		tempShort=0;
   uCHAR		tempChar = 0;

  // Return base class information
dptSCSIdev_C::rtnInfo(fromEng_P);

  // Return the RAID type
fromEng_P->insert(raidType);
#if defined (_DPT_STRICT_ALIGN)
fromEng_P->insert(tempShort);
#endif
  // Return the largest component stripe size
fromEng_P->insert(getMaxCompStripe());
  // Return the smallest component stripe size
fromEng_P->insert(getMinCompStripe());
  // Return the master stripe size
  // Note: This field is only valid for RAID types with no redundancy
fromEng_P->insert(getMasterStripe());

  // Return the next RAID manager that can use this device as a
  // RAID component
nextMgr_P = nextRAIDmgr();
if (nextMgr_P!=NULL)
   if (nextMgr_P->myMgr_P()==NULL)
      fromEng_P->insert((DPT_TAG_T) 0);
   else
      fromEng_P->insert(nextMgr_P->tag());
else
   fromEng_P->insert((DPT_TAG_T) -1);

// Return parent device information
if (isComponent())
     // Return the RAID parent device's tag
   fromEng_P->insert(parent.dev_P->tag());
else
   fromEng_P->insert((DPT_TAG_T) -1);
  // Return the stripe size used by the parent device
fromEng_P->insert(parent.stripeSize);
  // Return the # of stripes used by the parent device
fromEng_P->insert(parent.numStripes);

  // Return the supplemental flags word
fromEng_P->insert(scsiFlags2);
  // Return this device's HBA's slot #
tempShort = myHBA_P()->getRAIDid();
fromEng_P->insert(tempShort);
  // Return this device's HBA's flags
tempShort = 0;
myHBA_P()->getObjFlags(tempShort);
fromEng_P->insert(tempShort);

#if defined (_DPT_STRICT_ALIGN)
tempShort = 0;
fromEng_P->insert(tempShort);
#endif

  // Return this device's RAID magic number
fromEng_P->insert(magicNum);

// Return the device's HBA tag
fromEng_P->insert(myHBA_P()->tag());

// Return SCSI flags
fromEng_P->insert(scsiFlags3);
// Return the negotiated bus speed
fromEng_P->insert(busSpeed);
// Return the path2 flags
fromEng_P->insert(p2Flags);

  // Zero the reserved words
tempLong = 0;
fromEng_P->insert(tempChar);
tempLong = (maxRaidLBA) ? maxRaidLBA : capacity.maxLBA;
fromEng_P->insert(tempLong);
tempLong = 0;

fromEng_P->insert(udmaModeSupported);
fromEng_P->insert(udmaModeSelected);

fromEng_P->insert(tempChar);

  // Return the diagnostic test type
fromEng_P->insert(scheduledDiag);
  // Return this device's physical sector size
fromEng_P->insert(phyBlockSize);

  // Return extra bytes for future expansion
tempShort = 0;
#if defined (_DPT_STRICT_ALIGN)
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
#else
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
#endif

if (fromEng_P->insert(tempShort))
   retVal = MSG_RTN_COMPLETED;

return (retVal);

}
//dptRAIDdev_C::rtnInfo() - end


//Function - dptRAIDdev_C::getObjFlags() - start
//===========================================================================
//
//Description:
//
//    This function sets RAID device flags.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::getObjFlags(uSHORT &flg)
{

  // Call base class function
dptSCSIdev_C::getObjFlags(flg);

  // Set the valid RAID info flag
flg |= FLG_DEV_RAID_VALID;

if (nextRAIDmgr()!=NULL)
     // Indicate that the next RAID manager field is valid
   flg |= FLG_DEV_RAID_NEXT_MGR;

if (isComponent())
     // Indicate that this device is a component of another RAID device
   flg |= FLG_DEV_RAID_COMPONENT;

if (raidFlags & FLG_RDEV_HS_PROTECTED)
     // Indicate that this device is protected by a Hot Spare
   flg |= FLG_DEV_HS_PROTECTED;

}
//dptRAIDdev_C::getObjFlags() - end


//Function - dptRAIdev_C::nextRAIDmgr() - start
//===========================================================================
//
//Description:
//
//    This function returns a pointer to the next manager that can use
//this device as a RAID component device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptSCSImgr_C *	dptRAIDdev_C::nextRAIDmgr()
{

dptSCSImgr_C *mgr_P = myMgr_P();
if (isLogical() || (!mgr_P->isRAIDcapable() && !isSuppressed()) )
   mgr_P = mgr_P->myMgr_P();

return (mgr_P);

}
//dptRAIDdev_C::nextRAIDmgr() - end


//Function - dptRAIDdev_C::getCompAddr() - start
//===========================================================================
//
//Description:
//
//    This function uses this devices component addresses to find the
//next available address in the specified list.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	dptRAIDdev_C::getCompAddr(dptCoreList_C &list,uSHORT hbaCheck)
{

   uSHORT	found = 0;
   dptRAIDdev_C	*comp_P;

comp_P = (dptRAIDdev_C *) compList.reset();
while ((comp_P!=NULL) && !found) {
     // Update the component's HBA #
   comp_P->updateHBAnum();
   addr = comp_P->getAddr();
     // If the address is unique && the components HBA is
   if (isUniqueAddr(list,addr,0xf))
      found = 1;
     // If the components HBA must support RAID...
   if (hbaCheck)
	// If this component's HBA can configure RAID devices...
      if (!comp_P->myHBA_P()->isRAIDready())
         found = 0;
   if (!found)
      comp_P = (dptRAIDdev_C *) compList.next();
}

return (found);

}
//dptRAIDdev_C::getCompAddr() - end


//Function - dptRAIDdev_C::setHScoverage() - start
//===========================================================================
//
//Description:
//
//    This function sets a flag indicating that this RAID drive is
//protected by a Hot Spare drive if no component is larger than the
//specified Hot Spare.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::setHScoverage(uLONG hsMaxLBA)
{

if ( (getObjType()==DPT_SCSI_DASD) && (redundants>0) && isLogical() &&
     (getRAIDtype()!=RAID_HOT_SPARE) ) {
     // Indicate that this device is not protected by a Hot Spare
   raidFlags &= ~FLG_RDEV_HS_PROTECTED;
   if (hsMaxLBA>0) {
      uLONG numDataDrives = compList.getNumObjs() - redundants;
      uLONG reqMaxLBA = 0xffffffffL;
      if (numDataDrives)
	 reqMaxLBA = capacity.maxLBA / numDataDrives;
      if (hsMaxLBA >= reqMaxLBA)
	 raidFlags |= FLG_RDEV_HS_PROTECTED;
   }
}

}
//dptRAIDdev_C::setHScoverage() - end


//Function - dptRAIDdev_C::preDelete() - start
//===========================================================================
//
//Description:
//
//    This function is called prior to deleting this object from the
//engine.
//
//Parameters:
//
//Return Value:
//
//   0 = Take no action
//   1 = Remove from engine core and free from memory
//   2 = Remove from engine core but do not free from memory
//       (The object must be maintained at a higher level)
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	dptRAIDdev_C::preDelete()
{

   uSHORT	retVal = 1;

if (isComponent())
   retVal = 0;

return (retVal);

}
//dptRAIDdev_C::preDelete() - end


//Function - dptRAIDdev_C::handleMessage() - start
//===========================================================================
//
//Description:
//
//    This routine handles DPT events for the dptRAIDdev_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::handleMessage(DPT_MSG_T	message,
					    dptBuffer_S *fromEng_P,
					    dptBuffer_S *toEng_P
					   )
{

   DPT_RTN_T	retVal = MSG_RTN_IGNORED;

switch (message) {

     // Return device IDs from this device's component list
   case	MSG_ID_COMPONENTS:
	retVal = rtnIDfromList(compList,fromEng_P,toEng_P,0);
	break;

     // Return device IDs from this device's component list traversing
     // each component's component list
   case	MSG_ID_ALL_COMPONENTS:
	retVal = rtnIDfromList(compList,fromEng_P,toEng_P,OPT_TRAVERSE_COMP);
	break;

     // Flag this device as the target device for a RAID-1 rebuild (copy)
   case MSG_RAID1_SET_TARGET:
	retVal = handleCopyTarget();
	break;
	
	case MSG_ASSIGN_NEW_MAGIC_NUM:
		if (raidType != 0xffff)
			retVal = remagicNumberArray();
	break;

   default:
	  // Call base class event handler
	retVal = dptSCSIdev_C::handleMessage(message,fromEng_P,toEng_P);
	break;


} // end switch

return (retVal);

}
//dptRAIDdev_C::handleMessage() - end


//Function - dptRAIDdev_C::handleCopyTarget() - start
//===========================================================================
//
//Description:
//
//    This function sets this device to be the target of a RAID-1 copy.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::handleCopyTarget()
{

   DPT_RTN_T	retVal = MSG_RTN_IGNORED;

if (parent.dev_P!=NULL) {
   retVal = parent.dev_P->setCopyTarget(this);
}

return (retVal);

}
//dptRAIDdev_C::handleCopyTarget() - end


//Function - dptRAIDdev_C::setCopyTarget() - start
//===========================================================================
//
//Description:
//
//    This function sets the specified device as the target of a RAID-1
//rebuild command and insures that the other component is the source.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptRAIDdev_C::setCopyTarget(dptRAIDdev_C *tgt_P)
{

   DPT_RTN_T	retVal = MSG_RTN_IGNORED;

  // If this is an HBA level RAID-1 array...
if ((getRAIDtype()==1) && (getLevel()==1)) {
   retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
   dptRAIDdev_C *dev_P = (dptRAIDdev_C *) compList.reset();
   while (dev_P!=NULL) {
      if (dev_P==tgt_P) {
	 dev_P->raidFlags |= FLG_RDEV_RAID1_TARGET;
	 retVal = MSG_RTN_COMPLETED;
      }
      else
	 dev_P->raidFlags &= ~FLG_RDEV_RAID1_TARGET;
      dev_P = (dptRAIDdev_C *) compList.next();
   }
}

return (retVal);

}
//dptRAIDdev_C::setCopyTarget() - end


//Function - dptRAIDdev_C::isValidHotSpare() - start
//===========================================================================
//
//Description:
//
//	This function determines if this device is a valid Hot-Spare.
//A valid Hot-Spare is a Hot-Spare capable of protecting an array.
//
//---------------------------------------------------------------------------

uSHORT	dptRAIDdev_C::isValidHotSpare()
{

   uSHORT	retVal = 0;

  // If an Optimal Hot-Spare...
if ((getRAIDtype()==RAID_HOT_SPARE) && (isOptimal() || isAbsent())) {
     // If the component is not physically missing...
   dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
   if (comp_P != NULL) {
      if (!comp_P->isMissing())
	 retVal = 1;
   }
}

return (retVal);

}
//dptRAIDdev_C::isValidHotSpare() - end


//Function - dptRAIDdev_C::chkCompDiags() - start
//===========================================================================
//
//Description:
//
//	This function determines if a firmware based diagnostic is
//scheduled on this firmware array or a component of this firmware
//array.
//
//---------------------------------------------------------------------------

uINT	dptRAIDdev_C::chkCompDiags()
{

  // If this is a firmware logical device...
if (getLevel() != 1)
   return (0);

uINT foundDiag = 1;
  // If this firmware array doesn't have a diagnostic scheduled...
if (!scheduledDiag) {
     // Check all components for a scheduled diagnostic
   foundDiag = 0;
   dptRAIDdev_C *comp_P = (dptRAIDdev_C *) compList.reset();
   while (comp_P != NULL) {
      if (comp_P->getScheduledDiag()) {
	 foundDiag = 1;
	 break;
      }
      comp_P = (dptRAIDdev_C *) compList.next();
   }
}

return (foundDiag);

}
//dptRAIDdev_C::chkCompDiags() - end


//Function - dptRAIDdev_C::setNewPhyStatus() - start
//===========================================================================
//
//Description:
//	This function sets the proposed status for this physical
//device.
//
//---------------------------------------------------------------------------

void	dptRAIDdev_C::setNewPhyStatus(uCHAR inMain,uCHAR inSub)
{

  // If a physical device...
if (getLevel() == 2) {
     // Set the new status
   newPhyStatus = (inMain & 0x0f) | ((inSub & 0x07) << 4) | 0x80;
     // Indicate that newPhyStatus is valid
   raidFlags |= FLG_RDEV_NEWPHYSTATUS;
}

}
//dptRAIDdev_C::setNewPhyStatus() - end


//Function - dptRAIDdev_C::~dptRAIDdev_C() - start
//===========================================================================
//
//Description:
//
//    This function is the destructor for the dptRAIDdev_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptRAIDdev_C::~dptRAIDdev_C()
{

freeComponents();

if (segment_P != NULL) {
	delete[] segment_P;
	segment_P = NULL;
}

}
//dptRAIDdev_C::~dptRAIDdev_C() - end


// Function - DPT_RTN_T    dptRAIDdev_C::EnableExpandArray() - start
//===========================================================================
//
//Description:  
//
//
//
//Parameters:  
//
//Return Value:  
//
//Global Variables Affected:  
//
//Remarks: (Side effects, Assumptions, Warnings...) 
//
//
//===========================================================================
DPT_RTN_T    dptRAIDdev_C::EnableExpandArray()
{
	DPT_RTN_T rtnVal;
	rtnVal = MSG_RTN_FAILED | ERR_GET_CCB;
   
	// If in wolfpack cluster mode...
	if (myHBA_P()->isClusterMode()) {
		// Attempt to reserve this array...
		if (reserveDevice() != MSG_RTN_COMPLETED) {
			return ERR_RESERVATION_CONFLICT;
		}
	}

     // Get a CCB
	engCCB_C *ccb_P = getCCB();
	if (ccb_P!=NULL) {
	
		// send a synch cache to the array
		ccb_P->clrData();
		ccb_P->eataCP.scsiCDB[0] = 0x35;
		ccb_P->eataCP.scsiCDB[9] = 0x80;
		ccb_P->setInterpret();
		launchCCB(ccb_P);

		int numNewComps = 0;

		rtnVal = MSG_RTN_COMPLETED;
		// figure out the number if new components there are
		dptSCSIdev_C *comp_P = (dptSCSIdev_C *) compList.reset();
		while(comp_P) {
			
			if (comp_P->isNewDeviceToArray()) {
				numNewComps++;
				// If in wolfpack cluster mode...
				if (myHBA_P()->isClusterMode()) {
					// Attempt to reserve this component...
					rtnVal = comp_P->reserveDevice();
					if (rtnVal != MSG_RTN_COMPLETED) {
						rtnVal = ERR_RESERVATION_CONFLICT;
						break;
					}
				}
			}

			comp_P = (dptSCSIdev_C *) compList.next();
		}

		if (rtnVal == MSG_RTN_COMPLETED) {
			ccb_P->reInit();
			ccb_P->clrData();
			// set up the mode page
			ccb_P->modeSelect(0x39, 2+sizeof(dptExpandArrayPage_S) + (numNewComps * sizeof(dptExpandArrayComp_S)), 0x83);


			dptExpandArrayPage_S *page_P = (dptExpandArrayPage_S *) ccb_P->modeParam_P->getData();
			page_P->setRaidType((uCHAR)raidType);
			page_P->scsiSwap();

			// point to the components section
			dptExpandArrayComp_S *expComp_P = (dptExpandArrayComp_S *) (((uCHAR *) page_P) + sizeof(dptExpandArrayPage_S));

			// add the components to the mode page
			comp_P = (dptSCSIdev_C *) compList.reset();
			for (int x = 0; x < numNewComps;x++) {

				int found = 0;
				
				// find the next new device to the array
				while(!found) {
				
					if (comp_P->isNewDeviceToArray())
						found = 1;
					else 
						comp_P = (dptSCSIdev_C *) compList.next();
				}

				// clear the data
				//memset(expComp_P, 0, sizeof(dptExpandArrayComp_S));

				// fill it in
				uCHAR chanID = comp_P->addr.chan << 5;
				chanID |= (comp_P->addr.id & 0x1f);
				uCHAR extendedId = (comp_P->addr.id > 0x1f) ? comp_P->addr.id : 0;

				expComp_P->setChanID(chanID);
				expComp_P->setExtendedId(extendedId);
				expComp_P->setLUN(comp_P->addr.lun);
				expComp_P->setMagicNum(comp_P->getMagicNum());
				expComp_P->scsiSwap();

				// next
				expComp_P++;

				// reset the is 'part of expanded array' flags
				comp_P->clrNewDeviceToArray();

				comp_P = (dptSCSIdev_C *) compList.next();
			}
			
			// clear the expnaded array bit inside here so that
			// the engine can then do LAP commands
			clrExpandedArray();
			
			ccb_P->engFlags |= FLG_CCB_ENG_RAID;
			rtnVal = launchCCB(ccb_P);
		}
		
	// Free the CCB
		ccb_P->clrInUse();

	} // end if (ccb_P!=NULL) 

	return rtnVal;
} 
// end - DPT_RTN_T    dptRAIDdev_C::EnableExpandArray()


//Function - dptRAIDdev:remagicNumberArray() - start
//===========================================================================
//
//Description: assigns new magic numbers for the array and its comps
//
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
DPT_RTN_T  dptRAIDdev_C::remagicNumberArray()
{

	DPT_RTN_T rtnVal = MSG_RTN_COMPLETED;

	  // Find all lower level manager's physical objects
	dptRAIDdev_C *obj_P = (dptRAIDdev_C *) compList.reset();
	while (obj_P!=NULL) {
		if (obj_P->getRAIDtype() != 0xffff)
			// Find all of the sub-manager's physical objects
			if ((rtnVal = obj_P->remagicNumberArray()))
				break;
			// Get the next object
		obj_P = (dptRAIDdev_C *) compList.next();
	}

	if (!rtnVal) {
		// go thru the components and make a new magic number
		obj_P = (dptRAIDdev_C *) compList.reset();
	
		// go thru all the components and make a new magic number
		while(obj_P) {
			obj_P->magicNum = genMagicNum();
			compList.exists(obj_P);
			obj_P = (dptRAIDdev_C *) compList.next();
		}

		// make a new one for me
		magicNum = genMagicNum();

		rtnVal = ((dptDevice_C *) this)->raidLAPcmd(LAP_CMD_ASSIGN_MAGIC);
	}

	return rtnVal;
}


//Function - dptRAIDdev:decCompCount() - start
//===========================================================================
//Description:
//		This function decrements the component count.
//---------------------------------------------------------------------------

void  dptRAIDdev_C::decCompCount()
{

	if (compCount)
		--compCount;

}
//dptRAIDdev_C::decCompCount() - end


//Function - dptRAIDdev:updateMaxRaidLBA() - start
//===========================================================================
//Description:
//		This function updates maxRaidLBA from the manager's drive size
//table.
//---------------------------------------------------------------------------

void  dptRAIDdev_C::updateMaxRaidLBA()
{

	// If an HBA physical device
	if (getLevel() == 2)
		maxRaidLBA = myMgr_P()->getMaxRaidLBA(capacity.maxLBA);
	else
		maxRaidLBA = capacity.maxLBA;

}
//dptRAIDdev_C::updateMaxRaidLBA() - end