home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 27 Dec 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>RigidDiskBlock.c<< 12 Jan 1997 18:26:16 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/RigidDiskBlock p:pLib/StartCode.o p:/pOS_RKRM/pTrackdisk/RigidDiskBlock.c p:pLib/StdIO.o -l pOSStub -l pOS
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pExec/MsgPort.h"
- #include "p:pExec/Memory.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:Device/Trackdisk.h"
- #include "p:Device/Hardblocks.h"
-
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
-
- #define MAX(a,b) ( (a)>(b) ? (a):(b) )
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
-
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL ChkSum(const void* buf)
- {
- const ULONG *Buf=(ULONG*)buf;
- size_t Size=Buf[1];
- ULONG Sum;
-
- for(Sum=0; Size>0; --Size, ++Buf) Sum+=Buf[0];
- return(Sum==0);
- }
-
-
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL LoadBlk(pOS_TrackdiskIO* io,ULONG num,void* buf,size_t bufSize)
- {
- io->tdio_Command=CMD_READ;
- io->tdio_Data =buf;
- io->tdio_Length =bufSize;
- io->tdio_LOffset =num*bufSize;
- io->tdio_HOffset =0;
- return( pOS_DoIO((pOS_IORequest*)io)==0 );
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID PrintRDB(const pOS_RigidDiskBlock* rdb)
- {
- printf(
- "rdb_HostID = %ld\n"
- "rdb_BlockBytes = %ld\n"
- "rdb_Flags = 0x%lx\n"
- "rdb_BadBlockList = %ld\n"
- "rdb_PartitionList = %ld\n"
- "rdb_FSHeaderList = %ld\n"
- "rdb_DriveInit = %ld\n"
- "rdb_Cylinders = %ld\n"
- "rdb_Sectors = %ld\n"
- "rdb_Heads = %ld\n"
- "rdb_Interleave = %ld\n"
- "rdb_Park = %ld\n"
- "rdb_WritePreComp = %ld\n"
- "rdb_ReducedWrite = %ld\n"
- "rdb_StepRate = %ld\n"
- "rdb_RDBBlocksLo = %ld\n"
- "rdb_RDBBlocksHi = %ld\n"
- "rdb_LoCylinder = %ld\n"
- "rdb_HiCylinder = %ld\n"
- "rdb_CylBlocks = %ld\n"
- "rdb_AutoParkSec = %ld\n"
- "rdb_HighRDSKBlock = %ld\n"
- ,rdb->rdb_HostID
- ,rdb->rdb_BlockBytes
- ,rdb->rdb_Flags
- ,rdb->rdb_BadBlockList
- ,rdb->rdb_PartitionList
- ,rdb->rdb_FSHeaderList
- ,rdb->rdb_DriveInit
- ,rdb->rdb_Cylinders
- ,rdb->rdb_Sectors
- ,rdb->rdb_Heads
- ,rdb->rdb_Interleave
- ,rdb->rdb_Park
- ,rdb->rdb_WritePreComp
- ,rdb->rdb_ReducedWrite
- ,rdb->rdb_StepRate
- ,rdb->rdb_RDBBlocksLo
- ,rdb->rdb_RDBBlocksHi
- ,rdb->rdb_LoCylinder
- ,rdb->rdb_HiCylinder
- ,rdb->rdb_CylBlocks
- ,rdb->rdb_AutoParkSeconds
- ,rdb->rdb_HighRDSKBlock);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID PrintPart(const pOS_PartitionBlock* part)
- {
- printf(
- "pb_HostID = %ld\n"
- "pb_Next = %ld\n"
- "pb_Flags = %ld\n"
- "pb_DevFlags = 0x%lx\n"
- "pb_DriveName = <%.32s>\n"
- "pbde_TableSize = %ld\n"
- "pbde_SizeBlock = %ld\n"
- "pbde_Surfaces = %ld\n"
- "pbde_BlocksPerTrack = %ld\n"
- "pbde_Reserved = %ld\n"
- "pbde_PreAlloc = %ld\n"
- "pbde_Interleave = %ld\n"
- "pbde_LowCyl = %ld\n"
- "pbde_HighCyl = %ld\n"
- "pbde_NumBuffers = %ld\n"
- "pbde_BufMemType = 0x%lx\n"
- "pbde_MaxTransfer = 0x%lx\n"
- "pbde_Mask = 0x%lx\n"
- "pbde_BootPri = %ld\n"
- ,part->pb_HostID
- ,part->pb_Next
- ,part->pb_Flags
- ,part->pb_DevFlags
- ,&part->pb_DriveName[1]
- ,part->pb_Env.pbde_TableSize
- ,part->pb_Env.pbde_SizeBlock
- ,part->pb_Env.pbde_Surfaces
- ,part->pb_Env.pbde_BlocksPerTrack
- ,part->pb_Env.pbde_Reserved
- ,part->pb_Env.pbde_PreAlloc
- ,part->pb_Env.pbde_Interleave
- ,part->pb_Env.pbde_LowCyl
- ,part->pb_Env.pbde_HighCyl
- ,part->pb_Env.pbde_NumBuffers
- ,part->pb_Env.pbde_BufMemType
- ,part->pb_Env.pbde_MaxTransfer
- ,part->pb_Env.pbde_Mask
- ,part->pb_Env.pbde_BootPri);
- };
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[2]={0,(ULONG)"pScsi.device"};
-
- Args=pOS_ReadDosArgs(
- //
- "UNIT/N, DEVICE",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- pOS_RigidDiskBlock RDB;
- pOS_MsgPort Port;
- pOS_TrackdiskIO *IO;
- ULONG Unit =Ops[0] ? *((ULONG*)Ops[0]) : 0;
-
- if(pOS_ConstructMsgPort(&Port)) {
- if(IO=(pOS_TrackdiskIO*)pOS_CreateIORequest(&Port,sizeof(pOS_TrackdiskIO))) {
- pOS_OpenDevice((CHAR*)Ops[1],Unit,(pOS_IORequest*)IO,0,0);
- if(IO->tdio_Error==0) {
- pOS_DriveGeometry Geom;
- memset(&Geom,0,sizeof(pOS_DriveGeometry));
-
- IO->tdio_Command=TDCMD_GetGeometry;
- IO->tdio_Data =&Geom;
- IO->tdio_Length =sizeof(pOS_DriveGeometry);
- pOS_DoIO((pOS_IORequest*)IO);
- if(IO->tdio_Error) {
- printf("TDCMD_GetGeometry failed, error=%ld\n",IO->tdio_Error);
- Geom.dg_SectorSize=512;
- }
- {
- APTR Buf;
- Buf=pOS_AllocMem(MAX(512,Geom.dg_SectorSize),MEMF_PUBLIC);
- if(Buf) {
- ULONG Num;
- UWORD i;
-
- for(i=0; i<RDB_LOCATION_LIMIT; ++i) {
- LoadBlk(IO,i,Buf,512);
- if( ((pOS_RigidDiskBlock*)Buf)->rdb_ID==IDNAME_RIGIDDISK
- && ChkSum(Buf) ) break;
- }
- if(i<RDB_LOCATION_LIMIT) {
- pOS_PartitionBlock* Part;
- printf("Found RDG on %ld\n",i);
- RDB=*((pOS_RigidDiskBlock*)Buf);
- PrintRDB(&RDB);
- Part=(pOS_PartitionBlock*)Buf;
-
- for(Num=RDB.rdb_PartitionList,i=16;
- i>0 && Num!=~0;
- --i, Num=Part->pb_Next)
- {
- LoadBlk(IO,Num,Buf,512);
- if(ChkSum(Buf)) {
- printf("\nPartition Block=%ld\n",Num);
- PrintPart(Part);
- }
- else {
- printf("Checksum error on block %ld\n",Num);
- break;
- }
- }
- }
- else printf("Don't found RDB\n");
- IO->tdio_Command=TDCMD_Motor;
- IO->tdio_Length =0;
- pOS_DoIO((pOS_IORequest*)IO);
-
- pOS_FreeMem(Buf,MAX(512,Geom.dg_SectorSize));
- }
- else printf("Cannot alloc memory, size=%ld\n",Geom.dg_SectorSize);
- }
-
- pOS_CloseDevice((pOS_IORequest*)IO);
- }
- else printf("pOS_OpenDevice <%s> failed, error=%ld\n",Ops[1],IO->tdio_Error);
- pOS_DeleteIORequest((pOS_IORequest*)IO);
- }
- else printf("pOS_CreateIORequest failed\n");
- pOS_DestructMsgPort(&Port);
- }
- else printf("pOS_ConstructMsgPort failed\n");
-
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
- }
-