diff options
author | Michael I. Bushnell <mib@gnu.org> | 1995-12-08 19:07:30 +0000 |
---|---|---|
committer | Michael I. Bushnell <mib@gnu.org> | 1995-12-08 19:07:30 +0000 |
commit | e406e0aea2e40f21feb9e22f239fe8150b891bc0 (patch) | |
tree | bfecaa597736bf5ba9e9dcd0478aae2aebaf3444 /nfs | |
parent | d4d4564806372a79500859e0eff3388b99f8d4a3 (diff) |
Formerly mount.c.~3~
Diffstat (limited to 'nfs')
-rw-r--r-- | nfs/mount.c | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/nfs/mount.c b/nfs/mount.c index 07b19ff5..f0880d13 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -31,6 +31,7 @@ mount_root (char *name, char *host) void *rpcbuf; error_t err; int port; + struct netnode *np; /* Lookup the portmapper port number */ s = getservbyname ("portmap", "udp"); @@ -48,10 +49,12 @@ mount_root (char *name, char *host) return 0; } - addr->sin_family = h->h_addrtype; + addr.sin_family = h->h_addrtype; bcopy (h->h_addr_list[0], &addr.sin_addr, h->h_length); - addr->sin_port = htons (s->s_port); + addr.sin_port = htons (s->s_port); + connect (main_udp_socket, &addr, sizeof (struct sockaddr_in)); + /* Formulate and send a PMAPPROC_GETPORT request to lookup the mount program on the server. */ p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf); @@ -59,8 +62,8 @@ mount_root (char *name, char *host) *p++ = htonl (MOUNT_RPC_VERSION); *p++ = htonl (IPPROTO_UDP); *p++ = htonl (0); - err = conduct_rpc (&rpcbuf, &p); - if (err) + errno = conduct_rpc (&rpcbuf, &p); + if (errno) { perror ("portmap of mount"); return 0; @@ -68,19 +71,66 @@ mount_root (char *name, char *host) /* Fetch the reply port and clean the RPC */ port = ntohl (*p++); - addr->sin_port = htons (port); /* note: htons and ntohl aren't inverses */ + addr.sin_port = htons (port); /* note: htons and ntohl aren't inverses */ free (rpcbuf); - + /* Now talking to the mount program, fetch the file handle for the root. */ - + connect (main_udp_socket, &addr, sizeof (struct sockaddr_in)); p = mount_initialize_rpc (MOUNTPROC_MNT, &rpcbuf); p = xdr_encode_string (p, name); - err = conduct_rpc (&rpcbuf, &p); - if (err) + errno = conduct_rpc (&rpcbuf, &p); + if (errno) + { + free (rpcbuf); + perror (name); + return 0; + } + errno = mount_error_trans (htonl (*p++)); + if (errno) { + free (rpcbuf); perror (name); return 0; } + /* Create the node for root */ + np = netfs_make_node (); + p = xdr_decode_fhandle (p, &np->nn.fhandle); + free (rpcbuf); + + /* Now send another PMAPPROC_GETPORT request to lookup the nfs server. */ + addr.sin_port = htons (s->s_port); + connect (main_udp_socket, &addr, sizeof (struct sockaddr_in)); + p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf); + *p++ = htonl (NFSV2_RPC_PROGRAM); + *p++ = htonl (NFSV2_RPC_VERSION); + *p++ = htonl (IPPROTO_UDP); + *p++ = htonl (0); + errno = conduct_rpc (&rpcbuf, &p); + if (errno) + port = NFSV2_UDP_PORT; + else + port = ntohl (*p++); + free (rpcbuf); + + addr.sin_port = htons (port); + connect (main_udp_socket, &addr, sizeof (struct sockaddr_in)); + return np; +} + +int * +pmap_initialize_rpc (int procnum, void **buf) +{ + return initialize_rpc (PMAP_RPC_PROGRAM, PMAP_RPC_VERSION, procnum, + 0, buf, 0, 0, -1); +} + +int * +mount_initialize_rpc (int procnum, void **buf) +{ + return initialize_rpc (MOUNT_RPC_PROGRAM, MOUNT_RPC_VERSION, procnum, + 0, buf, 0, 0, -1); +} + |