]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/sysinstall/nfs.c
This commit was generated by cvs2svn to compensate for changes in r38494,
[FreeBSD/FreeBSD.git] / usr.sbin / sysinstall / nfs.c
1 /*
2  * The new sysinstall program.
3  *
4  * This is probably the last attempt in the `sysinstall' line, the next
5  * generation being slated to essentially a complete rewrite.
6  *
7  * $Id$
8  *
9  * Copyright (c) 1995
10  *      Jordan Hubbard.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer,
17  *    verbatim and that no modifications are made prior to this
18  *    point in the file.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36
37 #include "sysinstall.h"
38 #include <sys/errno.h>
39 #include <sys/fcntl.h>
40 #include <sys/syslimits.h>
41 #include <sys/param.h>
42 #include <sys/mount.h>
43
44 Boolean NFSMounted;
45
46 Boolean
47 mediaInitNFS(Device *dev)
48 {
49     char *mountpoint = "/dist";
50     Device *netDevice = (Device *)dev->private;
51
52     if (NFSMounted)
53         return TRUE;
54
55     if (netDevice && !netDevice->init(netDevice))
56         return FALSE;
57
58     if (Mkdir(mountpoint))
59         return FALSE;
60
61     msgNotify("Mounting %s over NFS on %s", dev->name, mountpoint);
62     if (vsystem("mount_nfs %s %s %s %s",
63                 variable_get(VAR_SLOW_ETHER) ? "-r 1024 -w 1024" : "",
64                 variable_get(VAR_NFS_SECURE) ? "-P" : "", dev->name, mountpoint)) {
65         msgConfirm("Error mounting %s on %s: %s.", dev->name, mountpoint, strerror(errno));
66         if (netDevice)
67             netDevice->shutdown(netDevice);
68         return FALSE;
69     }
70     NFSMounted = TRUE;
71     msgDebug("Mounted NFS device %s onto %s\n", dev->name, mountpoint);
72     return TRUE;
73 }
74
75 FILE *
76 mediaGetNFS(Device *dev, char *file, Boolean probe)
77 {
78     char        buf[PATH_MAX];
79
80     if (isDebug())
81         msgDebug("Request for %s from NFS\n", file);
82     snprintf(buf, PATH_MAX, "/dist/%s", file);
83     if (file_readable(buf))
84         return fopen(buf, "r");
85     snprintf(buf, PATH_MAX, "/dist/dists/%s", file);
86     if (file_readable(buf))
87         return fopen(buf, "r");
88     snprintf(buf, PATH_MAX, "/dist/%s/%s", variable_get(VAR_RELNAME), file);
89     if (file_readable(buf))
90         return fopen(buf, "r");
91     snprintf(buf, PATH_MAX, "/dist/%s/dists/%s", variable_get(VAR_RELNAME), file);
92     return fopen(buf, "r");
93 }
94
95 void
96 mediaShutdownNFS(Device *dev)
97 {
98     /* Device *netdev = (Device *)dev->private; */
99     char *mountpoint = "/dist";
100
101     if (!NFSMounted)
102         return;
103     msgNotify("Unmounting NFS partition on %s", mountpoint);
104     if (unmount(mountpoint, MNT_FORCE) != 0)
105         msgConfirm("Could not unmount the NFS partition: %s", strerror(errno));
106     msgDebug("Unmount of NFS partition successful\n");
107     /* if (netdev) netdev->shutdown(netdev); */
108     NFSMounted = FALSE;
109     return;
110 }