Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jul 2005 06:55:19 GMT
From:      soc-cjones <soc-cjones@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 79897 for review
Message-ID:  <200507100655.j6A6tJQl034882@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=79897

Change 79897 by soc-cjones@soc-cjones_ides on 2005/07/10 06:54:19

	Userland for 'rename', plus simplification of error handling for 
	'move'.

Affected files ...

.. //depot/projects/soc2005/gvinum/src/sbin/gvinum/gvinum.c#4 edit

Differences ...

==== //depot/projects/soc2005/gvinum/src/sbin/gvinum/gvinum.c#4 (text+ko) ====

@@ -617,10 +617,10 @@
 		optreset = 1;
 		optind = 1;
 		cmd = argv[0];
-		while ((j = getopt(argc, argv, "r")) != -1) {
+		while ((j = getopt(argc, argv, "f")) != -1) {
 			switch (j) {
-			case 'r':
-				flags |= GV_FLAG_R;
+			case 'f':
+				flags |= GV_FLAG_F;
 				break;
 			case '?':
 			default:
@@ -631,6 +631,17 @@
 		argv += optind;
 	}
 
+	switch (argc) {
+		case 0:
+			warnx("no destination or object(s) to move specified");
+			return;
+		case 1:
+			warnx("no object(s) to move specified");
+			return;
+		default:
+			break;
+	}
+
 	req = gctl_get_handle();
 	gctl_ro_param(req, "class", -1, "VINUM");
         gctl_ro_param(req, "verb", -1, "move");
@@ -641,26 +652,14 @@
 		for (i = 0; i < argc; i++) {
 			snprintf(buf, sizeof(buf), "argv%d", i);
 			gctl_ro_param(req, buf, -1, argv[i]);
+			if (i > 1) { /* argv[1..$] are objects to move */
+				snprintf(buf, sizeof(buf), "object%d", i - 1);
+				gctl_ro_param(req, buf, -1, argv[i]);
+			}
 		}
-	} else {
-		warnx("no destination or object(s) to move specified");
-		gctl_free(req);
-		return;
 	}
 
-	/* We incremented argv such that the 0th argument is 
-	   the destination, and arguments 1..$ are the objects. */
         gctl_ro_param(req, "destination", -1, argv[0]);
-	if (argc > 1) {
-		for (i = 1; i < argc; i++) {
-			snprintf(buf, sizeof(buf), "object%d", i - 1);
-			gctl_ro_param(req, buf, -1, argv[i]);
-		}
-	} else { /* There isn't at least one object specified! */
-		warnx("no object(s) to move specified");
-		gctl_free(req);
-		return;
-	}
 	errstr = gctl_issue(req); 
 	if (errstr != NULL) {
 		warnx("can't move object(s):  %s", errstr);
@@ -763,7 +762,68 @@
 void
 gvinum_rename(int argc, char **argv)
 {
-	/* NOP */
+	struct gctl_req *req;
+	int flags = 0, i, j;
+	const char *errstr;
+	char buf[20], *cmd;
+
+	if (argc) {
+		optreset = 1;
+		optind = 1;
+		cmd = argv[0];
+		while ((j = getopt(argc, argv, "r")) != -1) {
+			switch (j) {
+			case 'r':
+				flags |= GV_FLAG_R;
+				break;
+			case '?':
+			default:
+				return;
+			}
+		}
+		argc -= optind;
+		argv += optind;
+	}
+
+	switch (argc) {
+		case 0:
+			warnx("no object to rename specified");
+			return;
+		case 1:
+			warnx("no new name specified");
+			return;
+		case 2:
+			break;
+		default:
+			warnx("more than one new name specified");
+			return;
+	}
+
+	req = gctl_get_handle();
+	gctl_ro_param(req, "class", -1, "VINUM");
+        gctl_ro_param(req, "verb", -1, "move");
+        gctl_ro_param(req, "cmd", -1, cmd);
+        gctl_ro_param(req, "argc", sizeof(int), &argc);
+        gctl_ro_param(req, "flags", sizeof(int), &flags);
+
+	if (argc) {
+		for (i = 0; i < argc; i++) {
+			snprintf(buf, sizeof(buf), "argv%d", i);
+			gctl_ro_param(req, buf, -1, argv[i]);
+		}
+	}
+
+        gctl_ro_param(req, "object", -1, argv[0]);
+	gctl_ro_param(req, "newname", -1, argv[1]);
+
+	errstr = gctl_issue(req); 
+	if (errstr != NULL) {
+		warnx("can't rename object:  %s", errstr);
+		gctl_free(req);
+		return;
+	}
+	gctl_free(req);
+	return;
 }
 
 void



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