summaryrefslogtreecommitdiff
path: root/sys/nfs/nfs_boot.c
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1996-02-29 09:25:05 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1996-02-29 09:25:05 +0000
commit236ff0b91447f3ca43d97ac33e3181bd9ac3c910 (patch)
treef02e4b2e96ef542325efc1d007a83a7cb8f15b2b /sys/nfs/nfs_boot.c
parent9506179fee98a41211223399a1f10c4639d0690c (diff)
From NetBSD: merge with 960217 (still NFSv2)
Diffstat (limited to 'sys/nfs/nfs_boot.c')
-rw-r--r--sys/nfs/nfs_boot.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/sys/nfs/nfs_boot.c b/sys/nfs/nfs_boot.c
index 6e961f18114..130743a21a1 100644
--- a/sys/nfs/nfs_boot.c
+++ b/sys/nfs/nfs_boot.c
@@ -1,4 +1,5 @@
-/* $NetBSD: nfs_boot.c,v 1.20 1995/12/19 23:07:24 cgd Exp $ */
+/* $OpenBSD: nfs_boot.c,v 1.3 1996/02/29 09:24:49 niklas Exp $ */
+/* $NetBSD: nfs_boot.c,v 1.23 1996/02/13 17:53:33 gwr Exp $ */
/*
* Copyright (c) 1995 Adam Glass, Gordon Ross
@@ -51,6 +52,7 @@
#include <nfs/nfsdiskless.h>
#include <nfs/krpc.h>
#include <nfs/xdr_subs.h>
+#include <nfs/nfs_var.h>
#include "ether.h"
#if NETHER == 0
@@ -239,27 +241,29 @@ nfs_boot_init(nd, procp)
}
#endif
- get_path_and_handle(&bp_sin, "root", &nd->nd_root);
- get_path_and_handle(&bp_sin, "swap", &nd->nd_swap);
+ bcopy(&bp_sin, &nd->nd_boot, sizeof(bp_sin));
return (0);
}
-static void
-get_path_and_handle(bpsin, key, ndmntp)
+void
+nfs_boot_getfh(bpsin, key, ndmntp)
struct sockaddr_in *bpsin; /* bootparam server */
char *key; /* root or swap */
struct nfs_dlmount *ndmntp; /* output */
{
char pathname[MAXPATHLEN];
char *sp, *dp, *endp;
+ struct sockaddr_in *sin;
int error;
+ sin = &ndmntp->ndm_saddr;
+
/*
* Get server:pathname for "key" (root or swap)
* using RPC to bootparam/getfile
*/
- error = bp_getfile(bpsin, key, &ndmntp->ndm_saddr,
+ error = bp_getfile(bpsin, key, sin,
ndmntp->ndm_host, pathname);
if (error)
panic("nfs_boot: bootparam get %s: %d", key, error);
@@ -268,10 +272,16 @@ get_path_and_handle(bpsin, key, ndmntp)
* Get file handle for "key" (root or swap)
* using RPC to mountd/mount
*/
- error = md_mount(&ndmntp->ndm_saddr, pathname, ndmntp->ndm_fh);
+ error = md_mount(sin, pathname, ndmntp->ndm_fh);
if (error)
panic("nfs_boot: mountd %s, error=%d", key, error);
+ /* Set port number for NFS use. */
+ /* XXX: NFS port is always 2049, right? */
+ error = krpc_portmap(sin, NFS_PROG, NFS_VER2, &sin->sin_port);
+ if (error)
+ panic("nfs_boot: portmap NFS/v2, error=%d", error);
+
/* Construct remote path (for getmntinfo(3)) */
dp = ndmntp->ndm_host;
endp = dp + MNAMELEN - 1;
@@ -426,9 +436,13 @@ bp_getfile(bpsin, key, md_sin, serv_name, pathname)
/* client name (hostname) */
m = xdr_string_encode(hostname, hostnamelen);
+ if (m == NULL)
+ return (ENOMEM);
/* key name (root or swap) */
m->m_next = xdr_string_encode(key, strlen(key));
+ if (m->m_next == NULL)
+ return (ENOMEM);
/* RPC: bootparam/getfile */
error = krpc_call(bpsin, BOOTPARAM_PROG, BOOTPARAM_VERS,
@@ -502,6 +516,8 @@ md_mount(mdsin, path, fhp)
if (error) return error;
m = xdr_string_encode(path, strlen(path));
+ if (m == NULL)
+ return (ENOMEM);
/* Do RPC to mountd. */
error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER1,
@@ -509,20 +525,23 @@ md_mount(mdsin, path, fhp)
if (error)
return error; /* message already freed */
+ /* The reply might have only the errno. */
+ if (m->m_len < 4)
+ goto bad;
+ /* Have at least errno, so check that. */
+ rdata = mtod(m, struct rdata *);
+ error = fxdr_unsigned(u_int32_t, rdata->errno);
+ if (error)
+ goto out;
+
+ /* Have errno==0, so the fh must be there. */
if (m->m_len < sizeof(*rdata)) {
m = m_pullup(m, sizeof(*rdata));
if (m == NULL)
goto bad;
+ rdata = mtod(m, struct rdata *);
}
- rdata = mtod(m, struct rdata *);
- error = fxdr_unsigned(u_int32_t, rdata->errno);
- if (error)
- goto bad;
bcopy(rdata->fh, fhp, NFS_FHSIZE);
-
- /* Set port number for NFS use. */
- error = krpc_portmap(mdsin, NFS_PROG, NFS_VER2,
- &mdsin->sin_port);
goto out;
bad: