File: gbl_fns.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 (681 lines) | stat: -rw-r--r-- 17,765 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
/* 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 - GBL_FNS.CPP
//***************************************************************************
//
//Description:
//
//    This file contains definitions for the stand alone functions
//that are used globally throughout the DPT engine.
//
//Author:	Doug Anderson
//Date:		5/10/94
//
//Editors:
//
//Remarks:
//
//
//***************************************************************************



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

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


//Function - positionSCSI() - start
//===========================================================================
//
//Description:
//
//    This function positions the specified list's current position
//pointer to point to the first object with a higher SCSI address than
//the specified SCSI address.
//
//Parameters:
//
//Return Value:
//
//  1 = The specified address unique to the list
//  0 = The specified address is not unique to the list
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//  1. This function can be called by pre-add-to-list functions to
//     create a list of SCSI objects sorted in SCSI address order.
//
//---------------------------------------------------------------------------

uSHORT	positionSCSI(dptCoreList_C &list,dptAddr_S inAddr)
{

   uSHORT	unique = 1;
   uSHORT	done = 0;

dptSCSIobj_C *obj_P = (dptSCSIobj_C *) list.reset();
while ((obj_P!=NULL) && !done) {
     // Update the object's HBA number
   obj_P->updateHBAnum();
     // If the SCSI addr matches this object's addr...
   if (inAddr == obj_P->getAddr())
      unique = 0;
     // If the SCSI addr is less than this object's addr...
   if (inAddr < obj_P->getAddr())
	// Done traversing the list
      done = 1;
   else
	// Get the next object
      obj_P = (dptSCSIobj_C *) list.next();
}

  // Return the unique status of the
return (unique);

}
//positionSCSI() - end


//Function - isUniqueAddr() - start
//===========================================================================
//
//Description:
//
//    This function determines if the specified SCSI address exists
//within the specified list.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	isUniqueAddr(dptCoreList_C &list,dptAddr_S inAddr,uCHAR mask)
{

   uCHAR	addrMatch;
   uSHORT	unique = 1;

dptSCSIobj_C *obj_P = (dptSCSIobj_C *) list.reset();
while ((obj_P!=NULL) && (unique)) {
   addrMatch = 0;
     // Update the object's HBA #
   obj_P->updateHBAnum();
   if (obj_P->getHBA()==inAddr.hba)
      addrMatch |= 0x08;
   if (obj_P->getChan()==inAddr.chan)
      addrMatch |= 0x04;
   if (obj_P->getID()==inAddr.id)
      addrMatch |= 0x02;
   if (obj_P->getLUN()==inAddr.lun)
      addrMatch |= 0x01;
   if ((addrMatch&mask)==mask) unique = 0;
      // Get the next element
   obj_P = (dptSCSIobj_C *) list.next();
}

return (unique);

}
//isUniqueAddr() - end


//Function - rtnIDfromList() - start
//===========================================================================
//
//Description:
//
//    This function prepares to traverse a list and return the ID
//structures of all object's of the specified type.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	rtnIDfromList(dptCoreList_C &list,dptBuffer_S *fromEng_P,
			      dptBuffer_S *toEng_P,uSHORT action
			     )
{

   DPT_RTN_T		retVal;
   uSHORT		objType = DPT_ANY_OBJECT;
   uSHORT		allExcept = 0;
   uSHORT		raidType = 0xffff;

  // If an object type was specified...
if (toEng_P->extract(objType)) {
     // If the exception bit is set...
   if (objType & DPT_EXCEPT) {
	// Clear the exception bit in the object type
      objType &= ~DPT_EXCEPT;
      if (objType==DPT_ANY_MANAGER)
	 objType = DPT_ANY_DEVICE;
      else if (objType==DPT_ANY_DEVICE)
	 objType = DPT_ANY_MANAGER;
      else if (objType==DPT_ANY_OBJECT)
	 objType = 0xffff;
      else
	 allExcept = 1;
   }
}
if (!toEng_P->extract(raidType))
   raidType = 0xffff;

  // Return the ID structure of all objects of the specified type
retVal = rtnFromList(list,fromEng_P,objType,action,allExcept,raidType);

return (retVal);

}
//rtnIDfromList() - end


//Function - rtnFromList() - start
//===========================================================================
//
//Description:
//
//    This function traverses the specified list returning the DPT ID
//structure for the specified object type.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	rtnFromList(dptCoreList_C &list,dptBuffer_S *&fromEng_P,
			    uSHORT objType,uSHORT action,uSHORT allExcept,
			    uSHORT raidType
			   )
{

   DPT_RTN_T		retVal = MSG_RTN_COMPLETED;
   dptSCSImgr_C		*mgr_P;
   dptRAIDdev_C		*raid_P;

dptSCSIobj_C *obj_P = (dptSCSIobj_C *) list.reset();
while (obj_P!=NULL) {

     // If a standard object type...
   if (objType<0x1000) {
      if (allExcept) {
	   // If this object is not the specified type...
	 if (obj_P->getObjType()!=objType)
	    retVal = obj_P->returnID(fromEng_P);
      }
       // If this object is the specified type...
      else if (obj_P->getObjType()==objType)
	 retVal = obj_P->returnID(fromEng_P);
   }

   if (obj_P->isManager()) {
	// Cast the object as a manager
      mgr_P = (dptSCSImgr_C *)  obj_P;
      if ((objType==DPT_ANY_MANAGER) || (objType==DPT_ANY_OBJECT))
	   // Return the manager's ID
	 retVal = obj_P->returnID(fromEng_P);
	// If the sub-manager's logical list should be traversed...
      if (action==OPT_TRAVERSE_LOG) {
	 retVal = rtnFromList(mgr_P->logList,fromEng_P,objType,
			      action,allExcept,raidType);
      }
	// If the sub-manager's physical list should be traversed...
      if (action==OPT_TRAVERSE_PHY) {
	 mgr_P = (dptSCSImgr_C *)  obj_P;
	 retVal = rtnFromList(mgr_P->phyList,fromEng_P,objType,
			      action,allExcept,raidType);
      }
   }
   else {
      if ((objType==DPT_ANY_DEVICE) || (objType==DPT_ANY_OBJECT))
	   // Return the device's ID
	 retVal = obj_P->returnID(fromEng_P);

	// Cast the object as a RAID device
      raid_P = (dptRAIDdev_C *) obj_P;
      if (objType==DPT_RAID_TYPE) {
	 if (allExcept) {
	      // If the device is not the specified RAID type...
	    if (raid_P->getRAIDtype()!=raidType)
	       retVal = obj_P->returnID(fromEng_P);
	 }
	    // If the device is the specified RAID type...
	 else if (raid_P->getRAIDtype()==raidType)
	    retVal = obj_P->returnID(fromEng_P);
      }
	// If the component list should be traversed...
      if (action==OPT_TRAVERSE_COMP)
	 retVal = rtnFromList(raid_P->compList,fromEng_P,objType,
			      action,allExcept,raidType);
   } // end else if (isDevice())

     // Get the next object in the list
   obj_P = (dptSCSIobj_C *) list.next();
}

return (retVal);

}
//rtnFromList() - end


//Function - findSubString() - start
//===========================================================================
//
//Description:
//
//    This function attempts to find the subStr within the searchStr.
//The maximum size of each string is determined by the smaller of the
//specified input limit or the first invalid ASCII character found.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
// Search Type:
// ------------
//	0	= subStr must match searchStr exactly
//		  - All trailing spaces are ignored
//	1	= Match subStr to 1st characters of searchStr
//		  - Ignore any trailing characters in the searchStr
//	2	= Find subStr anywhere in the searchStr
//		  (sub-string search)
//
//---------------------------------------------------------------------------

uSHORT	findSubString(uCHAR *subStr,uCHAR *searchStr,
		      uSHORT subLimit,uSHORT searchLimit,
		      uCHAR searchType
		     )
{

   uSHORT	found = 0;
   uSHORT	firstCh,restOfCh,firstLimit;

// Determine the maximum size of the search string
subLimit = strSize(subStr,subLimit);
// Determine the maximum size of the search string
searchLimit = strSize(searchStr,searchLimit);

if ( (subLimit<=searchLimit) && (searchLimit>0) && (subLimit>0) ) {
   if (searchType==2)
	// Search for the sub-string anywhere in the search string
      firstLimit = searchLimit-subLimit+1;
   else
	// Search for the sub-string at the front of the search string
      firstLimit = 1;
     // Look for the sub string in the search string
   for (firstCh=0;firstCh<firstLimit && !found;firstCh++) {
      if (upCh(subStr[0])==upCh(searchStr[firstCh])) {
	 found = 1;
	 for (restOfCh=1;restOfCh<subLimit;restOfCh++) {
	    if (upCh(subStr[restOfCh])!=upCh(searchStr[firstCh+restOfCh]))
	       found = 0;
	 }
      }
   }
   if ((searchType==0) && (subLimit!=searchLimit))
      found = 0;
}

return (found);

}
//findSubString() - end


//Function - strSize() - start
//===========================================================================
//
//Description:
//
//    This function determines the maximum # of valid characters in
//the specified input string.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	strSize(uCHAR *&str_P,uSHORT inLimit)
{

   uSHORT	limit = 0;
   uSHORT	valid = 1;
   uSHORT	trailBlanks = 0;

// Determine the maximum size of the sub string
while (limit<inLimit && valid) {
     // If an invalid ASCII character...
   if ((str_P[limit]<32) || (str_P[limit]>126))
      valid = 0;
   else {
      if (str_P[limit]==' ')
	 trailBlanks++;
      else
	 trailBlanks = 0;
      limit++;
   }
}

limit -= trailBlanks;

return (limit);

}
//strSize() - end


//Function - upCh() - start
//===========================================================================
//
//Description:
//
//    This function returns the uppercase character of the specified
//input character.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uCHAR 	upCh(uCHAR inChar)
{

if ((inChar>=97) && (inChar<=122))
   inChar -= 32;

return (inChar);

}
//upCh() - end

//---------------------------------------------------------------------------

char 	upCh(char inChar)
{

if ((inChar>=97) && (inChar<=122))
   inChar -= 32;

return (inChar);

}
//upCh() - end


//Function - upperCase() - start
//===========================================================================
//
//Description:
//
//   This function converts the specified string to uppercase.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	upperCase(uCHAR *b_P)
{

uSHORT i = 0;
while ((b_P[i]>=32) && (b_P[i]<=126)) {
   b_P[i] = upCh(b_P[i]);
   i++;
}

}
//upperCase() - end


//Function - findDASD() - start
//===========================================================================
//
//Description:
//
//    This function searches the specified list for a non-removable
//DASD device.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	findDASD(dptCoreList_C &list)
{

  uSHORT	found = 0;

   // Check all sub-manager's logical device lists
dptObject_C *obj_P = (dptObject_C *) list.reset();
while ((obj_P!=NULL) && !found) {
   if (obj_P->isManager())
      found = findDASD(((dptManager_C *)obj_P)->logList);
     // If a non-removable DASD device is present...
   else if ((((dptDevice_C *)obj_P)->getObjType()==DPT_SCSI_DASD) &&
	    !((dptDevice_C *)obj_P)->isRemovable() )
      found = 1;
   obj_P = (dptObject_C *) list.next();
} // end while (obj_P!=NULL)

return (found);

}
//findDASD() - end


//Function - findObjectAt() - start
//===========================================================================
//
//Description:
//
//    This function searches for a device visible in the specified list
//or a sub-manager's logical device list.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptObject_C *	findObjectAt(dptCoreList_C &list,dptAddr_S inAddr)
{

   dptObject_C	*retObj_P = NULL;

dptObject_C *obj_P = (dptObject_C *) list.reset();
while ((obj_P!=NULL) && (retObj_P==NULL)) {
     // Update the object's HBA #
   obj_P->updateHBAnum();
     // If the object is a manager...
   if (obj_P->isManager()) {
	// Attempt to find a logical device
      retObj_P = findObjectAt(((dptManager_C *)obj_P)->logList,inAddr);
	// If a device was not found...
      if (retObj_P==NULL)
	   // If the manager's HBA/Channel/ID match return the manager
	 if ( (obj_P->getHBA()==inAddr.hba) &&
	      (obj_P->getChan()==inAddr.chan) &&
	      (obj_P->getID()==inAddr.id) )
	    retObj_P = obj_P;
   }
     // If the device's address matches exactly
   else if (obj_P->getAddr()==inAddr)
      retObj_P = obj_P;
     // Get the next physical device
   obj_P = (dptObject_C *) list.next();
}

  // Return a pointer to the device found
return (retObj_P);

}
//findObjectAt() - end


//Function - findMagicObject() - start
//===========================================================================
//
//Description:
//	This function searches the specified list for a device with
//the specified magic number.
//
//---------------------------------------------------------------------------

dptDevice_C *	findMagicObject(dptCoreList_C &list,uLONG inMagicNum,uINT noMgrLog)
{

dptDevice_C *dev_P = NULL;

dptObject_C *obj_P = (dptObject_C *) list.reset();
while (obj_P) {
     // Only check magic #s of device objects (no managers)
   if (obj_P->isDevice()) {
      dev_P = (dptDevice_C *) obj_P;
	// If the device's magic # matches the specified magic #
      if (dev_P->getMagicNum() == inMagicNum)
	 break;
      dev_P = NULL;
   }
     // If we want to traverse the manager's logical device list
   else if (!noMgrLog) {
      dptManager_C *mgr_P = (dptManager_C *) obj_P;
	// Check the manager's logical device list
      dev_P = findMagicObject(mgr_P->logList,inMagicNum);
      if (dev_P)
	 break;
   }
     // Try the next object
   obj_P = (dptObject_C *) list.next();
}

return (dev_P);

}
//findMagicObject() - end


//Function - findDeviceFromTag() - start
//===========================================================================
//Description:
//	This function searches the specified list for a device with
//the specified tag.  This function will search also search all
//manager logical lists unless "noMgrLog" is set.
//---------------------------------------------------------------------------

dptDevice_C *	findDeviceFromTag(dptCoreList_C &list,DPT_TAG_T inTag,uINT noMgrLog)
{

dptDevice_C *dev_P = NULL;

// Search the list for the object with the specified tag...
dptObject_C *obj_P = (dptObject_C *) list.getObject(inTag);
if (obj_P != NULL) {
	if (obj_P->isDevice())
		dev_P = (dptDevice_C *) obj_P;
}
// If not found & all manager logical lists should be searched as well...
else if ((obj_P == NULL) && !noMgrLog) {
	dptManager_C *mgr_P = NULL;
	obj_P = (dptObject_C *) list.reset();
	while (obj_P != NULL) {
		if (obj_P->isManager()) {
			mgr_P = (dptManager_C *) obj_P;
			obj_P = (dptObject_C *) mgr_P->logList.getObject(inTag);
			if (obj_P != NULL) {
				dev_P = (dptDevice_C *) obj_P;
				break;
			}
		}
		obj_P = (dptObject_C *) list.next();
	}
}

return (dev_P);

}
//findDeviceFromTag() - end