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