home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 202.img / SCO386N2.TD0 / usr / include / sys / disk.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-08  |  8.8 KB  |  283 lines

  1. /*
  2.  *    @(#) disk.h 1.2 88/06/07 
  3.  *
  4.  *    Copyright (C) The Santa Cruz Operation, 1985, 1986, 1987, 1988.
  5.  *    This Module contains Proprietary Information of
  6.  *    The Santa Cruz Operation and should be treated as Confidential.
  7.  *
  8.  */
  9.  
  10. /*
  11.  * Common include file for disk driver front and back ends.
  12.  * The 'front end' provides a common scheme for disk partitioning
  13.  * and bad track aliasing.
  14.  * The front end assumes an ibm style partition table on sector 0
  15.  * of each disk.  If this is not true certain routines in the front
  16.  * end would have to be rewritten.
  17.  */
  18.  
  19. /* 
  20.  * Drive parameter structures.
  21.  */
  22.  
  23. struct dkparms {
  24.     unsigned short    prcmp;            /* Write precomp    */
  25.     unsigned short    lzone;            /* Landing zone        */
  26.     unsigned short    wrt_reduce;        /* Write reduce cylinder*/
  27.     unsigned char    ecc;            /* Ecc level        */
  28.     unsigned char    ctrl;            /* Control        */
  29. };
  30.  
  31. #if defined(STANDALONE) || defined(M_I386)
  32. typedef    struct    badtrks        *btrkp_t;
  33. #else
  34. typedef    struct    badtrks    far     *btrkp_t;
  35. #endif
  36.  
  37.  
  38. /*
  39.  * The sprawling diskinfo structure.
  40.  */
  41.  
  42. struct diskinfo {
  43.  
  44. /*
  45.  * This field for disk.c internal use only;
  46.  * drivers should not test or set.
  47.  */
  48. int     dkflags;
  49. #define DK_USED        0x01        /* this structure in use    */
  50. #define DK_INIT        0x02        /* this structure initialized    */
  51. #define DK_PART        0x04        /* partition table read        */
  52. #define DK_VALID    0x08        /* we like it            */
  53. #define DK_PRINT    0x10        /* params printed        */
  54.  
  55. /*
  56.  * Fields drivers need to set or examine.
  57.  */
  58. int    (*dkstrat)();            /* driver strategy routine    */
  59. struct    dparam    dkparam;        /* drive params            */
  60. struct    dkparms    dkparms;        /* more drive params        */
  61. int    spcyl;                /* sectors per cylinder        */
  62. int    dkcinit;            /* controller must be init'd    */
  63.  
  64. /*
  65.  * Drivers should not set or examine
  66.  * anything in this structure past this point.
  67.  */
  68.  
  69. /*
  70.  * Virtual drive structures and constants.  See partition.h and dio.h
  71.  * A virtual drive is our concept of an fdisk partition.  The fdisk
  72.  * partition structure is not terribly useful so we have to convert.
  73.  * Virtual drive 0 is the whole physical disk - it is initialized to
  74.  * the size of the default disk.
  75.  */
  76.  
  77. #define NLVS        8        /* 2^3 - max "logical" virtuals */
  78. #define NVDS        4        /* actual number of virtual drives */
  79.  
  80. struct dkvdtab {
  81.     unsigned short v_magic;
  82.     unsigned short v_nvds;            /* number vds allowed */
  83.     struct   vdisk v_vdisk[NVDS+1];
  84. } dkvdt;
  85.  
  86. /*
  87.  * -1 indicates virtual drive does not exist, else entry points to itself 
  88.  */
  89. int    dkvds[NLVS];
  90.  
  91. int    dkvdflags[NVDS+1];        /* flags virtual drive open    */
  92. #define DK_VDVALID    1        /* good virtual drive        */
  93. #define DK_VDPART    2        /* partition table read        */
  94. #define DK_VDBAD    4        /* bad track table read        */
  95.  
  96. /*
  97.  * We now need another array similar to dkvds.  this one is needed
  98.  * to map fdisk partitions (0-4) into XENIX partitions.  This is cause
  99.  * only XENIX partitions have divvy and badtrk data structures set up
  100.  * for them according to the limit NXPD.  You can have MORE than NXPD
  101.  * XENIX partitions, but they cannot all be OPEN at the same time. 
  102.  * actually, once you open NXPD of them, you will not be able to open
  103.  * another w/o rebooting the machine.  nxd is the counter of the
  104.  * number of opened XENIX partitions.
  105.  */
  106.  
  107. int    nxd;
  108. int    dkxds[NVDS+1];        /* Also need to map the ACTIVE XENIX */
  109.  
  110. /************************************************************************
  111.  * Partition structures and constants.  See dio.h
  112.  * A XENIX virtual drive can be partitioned into up to DKNPARTS partitions.
  113.  * We only allow NXPD XENIX virtual drives per drive in order to not waste
  114.  * kernel data.  npartabs counts the number of struct dkpartabs allocated.
  115.  * dkpp[v] contains a virtual drive's pointer to its struct dkpartab.
  116.  *
  117.  * Each virtual drive has reserved space for alias tracks and system
  118.  * tables which are not available for the user.
  119.  *
  120.  * Each XENIX virtual drive requires a struct dkpartab and a struct dkbadtab.
  121.  */
  122.  
  123. #define DKNPARTS    8        /* max number of partitions of a vd */
  124. #define NXPD        3        /* number xenix partitions per drive */
  125. #define WHOLE_VIRT    7        /* partition which is whole virtual */
  126.  
  127. #ifdef M_I386
  128. #pragma pack(2)
  129. #endif
  130.  
  131. struct dkpartab  {
  132.     unsigned short    p_magic;
  133.     struct     parts    p[DKNPARTS];
  134. }dkpartab[NXPD];
  135.  
  136. #ifdef M_I386
  137. #pragma pack()
  138. #endif
  139.  
  140. struct dkpartab    *dkpp[NVDS+1];
  141.  
  142. int    npartabs;
  143.  
  144. /*************************************************************************
  145.  * Bad track structures and constants.  See dio.h
  146.  * Each virtual drive gets up to MAXBTRKS bad tracks.  Each virtual drive
  147.  * gets a struct dkbadtab in core and a struct badtab on disk.  
  148.  *
  149.  * dkbtp[v] is a virtual drive's pointer to its struct dkbadtab.
  150.  *
  151.  * Each virtual drive opened gets as many badtracks as the user desires, up
  152.  * to MAXBTRKS or the size of the virtual drive (in trks), whichever is less.
  153.  *
  154.  * DIOWBTRK takes effect immediately.  The table copied in is checked for bad
  155.  * tracks whick are as yet unaliased - the kernel assigns the alias track.
  156.  * Bad tracks and alias track in the tables are physical - this allows 
  157.  * access to them through the physical device.
  158.  *
  159.  * with new kernel badtrack structures, pre 2.2 disk layouts have the
  160.  * potential to have more badtracks by just tar'ing off the new kernel.  
  161.  * Old layouts will generally get more badtracks if the size of the virtual
  162.  * drive is greater than 20 Mb, assuming 17 sectors/track.
  163.  * Previously, max badtracks was min(~2% of size of the virtual drive,DKMAXBAD).
  164.  * Now it will be ~2% of the size of the virtual drive(for OLD layouts).  
  165.  *
  166.  * Of course, new (2.2) installations will get however much they want.
  167.  */
  168.  
  169. #define MAXBTRKS    1023
  170. #define BTRKSPERBLK    (BSIZE/(2*sizeof(unsigned short)) )
  171. #define STATSIZ        15    /* Fast access badtrk tbl size */
  172.  
  173. /* Next macro jumps us to next badblk if at end of this one */
  174. #define    BLKBNDY(nbad)    ( (nbad)>0 && (nbad)%(BTRKSPERBLK)==0 ) 
  175. #define DKBNDY(nbad)    ( (nbad)==STATSIZ || BLKBNDY((nbad)-STATSIZ) )
  176.  
  177. struct badtrks    dkbadtrks[NXPD][STATSIZ];    /* Static badtrk tables     */
  178.  
  179. struct dkbadtab  {
  180.     unsigned short b_magic;
  181.     unsigned b_maxbad;            /* tell user how max allowed */
  182.     unsigned b_nbad;            /* count of bad tracks       */
  183.     unsigned b_falias;            /* first alias trackno       */
  184.     unsigned b_nalias;            /* number of alias tracks    */
  185.     struct badtrks *b_btrkp;        /* ptr into static vd struct */
  186. }dkbadtab[NXPD];
  187.  
  188. struct dkbadtab *dkbtp[NVDS+1];
  189.  
  190. #define TWO13PARLOC    2L        /* Disk location of partition tbl */
  191. #define TWO2PARLOC    21L
  192.  
  193. #define TWO13BADLOC    1L        /* Disk location of bad blk tbl    */
  194. #define TWO2BADLOC    22L
  195.  
  196. #define    TWO13BADBLKS    1        /* Bad blocks used in 2.1.3    */
  197. #define    TWO2BADBLKS    4        /* Bad blocks used in 2.2    */
  198.  
  199. #define TWO13GDTRKS    4        /* Required # good trks in 2.1.3 */
  200.  
  201. unsigned short dklastbtrk[NXPD];    /* Last bad trk in each vd */
  202.  
  203. struct dkbuf {
  204.     struct buf     *buffer;    /* Max # outboard buffers    */
  205.     btrkp_t     bufptr;        /* Pointers into 'em         */
  206.     int        bad;        /* How many bad in this blk? */
  207.     char        inuse;        /* In use?             */
  208. } dkbuf [NVDS][TWO2BADBLKS];
  209.  
  210. /* Initialized in dktype() depending on which disk layout is found */
  211.  
  212. struct    dklayout {
  213.     long    parblkno;        /* Blk # of divvy table     */
  214.     long    badblkno;        /* Blk # of badtrk tbl start     */
  215.     int    badblks;        /* # of blks of badtrk tbl    */
  216.     int    nsystrks;        /* Tracks reserved for driver    */
  217.     int    aliastrks;        /* trks space reserved for    */
  218.     int    newdisk;        /* True if 2.2            */
  219. } dklayout[NVDS];
  220.  
  221. };
  222.  
  223. typedef struct diskinfo *dip_t;
  224.  
  225. #ifndef STANDALONE
  226. extern struct diskinfo diskinfo[];
  227. extern dip_t dkalloc();
  228. #endif
  229.  
  230.  
  231. /*
  232.  * Macros to extract appropriate bits from the minor device.
  233.  * These macros depend on a bit ordering of high 2 bits for
  234.  * physical drive, next 3 bits for virtual drive, and low 3
  235.  * bits for partition of a virtual drive.  More general macros 
  236.  * can be found in ../h/dio.h.
  237.  */
  238. #define DPHYS(d)    ((d >> 6) & 0x3)    /* 2 highest bits */
  239. #define DVIR(d)        ((d >> 3) & 0x7)    /* 3 middle bits */
  240. #define DPART(d)    (d & 0x7)
  241. #define DMKDEV(p,v,pa)    ((p << 6) | (v << 3) | pa)
  242.  
  243. #define WHOLE_DISK    0        /* virtual number of whole drive */
  244.  
  245. /*
  246.  * dksec{start,size}() return the starting sector number and size
  247.  * in sectors of a minor device.   They assume disks with sector 
  248.  * size of 512 bytes and XENIX block size of 1024 bytes.  They,
  249.  * along with the macros to convert sectors to blocks and back,
  250.  * would need to be rewritten for a driver for which
  251.  * those assumptions were untrue.
  252.  */
  253. long dksecstart(), dksecsize();
  254. #define BTOS(b)        (b << 1)    /* BSIZE blocks to sectors */
  255. #define STOB(s)        (s >> 1)
  256.  
  257. /*
  258.  * Misc
  259.  */
  260. #define DK_ERROR    -1
  261. #define DK_OK        0
  262.  
  263. #define DK_EXIST    1        /* exists */
  264. #define DK_READY    2        /* needs init */
  265. #define DK_PARAM    4        /* disk parameters read */
  266.  
  267. #define    DKSECTOR    512
  268. #define DKSSHIFT    9
  269. #define DKSMASK        0x01FF
  270. #define MAXRETRY        4
  271.  
  272. #ifdef STANDALONE
  273. int    dkctlr;                /* Identifies controller being used */
  274. #endif
  275.  
  276. struct dkcntlrtab {            /* Information passed to dksetup */
  277.     unsigned short    base;        /* I/O port base address */
  278.     unsigned short    offset;        /* Offset of I/O port highest address*/
  279.     short        vec;        /* Interrupt vector */
  280.     short        dma;        /* DMA channel */
  281.     char *        type;        /* Controller type, e.g. "W" */
  282. };
  283.