home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Includes_and_Autodocs_3.5 / include / libraries / hdwrench.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-20  |  14.2 KB  |  487 lines

  1. #ifndef LIBRARIES_HDWRENCH_H
  2. #define LIBRARIES_HDWRENCH_H
  3.  
  4. /*
  5. **    $VER: hdwrench.h 44.3 (29.7.1999)
  6. **    Includes Release 44.1
  7. **
  8. **    Disk Prep Support Library API includes
  9. **
  10. **    (C) Copyright 1999 Joanne B. Dow, Wizardess Designs,
  11. **        for license to Amiga, Inc.
  12. **
  13. **        All Rights Reserved
  14. */
  15.  
  16. /*****************************************************************************/
  17.  
  18. #ifndef EXEC_LIBRARIES_H
  19. #include <exec/libraries.h>
  20. #endif
  21.  
  22. #ifndef DEVICES_HARDBLOCKS_H
  23. #include <devices/hardblocks.h>
  24. #endif
  25.  
  26. /*****************************************************************************/
  27.  
  28. struct HDWLibrary
  29. {
  30.         struct Library       ml_Lib;
  31.         ULONG                ml_SegList;
  32.         ULONG                ml_Flags;
  33.         APTR                 ml_ExecBase; /* pointer to exec base  */
  34.         long                *ml_relocs;   /* pointer to relocs.    */
  35.         struct HDWLibrary   *ml_origbase; /* pointer to original library base  */
  36.         long                 ml_numjmps;
  37. };
  38.  
  39. #define  HDWBaseName    "hdwrench.library"
  40.  
  41. /* === General Constant Defines === */
  42.  
  43. /* Artificial unassigned value for the RDB structures. */
  44. #define UNASSIGNED  (ULONG) -131L
  45.  
  46. /* End block number link within RDB structures */
  47. #define RDBEND      (ULONG) -1L
  48.  
  49. #define DEFAULT_RDBBLOCKSHI 63
  50.  
  51. /* === Structure & Typedefs === */
  52.  
  53. typedef struct
  54. {
  55.     USHORT  ready [ 16 ];   /* Tests ready and first block read */
  56.     USHORT  there [ 16 ];   /* Tests as "there" but fails other tests */
  57. } ValidIDstruct;
  58.  
  59.  
  60. /* Actual disk read write return structure: */
  61. struct rw_return                /* Should fit within a ULONG */
  62. {
  63.     USHORT  success;            /* Error code */
  64.     USHORT  failed_word;        /* 0 on reads. */
  65.     USHORT  block_written;      /* 0 on reads. */
  66. };
  67.  
  68. enum rw_success_val             /* Return values for rw_return.success field. */
  69. {
  70.     success = 0,                /* 0 */
  71.     success_on_retry_write,     /* 1 */
  72.     success_on_retry_read,      /* 2 */
  73.     failed_on_write,            /* 3 */
  74.     failed_on_reread,           /* 4 */
  75.     illegal_command,            /* 5 */
  76.     io_command_failure,         /* 6 */
  77.     scsi_command_failure,       /* 7 */
  78.     out_of_memory,              /* 8 */
  79.     no_more_disk_blocks,        /* 9 */
  80.     rdsk_not_located,           /* 10 */
  81.     io_device_not_open,         /* 11 */
  82.     invalid_blocksize_found,    /* 12 */
  83.     no_callback_hook,           /* 13 */
  84.     user_aborted,               /* 14 */
  85.     operation_not_permitted     /* 15 */
  86. };
  87.  
  88. /* Internal bootblock structure. Create dummy structures to pass to read
  89.  * and write functions as necessary. Be sure that bb_BlockNum is filled in
  90.  * and that the actual size of the data area pointed to by the union is
  91.  * sufficiently large to contain one disk block.
  92.  */
  93. typedef struct bootblock
  94. {
  95.     struct MinNode   bb_Node;
  96.     LONG             allocsize;
  97.     LONG             bb_BlockNum;
  98.     WORD             bb_Changed;
  99.     LONG             unit;              /* Unit number for THIS set of RDBs. */
  100.     char             DeviceName [32];   /* Device name */
  101.     struct rw_return bb_RWErrors;
  102.     BOOL             wflag;             /* Written out flag. */
  103.     BYTE             spares[4-sizeof(BOOL)];/* Fill out short word */
  104.  
  105.     union
  106.     {
  107.         struct       RigidDiskBlock bd_RDB;
  108.         struct       PartitionBlock bd_PB;
  109.         struct       FileSysHeaderBlock bd_FHB;
  110.         struct       LoadSegBlock bd_LSB;
  111.         struct       BadBlockBlock bd_BB;
  112.         UBYTE        bd_Bytes[512];     /* NB: This is the MINIMUM size we */
  113.         UWORD        bd_Words[256];     /* can have here. It MAY be extended */
  114.         ULONG        bd_Longs[128];     /* if actual block size is larger. */
  115.     } bb_Data;
  116. } BootBlock;
  117.  
  118. /*  ==== Error report values for other functions ==== */
  119. #define E_NOERROR           0
  120.  
  121. #define E_ILLEGAL_SLASH     200
  122. #define E_EOF_IN_COMMENT    201
  123. #define E_ILLEGAL_STAR      202
  124. #define E_TOKEN_TO_LONG     203
  125. #define E_MEMORY_PANIC      204
  126. #define E_PREMATURE_EOF     205
  127. #define E_MISSING_EQUALS    206
  128. #define E_ILLEGAL_T_F       207
  129. #define E_ILLEGAL_TOKEN     208
  130. #define E_DUPLICATE_DISK    209
  131. #define E_NOT_LEGAL_NAME    210
  132. #define E_EXCEEDED_SIZE_LIM 211
  133. #define E_FILE_WRITE_ERROR  212
  134. #define E_TOOMANY_FS        213
  135. #define E_FSAVE_CONFUSION   214
  136. #define E_FS_CANNOT_OPEN    215
  137. #define E_LOST_IN_RDB_SPACE 216
  138. #define E_FS_WRITE_ERROR    217
  139. #define E_MULTIPLE_RDSKS    218
  140. #define E_RDSK_NOT_1ST      219
  141. #define E_NO_RDBS_LOADED    220
  142. #define E_RDBS_ALREADY_IN   221     /* RDBs already loaded. */
  143. #define E_FAILED_FILEOPEN   222
  144. #define E_FILE_READ_FAILED  223
  145. #define E_FILE_NOT_RDBS     224
  146. #define E_NO_BLOCKSIZE_SPEC 225
  147. #define E_FILE_WRITE_FAILED 226
  148. #define E_MEMORYP_NULL      227     /* prospective "memp" is null */
  149. #define E_ILLEGAL_BLOCKSIZE 228
  150. #define E_INSUFFICIENT_MEM  229
  151. #define E_RENUMBER_FAILED   230
  152. #define E_BLOCKS_EXCEEDED   231     /* Too many RDB blocks */
  153. #define E_INCOMPLETE_FSDESC 232
  154. #define E_FS_NOT_FOUND      233
  155. #define E_LIST_SCREWEDUP    234
  156. #define E_NO_SUCH_DIR       235
  157. #define E_EXALL_ERROR       236
  158. #define E_UNIT_DIFFERS      237
  159.  
  160. #define T_RENUMBER_LEFT     300
  161.  
  162. #define W_DUPLICATE_FS      100
  163. #define W_FS_NO_WRITE       101
  164.  
  165. /* Definitions for type field in FileSave */
  166. #define DRIVEINIT   0
  167. #define FILESYSTEM  1
  168.  
  169. struct DefaultsArray
  170. {
  171.     ULONG   TotalBlocks;
  172.     UWORD   BytesPerBlock;
  173.     UWORD   BlocksPerSurface;
  174.     UWORD   Surfaces;
  175.     UWORD   Cylinders;          /* note: MaxCyl = Cylinders - 1; */
  176.     UWORD   UnusedBlocks;
  177. };
  178.  
  179. /* Defaults Array filling error bit array */
  180. #define DA_NOERRORS             0
  181. #define DA_NO_CAPACITY_REPORT   1
  182. #define DA_NO_OPTIMIZE          2
  183. #define DA_BAD_MODESENSE_4      4
  184. #define DA_BAD_MODESENSE_3      8
  185. #define DA_FAILED               256
  186. #define DA_NO_DRIVE_OPEN        DA_FAILED
  187. #define DA_RIDICULOUS_VALUES    ( DA_FAILED << 1 )
  188.  
  189. /* Defaults Array filling "Optimize" Flags */
  190. #define DA_OPTIMIZE             1   /* Optimize storage if possible */
  191. #define DA_HUGE                 2   /* Allow partitioning huge disks */
  192. #define DA_HF_WAY               4   /* Use the old HardFrame algorithm */
  193. /* Note: DA_HF_WAY is forces DA_OPTIMIZE and DA_HUGE off. */
  194. /*       DA_BAD_MODESENSE_3 and DA_BAD_MODESENSE_4 only happen with DA_HF_WAY */
  195. /*       Errors below DA_FAILED are informational. */
  196.  
  197. /*  ==== Mountfile Recognized Strings ==== */
  198. #ifdef DONT_EVER_COMPILE_ME /* This stuff is for reference only, thank you. */
  199.  
  200. #ifdef FORREAL
  201. #define EXTERN
  202. #else
  203. #define EXTERN  extern
  204. #endif
  205.  
  206. EXTERN const char   *_Tokens[]
  207. #ifdef FORREAL
  208. = {
  209.     "/",                    /*0 */
  210.     "#",
  211.     "=",
  212.     "device",
  213.     "surfaces",
  214.     "blockspertrack",
  215.     "reserved",
  216.     "prealloc",
  217.     "interleave",
  218.     "lowcyl",
  219.     "highcyl",              /* 10 */
  220.     "buffers",
  221.     "bufmemtype",
  222.     "maxtransfer",
  223.     "mask",
  224.     "bootpri",
  225.     "dostype",
  226.     "unit",
  227.     "flags",
  228.     "stacksize",
  229.     "priority",             /* 20 */
  230.     "globvec",
  231.     "filesystem",
  232.     "mount",
  233.     "heads",
  234.     "bytesperblock",
  235.     "disk",
  236.     "rdblow",
  237.     "rdbhi",
  238.     "reselect",
  239.     "hilun",                /* 30 */
  240.     "hiid",
  241.     "hidrive",
  242.     "cylinders",
  243.     "cylinderblocks",
  244.     "mincyl",
  245.     "maxcyl",
  246.     "hicard",
  247.     "blocksize",
  248.     "bootable",
  249.     "readonly",             /* 40 */
  250.     "driveinit",
  251.     "baud",
  252.     "control",
  253.     "bootblocks",
  254.     "synch",
  255.     "sectorsperblock",
  256.     "\xff"
  257. }
  258. #endif
  259. ;
  260.  
  261. #define TSLASH          0
  262. #define THACK           1
  263. #define TEQUALS         2
  264. #define TDEVICE         3
  265. #define TSURFACES       4
  266. #define TBLOCKSPERTRACK 5
  267. #define TRESERVED       6
  268. #define TPREALLOC       7
  269. #define TINTERLEAVE     8
  270. #define TLOWCYL         9
  271. #define THICYL          10
  272. #define TBUFFERS        11
  273. #define TBUFMEMTYPE     12
  274. #define TMAXTRANSFER    13
  275. #define TMASK           14
  276. #define TBOOTPRI        15
  277. #define TDOSTYPE        16
  278. #define TUNIT           17
  279. #define TFLAGS          18
  280. #define TSTACKSIZE      19
  281. #define TPRIORITY       20
  282. #define TGLOBVEC        21
  283. #define TFILESYSTEM     22
  284. #define TMOUNT          23
  285. #define THEADS          24
  286. #define TBYTESPERBLOCK  25
  287. #define TDISK           26
  288. #define TRDBLOW         27
  289. #define TRDBHI          28
  290. #define TRESELECT       29
  291. #define THILUN          30
  292. #define THIID           31
  293. #define TLASTDRIVE      32
  294. #define TCYLINDERS      33
  295. #define TCYLINDERBLOCKS 34
  296. #define TMINCYL         35
  297. #define TMAXCYL         36
  298. #define THICARD         37
  299. #define TBLOCKSIZE      38
  300. #define TBOOTABLE       39
  301. #define TREADONLY       40
  302. #define TDRIVEINIT      41
  303. #define TBAUD           42
  304. #define TCONTROL        43
  305. #define TBOOTBLOCKS     44
  306. #define TSYNCH          45
  307. #define TSECSPERBLOCK   46
  308.  
  309. #define TokenCount      46
  310. #define TNOMATCH        TokenCount + 1
  311.  
  312. #endif /* COMPILEME */
  313.  
  314.  
  315.  
  316. typedef struct
  317. {
  318.     STRPTR  devicename;
  319.     LONG    board;
  320.     LONG    address;
  321.     LONG    lun;
  322.     STRPTR  messagestring;
  323.     LONG    extra;
  324.     LONG    param1;
  325.     LONG    param2;
  326.     LONG    param3;
  327. } HDWCallbackMsg;
  328.  
  329. #define EXTRA_BEFORE_TEST       0
  330. #define EXTRA_AFTER_TEST        1
  331. #define EXTRA_BEFORE_FORMAT     2       /* with no way to stop once you start.*/
  332. #define EXTRA_BEFORE_VERIFY     3       /* Setup the verify requester and
  333.                                            return "go ahead" */
  334. #define EXTRA_UPDATE_VERIFY     4       /* New string for requester - return
  335.                                            any Abort received */
  336. #define EXTRA_VERIFY_REASSIGN   5       /* New string - return "Yes" or "No" */
  337. #define EXTRA_VERIFY_FINISHED   6       /* Notify user, accept OK, close */
  338.  
  339. #define INQBUFSIZE  36  /* Standard size of Inquiry buffer */
  340.  
  341. /****************************************************************************/
  342.  
  343. /*
  344.  *    Callback messages for the hdwrench.library tester program.
  345.  *    These strings are "suggested" English strings for use with
  346.  *    the hdwrench.library callback hook.
  347.  */
  348.  
  349. #ifdef USE_SUGGESTED_MESSAGES
  350.     /* MESSAGE */                                   /* .extra usages */
  351. char *callback_messages[] =
  352. {
  353.     /* A) FINDVALID_SCANNING_STRING */              /* 0 and 1 */
  354.     "Scanning: %s: %d%d%d",         /* from message: devicename, board, lun, addr */
  355.  
  356.     /* B) LONGTIME_NOABORT_WARNING */               /* 2 */
  357.     "You are about to format LUN %d on\n"
  358.     "drive %d attached to board %d\n\n"
  359.     "***WARNING WARNING WARNING***\n"
  360.     "It can take up to several hours\n"
  361.     "to format a hard disk. And there\n"
  362.     "is no safe way to abort.\n\n"
  363.     "Are you VERY sure you want to do this?\n",
  364.     /* C) LONGTIME_VERIFY_WARNING */                /* 3 */
  365.     "LUN %d on drive %d on board %d\n"
  366.     "            Note\n"
  367.     "It can take up to several hours\n"
  368.     "to verify a hard disk. However,\n"
  369.     "you can abort during verify.\n\n"
  370.     "No data will be changed on the\n"
  371.     "drive.\n\n"
  372.     "Do you wish to continue?\n",
  373.  
  374.     /* D) FORMAT_USER_ABORTED_STRING */             /* 6 */
  375.     "User Aborted. Your drive is safe!\n",
  376.  
  377.     /* E) FORMAT_MOUNTED_DRIVE */                   /* 4 */
  378.     "%s\nShould we format a mounted drive?\n",
  379.  
  380.     /* F) FORMAT_NOT_PERMITTED */                   /* 6 */
  381.     "%s\nFormatting the system disk\nis not permitted. Aborting...\n",
  382.  
  383.     /* G) FORMAT_UNRECOGNIZED_STATUS */             /* 6 */
  384.     "Unrecognized SCSI status byte 0x%2.2x returned.\n",
  385.  
  386.     /* H) FORMAT_RESERVATION_CONFLICT */            /* 6 */
  387.     "Device is reserved by another initiator.\n",
  388.  
  389.     /* I) FORMAT_DRIVE_BUSY */                      /* 6 */
  390.     "Drive is busy.\n",
  391.  
  392.     /* J) FORMAT_COMMAND_PROBLEM */                 /* 6 */
  393.     "Unknown problem issuing SCSI Direct command!\n",
  394.  
  395.     /* K) FORMAT_SUCCESS_STRING */                  /* 6 */
  396.     "Format completed with no errors.",
  397.  
  398.     /* L) FORMAT_FAILED_STRING */                   /* 6 maybe */
  399.     "Format failed! Your drive may be dead.\n",
  400.  
  401.     /* M) VERIFY_USER_ABORTED_STRING */             /* 6 */
  402.     "User Aborted.\n",
  403.  
  404.     /* N) VERIFY_READCAPACITY_FAILED */             /* 6 */
  405.     "ReadCapacity failed! Verify impossible.\n",
  406.  
  407.     /* O) VERIFY_PROGRESS */                        /* 4 */
  408.     "Verifying blocks %d to %d of %d.\r",
  409.  
  410.     /* P) VERIFY_REASSIGN_Q */                      /* 5 */
  411.     "Block %d is bad.\n"
  412.     "Reassign this bad block?",
  413.  
  414.     /* Q) VERIFY_COMPLETED_STRING */                /* 6 */
  415.     "Verify completed:\n"
  416.     "    %d errors,\n"
  417.     "    %d successful reassignments,\n"
  418.     "and %d failed reassignments\n",
  419.  
  420.     /* R) VERIFY_ERROR_UNKNOWN_LOC */               /* 4 */
  421.     "Medium error at unknown location!\n"
  422.     "You should back up the drive and low-level format\n",
  423.  
  424.     /* S) VERIFY_HARDWARE_ERROR */                  /* 4 */
  425.     "Hardware error %ld!\n",
  426.  
  427.     /* T) VERIFY_RECOVERED_ERROR */                 /* 4 */
  428.     "Recovered read error at block %ld\n",
  429.  
  430.     /* U) VERIFY_RECOVERED_UNKNOWN_LOC */           /* 4 */
  431.     "Recovered error at unknown location!\n"
  432.     "You should consider backing up the\n"
  433.     "drive and reformatting\n",
  434.  
  435.     /* V) VERIFY_ILLEGAL_REQUEST */                 /* 4 */
  436.     "Drive returned an Illegal Request Error (%ld)\n",
  437.  
  438.     /* W) VERIFY_UNKNOWN_ERROR */
  439.     "Unknown error: sense key %ld (more)\n"
  440.     "Device returned sense code %ld (more)\n"
  441.     "Consult drive documentation\n",
  442.  
  443.     /* X) VERIFY_CONTINUE */                        /* 4 */
  444.     "Continuing verify at block %d...\n",
  445.  
  446.     /* Y) VERIFY_SEEK_ERROR */                      /* 4 */
  447.     "seek eror!\n",
  448.  
  449.     /* Z) VERIFY_MEDIUM_ERROR */                    /* 4 */
  450.     "Medium error at unknown location!\n"
  451.     "You should back up the drive and low-level format\n",
  452.  
  453.     /* [) VERIFY_ILLEGAL_COMMAND */                 /* 4 */
  454.     "Illegal command!\n",
  455.  
  456.     /* \) VERIFY_ILLEGAL_ADDRESS */                 /* 4 */
  457.     "Illegal address %ld!",
  458.  
  459.     /* ]) VERIFY_BAD_ARGUEMENT */                   /* 4 */
  460.     "Bad command arguement!\n",
  461.  
  462.     /* ^) VERIFY_CARTRIDGE_CHANGED */               /* 4 */
  463.     "Cartridge changed",
  464.  
  465.     /* _) VERIFY_ILLEGAL_LUN */                     /* 4 */
  466.     "Invalid LUN addressed!",
  467.  
  468.     /* `) VERIFY_UNFORMATTED_DRIVE */               /* 4 */
  469.     "Unformatted drive!",
  470.  
  471.     /* a) VERIFY_NONEXTENDED_SENSE */               /* 4 */
  472.     "Non-extended sense error is 0x%x",
  473.  
  474.     /* b) VERIFY_NO_SCSI_ERROR_RETURNED */          /* 4 */
  475.     "Device didn't return good sense data!",
  476.  
  477.     /* other */
  478.     "Illegal callback message %x"                   /* any */
  479. };
  480.  
  481. #define MIN_MESSAGE 'A'
  482. #define MAX_MESSAGE 'b'
  483.  
  484. #endif /* USE_SUGGESTED_MESSAGES */
  485.  
  486. #endif    /* LIBRARIES_HDWRENCH_H */
  487.