Date: Wed, 27 Jun 2012 11:34:56 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r237641 - user/ae/bootcode/sys/boot/common Message-ID: <201206271134.q5RBYuIx007902@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Wed Jun 27 11:34:56 2012 New Revision: 237641 URL: http://svn.freebsd.org/changeset/base/237641 Log: Add disk_parsedev() function. Modified: user/ae/bootcode/sys/boot/common/disk.c user/ae/bootcode/sys/boot/common/disk.h Modified: user/ae/bootcode/sys/boot/common/disk.c ============================================================================== --- user/ae/bootcode/sys/boot/common/disk.c Wed Jun 27 11:08:03 2012 (r237640) +++ user/ae/bootcode/sys/boot/common/disk.c Wed Jun 27 11:34:56 2012 (r237641) @@ -242,3 +242,55 @@ disk_fmtdev(struct disk_devdesc *dev) strcat(cp, ":"); return (buf); } + +int +disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path) +{ + int unit, slice, partition; + const char *np; + char *cp; + + np = devspec; + unit = slice = partition = -1; + if (*np != '\0' && *np != ':') { + unit = strtol(np, &cp, 10); + if (cp == np) + return (EUNIT); +#ifdef LOADER_GPT_SUPPORT + if (*cp == 'p') { + np = cp + 1; + slice = strtol(np, &cp, 10); + if (np == cp) + return (ESLICE); + /* we don't support nested partitions on GPT */ + if (*cp != '\0' && *cp != ':') + return (EINVAL); + partition = 255; + } else +#endif +#ifdef LOADER_MBR_SUPPORT + if (*cp == 's') { + np = cp + 1; + slice = strtol(np, &cp, 10); + if (np == cp) + return (ESLICE); + } +#endif + if (*cp != '\0' && *cp != ':') { + partition = *cp - 'a'; + if (partition < 0) + return (EPART); + cp++; + } + } else + return (EINVAL); + + if (*cp != '\0' && *cp != ':') + return (EINVAL); + dev->d_unit = unit; + dev->d_slice = slice; + dev->d_partition = partition; + if (path != NULL) + *path = (*cp == '\0') ? cp: cp + 1; + return (0); +} Modified: user/ae/bootcode/sys/boot/common/disk.h ============================================================================== --- user/ae/bootcode/sys/boot/common/disk.h Wed Jun 27 11:08:03 2012 (r237640) +++ user/ae/bootcode/sys/boot/common/disk.h Wed Jun 27 11:34:56 2012 (r237641) @@ -100,4 +100,6 @@ extern int disk_close(struct disk_devdes */ extern void disk_print(struct disk_devdesc *dev, char *prefix, int verbose); extern char* disk_fmtdev(struct disk_devdesc *dev); +extern int disk_parsedev(struct disk_devdesc *dev, const char *devspec, + const char **path);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206271134.q5RBYuIx007902>