Add an installer-fetchpkgs target and other related stuff to reduce the
[dragonfly.git] / release / sysinstall / dos.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/dos.c,v 1.23 1999/08/28 01:34:12 peter Exp $
8  * $DragonFly: src/release/sysinstall/Attic/dos.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
9  *
10  * Copyright (c) 1995
11  *      Jordan Hubbard.  All rights reserved.
12  * Copyright (c) 1995
13  *      Gary J Palmer. All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer,
20  *    verbatim and that no modifications are made prior to this
21  *    point in the file.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  *
26  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  */
39
40 #include "sysinstall.h"
41 #include <sys/stat.h>
42 #include <sys/errno.h>
43 #include <sys/param.h>
44 #include <sys/wait.h>
45 #include <unistd.h>
46 #include <fcntl.h>
47 #include <grp.h>
48 #define MSDOSFS
49 #include <sys/mount.h>
50 #include <msdosfs/msdosfsmount.h>
51 #undef MSDOSFS
52
53 static Boolean DOSMounted;
54 static char mountpoint[] = "/dist";
55
56 Boolean
57 mediaInitDOS(Device *dev)
58 {
59     struct msdosfs_args args;
60
61     if (DOSMounted)
62         return TRUE;
63      
64     Mkdir(mountpoint);
65     memset(&args, 0, sizeof(args));
66     args.fspec = dev->devname;
67     args.uid = args.gid = 0;
68     args.mask = 0777;
69
70     if (mount("msdos", mountpoint, MNT_RDONLY, (caddr_t)&args) == -1) {
71         msgConfirm("Error mounting %s on %s: %s (%u)", args.fspec, mountpoint, strerror(errno), errno);
72         return FALSE;
73     }
74     DOSMounted = TRUE;
75     return TRUE;
76 }
77
78 FILE *
79 mediaGetDOS(Device *dev, char *file, Boolean probe)
80 {
81     return mediaGenericGet(mountpoint, file);
82 }
83
84 void
85 mediaShutdownDOS(Device *dev)
86 {
87     if (!DOSMounted)
88         return;
89     if (unmount(mountpoint, MNT_FORCE) != 0)
90         msgConfirm("Could not unmount the DOS partition from %s: %s",
91                    mountpoint, strerror(errno));
92     else
93         DOSMounted = FALSE;
94     return;
95 }