Fix more __stdcall issues. Move the __stdcall into the function typedefs
[dragonfly.git] / release / 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  * $FreeBSD: src/release/sysinstall/nfs.c,v 1.21.2.1 2001/07/22 13:50:20 dd Exp $
8  * $DragonFly: src/release/sysinstall/Attic/nfs.c,v 1.3 2003/10/18 20:12:26 hmp Exp $
9  *
10  * Copyright (c) 1995
11  *      Jordan Hubbard.  All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer,
18  *    verbatim and that no modifications are made prior to this
19  *    point in the file.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  */
37
38 #include "sysinstall.h"
39 #include <sys/errno.h>
40 #include <sys/fcntl.h>
41 #include <sys/syslimits.h>
42 #include <sys/param.h>
43 #include <sys/mount.h>
44
45 Boolean NFSMounted;
46 static char mountpoint[] = "/dist";
47
48 Boolean
49 mediaInitNFS(Device *dev)
50 {
51     Device *netDevice = (Device *)dev->private;
52     WINDOW *w = savescr();
53
54     if (NFSMounted)
55         return TRUE;
56
57     if (!DEVICE_INIT(netDevice))
58         return FALSE;
59
60     if (Mkdir(mountpoint))
61         return FALSE;
62
63     msgNotify("Mounting %s over NFS on %s", dev->name, mountpoint);
64     if (vsystem("mount_nfs %s %s %s %s %s %s",
65                 !variable_cmp(VAR_NFS_TCP, "YES") ? "-T" : "",
66                 !variable_cmp(VAR_NFS_V3, "YES") ? "-3" : "",
67                 !variable_cmp(VAR_SLOW_ETHER, "YES") ?
68                         "-r 1024 -w 1024" : "-r 4096 -w 4096",
69                 !variable_cmp(VAR_NFS_SECURE, "YES") ? "-P" : "",
70                 dev->name, mountpoint)) {
71         msgConfirm("Error mounting %s on %s: %s.", dev->name, mountpoint, strerror(errno));
72         if (netDevice)
73             DEVICE_SHUTDOWN(netDevice);
74         restorescr(w);
75         return FALSE;
76     }
77     NFSMounted = TRUE;
78     if (isDebug())
79         msgDebug("Mounted NFS device %s onto %s\n", dev->name, mountpoint);
80     restorescr(w);
81     return TRUE;
82 }
83
84 FILE *
85 mediaGetNFS(Device *dev, char *file, Boolean probe)
86 {
87     return mediaGenericGet(mountpoint, file);
88 }
89
90 void
91 mediaShutdownNFS(Device *dev)
92 {
93     if (!NFSMounted)
94         return;
95
96     msgDebug("Unmounting NFS partition on %s", mountpoint);
97     if (unmount(mountpoint, MNT_FORCE) != 0)
98         msgConfirm("Could not unmount the NFS partition: %s", strerror(errno));
99     NFSMounted = FALSE;
100     return;
101 }