usrIde.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrIde.c - IDE initialization */
  2. /* Copyright 1992-1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01g,30jul99,jkf  fixed SPR#4429.
  7. 01f,18jul96,hdn  changed doc: DESCRIPTION
  8. 01e,18jun96,hdn  fixed a bug in "offset" calculation.
  9. 01d,24jan95,jdi  doc cleanup.
  10. 01c,12oct94,hdn  used ideRawio() instead of using raw file system.
  11. 01b,25oct93,hdn  tuned for IDE driver.
  12. 01a,07oct93,sst  part of this program was written by S.Stern
  13. */
  14. /*
  15. DESCRIPTION
  16. This file is used to configure and initialize the VxWorks IDE support.
  17. NOMANUAL
  18. */
  19. /* defines */
  20. #define VXDOS "VXDOS"
  21. #define VXEXT "VXEXT"
  22.  
  23. /* forward declaration */
  24. LOCAL int usrIdePartition (int drive, DOS_PART_TBL *pPart);
  25. /*******************************************************************************
  26. *
  27. * usrIdeConfig - mount a DOS file system from an IDE hard disk
  28. *
  29. * This routine mounts a DOS file system from an IDE hard disk.
  30. *
  31. * The <drive> parameter is the drive number of the hard disk;
  32. * 0 is `C:' and 1 is `D:'.
  33. *
  34. * The <fileName> parameter is the mount point, e.g., `/ide0/'.
  35. *
  36. * NOTE: Because VxWorks does not support partitioning, hard disks formatted
  37. * and initialized on VxWorks are not compatible with DOS machines.  This
  38. * routine does not refuse to mount a hard disk that was initialized on
  39. * VxWorks.  The hard disk is assumed to have only one partition with a
  40. * partition record in sector 0.
  41. *
  42. * RETURNS: OK or ERROR.
  43. *
  44. * SEE ALSO:
  45. * .pG "I/O System, Local File Systems, Intel i386/i486 Appendix"
  46. */
  47. STATUS usrIdeConfig
  48.     (
  49.     int     drive, /* drive number of hard disk (0 or 1) */
  50.     char *  fileName /* mount point */
  51.     )
  52.     {
  53.     BLK_DEV *pBlkDev;
  54.     char bootDir [BOOT_FILE_LEN];
  55.     char buffer [1024];
  56.     int offset = 0;
  57.     IDE_RAW ideRaw;
  58.     char *pSys;
  59.     DOS_PART_TBL *pPart;
  60.     if ((UINT)drive >= IDE_MAX_DRIVES)
  61. {
  62. printErr ("drive is out of range (0-%d).n", IDE_MAX_DRIVES - 1);
  63. return (ERROR);
  64. }
  65.     /* split off boot device from boot file */
  66.     devSplit (fileName, bootDir);
  67.     /* read the boot sector */
  68.     ideRaw.cylinder = 0;
  69.     ideRaw.head = 0;
  70.     ideRaw.sector = 1;
  71.     ideRaw.pBuf = buffer;
  72.     ideRaw.nSecs = 1;
  73.     ideRaw.direction = 0;
  74.     if (ERROR == (ideRawio (drive, &ideRaw)))
  75.         {
  76.         printErr("ideRawio, usrIde.c returned ERROR, bad drive params?n");
  77.         return (ERROR);
  78.         }
  79.     /* get an offset if it is formated by MSDOS */
  80.     pSys  = &buffer[DOS_BOOT_SYS_ID];
  81.     pPart = (DOS_PART_TBL *)&buffer[DOS_BOOT_PART_TBL];
  82.     if ((strncmp(pSys, VXDOS, strlen(VXDOS)) != 0) &&
  83.         (strncmp(pSys, VXEXT, strlen(VXEXT)) != 0))
  84.         {
  85.         offset = usrIdePartition (drive, pPart);
  86.         }
  87.     if ((pBlkDev = ideDevCreate(drive, 0, offset)) == (BLK_DEV *)NULL)
  88.         {
  89.         printErr ("Error during ideDevCreate: %xn", errno);
  90.         return (ERROR);
  91.         }
  92.     /* Make DOS file system */
  93.     if (dosFsDevInit(bootDir, pBlkDev, NULL) == (DOS_VOL_DESC *)NULL)
  94.         {
  95. printErr ("Error during dosFsDevInit: %xn", errno);
  96.         return (ERROR);
  97.         }
  98.     return (OK);
  99.     }
  100. /*******************************************************************************
  101. *
  102. * usrIdePartition - get an offset to the first partition of the drive.
  103. *
  104. * This routine gets an offset to the first partition of the drive.
  105. *
  106. * RETURNS: offset to the partition
  107. *
  108. */
  109. LOCAL int usrIdePartition
  110.     (
  111.     int     drive, /* drive number of hard disk (0 or 1) */
  112.     DOS_PART_TBL *pPart /* pointer to the partition table */
  113.     )
  114.     {
  115.     DOS_PART_TBL *pTemp = pPart;
  116.     int offset = 0;
  117.     int ix;
  118.     char buffer[1024];
  119.     IDE_RAW ideRaw;
  120.     for (ix = 0; ix < 4; ix++) /* active primary DOS partition */
  121. {
  122. if (pPart->dospt_status == 0x80)
  123.     if ((pPart->dospt_type == 0x01) ||
  124.         (pPart->dospt_type == 0x04) ||
  125.         (pPart->dospt_type == 0x06))
  126. {
  127.         offset = pPart->dospt_absSec;
  128. return (offset);
  129. }
  130. pPart++;
  131. }
  132.     pPart = pTemp;
  133.     for (ix = 0; ix < 4; ix++) /* primary DOS partition */
  134. {
  135. if ((pPart->dospt_type == 0x01) ||
  136.     (pPart->dospt_type == 0x04) ||
  137.     (pPart->dospt_type == 0x06))
  138.     {
  139.     offset = pPart->dospt_absSec;
  140.     return (offset);
  141.     }
  142. pPart++;
  143. }
  144.     pPart = pTemp;
  145.     for (ix = 0; ix < 4; ix++) /* extended DOS partition */
  146. {
  147. if (pPart->dospt_type == 0x05)
  148.     {
  149.     ideRaw.cylinder = (pPart->dospt_startSec & 0xf0) >> 4;
  150.     ideRaw.head = pPart->dospt_startHead;
  151.     ideRaw.sector = pPart->dospt_startSec & 0x0f;
  152.     ideRaw.pBuf = buffer;
  153.     ideRaw.nSecs = 1;
  154.     ideRaw.direction = 0;
  155.             if (ERROR == (ideRawio (drive, &ideRaw)))
  156.                 {
  157.                 printErr("ideRawio, usrIde.c returned ERROR");
  158.                 printErr(", bad drive params?n");
  159.                 return (ERROR);
  160.                 }
  161.     pPart = (DOS_PART_TBL *)&buffer[DOS_BOOT_PART_TBL];
  162.     offset = usrIdePartition (drive, pPart);
  163.     return (offset);
  164.     }
  165. pPart++;
  166. }
  167.     return (offset);
  168.     }