[klibc] [PATCH] kinit/nfsmount.c path from bootp

Thayne Harbaugh tharbaugh at lnxi.com
Wed Jan 5 14:35:14 PST 2005


On Wed, 2005-01-05 at 03:27 -0700, Thayne Harbaugh wrote:
> kinit/nfsmount.c:mount_nfs_root() should use the bootpath specified by
> bootp/dhcp.  If the "nfsroot" option is specified then it overrides the
> boot server bootpath and a message indicating the override is printed.

This is an updated patch that removes some of gratuitous debug
statements I had in the last patch.  This patch also fixes a bug where
mount_nfs_root() stomps on the argv of init - it now creates a new
"nfs_argv" to pass to nfsmount_main().

Yeah, it could be two separate patches, but it's all in one.

--- klibc-0.194/kinit/nfsroot.c.orig	2005-01-05 15:20:16.967505424 -0700
+++ klibc-0.194/kinit/nfsroot.c	2005-01-05 15:18:33.629215232 -0700
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "ipconfig.h"
 #include "kinit.h"
@@ -28,6 +29,9 @@
 	return path;
 }
 
+#define NFS_ARGC 6
+#define MOUNT_POINT "/root"
+
 int mount_nfs_root(int argc, char *argv[], int flags)
 {
 	(void) flags; // FIXME - don't ignore this
@@ -36,34 +40,21 @@
 	__u32 client = INADDR_NONE;
 	const int len = 1024;
 	struct netdev *dev;
+	char *mtpt = MOUNT_POINT;
 	char *path = NULL;
+	char *dev_bootpath = NULL;
 	char root[len];
 	char *x, *opts;
 	int ret = 0;
-	int a;
-
-	if ((path = get_arg(argc, argv, "nfsroot=")) == NULL) {
-		path = (char *) "/tftpboot/%s";
-	}
-
-	if (*path == '\0') {
-		fprintf(stderr, "Root-NFS: no path\n");
-		exit(1);
-	}
-
-	a = 1;
-	
-	if ((opts = strchr(path, ',')) != NULL) {
-		*opts++ = '\0';
-		argv[a++] = (char *) "-o";
-		argv[a++] = opts;
-	}
+	int a = 1;
+	char *nfs_argv[NFS_ARGC + 1] = { "NFS-Mount" };
 
 	for (dev = ifaces; dev; dev = dev->next) {
 		if (dev->ip_server != INADDR_NONE &&
 		    dev->ip_server != INADDR_ANY) {
 			addr.s_addr = dev->ip_server;
 			client = dev->ip_addr;
+			dev_bootpath = dev->bootpath;
 			break;
 		}
 		if (dev->ip_addr != INADDR_NONE &&
@@ -72,6 +63,25 @@
 		}
 	}
 
+	/*
+	 * if the "nfsroot" option is set then it overrides
+	 * bootpath supplied by the boot server.
+	 */
+	if ((path = get_arg(argc, argv, "nfsroot=")) == NULL ) {
+		if ((path = dev_bootpath) == NULL || path[0] == '\0')
+			/* no path - set a default */
+			path = (char *) "/tftpboot/%s";
+	} else if (dev_bootpath && dev_bootpath[0] != '\0')
+		fprintf(stderr,
+			"nsfroot=%s overrides boot server bootpath %s\n",
+			path, dev_bootpath);
+
+	if ((opts = strchr(path, ',')) != NULL) {
+		*opts++ = '\0';
+		nfs_argv[a++] = (char *) "-o";
+		nfs_argv[a++] = opts;
+	}
+
 	if ((x = strchr(path, ':')) == NULL) {
 		if (addr.s_addr == INADDR_NONE) {
 			fprintf(stderr, "Root-NFS: no server defined\n");
@@ -80,21 +90,20 @@
 
 		snprintf(root, len, "%s:%s", inet_ntoa(addr), path);
 
-		argv[a++] = sub_client(client, root, len);
+		nfs_argv[a++] = sub_client(client, root, len);
 	} else {
 		strcpy(root, path);
-		argv[a++] = sub_client(client, root, len);
+		nfs_argv[a++] = sub_client(client, root, len);
 	}
 
 	DEBUG(("NFS-Root: mounting %s on %s with options '%s'\n",
-	       argv[a - 1], local, opts ? opts : "none"));
-
-	argv[a++] = (char *) "/root";
-	argv[a] = NULL;
+	       argv[a - 1], mtpt, opts ? opts : "none"));
 
-	dump_args(a, argv);
+	nfs_argv[a++] = mtpt;
+	nfs_argv[a] = NULL;
+	assert(a <= NFS_ARGC);
 
-	if ((ret = nfsmount_main(a, argv)) != 0) {
+	if ((ret = nfsmount_main(a, nfs_argv)) != 0) {
 		ret = -1;
 		goto done;
 	}

-- 
Thayne Harbaugh
Linux Networx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.zytor.com/pipermail/klibc/attachments/20050105/93066ad3/attachment.bin


More information about the klibc mailing list