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

VxWorks

开发平台:

C/C++

  1. /* usrAta.c - ATA/ATAPI initialization */
  2. /* Copyright 1992-2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01l,02mar02,jkf  SPR#73841, fixed (cdrom) trailing paran indexing error.
  7.                  fixed warning: pn unitialized if INCLUDE_CDROMFS.
  8. 01k,26nov01,jac  added file system type check to allow support for specifying
  9.                  CDROM filesystem.
  10. 01j,02ocy01,jkf  fixing SPR#70377, usrAtaConfig altered char * arg, this 
  11.                  modifies .text seg and caused checksum error for tgtsvr. 
  12. 01i,21sep01,jkf  cbio API changes.
  13. 01h,21jun00,rsh  upgrade to dosFs 2.0
  14. 01g,14oct98,lrn  modified for DosFs 2.0
  15. 01f,30jul99,jkf  SPR#4429.
  16. 01e,02jun98,ms   created configlette.
  17. 01d,30oct97,db   added call to ATA_SWAP in usrAtaPartition. 
  18. 01c,30oct97,dat  added #include pccardLib.h and ataDrv.h
  19. 01b,14jul97,dgp  doc: update to match hard-copy
  20. 01a,11may95,hdn  re-written for ATA driver.
  21. */
  22. /*
  23. DESCRIPTION
  24. This file is used to configure and initialize the VxWorks ATA support.
  25. This file is included by the prjConfig.c configuration file created by the
  26. Project Manager.
  27. SEE ALSO: usrExtra.c
  28. NOMANUAL
  29. */
  30. #include "vxWorks.h"
  31. #include "string.h"
  32. #include "dosFsLib.h"
  33. #include "dcacheCbio.h"
  34. #include "dpartCbio.h"
  35. #include "usrFdiskPartLib.h"
  36. #include "drv/hdisk/ataDrv.h"
  37. #ifdef INCLUDE_CDROMFS
  38. #include "cdromFsLib.h"
  39. #endif
  40. /* forward declaration */
  41. /* macro's */
  42. #ifndef ATA_CACHE_SIZE
  43. #define ATA_CACHE_SIZE 0x0
  44. #endif /* !ATA_CACHE_SIZE */
  45. /*******************************************************************************
  46. *
  47. * usrAtaConfig - mount a DOS file system from an ATA hard disk or a CDROM
  48. *                file system from an ATAPI CDROM drive
  49. *
  50. * This routine mounts a DOS file system from an ATA hard disk. Parameters:
  51. *
  52. * .IP <drive> 
  53. * the drive number of the hard disk; 0 is `C:' and 1 is `D:'.
  54. * .IP <devName>
  55. * the mount point for all partitions which are expected to be present
  56. * on the disk, separated with commas, for example "/ata0,/ata1" or "C:,D:".
  57. * Blanks are not allowed in this string.  If the drive is an ATAPI CDROM
  58. * drive, then the CDROM filesystem is specified by appending "(cdrom)"
  59. * after the mount point name.  For example, a CDROM drive could be specified
  60. * as "/cd(cdrom)".
  61. * .LP
  62. *
  63. * NOTE: Because VxWorks does not support creation of partition tables,
  64. * hard disks formatted
  65. * and initialized on VxWorks are not compatible with DOS machines.  This
  66. * routine does not refuse to mount a hard disk that was initialized on
  67. * VxWorks. Up to 8 disk partitions are supported.
  68. *
  69. *
  70. * RETURNS: OK or ERROR.
  71. *
  72. * SEE ALSO:
  73. * `src/config/usrAta.c',
  74. * .pG "I/O System, Local File Systems, Intel i386/i486/Pentium"
  75. */
  76. STATUS usrAtaConfig
  77.     (
  78.     int     ctrl,  /* 0: primary address, 1: secondary address */
  79.     int     drive,  /* drive number of hard disk (0 or 1) */
  80.     char    *devNames    /* mount points for each partition */
  81.     )
  82.     {
  83.     BLK_DEV *pBlkDev;
  84.     CBIO_DEV_ID cbio, masterCbio;
  85.     STATUS  stat = OK;
  86.     char    *tmp; 
  87.     char    *devNamesCopy;
  88.     char    *freePtr;
  89.     char    *sysType;
  90.     char    *devName[PART_MAX_ENTRIES];
  91.     int     pn; 
  92.     int     numPart = 0;
  93.     /* check argument sanity */
  94.     if( NULL == devNames || EOS == *devNames )
  95.         {
  96. printErr ("usrAtaConfig: Invalid device name.n");
  97. return (ERROR);
  98.         }
  99.     if (ATA_MAX_DRIVES <= (UINT) drive)
  100. {
  101. printErr ("usrAtaConfig: drive is out of range (0-%d).n", 
  102.                   ATA_MAX_DRIVES - 1);
  103. return (ERROR);
  104. }
  105.     if (ATA_MAX_CTRLS <= (UINT) ctrl)
  106.         {
  107.         printErr ("usrAtaConfig: controller is out of range (0-%d).n",
  108.                   ATA_MAX_CTRLS - 1);
  109.         return (ERROR);
  110.         }
  111.     /* 
  112.      * make private copy of the devNames, SPR#70337 
  113.      * strlen does not count EOS, so we add 1 to malloc.
  114.      */
  115.     devNamesCopy = malloc (1 + (int) (strlen (devNames)));   
  116.     /* ensure malloc suceeded    */
  117.     if (NULL == devNamesCopy)       
  118.         {
  119. printErr ("usrAtaConfig: malloc returned NULLn");
  120.         return (ERROR); 
  121.         }
  122.     /* store the pointer for free, since devNamesCopy is modified */
  123.    
  124.     freePtr = devNamesCopy;
  125.     /* copy string, include EOS  */
  126.     strcpy (devNamesCopy, devNames); 
  127.     
  128.     /* Check for file system spec */
  129.     sysType = index (devNamesCopy, '(');
  130.     if (sysType != NULL)
  131.         {
  132.         *sysType = '';
  133.         sysType++;
  134.         tmp = index( sysType, ')' );
  135.         if (tmp != NULL)
  136.             {
  137.             *tmp = '';
  138.             }
  139. }
  140.     else
  141.         {
  142.         sysType = "dos";
  143.         }
  144.     /* Parse the partition device name string */
  145.     for (numPart = 0; numPart < PART_MAX_ENTRIES; numPart++)
  146. {
  147. if (EOS == *devNamesCopy)
  148.     break;
  149. tmp = devNamesCopy ;
  150. devName[numPart] = devNamesCopy ;
  151. tmp = index (tmp, ',');
  152. if (NULL == tmp)
  153.     {
  154.     numPart++;
  155.     break;
  156.     }
  157. *tmp = EOS ;
  158. devNamesCopy = tmp+1;
  159. }
  160.     /* create block device for the entire disk, */
  161.     if ((pBlkDev = ataDevCreate (ctrl, drive, 0, 0)) == (BLK_DEV *) NULL)
  162.         {
  163.         printErr ("Error during ataDevCreate: %xn", errno);
  164.         free (freePtr);
  165.         return (ERROR);
  166.         }
  167.     if (strcmp (sysType, "dos") == 0)
  168.         {
  169.         /* create disk cache for the entire drive */
  170.         cbio = dcacheDevCreate ((CBIO_DEV_ID) pBlkDev, NULL, ATA_CACHE_SIZE, freePtr);
  171.         if (NULL == cbio)
  172.             {
  173.             /* insufficient memory, will avoid the cache */
  174.             printErr ("WARNING: Failed to create %d bytes of disk cache"
  175.                       " ATA disk %s configured without cachen",
  176.                       ATA_CACHE_SIZE, devNames);
  177.             cbio = cbioWrapBlkDev (pBlkDev);
  178.             }
  179.         /* create partition manager */
  180.         masterCbio = dpartDevCreate (cbio, numPart, usrFdiskPartRead);
  181.         if (NULL == masterCbio)
  182.             {
  183.             printErr ("Error creating partition manager: %xn", errno);
  184.             free (freePtr);
  185.             return (ERROR);
  186.             }
  187.         /* Create a DosFs device for each partition required */
  188.         for (pn = 0; pn < numPart; pn ++)
  189.             {
  190.             stat = dosFsDevCreate (devName[pn], dpartPartGet (masterCbio, pn),
  191.                                    NUM_DOSFS_FILES, NONE);
  192.             if (stat == ERROR)
  193.                 {
  194.                 printErr ("Error creating dosFs device %s, errno=%xn",
  195.                           devName[pn], errno);
  196.                 free (freePtr);
  197.                 return (ERROR);
  198.                 }
  199.             }
  200.         }
  201. #ifdef INCLUDE_CDROMFS
  202.     else if (strcmp (sysType, "cdrom") == 0)
  203.         {
  204.         if (cdromFsDevCreate (devName[0], pBlkDev) == NULL)
  205.             {
  206.             printErr ("Error creating cdromFs device %s, errno=%xn",
  207.                       devName[0], errno);
  208.             free (freePtr);
  209.             return (ERROR);
  210.             }
  211.         }
  212. #endif
  213.     else
  214.         {
  215.         printErr ("Unknown or un-included filesystem type: "%s"n", sysType);
  216.         free (freePtr);
  217.         return (ERROR);
  218.         }
  219.     free (freePtr);
  220.     return (OK);
  221.     }
  222. /******************************************************************************
  223. *
  224. * usrAtaInit - intialize the hard disk driver
  225. *
  226. * This routine is called from usrConfig.c to initialize the hard drive.
  227. */
  228. void usrAtaInit (void)
  229.     {
  230.     int ix;
  231.     ATA_RESOURCE *pAtaResource;
  232.     for (ix = 0; ix < ATA_MAX_CTRLS; ix++)
  233.         {
  234.         pAtaResource = &ataResources[ix];
  235.         if (pAtaResource->ctrlType == IDE_LOCAL)
  236.             if ((ataDrv (ix, pAtaResource->drives, pAtaResource->intVector,
  237.                    pAtaResource->intLevel, pAtaResource->configType,
  238.                    pAtaResource->semTimeout, pAtaResource->wdgTimeout))
  239.                == ERROR)
  240.                 {
  241.                 printf ("ataDrv returned ERROR from usrRoot.n");
  242.                 }
  243.         }
  244.     }