From owner-svn-src-head@FreeBSD.ORG Wed Mar 3 21:27:54 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 899C9106566B; Wed, 3 Mar 2010 21:27:54 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 78BFD8FC14; Wed, 3 Mar 2010 21:27:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o23LRsFH070498; Wed, 3 Mar 2010 21:27:54 GMT (envelope-from lulf@svn.freebsd.org) Received: (from lulf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o23LRsYC070496; Wed, 3 Mar 2010 21:27:54 GMT (envelope-from lulf@svn.freebsd.org) Message-Id: <201003032127.o23LRsYC070496@svn.freebsd.org> From: Ulf Lilleengen Date: Wed, 3 Mar 2010 21:27:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r204665 - head/sbin/gvinum X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2010 21:27:54 -0000 Author: lulf Date: Wed Mar 3 21:27:54 2010 New Revision: 204665 URL: http://svn.freebsd.org/changeset/base/204665 Log: - Make function of finding an available drive name a macro. - Move check of /dev/ prefix and copy into a function to save code duplication. This also fixes a bug where the /dev/ prefix could not be used when creating volumes on the command line. Tested by: Niclas Zeising Modified: head/sbin/gvinum/gvinum.c Modified: head/sbin/gvinum/gvinum.c ============================================================================== --- head/sbin/gvinum/gvinum.c Wed Mar 3 21:22:53 2010 (r204664) +++ head/sbin/gvinum/gvinum.c Wed Mar 3 21:27:54 2010 (r204665) @@ -83,8 +83,9 @@ void printconfig(FILE *, char *); char *create_drive(char *); void create_volume(int, char **, char *); char *find_name(const char *, int, int); -char *find_drive(const char *); char *find_pattern(char *, char *); +void copy_device(struct gv_drive *, const char *); +#define find_drive() find_name("gvinumdrive", GV_TYPE_DRIVE, GV_MAXDRIVENAME) int main(int argc, char **argv) @@ -424,7 +425,7 @@ create_drive(char *device) drives = 1; dname = NULL; - drivename = find_drive(device); + drivename = find_drive(); if (drivename == NULL) return (NULL); @@ -436,7 +437,7 @@ create_drive(char *device) err(1, "unable to allocate for gv_drive object"); strlcpy(d->name, drivename, sizeof(d->name)); - strlcpy(d->device, device, sizeof(d->device)); + copy_device(d, device); gctl_ro_param(req, "drive0", sizeof(*d), d); gctl_ro_param(req, "flags", sizeof(int), &flags); gctl_ro_param(req, "drives", sizeof(int), &drives); @@ -626,14 +627,13 @@ find_name(const char *prefix, int type, return (NULL); } -char * -find_drive(const char *device) +void +copy_device(struct gv_drive *d, const char *device) { - - /* Strip possible /dev/ in front. */ if (strncmp(device, "/dev/", 5) == 0) - device += 5; - return (find_name("gvinumdrive", GV_TYPE_DRIVE, GV_MAXDRIVENAME)); + strlcpy(d->device, (device + 5), sizeof(d->device)); + else + strlcpy(d->device, device, sizeof(d->device)); } /* Detach a plex or subdisk from its parent. */ @@ -1275,7 +1275,7 @@ gvinum_grow(int argc, char **argv) return; } /* Lookup device and set an appropriate drive name. */ - drive = find_drive(argv[2]); + drive = find_drive(); if (drive == NULL) { warn("unable to find an appropriate drive name"); free(s); @@ -1283,10 +1283,8 @@ gvinum_grow(int argc, char **argv) return; } strlcpy(d->name, drive, sizeof(d->name)); - if (strncmp(argv[2], "/dev/", 5) == 0) - strlcpy(d->device, (argv[2] + 5), sizeof(d->device)); - else - strlcpy(d->device, argv[2], sizeof(d->device)); + copy_device(d, argv[2]); + drives = 1; /* We try to use the plex name as basis for the subdisk name. */