home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pTrackdisk / RigidDiskBlock.c next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  8.5 KB  |  324 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 27 Dec 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>RigidDiskBlock.c<<   12 Jan 1997    18:26:16 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##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
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pExec/MsgPort.h"
  53. #include "p:pExec/Memory.h"
  54. #include "p:pDOS/ArgTags.h"
  55. #include "p:pDOS/DosSig.h"
  56. #include "p:pDOS/DosErrors.h"
  57. #include "p:Device/Trackdisk.h"
  58. #include "p:Device/Hardblocks.h"
  59.  
  60. #include "p:proto/pLibExt.h"
  61. #include "p:proto/pExec2.h"
  62. #include "p:proto/pDOS2.h"
  63.  
  64. #ifdef _____ME_____
  65.   #include "grund/inc_string.h"
  66.   #include "grund/inc_stdio.h"
  67. #else
  68.  
  69.  #define MAX(a,b) ( (a)>(b) ? (a):(b) )
  70.  
  71.  #ifdef __cplusplus
  72.  extern "C" {
  73.  #endif
  74.   #include <string.h>
  75.   #include <stdio.h>
  76.  #ifdef __cplusplus
  77.  }
  78.  #endif
  79. #endif
  80.  
  81.  
  82. const CHAR *HelpText=
  83. ""
  84. ;
  85.  
  86. const CHAR *PrgHeader=
  87. "";
  88.  
  89. const CHAR *PrgVerText=
  90. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  91.  
  92.  
  93.  
  94. /*----------------------------------
  95. -----------------------------------*/
  96. BOOL ChkSum(const void* buf)
  97. {
  98.   const ULONG *Buf=(ULONG*)buf;
  99.   size_t Size=Buf[1];
  100.   ULONG Sum;
  101.  
  102.   for(Sum=0; Size>0; --Size, ++Buf) Sum+=Buf[0];
  103.   return(Sum==0);
  104. }
  105.  
  106.  
  107.  
  108.  
  109. /*----------------------------------
  110. -----------------------------------*/
  111. BOOL LoadBlk(pOS_TrackdiskIO* io,ULONG num,void* buf,size_t bufSize)
  112. {
  113.   io->tdio_Command=CMD_READ;
  114.   io->tdio_Data    =buf;
  115.   io->tdio_Length  =bufSize;
  116.   io->tdio_LOffset =num*bufSize;
  117.   io->tdio_HOffset =0;
  118.   return( pOS_DoIO((pOS_IORequest*)io)==0 );
  119. }
  120.  
  121.  
  122.  
  123. /*----------------------------------
  124. -----------------------------------*/
  125. VOID PrintRDB(const pOS_RigidDiskBlock* rdb)
  126. {
  127.   printf(
  128. "rdb_HostID        = %ld\n"
  129. "rdb_BlockBytes    = %ld\n"
  130. "rdb_Flags         = 0x%lx\n"
  131. "rdb_BadBlockList  = %ld\n"
  132. "rdb_PartitionList = %ld\n"
  133. "rdb_FSHeaderList  = %ld\n"
  134. "rdb_DriveInit     = %ld\n"
  135. "rdb_Cylinders     = %ld\n"
  136. "rdb_Sectors       = %ld\n"
  137. "rdb_Heads         = %ld\n"
  138. "rdb_Interleave    = %ld\n"
  139. "rdb_Park          = %ld\n"
  140. "rdb_WritePreComp  = %ld\n"
  141. "rdb_ReducedWrite  = %ld\n"
  142. "rdb_StepRate      = %ld\n"
  143. "rdb_RDBBlocksLo   = %ld\n"
  144. "rdb_RDBBlocksHi   = %ld\n"
  145. "rdb_LoCylinder    = %ld\n"
  146. "rdb_HiCylinder    = %ld\n"
  147. "rdb_CylBlocks     = %ld\n"
  148. "rdb_AutoParkSec   = %ld\n"
  149. "rdb_HighRDSKBlock = %ld\n"
  150. ,rdb->rdb_HostID
  151. ,rdb->rdb_BlockBytes
  152. ,rdb->rdb_Flags
  153. ,rdb->rdb_BadBlockList
  154. ,rdb->rdb_PartitionList
  155. ,rdb->rdb_FSHeaderList
  156. ,rdb->rdb_DriveInit
  157. ,rdb->rdb_Cylinders
  158. ,rdb->rdb_Sectors
  159. ,rdb->rdb_Heads
  160. ,rdb->rdb_Interleave
  161. ,rdb->rdb_Park
  162. ,rdb->rdb_WritePreComp
  163. ,rdb->rdb_ReducedWrite
  164. ,rdb->rdb_StepRate
  165. ,rdb->rdb_RDBBlocksLo
  166. ,rdb->rdb_RDBBlocksHi
  167. ,rdb->rdb_LoCylinder
  168. ,rdb->rdb_HiCylinder
  169. ,rdb->rdb_CylBlocks
  170. ,rdb->rdb_AutoParkSeconds
  171. ,rdb->rdb_HighRDSKBlock);
  172. }
  173.  
  174.  
  175. /*----------------------------------
  176. -----------------------------------*/
  177. VOID PrintPart(const pOS_PartitionBlock* part)
  178. {
  179.   printf(
  180. "pb_HostID           = %ld\n"
  181. "pb_Next             = %ld\n"
  182. "pb_Flags            = %ld\n"
  183. "pb_DevFlags         = 0x%lx\n"
  184. "pb_DriveName        = <%.32s>\n"
  185. "pbde_TableSize      = %ld\n"
  186. "pbde_SizeBlock      = %ld\n"
  187. "pbde_Surfaces       = %ld\n"
  188. "pbde_BlocksPerTrack = %ld\n"
  189. "pbde_Reserved       = %ld\n"
  190. "pbde_PreAlloc       = %ld\n"
  191. "pbde_Interleave     = %ld\n"
  192. "pbde_LowCyl         = %ld\n"
  193. "pbde_HighCyl        = %ld\n"
  194. "pbde_NumBuffers     = %ld\n"
  195. "pbde_BufMemType     = 0x%lx\n"
  196. "pbde_MaxTransfer    = 0x%lx\n"
  197. "pbde_Mask           = 0x%lx\n"
  198. "pbde_BootPri        = %ld\n"
  199. ,part->pb_HostID
  200. ,part->pb_Next
  201. ,part->pb_Flags
  202. ,part->pb_DevFlags
  203. ,&part->pb_DriveName[1]
  204. ,part->pb_Env.pbde_TableSize
  205. ,part->pb_Env.pbde_SizeBlock
  206. ,part->pb_Env.pbde_Surfaces
  207. ,part->pb_Env.pbde_BlocksPerTrack
  208. ,part->pb_Env.pbde_Reserved
  209. ,part->pb_Env.pbde_PreAlloc
  210. ,part->pb_Env.pbde_Interleave
  211. ,part->pb_Env.pbde_LowCyl
  212. ,part->pb_Env.pbde_HighCyl
  213. ,part->pb_Env.pbde_NumBuffers
  214. ,part->pb_Env.pbde_BufMemType
  215. ,part->pb_Env.pbde_MaxTransfer
  216. ,part->pb_Env.pbde_Mask
  217. ,part->pb_Env.pbde_BootPri);
  218. };
  219.  
  220.  
  221. /*----------------------------------
  222. -----------------------------------*/
  223. #ifdef __cplusplus
  224. extern "C"
  225. #endif
  226.  
  227. VOID main()
  228. {
  229.   struct pOS_DosArgs* Args;
  230.   UWORD Err=0;
  231.   ULONG Ops[2]={0,(ULONG)"pScsi.device"};
  232.  
  233.   Args=pOS_ReadDosArgs(
  234. //
  235. "UNIT/N, DEVICE",
  236. Ops,sizeof(Ops)/sizeof(ULONG),
  237.  
  238.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  239.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  240.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  241.     TAG_END);
  242.  
  243.   if(Args) {
  244.     pOS_RigidDiskBlock RDB;
  245.     pOS_MsgPort        Port;
  246.     pOS_TrackdiskIO *IO;
  247.     ULONG Unit  =Ops[0] ? *((ULONG*)Ops[0]) : 0;
  248.  
  249.     if(pOS_ConstructMsgPort(&Port)) {
  250.       if(IO=(pOS_TrackdiskIO*)pOS_CreateIORequest(&Port,sizeof(pOS_TrackdiskIO))) {
  251.         pOS_OpenDevice((CHAR*)Ops[1],Unit,(pOS_IORequest*)IO,0,0);
  252.         if(IO->tdio_Error==0) {
  253.           pOS_DriveGeometry Geom;
  254.           memset(&Geom,0,sizeof(pOS_DriveGeometry));
  255.  
  256.           IO->tdio_Command=TDCMD_GetGeometry;
  257.           IO->tdio_Data    =&Geom;
  258.           IO->tdio_Length  =sizeof(pOS_DriveGeometry);
  259.           pOS_DoIO((pOS_IORequest*)IO);
  260.           if(IO->tdio_Error) {
  261.             printf("TDCMD_GetGeometry failed, error=%ld\n",IO->tdio_Error);
  262.             Geom.dg_SectorSize=512;
  263.           }
  264.           {
  265.             APTR Buf;
  266.             Buf=pOS_AllocMem(MAX(512,Geom.dg_SectorSize),MEMF_PUBLIC);
  267.             if(Buf) {
  268.               ULONG Num;
  269.               UWORD i;
  270.  
  271.               for(i=0; i<RDB_LOCATION_LIMIT; ++i) {
  272.                 LoadBlk(IO,i,Buf,512);
  273.                 if( ((pOS_RigidDiskBlock*)Buf)->rdb_ID==IDNAME_RIGIDDISK
  274.                     && ChkSum(Buf) ) break;
  275.               }
  276.               if(i<RDB_LOCATION_LIMIT) {
  277.                 pOS_PartitionBlock* Part;
  278.                 printf("Found RDG on %ld\n",i);
  279.                 RDB=*((pOS_RigidDiskBlock*)Buf);
  280.                 PrintRDB(&RDB);
  281.                 Part=(pOS_PartitionBlock*)Buf;
  282.  
  283.                 for(Num=RDB.rdb_PartitionList,i=16;
  284.                     i>0 && Num!=~0;
  285.                     --i, Num=Part->pb_Next)
  286.                 {
  287.                   LoadBlk(IO,Num,Buf,512);
  288.                   if(ChkSum(Buf)) {
  289.                     printf("\nPartition Block=%ld\n",Num);
  290.                     PrintPart(Part);
  291.                   }
  292.                   else {
  293.                     printf("Checksum error on block %ld\n",Num);
  294.                     break;
  295.                   }
  296.                 }
  297.               }
  298.               else printf("Don't found RDB\n");
  299.               IO->tdio_Command=TDCMD_Motor;
  300.               IO->tdio_Length  =0;
  301.               pOS_DoIO((pOS_IORequest*)IO);
  302.  
  303.               pOS_FreeMem(Buf,MAX(512,Geom.dg_SectorSize));
  304.             }
  305.             else printf("Cannot alloc memory, size=%ld\n",Geom.dg_SectorSize);
  306.           }
  307.  
  308.           pOS_CloseDevice((pOS_IORequest*)IO);
  309.         }
  310.         else printf("pOS_OpenDevice <%s> failed, error=%ld\n",Ops[1],IO->tdio_Error);
  311.         pOS_DeleteIORequest((pOS_IORequest*)IO);
  312.       }
  313.       else printf("pOS_CreateIORequest failed\n");
  314.       pOS_DestructMsgPort(&Port);
  315.     }
  316.     else printf("pOS_ConstructMsgPort failed\n");
  317.  
  318.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  319.   }
  320.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  321.  
  322.   pOS_SetShellFail(Err);
  323. }
  324.