home *** CD-ROM | disk | FTP | other *** search
- (*=================== S D L P H I G H U N I T ====================
- = =
- = REVISION 1.1 08/01/90 J.R. TAYLOR =
- = =
- ==========================================================================
- = =
- = SDLP Management Library for TP V:4.0, 5.0, 5.5, 6.0 =
- = =
- = Written By Jonathan Robert Taylor =
- = =
- = =
- = This code is the property of Columbia Data Products, Inc. =
- = It may be distributed and used outside CDP so long as this header =
- = remains intact and unmodified, and as long as it is used with a =
- = licensed Standard Device Level Protocol Kernel. =
- = =
- = Copyright 1989,1990 Columbia Data Products, Inc. =
- = ALL RIGHTS RESERVED =
- = ---------------------------------------------------------------------- =
- = Revision History Procedures changed; overall purpose of change.=
- = Procedure specific revision notes below. =
- = Reverse chronological order. =
- = ---------------------------------------------------------------------- =
- = date initials change description =
- = ---------------------------------------------------------------------- =
- = 08-30-90 jrt made getpartinfo work on non-512 media =
- = 08-05-90 jrt made sdlpscanunit so that it can re-scan device =
- = 08-01-90 jrt Got rid of all references to b[1] =
- = 07-16-90 jrt Started =
- = =
- ==========================================================================
- *)
-
-
- Unit SDLPHIGH;
-
- {-------------------------------------------------------------------------}
- { UNIT SDLPhigh }
- {-------------------------------------------------------------------------}
- { PURPOSE: High-Level SDLP Library. This unit provides a complete list }
- { all attached devices with basic information available on each, including}
- { device type & name as well as the partitioning data (where it exists) }
- { SOURCE : JR Taylor }
- {-------------------------------------------------------------------------}
-
-
- Uses
-
- DOS,
- VSDLPLOW;
-
-
- Type
-
- {----------------------------------}
- { SDLPDev -- Info on a SDLP device }
- {----------------------------------}
-
- SDLPDev = RECORD
- UnitNum : BYTE;
- HAC : BYTE;
- Target : BYTE;
- LUN : BYTE;
- TypeNum : WORD;
- Blocks : LONGINT;
- BlockSize: WORD;
- DevSizeB : LONGINT;
- DevSizeM : LONGINT;
- VendorID : Array[1..08] of CHAR;
- ProdName : Array[1..16] of CHAR;
- RevLevel : Array[1..04] of CHAR;
- Name : STRING[32];
- NumPars : WORD;
- END;
-
- PtrToSDLPDev = ^SDLPDev;
-
- {------------------------------------------------------}
- { CHAR_BYTE -- Union of character and byte for buffers }
- {------------------------------------------------------}
-
- CHAR_BYTE = RECORD
- Case INTEGER of
- 1 : (C:CHAR);
- 2 : (B:BYTE);
- END;
-
-
- Var
-
- Dev : Array[1..64] of PtrToSDLPDev;
- NumDev : WORD;
-
- {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
-
- Procedure SDLPScanLUN( SUnit : INTEGER;
- var DType : BYTE;
- var Err : BYTE );
-
- Procedure SDLPScanUnit( UnitNumber : INTEGER );
-
- Procedure SDLPScanHAC( HAC : INTEGER );
-
- Procedure SDLPScanSystem;
-
- Procedure Open_SDLPHigh;
-
- Procedure Close_SDLPHigh;
-
-
- Implementation {===========================================================}
-
- {-------------------------------------------------------------------------}
- { Procedure TestUnitReady }
- {-------------------------------------------------------------------------}
- { IN: SUnit (INTEGER) SCSI Unit Number (... hhtt tlll) }
- { VAR Err (BYTE) operation error code }
- { OUT: (none) }
- { Simple test to determine if device exists at the unit number provided. }
- {-------------------------------------------------------------------------}
-
- Procedure TestUnitReady(SUnit : INTEGER; VAR Err:BYTE);
- VAR
- CDB : ARRAY[1..6] of BYTE;
- BUF : ARRAY[1..6] of BYTE;
- Error : WORD;
- Error2 : WORD;
-
- BEGIN
- FillChar( CDB, SizeOf( CDB ), 0 );
-
- Error := InSCSI( SUnit, Addr( CDB ), Addr( Buf ), 6, 0 );
-
- If Error AND $0F = 2 Then
- BEGIN
- CDB[1] := $03;
- CDB[2] := $00;
- CDB[3] := $00;
- CDB[4] := $00;
- CDB[5] := $18;
- CDB[6] := $00;
-
- Error2 := InSCSI( SUnit, Addr( CDB ), Addr( Buf ), 6, 0 );
- END; { Of Then }
-
- Err := Error;
- END; { Of TestUnitReady }
-
- {-------------------------------------------------------------------------}
- { Procedure SDLPScanLUN }
- {-------------------------------------------------------------------------}
- { IN: SUnit (INTEGER) target SCSI Unit Number (... hhtt tlll) }
- { VAR DType (BYTE) returned device Type }
- { VAR Err (BYTE) returned error code }
- { OUT: (none) }
- { Detects if the given LUN exists, and if so, Scans the device for all }
- { information. This data is stored in the Dev structure. }
- {-------------------------------------------------------------------------}
-
- Procedure SDLPScanLUN( SUnit : INTEGER;
- var DType : BYTE;
- var Err : BYTE );
-
- Var
-
- Z : INTEGER;
- CDB : ARRAY[1..12] of BYTE;
- NumB : LONGINT;
- Bsize : WORD;
- Buff : ARRAY[1..40] of CHAR_BYTE;
- dnumdev : INTEGER;
- R,R2 : REAL;
-
-
- BEGIN
- {--------------------------------------------}
- { Check for Drive present and if so the type }
- {--------------------------------------------}
-
- SDLP_GetDevInfo( SUnit, TRUE, FALSE, NumB, BSize, DType, Err );
-
- If ( Err = 0 ) AND ( DType < 10 ) OR ( DType = $80 ) Then
- BEGIN
- dnumdev:=-1;
-
- For Z:=1 to NumDev Do
- BEGIN
- if dev[z]^.UnitNum=SUnit Then
- dnumdev:=Z;
- END;
-
- If DNumDev=-1 Then
- BEGIN
- inc(numdev);
- dnumdev:=numdev;
- END;
-
- If Dev[DNumDev]=Nil Then
- BEGIN
- New(Dev[DNumDev]);
- END;
-
- With Dev[DNumDev]^ Do
- BEGIN
- TypeNum:=DType;
- UnitNum:= SUnit;
- HAC := SUnit SHR 6;
- Target :=(SUnit SHR 3) AND$07;
- Lun := SUnit AND $07;
- END;
-
- {----------------------}
- { Get the Devices Size }
- {----------------------}
-
- SDLP_GetDevInfo( SUnit, TRUE, TRUE, NumB, BSize, DType, Err);
-
- If Err = 0 Then
- BEGIN
- With Dev[DNumDev]^ Do
- BEGIN
- Blocks:=NumB;
- BlockSize:=BSize;
- DevSizeB:=Blocks*BlockSize;
- DevSizeM:=DevSizeB DIV 1048576;
-
- { ^%^ Jon T Mod 04/21/92 }
-
- R := Blocks;
- R2 := BlockSize;
-
- DevSizeM:=Round( R * R2 / 1048576.0 );
-
- { End Jon T Mod ^%^ }
-
- END; { With Dev[NumDev]^ }
- END
- ELSE
- BEGIN
- With Dev[DNumDev]^ Do
- BEGIN
- Blocks:=-1;
- BlockSize:=0;
- DevSizeB:=-1;
- DevSizeM:=-1;
- END;
- END; { if nocarry(r.flags) / else }
-
- CDB[1]:=$12;
- CDB[2]:=$0;
- CDB[3]:=$0;
- CDB[4]:=$0;
- CDB[5]:=$24;
- CDB[6]:=$0;
-
- If InSCSI(Dev[DNumDev]^.UnitNum, Addr(CDB), Addr(Buff), 6, $24)<>0 Then
- BEGIN
-
- { Fill with something here }
-
- END;
-
- With Dev[DNumDev]^ DO
- BEGIN
- For Z:=1 to 8 DO
- VendorID[Z]:=Buff[8+Z].C;
- For Z:=1 to 16 DO
- ProdName[Z]:=Buff[16+Z].C;
- For Z:=1 to 4 DO
- RevLevel[Z]:=Buff[32+Z].C;
- Name:=VendorID+ProdName+RevLevel;
- END; { With Dev[NumDev]^ }
-
- Err := 0;
-
- END; { If Device was found }
-
- END;
-
- {-------------------------------------------------------------------------}
- { Procedure SDLPScanUnit }
- {-------------------------------------------------------------------------}
- { IN: UnitNumber (INTEGER) selected target ID }
- { OUT: (none) }
- { Scans the LUNs of the given Target for device information }
- {-------------------------------------------------------------------------}
-
- Procedure SDLPScanUnit( UnitNumber : INTEGER );
-
- Var
- Z : INTEGER;
- Error : BYTE;
- DType : BYTE;
- Test : BOOLEAN;
-
- BEGIN
-
- Z := -1;
-
- Repeat
-
- {MT_Do( 0 );}
-
- Inc( Z );
-
- SDLPScanLUN( UnitNumber + Z, DType, Error );
-
- Test := NOT ( ( Error = 0 ) AND ( DType < 10 ) OR ( DType = $80 ) );
-
- Until ( Test ) OR ( Z = 7 );
-
- END;
-
- {-------------------------------------------------------------------------}
- { Procedure SDLPScanHAC }
- {-------------------------------------------------------------------------}
- { IN: HAC (INTEGER) target Host Adapter }
- { OUT: (none) }
- { Scans each Target ID on the given HAC for device information }
- {-------------------------------------------------------------------------}
-
- Procedure SDLPScanHAC( HAC : INTEGER );
-
- Var
-
- Z : INTEGER;
-
- BEGIN
-
- For Z := 0 to 6 Do
- BEGIN
-
- SDLPScanUnit( ( HAC * 64 ) + ( Z * 8 ) );
-
- END;
-
- END;
-
- {-------------------------------------------------------------------------}
- { Procedure SDLPScanSystem }
- {-------------------------------------------------------------------------}
- { IN: (none) }
- { OUT: (none) }
- { Checks that SDLP exists and if so Scans entire system for device }
- { information }
- {-------------------------------------------------------------------------}
-
- Procedure SDLPScanSystem;
-
- Var
-
- VerNum : BYTE;
- NumHAC : BYTE;
- Err : BYTE;
- RamRes : BOOLEAN;
- Z : BYTE;
-
- BEGIN
-
- Repeat
-
- SDLP_SysIdent( VerNum, RamRes, NumHAC, Err );
-
- Until Err <> 4;
-
- If Err=0 Then
- For Z := 1 to NumHAC Do
- SDLPScanHac(Z-1);
-
- END;
-
-
- {-------------------------------------------------------------------------}
- { Procedure Open_SDLPHIGH }
- {-------------------------------------------------------------------------}
- { IN: (none) }
- { OUT: (none) }
- { Initializes all the structures and scans the bus to find all devices. }
- { data is stored in the Dev Structure. }
- {-------------------------------------------------------------------------}
-
-
- Procedure Open_SDLPHIGH;
-
- BEGIN
-
- SDLPScanSystem;
-
- END;
-
- {-------------------------------------------------------------------------}
- { Procedure Close_SDLPHIGH }
- {-------------------------------------------------------------------------}
- { IN: (none) }
- { OUT: (none) }
- { Does nothing for DOS, but exists for compatibility to other OS platforms}
- {-------------------------------------------------------------------------}
-
-
- Procedure Close_SDLPHigh;
-
- BEGIN
- {----------------------------------}
- { no actions need be taken for DOS }
- {----------------------------------}
- END;
-
-
- {-------------------------------------------------------------------------}
- { Unit SDLPHigh }
- {-------------------------------------------------------------------------}
-
- BEGIN
-
- For NumDev:=1 to 64 Do
- BEGIN
- Dev[NumDev]:=NIL;
- END;
-
- NumDev:=0;
-
- END.
-
-
-