在target\config\comps\src\dosfs2的usrata.c中,是由ataload()调用的
STATUS usrAtaConfig
(
int ctrl, /* 0: primary address, 1: secondary address */
int drive, /* drive number of hard disk (0 or 1) */
char *devNames /* mount points for each partition */
)
{
BLK_DEV *pBlkDev;
CBIO_DEV_ID cbio, masterCbio;
STATUS stat = OK;
char *tmp;
char *devNamesCopy;
char *freePtr;
char *sysType;
char *devName[PART_MAX_ENTRIES];
int pn;
int numPart = 0;
/* check argument sanity */
if( NULL == devNames || EOS == *devNames )
{
printErr ("usrAtaConfig: Invalid device name.\n");
return (ERROR);
}
if (ATA_MAX_DRIVES <= (UINT) drive)
{
printErr ("usrAtaConfig: drive is out of range (0-%d).\n",
ATA_MAX_DRIVES - 1);
return (ERROR);
}
if (ATA_MAX_CTRLS <= (UINT) ctrl)
{
printErr ("usrAtaConfig: controller is out of range (0-%d).\n",
ATA_MAX_CTRLS - 1);
return (ERROR);
}
/*
* make private copy of the devNames, SPR#70337
* strlen does not count EOS, so we add 1 to malloc.
*/
devNamesCopy = malloc (1 + (int) (strlen (devNames)));
/* ensure malloc suceeded */
if (NULL == devNamesCopy)
{
printErr ("usrAtaConfig: malloc returned NULL\n");
return (ERROR);
}
/* store the pointer for free, since devNamesCopy is modified */
freePtr = devNamesCopy;
/* copy string, include EOS */
strcpy (devNamesCopy, devNames);
/* Check for file system spec */
sysType = index (devNamesCopy, '(');
if (sysType != NULL)
{
*sysType = '\0';
sysType++;
tmp = index( sysType, ')' );
if (tmp != NULL)
{
*tmp = '\0';
}
}
else
{
sysType = "dos";
}
/* Parse the partition device name string */
for (numPart = 0; numPart < PART_MAX_ENTRIES; numPart++)
{
if (EOS == *devNamesCopy)
break;
tmp = devNamesCopy ;
devName[numPart] = devNamesCopy ;
tmp = index (tmp, ',');
if (NULL == tmp)
{
numPart++;
break;
}
*tmp = EOS ;
devNamesCopy = tmp+1;
}
/* create block device for the entire disk, */
if ((pBlkDev = ataDevCreate (ctrl, drive, 0, 0)) == (BLK_DEV *) NULL)
{
printErr ("Error during ataDevCreate: %x\n", errno);
free (freePtr);
return (ERROR);
}
if (strcmp (sysType, "dos") == 0)
{
/* create disk cache for the entire drive */
cbio = dcacheDevCreate ((CBIO_DEV_ID) pBlkDev, NULL, ATA_CACHE_SIZE, freePtr);
if (NULL == cbio)
{
/* insufficient memory, will avoid the cache */
printErr ("WARNING: Failed to create %d bytes of disk cache"
" ATA disk %s configured without cache\n",
ATA_CACHE_SIZE, devNames);
cbio = cbioWrapBlkDev (pBlkDev);
}
/* create partition manager */
masterCbio = dpartDevCreate (cbio, numPart, usrFdiskPartRead);
if (NULL == masterCbio)
{
printErr ("Error creating partition manager: %x\n", errno);
free (freePtr);
return (ERROR);
}
/* Create a DosFs device for each partition required */
for (pn = 0; pn < numPart; pn ++)
{
stat = dosFsDevCreate (devName[pn], dpartPartGet (masterCbio, pn),
NUM_DOSFS_FILES, NONE);
if (stat == ERROR)
{
printErr ("Error creating dosFs device %s, errno=%x\n",
devName[pn], errno);
free (freePtr);
return (ERROR);
}
}
}
#ifdef INCLUDE_CDROMFS
else if (strcmp (sysType, "cdrom") == 0)
{
if (cdromFsDevCreate (devName[0], pBlkDev) == NULL)
{
printErr ("Error creating cdromFs device %s, errno=%x\n",
devName[0], errno);
free (freePtr);
return (ERROR);
}
}
#endif
else
{
printErr ("Unknown or un-included filesystem type: \"%s\"\n", sysType);
free (freePtr);
return (ERROR);
}
free (freePtr);
return (OK);
}
/******************************************************************************
*
* usrAtaInit - intialize the hard disk driver
*
* This routine is called from usrConfig.c to initialize the hard drive.
*/
void usrAtaInit (void)
{
int ix;
ATA_RESOURCE *pAtaResource;
for (ix = 0; ix < ATA_MAX_CTRLS; ix++)
{
pAtaResource = &ataResources[ix];
if (pAtaResource->ctrlType == IDE_LOCAL)
if ((ataDrv (ix, pAtaResource->drives, pAtaResource->intVector,
pAtaResource->intLevel, pAtaResource->configType,
pAtaResource->semTimeout, pAtaResource->wdgTimeout))
== ERROR)
{
printf ("ataDrv returned ERROR from usrRoot.\n");
}
}
}