1995-05-23 02:41:18 +00:00
|
|
|
/*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-05-23 02:41:18 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-05-30 08:29:07 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
1995-05-23 02:41:18 +00:00
|
|
|
* point in the file.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-08-07 23:35:49 +00:00
|
|
|
#include "sade.h"
|
1995-05-23 02:41:18 +00:00
|
|
|
#include <sys/disklabel.h>
|
1995-05-26 19:28:06 +00:00
|
|
|
#include <sys/wait.h>
|
1996-04-28 01:07:27 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mount.h>
|
2004-08-02 23:18:48 +00:00
|
|
|
#include <libdisk.h>
|
2001-03-13 06:42:12 +00:00
|
|
|
#include <time.h>
|
2003-05-31 11:28:28 +00:00
|
|
|
#include <kenv.h>
|
1995-05-23 02:41:18 +00:00
|
|
|
|
|
|
|
static Chunk *chunk_list[MAX_CHUNKS];
|
|
|
|
static int nchunks;
|
1996-12-14 23:09:10 +00:00
|
|
|
static int rootdev_is_od;
|
1995-05-23 02:41:18 +00:00
|
|
|
|
|
|
|
/* arg to sort */
|
|
|
|
static int
|
1995-12-07 10:34:59 +00:00
|
|
|
chunk_compare(Chunk *c1, Chunk *c2)
|
1995-05-23 02:41:18 +00:00
|
|
|
{
|
1995-12-07 10:34:59 +00:00
|
|
|
if (!c1 && !c2)
|
1995-05-23 02:41:18 +00:00
|
|
|
return 0;
|
1995-12-07 10:34:59 +00:00
|
|
|
else if (!c1 && c2)
|
|
|
|
return 1;
|
|
|
|
else if (c1 && !c2)
|
1995-05-23 02:41:18 +00:00
|
|
|
return -1;
|
1996-03-24 18:57:37 +00:00
|
|
|
else if (!c1->private_data && !c2->private_data)
|
1995-12-07 10:34:59 +00:00
|
|
|
return 0;
|
1996-03-24 18:57:37 +00:00
|
|
|
else if (c1->private_data && !c2->private_data)
|
1995-05-23 02:41:18 +00:00
|
|
|
return 1;
|
1996-03-24 18:57:37 +00:00
|
|
|
else if (!c1->private_data && c2->private_data)
|
1995-12-07 10:34:59 +00:00
|
|
|
return -1;
|
1995-05-23 02:41:18 +00:00
|
|
|
else
|
1996-03-24 18:57:37 +00:00
|
|
|
return strcmp(((PartInfo *)(c1->private_data))->mountpoint, ((PartInfo *)(c2->private_data))->mountpoint);
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chunk_sort(void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < nchunks; i++) {
|
|
|
|
for (j = 0; j < nchunks; j++) {
|
|
|
|
if (chunk_compare(chunk_list[j], chunk_list[j + 1]) > 0) {
|
|
|
|
Chunk *tmp = chunk_list[j];
|
|
|
|
|
|
|
|
chunk_list[j] = chunk_list[j + 1];
|
|
|
|
chunk_list[j + 1] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
1996-12-14 23:09:10 +00:00
|
|
|
static void
|
|
|
|
check_rootdev(Chunk **list, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Chunk *c;
|
|
|
|
|
|
|
|
rootdev_is_od = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
c = *list++;
|
|
|
|
if (c->type == part && (c->flags & CHUNK_IS_ROOT)
|
|
|
|
&& strncmp(c->disk->name, "od", 2) == 0)
|
|
|
|
rootdev_is_od = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-05-25 18:48:33 +00:00
|
|
|
static char *
|
1995-12-07 10:34:59 +00:00
|
|
|
name_of(Chunk *c1)
|
1995-05-25 18:48:33 +00:00
|
|
|
{
|
1998-03-09 08:39:46 +00:00
|
|
|
return c1->name;
|
1995-05-25 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
static char *
|
|
|
|
mount_point(Chunk *c1)
|
|
|
|
{
|
1995-06-11 19:33:05 +00:00
|
|
|
if (c1->type == part && c1->subtype == FS_SWAP)
|
1995-05-23 02:41:18 +00:00
|
|
|
return "none";
|
2002-11-13 05:39:59 +00:00
|
|
|
else if (c1->type == part || c1->type == fat || c1->type == efi)
|
1996-03-24 18:57:37 +00:00
|
|
|
return ((PartInfo *)c1->private_data)->mountpoint;
|
1995-05-23 02:41:18 +00:00
|
|
|
return "/bogus";
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
fstype(Chunk *c1)
|
|
|
|
{
|
2002-11-13 05:39:59 +00:00
|
|
|
if (c1->type == fat || c1->type == efi)
|
2001-06-01 12:16:09 +00:00
|
|
|
return "msdosfs";
|
1995-05-23 02:41:18 +00:00
|
|
|
else if (c1->type == part) {
|
|
|
|
if (c1->subtype != FS_SWAP)
|
|
|
|
return "ufs";
|
|
|
|
else
|
|
|
|
return "swap";
|
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
return "bogus";
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
fstype_short(Chunk *c1)
|
|
|
|
{
|
|
|
|
if (c1->type == part) {
|
1996-12-14 23:09:10 +00:00
|
|
|
if (c1->subtype != FS_SWAP) {
|
|
|
|
if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
|
|
|
|
return "rw,noauto";
|
|
|
|
else
|
|
|
|
return "rw";
|
|
|
|
}
|
1995-05-23 02:41:18 +00:00
|
|
|
else
|
|
|
|
return "sw";
|
|
|
|
}
|
1996-12-14 23:09:10 +00:00
|
|
|
else if (c1->type == fat) {
|
|
|
|
if (strncmp(c1->name, "od", 2) == 0)
|
|
|
|
return "ro,noauto";
|
|
|
|
else
|
|
|
|
return "ro";
|
|
|
|
}
|
2002-11-13 05:39:59 +00:00
|
|
|
else if (c1->type == efi)
|
|
|
|
return "rw";
|
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
return "bog";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
seq_num(Chunk *c1)
|
|
|
|
{
|
1996-12-14 23:09:10 +00:00
|
|
|
if (c1->type == part && c1->subtype != FS_SWAP) {
|
|
|
|
if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
|
|
|
|
return 0;
|
1997-08-18 21:47:34 +00:00
|
|
|
else if (c1->flags & CHUNK_IS_ROOT)
|
1996-12-14 23:09:10 +00:00
|
|
|
return 1;
|
1997-08-18 21:47:34 +00:00
|
|
|
else
|
|
|
|
return 2;
|
1996-12-14 23:09:10 +00:00
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
return 0;
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
int
|
1998-11-15 09:06:20 +00:00
|
|
|
configFstab(dialogMenuItem *self)
|
1995-05-23 02:41:18 +00:00
|
|
|
{
|
|
|
|
Device **devs;
|
|
|
|
Disk *disk;
|
|
|
|
FILE *fstab;
|
2006-08-08 13:45:46 +00:00
|
|
|
int i;
|
1995-05-23 02:41:18 +00:00
|
|
|
Chunk *c1, *c2;
|
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
if (file_readable("/etc/fstab"))
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_SUCCESS;
|
1995-12-07 10:34:59 +00:00
|
|
|
else {
|
|
|
|
msgConfirm("Attempting to rebuild your /etc/fstab file. Warning: If you had\n"
|
2008-05-11 07:13:08 +00:00
|
|
|
"any CD devices in use before running %s then they may NOT\n"
|
2008-05-11 17:23:57 +00:00
|
|
|
"be found by this run!", ProgName);
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
devs = deviceFind(NULL, DEVICE_TYPE_DISK);
|
|
|
|
if (!devs) {
|
|
|
|
msgConfirm("No disks found!");
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Record all the chunks */
|
1995-06-11 19:33:05 +00:00
|
|
|
nchunks = 0;
|
1995-05-23 02:41:18 +00:00
|
|
|
for (i = 0; devs[i]; i++) {
|
|
|
|
if (!devs[i]->enabled)
|
|
|
|
continue;
|
|
|
|
disk = (Disk *)devs[i]->private;
|
|
|
|
if (!disk->chunks)
|
|
|
|
msgFatal("No chunk list found for %s!", disk->name);
|
1995-05-25 18:48:33 +00:00
|
|
|
for (c1 = disk->chunks->part; c1; c1 = c1->next) {
|
2005-07-21 03:32:29 +00:00
|
|
|
#ifdef __powerpc__
|
|
|
|
if (c1->type == apple) {
|
|
|
|
#else
|
1995-05-25 18:48:33 +00:00
|
|
|
if (c1->type == freebsd) {
|
2005-07-21 03:32:29 +00:00
|
|
|
#endif
|
1995-05-25 18:48:33 +00:00
|
|
|
for (c2 = c1->part; c2; c2 = c2->next) {
|
1996-03-24 18:57:37 +00:00
|
|
|
if (c2->type == part && (c2->subtype == FS_SWAP || c2->private_data))
|
1995-05-23 02:41:18 +00:00
|
|
|
chunk_list[nchunks++] = c2;
|
1995-05-25 18:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-07 19:15:56 +00:00
|
|
|
else if (((c1->type == fat || c1->type == efi || c1->type == part) &&
|
|
|
|
c1->private_data) || (c1->type == part && c1->subtype == FS_SWAP))
|
1995-05-25 18:48:33 +00:00
|
|
|
chunk_list[nchunks++] = c1;
|
|
|
|
}
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
1995-12-07 10:34:59 +00:00
|
|
|
chunk_list[nchunks] = 0;
|
|
|
|
chunk_sort();
|
1998-11-15 09:06:20 +00:00
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
fstab = fopen("/etc/fstab", "w");
|
|
|
|
if (!fstab) {
|
1995-12-07 10:34:59 +00:00
|
|
|
msgConfirm("Unable to create a new /etc/fstab file! Manual intervention\n"
|
|
|
|
"will be required.");
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
1998-11-15 09:06:20 +00:00
|
|
|
|
1996-12-14 23:09:10 +00:00
|
|
|
check_rootdev(chunk_list, nchunks);
|
1998-11-15 09:06:20 +00:00
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
/* Go for the burn */
|
1995-05-29 11:01:42 +00:00
|
|
|
msgDebug("Generating /etc/fstab file\n");
|
1997-03-12 02:31:28 +00:00
|
|
|
fprintf(fstab, "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#\n");
|
1995-06-11 19:33:05 +00:00
|
|
|
for (i = 0; i < nchunks; i++)
|
1997-02-14 21:17:00 +00:00
|
|
|
fprintf(fstab, "/dev/%s\t\t%s\t\t%s\t%s\t\t%d\t%d\n", name_of(chunk_list[i]), mount_point(chunk_list[i]),
|
1995-06-11 19:33:05 +00:00
|
|
|
fstype(chunk_list[i]), fstype_short(chunk_list[i]), seq_num(chunk_list[i]), seq_num(chunk_list[i]));
|
1998-11-15 09:06:20 +00:00
|
|
|
|
|
|
|
|
1995-05-23 02:41:18 +00:00
|
|
|
fclose(fstab);
|
1995-06-11 19:33:05 +00:00
|
|
|
if (isDebug())
|
|
|
|
msgDebug("Wrote out /etc/fstab file\n");
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_SUCCESS;
|
1995-05-23 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
2006-08-07 23:35:49 +00:00
|
|
|
#if 0
|
1997-02-14 20:59:07 +00:00
|
|
|
/* Do the work of sucking in a config file.
|
|
|
|
* config is the filename to read in.
|
1998-11-15 09:06:20 +00:00
|
|
|
* lines is a fixed (max) sized array of char*
|
1997-02-14 20:59:07 +00:00
|
|
|
* returns number of lines read. line contents
|
|
|
|
* are malloc'd and must be freed by the caller.
|
|
|
|
*/
|
2006-02-28 21:49:33 +00:00
|
|
|
static int
|
1997-02-14 20:59:07 +00:00
|
|
|
readConfig(char *config, char **lines, int max)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char line[256];
|
|
|
|
int i, nlines;
|
|
|
|
|
|
|
|
fp = fopen(config, "r");
|
|
|
|
if (!fp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nlines = 0;
|
|
|
|
/* Read in the entire file */
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
if (!fgets(line, sizeof line, fp))
|
|
|
|
break;
|
|
|
|
lines[nlines++] = strdup(line);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
if (isDebug())
|
|
|
|
msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
|
|
|
|
return nlines;
|
|
|
|
}
|
2006-08-07 23:35:49 +00:00
|
|
|
#endif
|
1997-02-14 20:59:07 +00:00
|
|
|
|
|
|
|
#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
|
|
|
|
|
2006-08-07 23:35:49 +00:00
|
|
|
#if 0
|
1999-01-27 02:32:47 +00:00
|
|
|
static void
|
1999-02-05 22:15:52 +00:00
|
|
|
readConfigFile(char *config, int marked)
|
1997-02-14 20:59:07 +00:00
|
|
|
{
|
1997-02-14 21:17:00 +00:00
|
|
|
char *lines[MAX_LINES], *cp, *cp2;
|
1997-06-11 08:41:10 +00:00
|
|
|
int i, nlines;
|
1997-02-14 20:59:07 +00:00
|
|
|
|
|
|
|
nlines = readConfig(config, lines, MAX_LINES);
|
|
|
|
if (nlines == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < nlines; i++) {
|
|
|
|
/* Skip the comments & non-variable settings */
|
|
|
|
if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
|
|
|
|
free(lines[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*cp++ = '\0';
|
1997-06-11 08:41:10 +00:00
|
|
|
/* Find quotes */
|
|
|
|
if ((cp2 = index(cp, '"')) || (cp2 = index(cp, '\047'))) {
|
1997-02-14 21:17:00 +00:00
|
|
|
cp = cp2 + 1;
|
1997-06-11 08:41:10 +00:00
|
|
|
cp2 = index(cp, *cp2);
|
|
|
|
}
|
|
|
|
/* If valid quotes, use it */
|
|
|
|
if (cp2) {
|
|
|
|
*cp2 = '\0';
|
2006-08-07 23:35:49 +00:00
|
|
|
/* If we have a legit value, set it */
|
1999-02-05 22:15:52 +00:00
|
|
|
if (strlen(cp))
|
|
|
|
variable_set2(lines[i], cp, marked);
|
1997-06-11 08:41:10 +00:00
|
|
|
}
|
1997-02-14 20:59:07 +00:00
|
|
|
free(lines[i]);
|
|
|
|
}
|
|
|
|
}
|
1997-06-11 08:41:10 +00:00
|
|
|
|
1999-01-27 02:32:47 +00:00
|
|
|
/* Load the environment from rc.conf file(s) */
|
|
|
|
void
|
|
|
|
configEnvironmentRC_conf(void)
|
|
|
|
{
|
1999-02-05 22:15:52 +00:00
|
|
|
static struct {
|
|
|
|
char *fname;
|
|
|
|
int marked;
|
|
|
|
} configs[] = {
|
1999-02-09 22:18:10 +00:00
|
|
|
{ "/etc/defaults/rc.conf", 0 },
|
1999-02-14 07:35:27 +00:00
|
|
|
{ "/etc/rc.conf", 0 },
|
1999-02-05 22:15:52 +00:00
|
|
|
{ "/etc/rc.conf.local", 0 },
|
|
|
|
{ NULL, 0 },
|
1999-01-27 02:32:47 +00:00
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
1999-02-05 22:15:52 +00:00
|
|
|
for (i = 0; configs[i].fname; i++) {
|
|
|
|
if (file_readable(configs[i].fname))
|
|
|
|
readConfigFile(configs[i].fname, configs[i].marked);
|
1999-01-27 02:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-31 11:28:28 +00:00
|
|
|
#endif
|
2003-07-12 15:33:09 +00:00
|
|
|
|