]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/sysinstall/ufs.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / sysinstall / ufs.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$
8  *
9  * Copyright (c) 1995
10  *      Jordan Hubbard.  All rights reserved.
11  * Copyright (c) 1995
12  *      Gary J Palmer. All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer,
19  *    verbatim and that no modifications are made prior to this
20  *    point in the file.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  */
38
39 #include "sysinstall.h"
40 #include <sys/fcntl.h>
41 #include <sys/param.h>
42 #include <sys/mount.h>
43 #include <ufs/ufs/ufsmount.h>
44
45 static Boolean UFSMounted;
46 static char mountpoint[] = "/dist";
47
48 Boolean
49 mediaInitUFS(Device *dev)
50 {
51     struct ufs_args args;
52
53     if (UFSMounted)
54         return TRUE;
55      
56     Mkdir(mountpoint);
57     memset(&args, 0, sizeof(args));
58     args.fspec = dev->devname;
59
60     if (mount("ufs", mountpoint, MNT_RDONLY, (caddr_t)&args) == -1) {
61         msgConfirm("Error mounting %s on %s: %s (%u)", args.fspec, mountpoint, strerror(errno), errno);
62         return FALSE;
63     }
64     UFSMounted = TRUE;
65     return TRUE;
66 }
67
68 FILE *
69 mediaGetUFS(Device *dev, char *file, Boolean probe)
70 {
71     return mediaGenericGet((char *)dev->private, file);
72 }
73
74 void
75 mediaShutdownUFS(Device *dev)
76 {
77     if (!UFSMounted)
78         return;
79     if (unmount(mountpoint, MNT_FORCE) != 0)
80         msgConfirm("Could not unmount the UFS partition from %s: %s",
81                    mountpoint, strerror(errno));
82     else
83         UFSMounted = FALSE;
84     return;
85 }