X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fdevsparts.c;h=440739fd66e89b7006be120f37a1849a197cc063;hb=31fba8d8033216f8a288e75fe3f575b73b9ef925;hp=52a6d304d5afb6a1e45c33eb9ab25d723b59a46f;hpb=7c020a14802255c966b2b402b983551b86a08bba;p=libguestfs.git diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 52a6d30..440739f 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -220,3 +220,28 @@ do_part_to_dev (const char *part) return r; } + +int +do_part_to_partnum (const char *part) +{ + int err = 1; + size_t n = strlen (part); + + while (n >= 1 && c_isdigit (part[n-1])) { + err = 0; + n--; + } + + if (err) { + reply_with_error ("device name is not a partition"); + return -1; + } + + int r; + if (sscanf (&part[n], "%d", &r) != 1) { + reply_with_error ("could not parse number"); + return -1; + } + + return r; +}