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

VxWorks

开发平台:

C/C++

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