FreeBSD/sys/boot/powerpc/ps3/devicename.c
/*
 * Point (dev) at an allocated device specifier matching the string version
 * at the beginning of (devspec).  Return a pointer to the remaining
 * text in (path).
 *
 * In all cases, the beginning of (devspec) is compared to the names
 * of known devices in the device switch, and then any following text
 * is parsed according to the rules applied to the device type.
 *
 * For disk-type devices, the syntax is:
 *
 * disk<unit>[<partition>]:
 *
 */
Point (dev) at an allocated device specifier matching the string version
at the beginning of (devspec).  Return a pointer to the remaining
text in (path).

In all cases, the beginning of (devspec) is compared to the names
of known devices in the device switch, and then any following text
is parsed according to the rules applied to the device type.

For disk-type devices, the syntax is.


Point ( dev ) at an allocated device specifier matching the string version at the beginning of ( devspec ) . Return a pointer to the remaining text in ( path ) . In all cases the beginning of ( devspec ) is compared to the names of known devices in the device switch and then any following text is parsed according to the rules applied to the device type . For disk - type devices the syntax is .
static int
ps3_parsedev(struct ps3_devdesc **dev, const char *devspec, const char **path)
{
	struct ps3_devdesc *idev;
	struct devsw *dv;
	char *cp;
	const char *np;
	int i, unit, pnum, ptype, err;
	if (strlen(devspec) < 2)
		return(EINVAL);
	for (i = 0, dv = NULL; devsw[i] != NULL; i++) {
		if (!strncmp(devspec, devsw[i]->dv_name,
		    strlen(devsw[i]->dv_name))) {
			dv = devsw[i];
			break;
		}
	}
	if (dv == NULL)
		return(ENOENT);
	idev = malloc(sizeof(struct ps3_devdesc));
	err = 0;
	np = (devspec + strlen(dv->dv_name));
	switch(dv->dv_type) {
	case DEVT_NONE:
		break;
	case DEVT_DISK:
		unit = -1;
		pnum = -1;
		ptype = -1;
		if (*np && (*np != ':')) {
			unit = strtol(np, &cp, 10);
			if (cp == np) {
				err = EUNIT;
				goto fail;
			}
			if (*cp && (*cp != ':')) {
				if (*cp == 'p' && *(cp + 1) &&
				    *(cp + 1) != ':') {
					pnum = strtol(cp + 1, &cp, 10);
					ptype = PTYPE_GPT;
				} else {
					pnum = *cp - 'a';
					ptype = PTYPE_BSDLABEL;
					if ((pnum < 0) ||
					    (pnum >= MAXPARTITIONS)) {
						err = EPART;
						goto fail;
					}
					cp++;
				}
			}
		}
		if (*cp && (*cp != ':')) {
			err = EINVAL;
			goto fail;
		}
		idev->d_unit = unit;
		idev->d_disk.pnum = pnum;
		idev->d_disk.ptype = ptype;
		idev->d_disk.data = NULL;
		if (path != NULL)
			*path = (*cp == 0) ? cp : cp + 1;
		break;
	case DEVT_NET:
	case DEVT_CD:
		idev->d_unit = 0;
		break;
	default:
		err = EINVAL;
		goto fail;
	}
	idev->d_dev = dv;
	idev->d_type = dv->dv_type;
	if (dev == NULL) {
		free(idev);
	} else {
		*dev = idev;
	}
	return (0);
fail:
	free(idev);
	return (err);
}
static int ps3_parsedev ( struct ps3_devdesc * * dev , const char * devspec , const char * * path ) { struct ps3_devdesc * idev ; struct devsw * dv ; char * cp ; const char * np ; int i , unit , pnum , ptype , err ; if ( strlen ( devspec ) < 2 ) return ( EINVAL ) ; for ( i = 0 , dv = NULL ; devsw [ i ] != NULL ; i ++ ) { if ( ! strncmp ( devspec , devsw [ i ] -> dv_name , strlen ( devsw [ i ] -> dv_name ) ) ) { dv = devsw [ i ] ; break ; } } if ( dv == NULL ) return ( ENOENT ) ; idev = malloc ( sizeof ( struct ps3_devdesc ) ) ; err = 0 ; np = ( devspec + strlen ( dv -> dv_name ) ) ; switch ( dv -> dv_type ) { case DEVT_NONE : break ; case DEVT_DISK : unit = -1 ; pnum = -1 ; ptype = -1 ; if ( * np && ( * np != ' ' ) ) { unit = strtol ( np , & cp , 10 ) ; if ( cp == np ) { err = EUNIT ; goto fail ; } if ( * cp && ( * cp != ' ' ) ) { if ( * cp == ' ' && * ( cp + 1 ) && * ( cp + 1 ) != ' ' ) { pnum = strtol ( cp + 1 , & cp , 10 ) ; ptype = PTYPE_GPT ; } else { pnum = * cp - ' ' ; ptype = PTYPE_BSDLABEL ; if ( ( pnum < 0 ) || ( pnum >= MAXPARTITIONS ) ) { err = EPART ; goto fail ; } cp ++ ; } } } if ( * cp && ( * cp != ' ' ) ) { err = EINVAL ; goto fail ; } idev -> d_unit = unit ; idev -> d_disk . pnum = pnum ; idev -> d_disk . ptype = ptype ; idev -> d_disk . data = NULL ; if ( path != NULL ) * path = ( * cp == 0 ) ? cp : cp + 1 ; break ; case DEVT_NET : case DEVT_CD : idev -> d_unit = 0 ; break ; default : err = EINVAL ; goto fail ; } idev -> d_dev = dv ; idev -> d_type = dv -> dv_type ; if ( dev == NULL ) { free ( idev ) ; } else { * dev = idev ; } return ( 0 ) ; fail : free ( idev ) ; return ( err ) ; }
Point (dev) at an allocated device specifier matching the string version
 at the beginning of (devspec).
Point ( dev ) at an allocated device specifier matching the string version at the beginning of ( devspec ) .
/* minimum length check */ /* look for a device that matches */ /* next comes the unit number */ /* get partition */ /*
		 * PS3 only has one network interface (well, two, but
		 * netbooting over wireless is not something I'm going
		 * to worry about.
		 */