5 * Jordan Hubbard. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/consio.h>
35 #include <sys/disklabel.h>
36 #include <sys/errno.h>
37 #include <sys/ioctl.h>
38 #include <sys/fcntl.h>
41 #include <sys/param.h>
43 #include <sys/mount.h>
44 #include <ufs/ufs/ufsmount.h>
45 #include <fs/msdosfs/msdosfsmount.h>
48 #include <sys/sysctl.h>
54 #define TERMCAP_FILE "/usr/share/misc/termcap"
57 checkLabels(Boolean whinge)
61 /* Don't allow whinging if noWarn is set */
62 if (variable_get(VAR_NO_WARN))
66 HomeChunk = RootChunk = SwapChunk = NULL;
67 TmpChunk = UsrChunk = VarChunk = NULL;
72 /* We don't need to worry about root/usr/swap if we're already multiuser */
79 performNewfs(PartInfo *pi, char *dname, int queue)
81 char buffer[LINE_MAX];
84 switch(pi->newfs_type) {
86 snprintf(buffer, LINE_MAX, "%s %s %s %s %s",
88 pi->newfs_data.newfs_ufs.softupdates ? "-U" : "",
89 pi->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2",
90 pi->newfs_data.newfs_ufs.user_options,
95 snprintf(buffer, LINE_MAX, "%s %s", NEWFS_MSDOS_CMD,
100 snprintf(buffer, LINE_MAX, "%s %s",
101 pi->newfs_data.newfs_custom.command, dname);
105 if (queue == QUEUE_YES) {
106 command_shell_add(pi->mountpoint, buffer);
109 return (vsystem(buffer));
114 /* Go newfs and/or mount all the filesystems we've been asked to */
116 installFilesystems(dialogMenuItem *self)
124 Boolean upgrade = FALSE;
126 /* If we've already done this, bail out */
127 if (!variable_cmp(DISK_LABELLED, "written"))
128 return DITEM_SUCCESS;
130 upgrade = !variable_cmp(SYSTEM_STATE, "upgrade");
131 if (!checkLabels(TRUE))
132 return DITEM_FAILURE;
134 root = (RootChunk != NULL) ? (PartInfo *)RootChunk->private_data : NULL;
138 /* Now buzz through the rest of the partitions and mount them too */
139 devs = deviceFind(NULL, DEVICE_TYPE_DISK);
140 for (i = 0; devs[i]; i++) {
141 if (!devs[i]->enabled)
144 disk = (Disk *)devs[i]->private;
146 msgConfirm("No chunk list found for %s!", disk->name);
147 return DITEM_FAILURE | DITEM_RESTORE;
149 for (c1 = disk->chunks->part; c1; c1 = c1->next) {
151 if (c1->type == part) {
154 #elif defined(__powerpc__)
155 if (c1->type == apple) {
156 for (c2 = c1->part; c2; c2 = c2->next) {
158 if (c1->type == freebsd) {
159 for (c2 = c1->part; c2; c2 = c2->next) {
161 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
162 PartInfo *tmp = (PartInfo *)c2->private_data;
164 /* Already did root */
168 sprintf(dname, "/dev/%s", c2->name);
170 if (tmp->do_newfs && (!upgrade ||
171 !msgNoYes("You are upgrading - are you SURE you"
172 " want to newfs /dev/%s?", c2->name)))
173 performNewfs(tmp, dname, QUEUE_YES);
175 command_shell_add(tmp->mountpoint,
176 "fsck_ffs -y /dev/%s", c2->name);
177 command_func_add(tmp->mountpoint, Mount, c2->name);
179 else if (c2->type == part && c2->subtype == FS_SWAP) {
185 sprintf(fname, "/dev/%s", c2->name);
186 i = (Fake || swapon(fname));
188 dialog_clear_norefresh();
189 msgNotify("Added %s as an additional swap device", fname);
192 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno));
197 else if (c1->type == fat && c1->private_data &&
198 (root->do_newfs || upgrade)) {
199 char name[FILENAME_MAX];
201 sprintf(name, "/%s", ((PartInfo *)c1->private_data)->mountpoint);
204 #if defined(__ia64__)
205 else if (c1->type == efi && c1->private_data) {
206 PartInfo *pi = (PartInfo *)c1->private_data;
208 sprintf(dname, "/dev/%s", c1->name);
210 if (pi->do_newfs && (!upgrade ||
211 !msgNoYes("You are upgrading - are you SURE you want to "
212 "newfs /dev/%s?", c1->name)))
213 performNewfs(pi, dname, QUEUE_YES);
221 dialog_clear_norefresh();
222 return DITEM_SUCCESS | DITEM_RESTORE;
229 size_t sz = (sizeof buf) - 1;
231 if (sysctlbyname("kern.osrelease", buf, &sz, NULL, 0) != -1) {
239 /* Initialize various user-settable values to their defaults */
241 installVarDefaults(dialogMenuItem *self)
244 /* Set default startup options */
245 variable_set2(VAR_RELNAME, getRelname(), 0);
246 variable_set2(SYSTEM_STATE, "update", 0);
247 variable_set2(VAR_NEWFS_ARGS, "-b 16384 -f 2048", 0);
248 variable_set2(VAR_CONSTERM, "NO", 0);
249 return DITEM_SUCCESS;
252 /* Load the environment up from various system configuration files */
254 installEnvironment(void)