FreeBSD/sys/boot/ofw/libofw/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).
 */
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).
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 ) .
static int
ofw_parsedev(struct ofw_devdesc **dev, const char *devspec, const char **path)
{
    struct ofw_devdesc	*idev;
    struct devsw	*dv;
    phandle_t		handle;
    const char		*p;
    const char		*s;
    char		*ep;
    char		name[256];
    char		type[64];
    int			err;
    int			len;
    int			i;
    for (p = s = devspec; *s != '\0'; p = s) {
	if ((s = strchr(p + 1, '/')) == NULL)
	    s = strchr(p, '\0');
	len = s - devspec;
	bcopy(devspec, name, len);
	name[len] = '\0';
	if ((handle = OF_finddevice(name)) == -1) {
	    bcopy(name, type, len);
	    type[len] = '\0';
	} else if (OF_getprop(handle, "device_type", type, sizeof(type)) == -1)
	    continue;
	for (i = 0; (dv = devsw[i]) != NULL; i++) {
	    if (strncmp(dv->dv_name, type, strlen(dv->dv_name)) == 0)
		goto found;
	}
    }
    return(ENOENT);
found:
    if (path != NULL)
	*path = s;
    idev = malloc(sizeof(struct ofw_devdesc));
    if (idev == NULL) {
	printf("ofw_parsedev: malloc failed\n");
	return ENOMEM;
    }
    strcpy(idev->d_path, name);
    idev->d_dev = dv;
    idev->d_type = dv->dv_type;
    if (idev->d_type == DEVT_ZFS) {
	p = devspec + strlen(dv->dv_name);
	err = zfs_parsedev((struct zfs_devdesc *)idev, p, path);
	if (err != 0) {
	    free(idev);
	    return (err);
	}
    }
    if (dev == NULL) {
	free(idev);
    } else {
	*dev = idev;
    }
    return(0);
}
static int ofw_parsedev ( struct ofw_devdesc * * dev , const char * devspec , const char * * path ) { struct ofw_devdesc * idev ; struct devsw * dv ; phandle_t handle ; const char * p ; const char * s ; char * ep ; char name [ 256 ] ; char type [ 64 ] ; int err ; int len ; int i ; for ( p = s = devspec ; * s != ' \0 ' ; p = s ) { if ( ( s = strchr ( p + 1 , ' ' ) ) == NULL ) s = strchr ( p , ' \0 ' ) ; len = s - devspec ; bcopy ( devspec , name , len ) ; name [ len ] = ' \0 ' ; if ( ( handle = OF_finddevice ( name ) ) == -1 ) { bcopy ( name , type , len ) ; type [ len ] = ' \0 ' ; } else if ( OF_getprop ( handle , " " , type , sizeof ( type ) ) == -1 ) continue ; for ( i = 0 ; ( dv = devsw [ i ] ) != NULL ; i ++ ) { if ( strncmp ( dv -> dv_name , type , strlen ( dv -> dv_name ) ) == 0 ) goto found ; } } return ( ENOENT ) ; found : if ( path != NULL ) * path = s ; idev = malloc ( sizeof ( struct ofw_devdesc ) ) ; if ( idev == NULL ) { printf ( " \n " ) ; return ENOMEM ; } strcpy ( idev -> d_path , name ) ; idev -> d_dev = dv ; idev -> d_type = dv -> dv_type ; if ( idev -> d_type == DEVT_ZFS ) { p = devspec + strlen ( dv -> dv_name ) ; err = zfs_parsedev ( ( struct zfs_devdesc * ) idev , p , path ) ; if ( err != 0 ) { free ( idev ) ; return ( err ) ; } } if ( dev == NULL ) { free ( idev ) ; } else { * dev = idev ; } return ( 0 ) ; }
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 ) .