Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2012 11:36:33 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r237642 - in user/ae/bootcode/sys/boot: i386/libi386 userboot/userboot
Message-ID:  <201206271136.q5RBaX70008039@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Wed Jun 27 11:36:33 2012
New Revision: 237642
URL: http://svn.freebsd.org/changeset/base/237642

Log:
  Use disk_parsedev() and disk_fmtdev() functions.

Modified:
  user/ae/bootcode/sys/boot/i386/libi386/devicename.c
  user/ae/bootcode/sys/boot/userboot/userboot/devicename.c

Modified: user/ae/bootcode/sys/boot/i386/libi386/devicename.c
==============================================================================
--- user/ae/bootcode/sys/boot/i386/libi386/devicename.c	Wed Jun 27 11:34:56 2012	(r237641)
+++ user/ae/bootcode/sys/boot/i386/libi386/devicename.c	Wed Jun 27 11:36:33 2012	(r237642)
@@ -29,8 +29,8 @@ __FBSDID("$FreeBSD$");
 
 #include <stand.h>
 #include <string.h>
-#include <sys/disklabel.h>
 #include "bootstrap.h"
+#include "disk.h"
 #include "libi386.h"
 #include "../zfs/libzfs.h"
 
@@ -86,7 +86,7 @@ i386_parsedev(struct i386_devdesc **dev,
 {
     struct i386_devdesc *idev;
     struct devsw	*dv;
-    int			i, unit, slice, partition, err;
+    int			i, unit, err;
     char		*cp;
     const char		*np;
 
@@ -112,62 +112,9 @@ i386_parsedev(struct i386_devdesc **dev,
 	break;
 
     case DEVT_DISK:
-	unit = -1;
-	slice = -1;
-	partition = -1;
-	if (*np && (*np != ':')) {
-	    unit = strtol(np, &cp, 10);	/* next comes the unit number */
-	    if (cp == np) {
-		err = EUNIT;
-		goto fail;
-	    }
-#ifdef LOADER_GPT_SUPPORT
-	    if (*cp == 'p') {		/* got a GPT partition */
-		np = cp + 1;
-		slice = strtol(np, &cp, 10);
-		if (cp == np) {
-		    err = ESLICE;
-		    goto fail;
-		}
-		if (*cp && (*cp != ':')) {
-		    err = EINVAL;
-		    goto fail;
-		}
-		partition = 0xff;
-	    } else {
-#endif
-		if (*cp == 's') {		/* got a slice number */
-		    np = cp + 1;
-		    slice = strtol(np, &cp, 10);
-		    if (cp == np) {
-			err = ESLICE;
-			goto fail;
-		    }
-		}
-		if (*cp && (*cp != ':')) {
-		    partition = *cp - 'a';	/* got a partition number */
-		    if ((partition < 0) || (partition >= MAXPARTITIONS)) {
-			err = EPART;
-			goto fail;
-		    }
-		    cp++;
-		}
-#ifdef LOADER_GPT_SUPPORT
-	    }
-#endif
-	} else {
-		cp = np;
-	}
-	if (*cp && (*cp != ':')) {
-	    err = EINVAL;
+	err = disk_parsedev((struct disk_devdesc *)idev, np, path);
+	if (err != 0)
 	    goto fail;
-	}
-
-	idev->d_unit = unit;
-	idev->d_kind.biosdisk.slice = slice;
-	idev->d_kind.biosdisk.partition = partition;
-	if (path != NULL)
-	    *path = (*cp == 0) ? cp : cp + 1;
 	break;
 
     case DEVT_CD:
@@ -221,38 +168,20 @@ i386_fmtdev(void *vdev)
 {
     struct i386_devdesc	*dev = (struct i386_devdesc *)vdev;
     static char		buf[128];	/* XXX device length constant? */
-    char		*cp;
-    
+
     switch(dev->d_type) {
     case DEVT_NONE:
 	strcpy(buf, "(no device)");
 	break;
 
     case DEVT_CD:
+    case DEVT_NET:
 	sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
 	break;
 
     case DEVT_DISK:
-	cp = buf;
-	cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
-#ifdef LOADER_GPT_SUPPORT
-	if (dev->d_kind.biosdisk.partition == 0xff) {
-	    cp += sprintf(cp, "p%d", dev->d_kind.biosdisk.slice);
-	} else {
-#endif
-	    if (dev->d_kind.biosdisk.slice > 0)
-		cp += sprintf(cp, "s%d", dev->d_kind.biosdisk.slice);
-	    if (dev->d_kind.biosdisk.partition >= 0)
-		cp += sprintf(cp, "%c", dev->d_kind.biosdisk.partition + 'a');
-#ifdef LOADER_GPT_SUPPORT
-	}
-#endif
-	strcat(cp, ":");
-	break;
+	return (disk_fmtdev(vdev));
 
-    case DEVT_NET:
-	sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
-	break;
     case DEVT_ZFS:
 	return(zfs_fmtdev(vdev));
     }

Modified: user/ae/bootcode/sys/boot/userboot/userboot/devicename.c
==============================================================================
--- user/ae/bootcode/sys/boot/userboot/userboot/devicename.c	Wed Jun 27 11:34:56 2012	(r237641)
+++ user/ae/bootcode/sys/boot/userboot/userboot/devicename.c	Wed Jun 27 11:36:33 2012	(r237642)
@@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$");
 
 #include <stand.h>
 #include <string.h>
-#include <sys/disklabel.h>
 
 #include "bootstrap.h"
 #include "disk.h"
@@ -87,7 +86,7 @@ userboot_parsedev(struct disk_devdesc **
 {
     struct disk_devdesc *idev;
     struct devsw	*dv;
-    int			i, unit, slice, partition, err;
+    int			i, unit, err;
     char		*cp;
     const char		*np;
 
@@ -113,62 +112,9 @@ userboot_parsedev(struct disk_devdesc **
 	break;
 
     case DEVT_DISK:
-	unit = -1;
-	slice = -1;
-	partition = -1;
-	if (*np && (*np != ':')) {
-	    unit = strtol(np, &cp, 10);	/* next comes the unit number */
-	    if (cp == np) {
-		err = EUNIT;
-		goto fail;
-	    }
-#ifdef LOADER_GPT_SUPPORT
-	    if (*cp == 'p') {		/* got a GPT partition */
-		np = cp + 1;
-		slice = strtol(np, &cp, 10);
-		if (cp == np) {
-		    err = ESLICE;
-		    goto fail;
-		}
-		if (*cp && (*cp != ':')) {
-		    err = EINVAL;
-		    goto fail;
-		}
-		partition = 0xff;
-	    } else {
-#endif
-		if (*cp == 's') {		/* got a slice number */
-		    np = cp + 1;
-		    slice = strtol(np, &cp, 10);
-		    if (cp == np) {
-			err = ESLICE;
-			goto fail;
-		    }
-		}
-		if (*cp && (*cp != ':')) {
-		    partition = *cp - 'a';	/* got a partition number */
-		    if ((partition < 0) || (partition >= MAXPARTITIONS)) {
-			err = EPART;
-			goto fail;
-		    }
-		    cp++;
-		}
-#ifdef LOADER_GPT_SUPPORT
-	    }
-#endif
-	} else {
-		cp = np;
-	}
-	if (*cp && (*cp != ':')) {
-	    err = EINVAL;
+	err = disk_parsedev(idev, np, path);
+	if (err != 0)
 	    goto fail;
-	}
-
-	idev->d_unit = unit;
-	idev->d_slice = slice;
-	idev->d_partition = partition;
-	if (path != NULL)
-	    *path = (*cp == 0) ? cp : cp + 1;
 	break;
 
     case DEVT_CD:
@@ -219,8 +165,7 @@ userboot_fmtdev(void *vdev)
 {
     struct disk_devdesc	*dev = (struct disk_devdesc *)vdev;
     static char		buf[128];	/* XXX device length constant? */
-    char		*cp;
-    
+
     switch(dev->d_type) {
     case DEVT_NONE:
 	strcpy(buf, "(no device)");
@@ -231,22 +176,7 @@ userboot_fmtdev(void *vdev)
 	break;
 
     case DEVT_DISK:
-	cp = buf;
-	cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
-#ifdef LOADER_GPT_SUPPORT
-	if (dev->d_partition == 0xff) {
-	    cp += sprintf(cp, "p%d", dev->d_slice);
-	} else {
-#endif
-	    if (dev->d_slice > 0)
-		cp += sprintf(cp, "s%d", dev->d_slice);
-	    if (dev->d_partition >= 0)
-		cp += sprintf(cp, "%c", dev->d_partition + 'a');
-#ifdef LOADER_GPT_SUPPORT
-	}
-#endif
-	strcat(cp, ":");
-	break;
+	return (disk_fmtdev(vdev));
 
     case DEVT_NET:
     case DEVT_ZFS:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206271136.q5RBaX70008039>