2016-01-26 17:05:29 +03:00
|
|
|
/* $NetBSD: disks.c,v 1.12 2016/01/26 14:05:29 martin Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 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.
|
2011-04-04 12:30:12 +04:00
|
|
|
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
|
1997-09-27 03:02:53 +04:00
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2003-05-19 00:04:21 +04:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
1997-09-27 03:02:53 +04:00
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
2003-05-19 00:04:21 +04:00
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
1997-09-27 03:02:53 +04:00
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* disks.c -- routines to deal with finding disks and labeling disks. */
|
|
|
|
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
#include <errno.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
1997-11-03 03:04:53 +03:00
|
|
|
#include <util.h>
|
2014-08-03 20:09:38 +04:00
|
|
|
#include <uuid.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2012-06-23 00:54:39 +04:00
|
|
|
#include <sys/sysctl.h>
|
2003-06-16 14:42:47 +04:00
|
|
|
#include <sys/swap.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
2012-01-06 02:18:36 +04:00
|
|
|
#define FSTYPENAMES
|
2003-01-10 23:00:27 +03:00
|
|
|
#include <sys/disklabel.h>
|
2014-08-03 20:09:38 +04:00
|
|
|
#include <sys/disklabel_gpt.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2009-08-23 22:43:33 +04:00
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <sys/scsiio.h>
|
|
|
|
|
|
|
|
#include <dev/ata/atareg.h>
|
|
|
|
#include <sys/ataio.h>
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "defs.h"
|
1997-10-29 04:06:42 +03:00
|
|
|
#include "md.h"
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
#include "txtwalk.h"
|
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
/* Disk descriptions */
|
|
|
|
struct disk_desc {
|
2004-05-16 01:53:29 +04:00
|
|
|
char dd_name[SSTRSIZE];
|
2009-08-23 22:43:33 +04:00
|
|
|
char dd_descr[70];
|
2004-05-16 01:53:29 +04:00
|
|
|
uint dd_no_mbr;
|
|
|
|
uint dd_cyl;
|
|
|
|
uint dd_head;
|
|
|
|
uint dd_sec;
|
|
|
|
uint dd_secsize;
|
|
|
|
uint dd_totsec;
|
2003-07-11 19:28:58 +04:00
|
|
|
};
|
1997-11-02 11:20:40 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
/* gpt(8) use different filesystem names.
|
|
|
|
So, we cant use ./common/lib/libutil/getfstypename.c */
|
|
|
|
struct gptfs_t {
|
|
|
|
const char *name;
|
|
|
|
int id;
|
|
|
|
uuid_t uuid;
|
|
|
|
};
|
|
|
|
static const struct gptfs_t gpt_filesystems[] = {
|
|
|
|
{ "swap", FS_SWAP, GPT_ENT_TYPE_NETBSD_SWAP, },
|
|
|
|
{ "ffs", FS_BSDFFS, GPT_ENT_TYPE_NETBSD_FFS, },
|
|
|
|
{ "lfs", FS_BSDLFS, GPT_ENT_TYPE_NETBSD_LFS, },
|
|
|
|
{ "linux", FS_EX2FS, GPT_ENT_TYPE_LINUX_DATA, },
|
|
|
|
{ "windows,", FS_MSDOS, GPT_ENT_TYPE_MS_BASIC_DATA, },
|
|
|
|
{ "hfs", FS_HFS, GPT_ENT_TYPE_APPLE_HFS, },
|
|
|
|
{ "ufs", FS_OTHER, GPT_ENT_TYPE_APPLE_UFS, },
|
|
|
|
{ "ccd", FS_CCD, GPT_ENT_TYPE_NETBSD_CCD, },
|
|
|
|
{ "raid", FS_RAID, GPT_ENT_TYPE_NETBSD_RAIDFRAME, },
|
|
|
|
{ "cgd", FS_CGD, GPT_ENT_TYPE_NETBSD_CGD, },
|
|
|
|
{ "efi", FS_OTHER, GPT_ENT_TYPE_EFI, },
|
|
|
|
{ "bios", FS_OTHER, GPT_ENT_TYPE_BIOS, },
|
|
|
|
{ NULL, -1, GPT_ENT_TYPE_UNUSED, },
|
|
|
|
};
|
|
|
|
|
1997-10-01 09:04:24 +04:00
|
|
|
/* Local prototypes */
|
2003-11-30 17:36:43 +03:00
|
|
|
static int foundffs(struct data *, size_t);
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
static int foundsysvbfs(struct data *, size_t);
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
static int fsck_preen(const char *, int, const char *);
|
2004-04-25 22:40:37 +04:00
|
|
|
static void fixsb(const char *, const char *, char);
|
2014-12-28 15:05:27 +03:00
|
|
|
static bool is_gpt(const char *);
|
2014-08-03 20:09:38 +04:00
|
|
|
static int incoregpt(pm_devs_t *, partinfo *);
|
1997-11-05 10:28:20 +03:00
|
|
|
|
2003-05-30 15:56:23 +04:00
|
|
|
#ifndef DISK_NAMES
|
2005-06-10 02:14:20 +04:00
|
|
|
#define DISK_NAMES "wd", "sd", "ld", "raid"
|
2003-05-30 15:56:23 +04:00
|
|
|
#endif
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
static const char *disk_names[] = { DISK_NAMES, "vnd", "cgd", NULL };
|
1997-11-02 11:20:40 +03:00
|
|
|
|
2013-12-08 00:40:42 +04:00
|
|
|
static bool tmpfs_on_var_shm(void);
|
|
|
|
|
2012-01-06 02:18:36 +04:00
|
|
|
const char *
|
|
|
|
getfslabelname(uint8_t f)
|
|
|
|
{
|
|
|
|
if (f >= __arraycount(fstypenames) || fstypenames[f] == NULL)
|
|
|
|
return "invalid";
|
|
|
|
return fstypenames[f];
|
|
|
|
}
|
|
|
|
|
2013-12-08 00:40:42 +04:00
|
|
|
/*
|
|
|
|
* Decide wether we want to mount a tmpfs on /var/shm: we do this always
|
|
|
|
* when the machine has more than 16 MB of user memory. On smaller machines,
|
|
|
|
* shm_open() and friends will not perform well anyway.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
tmpfs_on_var_shm()
|
|
|
|
{
|
|
|
|
uint64_t ram;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = sizeof(ram);
|
|
|
|
if (sysctlbyname("hw.usermem64", &ram, &len, NULL, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ram > 16UL*1024UL*1024UL;
|
|
|
|
}
|
|
|
|
|
2009-08-23 22:43:33 +04:00
|
|
|
/* from src/sbin/atactl/atactl.c
|
|
|
|
* extract_string: copy a block of bytes out of ataparams and make
|
|
|
|
* a proper string out of it, truncating trailing spaces and preserving
|
|
|
|
* strict typing. And also, not doing unaligned accesses.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ata_extract_string(char *buf, size_t bufmax,
|
|
|
|
uint8_t *bytes, unsigned numbytes,
|
|
|
|
int needswap)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
size_t j;
|
|
|
|
unsigned char ch1, ch2;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < numbytes; i += 2) {
|
|
|
|
ch1 = bytes[i];
|
|
|
|
ch2 = bytes[i+1];
|
|
|
|
if (needswap && j < bufmax-1) {
|
|
|
|
buf[j++] = ch2;
|
|
|
|
}
|
|
|
|
if (j < bufmax-1) {
|
|
|
|
buf[j++] = ch1;
|
|
|
|
}
|
|
|
|
if (!needswap && j < bufmax-1) {
|
|
|
|
buf[j++] = ch2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (j > 0 && buf[j-1] == ' ') {
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
buf[j] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* from src/sbin/scsictl/scsi_subr.c
|
|
|
|
*/
|
|
|
|
#define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377')
|
|
|
|
|
|
|
|
static void
|
|
|
|
scsi_strvis(char *sdst, size_t dlen, const char *ssrc, size_t slen)
|
|
|
|
{
|
|
|
|
u_char *dst = (u_char *)sdst;
|
|
|
|
const u_char *src = (const u_char *)ssrc;
|
|
|
|
|
|
|
|
/* Trim leading and trailing blanks and NULs. */
|
|
|
|
while (slen > 0 && STRVIS_ISWHITE(src[0]))
|
|
|
|
++src, --slen;
|
|
|
|
while (slen > 0 && STRVIS_ISWHITE(src[slen - 1]))
|
|
|
|
--slen;
|
|
|
|
|
|
|
|
while (slen > 0) {
|
|
|
|
if (*src < 0x20 || *src >= 0x80) {
|
|
|
|
/* non-printable characters */
|
|
|
|
dlen -= 4;
|
|
|
|
if (dlen < 1)
|
|
|
|
break;
|
|
|
|
*dst++ = '\\';
|
|
|
|
*dst++ = ((*src & 0300) >> 6) + '0';
|
|
|
|
*dst++ = ((*src & 0070) >> 3) + '0';
|
|
|
|
*dst++ = ((*src & 0007) >> 0) + '0';
|
|
|
|
} else if (*src == '\\') {
|
|
|
|
/* quote characters */
|
|
|
|
dlen -= 2;
|
|
|
|
if (dlen < 1)
|
|
|
|
break;
|
|
|
|
*dst++ = '\\';
|
|
|
|
*dst++ = '\\';
|
|
|
|
} else {
|
|
|
|
/* normal characters */
|
|
|
|
if (--dlen < 1)
|
|
|
|
break;
|
|
|
|
*dst++ = *src;
|
|
|
|
}
|
|
|
|
++src, --slen;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_descr_scsi(struct disk_desc *dd, int fd)
|
|
|
|
{
|
|
|
|
struct scsipi_inquiry_data inqbuf;
|
|
|
|
struct scsipi_inquiry cmd;
|
|
|
|
scsireq_t req;
|
|
|
|
/* x4 in case every character is escaped, +1 for NUL. */
|
|
|
|
char vendor[(sizeof(inqbuf.vendor) * 4) + 1],
|
|
|
|
product[(sizeof(inqbuf.product) * 4) + 1],
|
|
|
|
revision[(sizeof(inqbuf.revision) * 4) + 1];
|
|
|
|
char size[5];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
memset(&inqbuf, 0, sizeof(inqbuf));
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
cmd.opcode = INQUIRY;
|
|
|
|
cmd.length = sizeof(inqbuf);
|
|
|
|
memcpy(req.cmd, &cmd, sizeof(cmd));
|
|
|
|
req.cmdlen = sizeof(cmd);
|
|
|
|
req.databuf = &inqbuf;
|
|
|
|
req.datalen = sizeof(inqbuf);
|
|
|
|
req.timeout = 10000;
|
|
|
|
req.flags = SCCMD_READ;
|
|
|
|
req.senselen = SENSEBUFLEN;
|
|
|
|
|
|
|
|
error = ioctl(fd, SCIOCCOMMAND, &req);
|
|
|
|
if (error == -1 || req.retsts != SCCMD_OK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
scsi_strvis(vendor, sizeof(vendor), inqbuf.vendor,
|
|
|
|
sizeof(inqbuf.vendor));
|
|
|
|
scsi_strvis(product, sizeof(product), inqbuf.product,
|
|
|
|
sizeof(inqbuf.product));
|
|
|
|
scsi_strvis(revision, sizeof(revision), inqbuf.revision,
|
|
|
|
sizeof(inqbuf.revision));
|
|
|
|
|
|
|
|
humanize_number(size, sizeof(size),
|
|
|
|
(uint64_t)dd->dd_secsize * (uint64_t)dd->dd_totsec,
|
|
|
|
"", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
2011-04-04 12:30:12 +04:00
|
|
|
|
2009-08-23 22:43:33 +04:00
|
|
|
snprintf(dd->dd_descr, sizeof(dd->dd_descr),
|
|
|
|
"%s (%s, %s %s)",
|
|
|
|
dd->dd_name, size, vendor, product);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_descr_ata(struct disk_desc *dd, int fd)
|
|
|
|
{
|
|
|
|
struct atareq req;
|
|
|
|
static union {
|
|
|
|
unsigned char inbuf[DEV_BSIZE];
|
|
|
|
struct ataparams inqbuf;
|
|
|
|
} inbuf;
|
|
|
|
struct ataparams *inqbuf = &inbuf.inqbuf;
|
|
|
|
char model[sizeof(inqbuf->atap_model)+1];
|
|
|
|
char size[5];
|
|
|
|
int error, needswap = 0;
|
|
|
|
|
|
|
|
memset(&inbuf, 0, sizeof(inbuf));
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.flags = ATACMD_READ;
|
|
|
|
req.command = WDCC_IDENTIFY;
|
|
|
|
req.databuf = (void *)&inbuf;
|
|
|
|
req.datalen = sizeof(inbuf);
|
|
|
|
req.timeout = 1000;
|
|
|
|
|
|
|
|
error = ioctl(fd, ATAIOCCOMMAND, &req);
|
|
|
|
if (error == -1 || req.retsts != ATACMD_OK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
/*
|
|
|
|
* On little endian machines, we need to shuffle the string
|
|
|
|
* byte order. However, we don't have to do this for NEC or
|
|
|
|
* Mitsumi ATAPI devices
|
|
|
|
*/
|
|
|
|
|
2013-10-30 19:37:49 +04:00
|
|
|
if (!(inqbuf->atap_config != WDC_CFG_CFA_MAGIC &&
|
|
|
|
(inqbuf->atap_config & WDC_CFG_ATAPI) &&
|
2009-08-23 22:43:33 +04:00
|
|
|
((inqbuf->atap_model[0] == 'N' &&
|
2015-07-25 10:12:30 +03:00
|
|
|
inqbuf->atap_model[1] == 'E') ||
|
2009-08-23 22:43:33 +04:00
|
|
|
(inqbuf->atap_model[0] == 'F' &&
|
2015-07-25 10:12:30 +03:00
|
|
|
inqbuf->atap_model[1] == 'X')))) {
|
2009-08-23 22:43:33 +04:00
|
|
|
needswap = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ata_extract_string(model, sizeof(model),
|
|
|
|
inqbuf->atap_model, sizeof(inqbuf->atap_model), needswap);
|
|
|
|
humanize_number(size, sizeof(size),
|
|
|
|
(uint64_t)dd->dd_secsize * (uint64_t)dd->dd_totsec,
|
|
|
|
"", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
2011-04-04 12:30:12 +04:00
|
|
|
|
2009-08-23 22:43:33 +04:00
|
|
|
snprintf(dd->dd_descr, sizeof(dd->dd_descr), "%s (%s, %s)",
|
|
|
|
dd->dd_name, size, model);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_descr(struct disk_desc *dd)
|
|
|
|
{
|
|
|
|
char diskpath[MAXPATHLEN];
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
fd = opendisk(dd->dd_name, O_RDONLY, diskpath, sizeof(diskpath), 0);
|
|
|
|
if (fd < 0)
|
|
|
|
goto done;
|
|
|
|
|
2009-10-01 14:41:03 +04:00
|
|
|
dd->dd_descr[0] = '\0';
|
|
|
|
|
2009-08-23 22:43:33 +04:00
|
|
|
/* try ATA */
|
|
|
|
if (get_descr_ata(dd, fd))
|
|
|
|
goto done;
|
|
|
|
/* try SCSI */
|
|
|
|
if (get_descr_scsi(dd, fd))
|
|
|
|
goto done;
|
2014-08-03 20:09:38 +04:00
|
|
|
/* XXX: get description from raid, cgd, vnd... */
|
2009-08-23 22:43:33 +04:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
if (strlen(dd->dd_descr) == 0)
|
|
|
|
strcpy(dd->dd_descr, dd->dd_name);
|
|
|
|
}
|
|
|
|
|
2012-06-23 00:54:39 +04:00
|
|
|
/* disknames - contains device names without partition letters
|
|
|
|
* cdrom_devices - contains devices including partition letters
|
|
|
|
* returns the first entry in hw.disknames matching a cdrom_device, or
|
|
|
|
* first entry on error or no match
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
get_default_cdrom(void)
|
|
|
|
{
|
|
|
|
static const char *cdrom_devices[] = { CD_NAMES, 0};
|
|
|
|
static const char mib_name[] = "hw.disknames";
|
|
|
|
size_t len;
|
|
|
|
char *disknames;
|
|
|
|
char *last;
|
|
|
|
char *name;
|
|
|
|
const char **arg;
|
|
|
|
const char *cd_dev;
|
|
|
|
|
|
|
|
/* On error just use first entry in cdrom_devices */
|
2012-06-23 18:06:02 +04:00
|
|
|
if (sysctlbyname(mib_name, NULL, &len, NULL, 0) == -1)
|
2012-06-23 00:54:39 +04:00
|
|
|
return cdrom_devices[0];
|
2012-06-23 18:06:02 +04:00
|
|
|
if ((disknames = malloc(len + 2)) == 0) /* skip on malloc fail */
|
2012-06-23 00:54:39 +04:00
|
|
|
return cdrom_devices[0];
|
|
|
|
|
2012-06-23 18:06:02 +04:00
|
|
|
(void)sysctlbyname(mib_name, disknames, &len, NULL, 0);
|
2015-07-25 10:12:30 +03:00
|
|
|
for ((name = strtok_r(disknames, " ", &last)); name;
|
2012-06-23 00:54:39 +04:00
|
|
|
(name = strtok_r(NULL, " ", &last))) {
|
2012-06-23 18:06:02 +04:00
|
|
|
for (arg = cdrom_devices; *arg; ++arg) {
|
2012-06-23 00:54:39 +04:00
|
|
|
cd_dev = *arg;
|
2012-06-23 18:06:02 +04:00
|
|
|
/* skip unit and partition */
|
|
|
|
if (strncmp(cd_dev, name, strlen(cd_dev) - 2) != 0)
|
|
|
|
continue;
|
|
|
|
if (name != disknames)
|
|
|
|
strcpy(disknames, name);
|
|
|
|
strcat(disknames, "a");
|
|
|
|
/* XXX: leaks, but so what? */
|
|
|
|
return disknames;
|
2012-06-23 00:54:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(disknames);
|
|
|
|
return cdrom_devices[0];
|
|
|
|
}
|
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
static int
|
|
|
|
get_disks(struct disk_desc *dd)
|
1997-10-15 08:35:17 +04:00
|
|
|
{
|
2003-07-25 12:26:21 +04:00
|
|
|
const char **xd;
|
2004-05-16 01:53:29 +04:00
|
|
|
char *cp;
|
1997-10-15 08:35:17 +04:00
|
|
|
struct disklabel l;
|
|
|
|
int i;
|
2003-07-11 19:28:58 +04:00
|
|
|
int numdisks;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2003-05-19 00:04:21 +04:00
|
|
|
/* initialize */
|
|
|
|
numdisks = 0;
|
|
|
|
|
|
|
|
for (xd = disk_names; *xd != NULL; xd++) {
|
|
|
|
for (i = 0; i < MAX_DISKS; i++) {
|
2004-05-16 01:53:29 +04:00
|
|
|
strlcpy(dd->dd_name, *xd, sizeof dd->dd_name - 2);
|
|
|
|
cp = strchr(dd->dd_name, ':');
|
|
|
|
if (cp != NULL)
|
2006-01-13 01:02:44 +03:00
|
|
|
dd->dd_no_mbr = !strcmp(cp, ":no_mbr");
|
2004-05-18 18:07:06 +04:00
|
|
|
else {
|
|
|
|
dd->dd_no_mbr = 0;
|
2004-05-16 01:53:29 +04:00
|
|
|
cp = strchr(dd->dd_name, 0);
|
2004-05-18 18:07:06 +04:00
|
|
|
}
|
2004-05-16 01:53:29 +04:00
|
|
|
|
|
|
|
snprintf(cp, 2 + 1, "%d", i);
|
|
|
|
if (!get_geom(dd->dd_name, &l)) {
|
2003-05-30 15:56:23 +04:00
|
|
|
if (errno == ENOENT)
|
|
|
|
break;
|
2003-05-19 00:04:21 +04:00
|
|
|
continue;
|
2003-05-30 15:56:23 +04:00
|
|
|
}
|
2012-11-18 00:34:24 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exclude a disk mounted as root partition,
|
|
|
|
* in case of install-image on a USB memstick.
|
|
|
|
*/
|
|
|
|
if (is_active_rootpart(dd->dd_name, 0))
|
|
|
|
continue;
|
|
|
|
|
2003-05-19 00:04:21 +04:00
|
|
|
dd->dd_cyl = l.d_ncylinders;
|
|
|
|
dd->dd_head = l.d_ntracks;
|
|
|
|
dd->dd_sec = l.d_nsectors;
|
|
|
|
dd->dd_secsize = l.d_secsize;
|
|
|
|
dd->dd_totsec = l.d_secperunit;
|
2009-08-23 22:43:33 +04:00
|
|
|
get_descr(dd);
|
2003-05-19 00:04:21 +04:00
|
|
|
dd++;
|
|
|
|
numdisks++;
|
|
|
|
if (numdisks >= MAX_DISKS)
|
2003-07-11 19:28:58 +04:00
|
|
|
return numdisks;
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
2003-07-11 19:28:58 +04:00
|
|
|
return numdisks;
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
2003-05-19 00:04:21 +04:00
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
2003-06-28 02:20:14 +04:00
|
|
|
find_disks(const char *doingwhat)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
2003-07-11 19:28:58 +04:00
|
|
|
struct disk_desc disks[MAX_DISKS];
|
2014-08-03 20:09:38 +04:00
|
|
|
menu_ent dsk_menu[nelem(disks) + 1]; // + 1 for extended partitioning entry
|
2003-07-11 19:28:58 +04:00
|
|
|
struct disk_desc *disk;
|
2014-08-03 20:09:38 +04:00
|
|
|
int i, already_found;
|
|
|
|
int numdisks, selected_disk = -1;
|
2003-07-11 19:28:58 +04:00
|
|
|
int menu_no;
|
2014-08-03 20:09:38 +04:00
|
|
|
pm_devs_t *pm_i, *pm_last = NULL;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
/* Find disks. */
|
2003-07-11 19:28:58 +04:00
|
|
|
numdisks = get_disks(disks);
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/* need a redraw here, kernel messages hose everything */
|
|
|
|
touchwin(stdscr);
|
|
|
|
refresh();
|
2006-02-25 23:21:00 +03:00
|
|
|
/* Kill typeahead, it won't be what the user had in mind */
|
|
|
|
fpurge(stdin);
|
1999-01-21 11:02:17 +03:00
|
|
|
|
2015-07-25 10:12:30 +03:00
|
|
|
/*
|
|
|
|
* partman_go: <0 - we want to see menu with extended partitioning
|
|
|
|
* ==0 - we want to see simple select disk menu
|
|
|
|
* >0 - we do not want to see any menus, just detect
|
|
|
|
* all disks
|
|
|
|
*/
|
2014-08-03 20:09:38 +04:00
|
|
|
if (partman_go <= 0) {
|
|
|
|
if (numdisks == 0) {
|
|
|
|
/* No disks found! */
|
|
|
|
msg_display(MSG_nodisk);
|
|
|
|
process_menu(MENU_ok, NULL);
|
|
|
|
/*endwin();*/
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
/* One or more disks found! */
|
|
|
|
for (i = 0; i < numdisks; i++) {
|
|
|
|
dsk_menu[i].opt_name = disks[i].dd_descr;
|
|
|
|
dsk_menu[i].opt_menu = OPT_NOMENU;
|
|
|
|
dsk_menu[i].opt_flags = OPT_EXIT;
|
|
|
|
dsk_menu[i].opt_action = set_menu_select;
|
|
|
|
}
|
|
|
|
if (partman_go < 0) {
|
|
|
|
dsk_menu[i].opt_name = MSG_partman;
|
|
|
|
dsk_menu[i].opt_menu = OPT_NOMENU;
|
|
|
|
dsk_menu[i].opt_flags = OPT_EXIT;
|
|
|
|
dsk_menu[i].opt_action = set_menu_select;
|
|
|
|
}
|
|
|
|
menu_no = new_menu(MSG_Available_disks,
|
|
|
|
dsk_menu, numdisks + ((partman_go<0)?1:0), -1, 4, 0, 0, MC_SCROLL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
|
|
|
if (menu_no == -1)
|
|
|
|
return -1;
|
|
|
|
msg_display(MSG_ask_disk, doingwhat);
|
|
|
|
process_menu(menu_no, &selected_disk);
|
|
|
|
free_menu(menu_no);
|
|
|
|
}
|
|
|
|
if (partman_go < 0 && selected_disk == numdisks) {
|
|
|
|
partman_go = 1;
|
2015-07-25 10:12:30 +03:00
|
|
|
return -2;
|
2014-08-03 20:09:38 +04:00
|
|
|
} else
|
|
|
|
partman_go = 0;
|
|
|
|
if (selected_disk < 0 || selected_disk >= numdisks)
|
2015-07-25 10:12:30 +03:00
|
|
|
return -1;
|
2003-05-19 00:04:21 +04:00
|
|
|
}
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
/* Fill pm struct with device(s) info */
|
|
|
|
for (i = 0; i < numdisks; i++) {
|
|
|
|
if (! partman_go)
|
|
|
|
disk = disks + selected_disk;
|
|
|
|
else {
|
|
|
|
disk = disks + i;
|
|
|
|
already_found = 0;
|
|
|
|
SLIST_FOREACH(pm_i, &pm_head, l) {
|
|
|
|
pm_last = pm_i;
|
2015-07-25 10:12:30 +03:00
|
|
|
if (!already_found &&
|
|
|
|
strcmp(pm_i->diskdev, disk->dd_name) == 0) {
|
2014-08-03 20:09:38 +04:00
|
|
|
pm_i->found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pm_i != NULL && pm_i->found)
|
|
|
|
/* We already added this device, skipping */
|
|
|
|
continue;
|
2003-07-11 19:28:58 +04:00
|
|
|
}
|
2014-08-03 20:09:38 +04:00
|
|
|
pm = pm_new;
|
|
|
|
pm->found = 1;
|
|
|
|
pm->bootable = 0;
|
|
|
|
pm->pi.menu_no = -1;
|
|
|
|
pm->disktype = "unknown";
|
|
|
|
pm->doessf = "";
|
|
|
|
strlcpy(pm->diskdev, disk->dd_name, sizeof pm->diskdev);
|
|
|
|
strlcpy(pm->diskdev_descr, disk->dd_descr, sizeof pm->diskdev_descr);
|
|
|
|
/* Use as a default disk if the user has the sets on a local disk */
|
|
|
|
strlcpy(localfs_dev, disk->dd_name, sizeof localfs_dev);
|
|
|
|
|
|
|
|
pm->gpt = is_gpt(pm->diskdev);
|
|
|
|
pm->no_mbr = disk->dd_no_mbr || pm->gpt;
|
|
|
|
pm->sectorsize = disk->dd_secsize;
|
|
|
|
pm->dlcyl = disk->dd_cyl;
|
|
|
|
pm->dlhead = disk->dd_head;
|
|
|
|
pm->dlsec = disk->dd_sec;
|
|
|
|
pm->dlsize = disk->dd_totsec;
|
|
|
|
if (pm->dlsize == 0)
|
|
|
|
pm->dlsize = disk->dd_cyl * disk->dd_head * disk->dd_sec;
|
|
|
|
if (pm->dlsize > UINT32_MAX && ! partman_go) {
|
|
|
|
if (logfp)
|
|
|
|
fprintf(logfp, "Cannot process disk %s: too big size (%d)\n",
|
|
|
|
pm->diskdev, (int)pm->dlsize);
|
|
|
|
msg_display(MSG_toobigdisklabel);
|
|
|
|
process_menu(MENU_ok, NULL);
|
2003-07-11 19:28:58 +04:00
|
|
|
return -1;
|
2014-08-03 20:09:38 +04:00
|
|
|
}
|
|
|
|
pm->dlcylsize = pm->dlhead * pm->dlsec;
|
2003-05-19 00:04:21 +04:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
label_read();
|
|
|
|
if (partman_go) {
|
|
|
|
pm_getrefdev(pm_new);
|
|
|
|
if (SLIST_EMPTY(&pm_head) || pm_last == NULL)
|
|
|
|
SLIST_INSERT_HEAD(&pm_head, pm_new, l);
|
|
|
|
else
|
|
|
|
SLIST_INSERT_AFTER(pm_last, pm_new, l);
|
|
|
|
pm_new = malloc(sizeof (pm_devs_t));
|
|
|
|
memset(pm_new, 0, sizeof *pm_new);
|
|
|
|
} else
|
|
|
|
/* We is not in partman and do not want to process all devices, exit */
|
|
|
|
break;
|
2009-05-14 20:23:38 +04:00
|
|
|
}
|
1997-09-27 03:02:53 +04:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
return numdisks;
|
|
|
|
}
|
2003-07-07 16:30:19 +04:00
|
|
|
|
2014-12-28 15:05:27 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
void
|
|
|
|
label_read(void)
|
|
|
|
{
|
2015-05-09 15:06:31 +03:00
|
|
|
check_available_binaries();
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
/* Get existing/default label */
|
|
|
|
memset(&pm->oldlabel, 0, sizeof pm->oldlabel);
|
2015-05-09 15:06:31 +03:00
|
|
|
if (!have_gpt || !pm->gpt)
|
2014-08-03 20:09:38 +04:00
|
|
|
incorelabel(pm->diskdev, pm->oldlabel);
|
|
|
|
else
|
|
|
|
incoregpt(pm, pm->oldlabel);
|
2004-03-26 20:28:55 +03:00
|
|
|
/* Set 'target' label to current label in case we don't change it */
|
2014-08-03 20:09:38 +04:00
|
|
|
memcpy(&pm->bsdlabel, &pm->oldlabel, sizeof pm->bsdlabel);
|
|
|
|
#ifndef NO_DISKLABEL
|
|
|
|
if (! pm->gpt)
|
|
|
|
savenewlabel(pm->oldlabel, getmaxpartitions());
|
|
|
|
#endif
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2003-06-09 23:06:48 +04:00
|
|
|
void
|
2003-07-07 16:30:19 +04:00
|
|
|
fmt_fspart(menudesc *m, int ptn, void *arg)
|
2003-06-09 23:06:48 +04:00
|
|
|
{
|
2009-05-14 20:23:38 +04:00
|
|
|
unsigned int poffset, psize, pend;
|
2003-06-09 23:06:48 +04:00
|
|
|
const char *desc;
|
2013-10-30 12:39:01 +04:00
|
|
|
static const char *Yes;
|
2014-08-03 20:09:38 +04:00
|
|
|
partinfo *p = pm->bsdlabel + ptn;
|
2003-07-07 16:30:19 +04:00
|
|
|
|
2013-10-30 12:39:01 +04:00
|
|
|
if (Yes == NULL)
|
2003-07-07 16:30:19 +04:00
|
|
|
Yes = msg_string(MSG_Yes);
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
poffset = p->pi_offset / sizemult;
|
|
|
|
psize = p->pi_size / sizemult;
|
2003-06-09 23:06:48 +04:00
|
|
|
if (psize == 0)
|
|
|
|
pend = 0;
|
|
|
|
else
|
2003-11-30 17:36:43 +03:00
|
|
|
pend = (p->pi_offset + p->pi_size) / sizemult - 1;
|
|
|
|
|
|
|
|
if (p->pi_fstype == FS_BSDFFS)
|
|
|
|
if (p->pi_flags & PIF_FFSv2)
|
|
|
|
desc = "FFSv2";
|
|
|
|
else
|
|
|
|
desc = "FFSv1";
|
|
|
|
else
|
2012-01-06 02:18:36 +04:00
|
|
|
desc = getfslabelname(p->pi_fstype);
|
2003-06-09 23:06:48 +04:00
|
|
|
|
|
|
|
#ifdef PART_BOOT
|
|
|
|
if (ptn == PART_BOOT)
|
|
|
|
desc = msg_string(MSG_Boot_partition_cant_change);
|
|
|
|
#endif
|
|
|
|
if (ptn == getrawpartition())
|
|
|
|
desc = msg_string(MSG_Whole_disk_cant_change);
|
|
|
|
else {
|
2003-11-30 17:36:43 +03:00
|
|
|
if (ptn == PART_C)
|
2003-06-09 23:06:48 +04:00
|
|
|
desc = msg_string(MSG_NetBSD_partition_cant_change);
|
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
wprintw(m->mw, msg_string(MSG_fspart_row),
|
|
|
|
poffset, pend, psize, desc,
|
2003-11-30 17:36:43 +03:00
|
|
|
p->pi_flags & PIF_NEWFS ? Yes : "",
|
|
|
|
p->pi_flags & PIF_MOUNT ? Yes : "",
|
|
|
|
p->pi_mount);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-09 07:14:10 +03:00
|
|
|
/*
|
|
|
|
* Label a disk using an MD-specific string DISKLABEL_CMD for
|
2003-06-17 00:10:02 +04:00
|
|
|
* to invoke disklabel.
|
1997-11-09 07:14:10 +03:00
|
|
|
* if MD code does not define DISKLABEL_CMD, this is a no-op.
|
|
|
|
*
|
2003-06-17 00:10:02 +04:00
|
|
|
* i386 port uses "/sbin/disklabel -w -r", just like i386
|
1997-11-09 07:14:10 +03:00
|
|
|
* miniroot scripts, though this may leave a bogus incore label.
|
|
|
|
*
|
2003-06-17 00:10:02 +04:00
|
|
|
* Sun ports should use DISKLABEL_CMD "/sbin/disklabel -w"
|
|
|
|
* to get incore to ondisk inode translation for the Sun proms.
|
1997-11-09 07:14:10 +03:00
|
|
|
*/
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
write_disklabel (void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
2015-05-09 15:06:31 +03:00
|
|
|
int rv = 0;
|
1997-11-09 07:14:10 +03:00
|
|
|
|
|
|
|
#ifdef DISKLABEL_CMD
|
1997-09-27 03:02:53 +04:00
|
|
|
/* disklabel the disk */
|
2015-05-09 15:06:31 +03:00
|
|
|
rv = run_program(RUN_DISPLAY, "%s -f /tmp/disktab %s '%s'",
|
2014-08-03 20:09:38 +04:00
|
|
|
DISKLABEL_CMD, pm->diskdev, pm->bsddiskname);
|
2015-05-09 15:06:31 +03:00
|
|
|
if (rv == 0)
|
|
|
|
update_wedges(pm->diskdev);
|
2003-01-10 23:00:27 +03:00
|
|
|
#endif
|
2015-05-09 15:06:31 +03:00
|
|
|
return rv;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
ptn_sort(const void *a, const void *b)
|
|
|
|
{
|
2014-08-03 20:09:38 +04:00
|
|
|
return strcmp(pm->bsdlabel[*(const int *)a].pi_mount,
|
|
|
|
pm->bsdlabel[*(const int *)b].pi_mount);
|
2003-07-07 16:30:19 +04:00
|
|
|
}
|
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
make_filesystems(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
2010-01-02 21:06:57 +03:00
|
|
|
unsigned int i;
|
2003-07-07 16:30:19 +04:00
|
|
|
int ptn;
|
2014-08-03 20:09:38 +04:00
|
|
|
int ptn_order[nelem(pm->bsdlabel)];
|
2003-11-30 17:36:43 +03:00
|
|
|
int error = 0;
|
2010-01-02 21:06:57 +03:00
|
|
|
unsigned int maxpart = getmaxpartitions();
|
2014-08-03 20:09:38 +04:00
|
|
|
char *newfs = NULL, *dev = NULL, *devdev = NULL;
|
2003-11-30 17:36:43 +03:00
|
|
|
partinfo *lbl;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (maxpart > nelem(pm->bsdlabel))
|
|
|
|
maxpart = nelem(pm->bsdlabel);
|
2003-07-07 16:30:19 +04:00
|
|
|
|
|
|
|
/* Making new file systems and mounting them */
|
|
|
|
|
|
|
|
/* sort to ensure /usr/local is mounted after /usr (etc) */
|
|
|
|
for (i = 0; i < maxpart; i++)
|
|
|
|
ptn_order[i] = i;
|
|
|
|
qsort(ptn_order, maxpart, sizeof ptn_order[0], ptn_sort);
|
|
|
|
|
|
|
|
for (i = 0; i < maxpart; i++) {
|
1997-11-03 03:04:53 +03:00
|
|
|
/*
|
2003-05-19 00:04:21 +04:00
|
|
|
* newfs and mount. For now, process only BSD filesystems.
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
* but if this is the mounted-on root, has no mount
|
2003-05-19 00:04:21 +04:00
|
|
|
* point defined, or is marked preserve, don't touch it!
|
1997-11-03 03:04:53 +03:00
|
|
|
*/
|
2003-07-07 16:30:19 +04:00
|
|
|
ptn = ptn_order[i];
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl = pm->bsdlabel + ptn;
|
2003-11-30 17:36:43 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (is_active_rootpart(pm->diskdev, ptn))
|
2003-07-07 16:30:19 +04:00
|
|
|
continue;
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
if (*lbl->pi_mount == 0)
|
|
|
|
/* No mount point */
|
|
|
|
continue;
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (pm->isspecial) {
|
|
|
|
asprintf(&dev, "%s", pm->diskdev);
|
|
|
|
ptn = 0 - 'a';
|
|
|
|
} else {
|
|
|
|
asprintf(&dev, "%s%c", pm->diskdev, 'a' + ptn);
|
|
|
|
}
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
asprintf(&devdev, "/dev/%s", dev);
|
|
|
|
if (devdev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
newfs = NULL;
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = NULL;
|
|
|
|
lbl->fsname = NULL;
|
2003-11-30 17:36:43 +03:00
|
|
|
switch (lbl->pi_fstype) {
|
|
|
|
case FS_APPLEUFS:
|
|
|
|
asprintf(&newfs, "/sbin/newfs %s%.0d",
|
|
|
|
lbl->pi_isize != 0 ? "-i" : "", lbl->pi_isize);
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tffs -o async";
|
|
|
|
lbl->fsname = "ffs";
|
2003-11-30 17:36:43 +03:00
|
|
|
break;
|
2003-06-09 23:06:48 +04:00
|
|
|
case FS_BSDFFS:
|
2006-01-15 23:33:05 +03:00
|
|
|
asprintf(&newfs,
|
|
|
|
"/sbin/newfs -V2 -O %d -b %d -f %d%s%.0d",
|
|
|
|
lbl->pi_flags & PIF_FFSv2 ? 2 : 1,
|
|
|
|
lbl->pi_fsize * lbl->pi_frag, lbl->pi_fsize,
|
|
|
|
lbl->pi_isize != 0 ? " -i " : "", lbl->pi_isize);
|
2008-08-08 06:54:06 +04:00
|
|
|
if (lbl->pi_flags & PIF_LOG)
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tffs -o log";
|
2008-08-08 06:54:06 +04:00
|
|
|
else
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tffs -o async";
|
|
|
|
lbl->fsname = "ffs";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
|
|
|
case FS_BSDLFS:
|
2003-11-30 17:36:43 +03:00
|
|
|
asprintf(&newfs, "/sbin/newfs_lfs -b %d",
|
|
|
|
lbl->pi_fsize * lbl->pi_frag);
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tlfs";
|
|
|
|
lbl->fsname = "lfs";
|
2003-11-30 17:36:43 +03:00
|
|
|
break;
|
|
|
|
case FS_MSDOS:
|
2008-02-02 07:15:27 +03:00
|
|
|
#ifdef USE_NEWFS_MSDOS
|
|
|
|
asprintf(&newfs, "/sbin/newfs_msdos");
|
|
|
|
#endif
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tmsdos";
|
|
|
|
lbl->fsname = "msdos";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
case FS_SYSVBFS:
|
|
|
|
asprintf(&newfs, "/sbin/newfs_sysvbfs");
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-tsysvbfs";
|
|
|
|
lbl->fsname = "sysvbfs";
|
2006-01-09 13:00:34 +03:00
|
|
|
break;
|
2008-02-02 12:26:45 +03:00
|
|
|
#endif
|
|
|
|
#ifdef USE_EXT2FS
|
|
|
|
case FS_EX2FS:
|
|
|
|
asprintf(&newfs, "/sbin/newfs_ext2fs");
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->mnt_opts = "-text2fs";
|
|
|
|
lbl->fsname = "ext2fs";
|
2008-02-02 12:26:45 +03:00
|
|
|
break;
|
2006-01-09 13:00:34 +03:00
|
|
|
#endif
|
2003-06-09 23:06:48 +04:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
if (lbl->pi_flags & PIF_NEWFS && newfs != NULL) {
|
2008-02-02 07:15:27 +03:00
|
|
|
#ifdef USE_NEWFS_MSDOS
|
|
|
|
if (lbl->pi_fstype == FS_MSDOS) {
|
|
|
|
/* newfs only if mount fails */
|
|
|
|
if (run_program(RUN_SILENT | RUN_ERROR_OK,
|
2014-08-03 20:09:38 +04:00
|
|
|
"mount -rt msdos /dev/%s /mnt2", dev) != 0)
|
2008-02-02 07:15:27 +03:00
|
|
|
error = run_program(
|
|
|
|
RUN_DISPLAY | RUN_PROGRESS,
|
2014-08-03 20:09:38 +04:00
|
|
|
"%s /dev/r%s",
|
|
|
|
newfs, dev);
|
2008-02-02 07:15:27 +03:00
|
|
|
else {
|
2015-07-25 10:12:30 +03:00
|
|
|
run_program(RUN_SILENT | RUN_ERROR_OK,
|
2008-02-02 07:15:27 +03:00
|
|
|
"umount /mnt2");
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
error = run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2014-08-03 20:09:38 +04:00
|
|
|
"%s /dev/r%s", newfs, dev);
|
2003-11-30 17:36:43 +03:00
|
|
|
} else {
|
|
|
|
/* We'd better check it isn't dirty */
|
2014-08-03 20:09:38 +04:00
|
|
|
error = fsck_preen(pm->diskdev, ptn, lbl->fsname);
|
2003-11-30 17:36:43 +03:00
|
|
|
}
|
|
|
|
free(newfs);
|
2016-01-26 17:05:29 +03:00
|
|
|
if (error != 0) {
|
|
|
|
free(devdev);
|
|
|
|
free(dev);
|
2003-11-30 17:36:43 +03:00
|
|
|
return error;
|
2016-01-26 17:05:29 +03:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
lbl->pi_flags ^= PIF_NEWFS;
|
2011-11-04 15:27:00 +04:00
|
|
|
md_pre_mount();
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (partman_go == 0 && lbl->pi_flags & PIF_MOUNT &&
|
|
|
|
lbl->mnt_opts != NULL) {
|
2003-11-30 17:36:43 +03:00
|
|
|
make_target_dir(lbl->pi_mount);
|
2014-08-03 20:09:38 +04:00
|
|
|
error = target_mount_do(lbl->mnt_opts, devdev, lbl->pi_mount);
|
2003-11-30 17:36:43 +03:00
|
|
|
if (error) {
|
2014-08-03 20:09:38 +04:00
|
|
|
msg_display(MSG_mountfail, dev, ' ', lbl->pi_mount);
|
2003-11-30 17:36:43 +03:00
|
|
|
process_menu(MENU_ok, NULL);
|
2016-01-26 17:05:29 +03:00
|
|
|
free(devdev);
|
|
|
|
free(dev);
|
2003-11-30 17:36:43 +03:00
|
|
|
return error;
|
|
|
|
}
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
}
|
2014-08-03 20:09:38 +04:00
|
|
|
free(devdev);
|
|
|
|
free(dev);
|
1997-11-03 03:04:53 +03:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
make_fstab(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
FILE *f;
|
2003-01-10 23:00:27 +03:00
|
|
|
int i, swap_dev = -1;
|
2009-10-03 16:00:00 +04:00
|
|
|
const char *dump_dev;
|
2014-08-03 20:09:38 +04:00
|
|
|
char *dev = NULL;
|
|
|
|
pm_devs_t *pm_i;
|
|
|
|
#ifndef HAVE_TMPFS
|
2014-08-04 08:20:01 +04:00
|
|
|
pm_devs_t *pm_with_swap = NULL;
|
2014-08-03 20:09:38 +04:00
|
|
|
#endif
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Create the fstab. */
|
1997-11-02 11:20:40 +03:00
|
|
|
make_target_dir("/etc");
|
1999-03-31 04:44:48 +04:00
|
|
|
f = target_fopen("/etc/fstab", "w");
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >%s/etc/fstab\n", target_prefix());
|
1999-01-21 11:02:17 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (logfp)
|
|
|
|
(void)fprintf(logfp,
|
|
|
|
"Making %s/etc/fstab (%s).\n", target_prefix(), pm->diskdev);
|
2015-07-25 10:12:30 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (f == NULL) {
|
1999-04-09 14:24:38 +04:00
|
|
|
msg_display(MSG_createfstab);
|
2012-01-06 01:29:24 +04:00
|
|
|
if (logfp)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp, "Failed to make /etc/fstab!\n");
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
2014-08-03 20:09:38 +04:00
|
|
|
#ifndef DEBUG
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
#else
|
|
|
|
f = stdout;
|
2003-05-19 00:04:21 +04:00
|
|
|
#endif
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
|
2012-01-06 01:22:49 +04:00
|
|
|
scripting_fprintf(f, "# NetBSD %s/etc/fstab\n# See /usr/share/examples/"
|
2014-08-03 20:09:38 +04:00
|
|
|
"fstab/ for more examples.\n", target_prefix());
|
|
|
|
if (! partman_go) {
|
|
|
|
/* We want to process only one disk... */
|
|
|
|
pm_i = pm;
|
|
|
|
goto onlyonediskinfstab;
|
|
|
|
}
|
|
|
|
SLIST_FOREACH(pm_i, &pm_head, l) {
|
|
|
|
onlyonediskinfstab:
|
|
|
|
for (i = 0; i < getmaxpartitions(); i++) {
|
|
|
|
const char *s = "";
|
|
|
|
const char *mp = pm_i->bsdlabel[i].pi_mount;
|
|
|
|
const char *fstype = "ffs";
|
|
|
|
int fsck_pass = 0, dump_freq = 0;
|
2015-07-25 10:12:30 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (dev != NULL)
|
|
|
|
free(dev);
|
|
|
|
if (pm_i->isspecial)
|
|
|
|
asprintf(&dev, "%s", pm_i->diskdev);
|
|
|
|
else
|
|
|
|
asprintf(&dev, "%s%c", pm_i->diskdev, 'a' + i);
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
if (!*mp) {
|
|
|
|
/*
|
|
|
|
* No mount point specified, comment out line and
|
|
|
|
* use /mnt as a placeholder for the mount point.
|
|
|
|
*/
|
2003-06-09 23:06:48 +04:00
|
|
|
s = "# ";
|
2014-08-03 20:09:38 +04:00
|
|
|
mp = "/mnt";
|
2009-10-03 16:00:00 +04:00
|
|
|
}
|
2014-08-03 20:09:38 +04:00
|
|
|
|
|
|
|
switch (pm_i->bsdlabel[i].pi_fstype) {
|
|
|
|
case FS_UNUSED:
|
|
|
|
continue;
|
|
|
|
case FS_BSDLFS:
|
|
|
|
/* If there is no LFS, just comment it out. */
|
|
|
|
if (!check_lfs_progs())
|
|
|
|
s = "# ";
|
|
|
|
fstype = "lfs";
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case FS_BSDFFS:
|
|
|
|
fsck_pass = (strcmp(mp, "/") == 0) ? 1 : 2;
|
|
|
|
dump_freq = 1;
|
|
|
|
break;
|
|
|
|
case FS_MSDOS:
|
|
|
|
fstype = "msdos";
|
|
|
|
break;
|
|
|
|
case FS_SWAP:
|
|
|
|
if (pm_i->isspecial)
|
|
|
|
continue;
|
|
|
|
if (swap_dev == -1) {
|
|
|
|
swap_dev = i;
|
|
|
|
dump_dev = ",dp";
|
|
|
|
#ifndef HAVE_TMPFS
|
|
|
|
pm_with_swap = pm_i;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
dump_dev = "";
|
|
|
|
}
|
|
|
|
scripting_fprintf(f, "/dev/%s\t\tnone\tswap\tsw%s\t\t 0 0\n",
|
|
|
|
dev, dump_dev);
|
|
|
|
continue;
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
2014-08-03 20:09:38 +04:00
|
|
|
case FS_SYSVBFS:
|
|
|
|
fstype = "sysvbfs";
|
|
|
|
make_target_dir("/stand");
|
|
|
|
break;
|
2006-01-09 13:00:34 +03:00
|
|
|
#endif
|
2014-08-03 20:09:38 +04:00
|
|
|
default:
|
|
|
|
fstype = "???";
|
|
|
|
s = "# ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* The code that remounts root rw doesn't check the partition */
|
|
|
|
if (strcmp(mp, "/") == 0 && !(pm_i->bsdlabel[i].pi_flags & PIF_MOUNT))
|
|
|
|
s = "# ";
|
|
|
|
|
|
|
|
scripting_fprintf(f,
|
|
|
|
"%s/dev/%s\t\t%s\t%s\trw%s%s%s%s%s%s%s%s\t\t %d %d\n",
|
|
|
|
s, dev, mp, fstype,
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_LOG ? ",log" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_MOUNT ? "" : ",noauto",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_ASYNC ? ",async" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_NOATIME ? ",noatime" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_NODEV ? ",nodev" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_NODEVMTIME ? ",nodevmtime" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_NOEXEC ? ",noexec" : "",
|
|
|
|
pm_i->bsdlabel[i].pi_flags & PIF_NOSUID ? ",nosuid" : "",
|
|
|
|
dump_freq, fsck_pass);
|
|
|
|
if (pm_i->isspecial)
|
|
|
|
/* Special device (such as dk*) have only one partition */
|
|
|
|
break;
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
2014-08-03 20:09:38 +04:00
|
|
|
/* Simple install, only one disk */
|
|
|
|
if (!partman_go)
|
|
|
|
break;
|
2003-06-09 23:06:48 +04:00
|
|
|
}
|
2009-10-18 16:09:48 +04:00
|
|
|
if (tmp_ramdisk_size != 0) {
|
|
|
|
#ifdef HAVE_TMPFS
|
2011-08-21 19:06:41 +04:00
|
|
|
scripting_fprintf(f, "tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,-s=%"
|
|
|
|
PRIi64 "\n",
|
2009-10-18 16:09:48 +04:00
|
|
|
tmp_ramdisk_size * 512);
|
|
|
|
#else
|
2014-08-03 20:09:38 +04:00
|
|
|
if (swap_dev != -1 && pm_with_swap != NULL)
|
2011-08-21 19:06:41 +04:00
|
|
|
scripting_fprintf(f, "/dev/%s%c\t\t/tmp\tmfs\trw,-s=%"
|
|
|
|
PRIi64 "\n",
|
2014-08-03 20:09:38 +04:00
|
|
|
pm_with_swap->diskdev, 'a' + swap_dev, tmp_ramdisk_size);
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
else
|
2011-08-21 19:06:41 +04:00
|
|
|
scripting_fprintf(f, "swap\t\t/tmp\tmfs\trw,-s=%"
|
|
|
|
PRIi64 "\n",
|
|
|
|
tmp_ramdisk_size);
|
2009-10-18 16:09:48 +04:00
|
|
|
#endif
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2007-06-18 20:58:42 +04:00
|
|
|
/* Add /kern, /proc and /dev/pts to fstab and make mountpoint. */
|
2009-02-24 02:12:24 +03:00
|
|
|
scripting_fprintf(f, "kernfs\t\t/kern\tkernfs\trw\n");
|
2007-06-18 20:58:42 +04:00
|
|
|
scripting_fprintf(f, "ptyfs\t\t/dev/pts\tptyfs\trw\n");
|
2009-02-24 01:51:47 +03:00
|
|
|
scripting_fprintf(f, "procfs\t\t/proc\tprocfs\trw\n");
|
2012-06-23 00:54:39 +04:00
|
|
|
scripting_fprintf(f, "/dev/%s\t\t/cdrom\tcd9660\tro,noauto\n",
|
2012-06-23 18:06:02 +04:00
|
|
|
get_default_cdrom());
|
2013-12-08 00:40:42 +04:00
|
|
|
scripting_fprintf(f, "%stmpfs\t\t/var/shm\ttmpfs\trw,-m1777,-sram%%25\n",
|
|
|
|
tmpfs_on_var_shm() ? "" : "#");
|
2003-06-09 23:06:48 +04:00
|
|
|
make_target_dir("/kern");
|
2003-08-05 17:35:26 +04:00
|
|
|
make_target_dir("/proc");
|
2007-06-18 20:58:42 +04:00
|
|
|
make_target_dir("/dev/pts");
|
2008-01-15 15:09:24 +03:00
|
|
|
make_target_dir("/cdrom");
|
2013-12-08 00:40:42 +04:00
|
|
|
make_target_dir("/var/shm");
|
2003-06-09 23:06:48 +04:00
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
if (dev != NULL)
|
|
|
|
free(dev);
|
1997-09-27 03:02:53 +04:00
|
|
|
fclose(f);
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
|
1997-11-13 06:06:44 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
static int
|
2003-01-10 23:00:27 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
foundffs(struct data *list, size_t num)
|
1997-10-01 09:04:24 +04:00
|
|
|
{
|
2003-11-30 17:36:43 +03:00
|
|
|
int error;
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
if (num < 2 || strcmp(list[1].u.s_val, "/") == 0 ||
|
|
|
|
strstr(list[2].u.s_val, "noauto") != NULL)
|
|
|
|
return 0;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
error = fsck_preen(list[0].u.s_val, ' '-'a', "ffs");
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
error = target_mount("", list[0].u.s_val, ' '-'a', list[1].u.s_val);
|
2012-05-22 02:38:25 +04:00
|
|
|
if (error != 0) {
|
|
|
|
msg_display(MSG_mount_failed, list[0].u.s_val);
|
2015-05-10 13:14:02 +03:00
|
|
|
if (!ask_noyes(NULL))
|
2012-05-22 02:38:25 +04:00
|
|
|
return error;
|
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
return 0;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
static int
|
|
|
|
/*ARGSUSED*/
|
|
|
|
foundsysvbfs(struct data *list, size_t num)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (num < 2 || strcmp(list[1].u.s_val, "/") == 0 ||
|
|
|
|
strstr(list[2].u.s_val, "noauto") != NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error = target_mount("", list[0].u.s_val, ' '-'a', list[1].u.s_val);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
2004-04-25 21:15:27 +04:00
|
|
|
* Do an fsck. On failure, inform the user by showing a warning
|
1997-11-05 10:28:20 +03:00
|
|
|
* message and doing menu_ok() before proceeding.
|
2003-11-30 17:36:43 +03:00
|
|
|
* Returns 0 on success, or nonzero return code from fsck() on failure.
|
1997-11-05 10:28:20 +03:00
|
|
|
*/
|
2003-11-30 17:36:43 +03:00
|
|
|
static int
|
|
|
|
fsck_preen(const char *disk, int ptn, const char *fsname)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
2003-11-30 17:36:43 +03:00
|
|
|
char *prog;
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
int error;
|
2011-04-04 12:30:12 +04:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
ptn = (ptn < 0)? 0 : 'a' + ptn;
|
2003-11-30 17:36:43 +03:00
|
|
|
if (fsname == NULL)
|
|
|
|
return 0;
|
2011-08-16 22:28:41 +04:00
|
|
|
/* first, check if fsck program exists, if not, assume ok */
|
2003-11-30 17:36:43 +03:00
|
|
|
asprintf(&prog, "/sbin/fsck_%s", fsname);
|
|
|
|
if (prog == NULL)
|
|
|
|
return 0;
|
2016-01-26 17:05:29 +03:00
|
|
|
if (access(prog, X_OK) != 0) {
|
|
|
|
free(prog);
|
2003-11-30 17:36:43 +03:00
|
|
|
return 0;
|
2016-01-26 17:05:29 +03:00
|
|
|
}
|
2004-04-25 00:42:39 +04:00
|
|
|
if (!strcmp(fsname,"ffs"))
|
2004-04-25 22:40:37 +04:00
|
|
|
fixsb(prog, disk, ptn);
|
2003-11-30 17:36:43 +03:00
|
|
|
error = run_program(0, "%s -p -q /dev/r%s%c", prog, disk, ptn);
|
|
|
|
free(prog);
|
|
|
|
if (error != 0) {
|
|
|
|
msg_display(MSG_badfs, disk, ptn, error);
|
2015-05-10 13:14:02 +03:00
|
|
|
if (ask_noyes(NULL))
|
2012-05-22 02:38:25 +04:00
|
|
|
error = 0;
|
2004-04-25 21:15:27 +04:00
|
|
|
/* XXX at this point maybe we should run a full fsck? */
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2004-04-25 22:40:37 +04:00
|
|
|
/* This performs the same function as the etc/rc.d/fixsb script
|
|
|
|
* which attempts to correct problems with ffs1 filesystems
|
|
|
|
* which may have been introduced by booting a netbsd-current kernel
|
|
|
|
* from between April of 2003 and January 2004. For more information
|
|
|
|
* This script was developed as a response to NetBSD pr install/25138
|
|
|
|
* Additional prs regarding the original issue include:
|
|
|
|
* bin/17910 kern/21283 kern/21404 port-macppc/23925 port-macppc/23926
|
2004-04-25 21:15:27 +04:00
|
|
|
*/
|
2004-04-25 00:42:39 +04:00
|
|
|
static void
|
2004-04-25 22:40:37 +04:00
|
|
|
fixsb(const char *prog, const char *disk, char ptn)
|
2004-04-25 00:42:39 +04:00
|
|
|
{
|
|
|
|
int fd;
|
2004-04-25 00:48:57 +04:00
|
|
|
int rval;
|
2004-04-25 22:40:37 +04:00
|
|
|
union {
|
|
|
|
struct fs fs;
|
|
|
|
char buf[SBLOCKSIZE];
|
|
|
|
} sblk;
|
|
|
|
struct fs *fs = &sblk.fs;
|
|
|
|
|
2004-04-29 00:59:32 +04:00
|
|
|
snprintf(sblk.buf, sizeof(sblk.buf), "/dev/r%s%c",
|
|
|
|
disk, ptn == ' ' ? 0 : ptn);
|
2004-04-25 22:40:37 +04:00
|
|
|
fd = open(sblk.buf, O_RDONLY);
|
2004-04-25 00:42:39 +04:00
|
|
|
if (fd == -1)
|
|
|
|
return;
|
2004-04-25 21:15:27 +04:00
|
|
|
|
|
|
|
/* Read ffsv1 main superblock */
|
2004-04-25 22:40:37 +04:00
|
|
|
rval = pread(fd, sblk.buf, sizeof sblk.buf, SBLOCK_UFS1);
|
2004-04-25 00:42:39 +04:00
|
|
|
close(fd);
|
2004-04-25 22:40:37 +04:00
|
|
|
if (rval != sizeof sblk.buf)
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (fs->fs_magic != FS_UFS1_MAGIC &&
|
|
|
|
fs->fs_magic != FS_UFS1_MAGIC_SWAPPED)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* Not FFSv1 */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
if (fs->fs_old_flags & FS_FLAGS_UPDATED)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* properly updated fslevel 4 */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
if (fs->fs_bsize != fs->fs_maxbsize)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* not messed up */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
|
2004-04-25 21:15:27 +04:00
|
|
|
/*
|
|
|
|
* OK we have a munged fs, first 'upgrade' to fslevel 4,
|
|
|
|
* We specify -b16 in order to stop fsck bleating that the
|
|
|
|
* sb doesn't match the first alternate.
|
|
|
|
*/
|
2004-04-25 22:40:37 +04:00
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2004-04-25 22:50:44 +04:00
|
|
|
"%s -p -b 16 -c 4 /dev/r%s%c", prog, disk, ptn);
|
2004-04-25 21:15:27 +04:00
|
|
|
/* Then downgrade to fslevel 3 */
|
2004-04-25 22:40:37 +04:00
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"%s -p -c 3 /dev/r%s%c", prog, disk, ptn);
|
2004-04-25 00:42:39 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* fsck and mount the root partition.
|
|
|
|
*/
|
2006-01-13 01:02:44 +03:00
|
|
|
static int
|
2003-11-30 17:36:43 +03:00
|
|
|
mount_root(void)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
2003-06-17 00:10:02 +04:00
|
|
|
int error;
|
2014-08-03 20:09:38 +04:00
|
|
|
int ptn = (pm->isspecial)? 0 - 'a' : pm->rootpart;
|
1997-11-05 10:28:20 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
error = fsck_preen(pm->diskdev, ptn, "ffs");
|
1997-11-05 10:28:20 +03:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
2011-11-04 15:27:00 +04:00
|
|
|
md_pre_mount();
|
|
|
|
|
2003-06-17 00:10:02 +04:00
|
|
|
/* Mount /dev/<diskdev>a on target's "".
|
2003-05-19 00:04:21 +04:00
|
|
|
* If we pass "" as mount-on, Prefixing will DTRT.
|
1997-11-05 10:28:20 +03:00
|
|
|
* for now, use no options.
|
|
|
|
* XXX consider -o remount in case target root is
|
2003-06-17 00:10:02 +04:00
|
|
|
* current root, still readonly from single-user?
|
1997-11-05 10:28:20 +03:00
|
|
|
*/
|
2014-08-03 20:09:38 +04:00
|
|
|
return target_mount("", pm->diskdev, ptn, "");
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
/* Get information on the file systems mounted from the root filesystem.
|
|
|
|
* Offer to convert them into 4.4BSD inodes if they are not 4.4BSD
|
|
|
|
* inodes. Fsck them. Mount them.
|
|
|
|
*/
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
int
|
2003-11-30 17:36:43 +03:00
|
|
|
mount_disks(void)
|
2003-06-16 23:42:13 +04:00
|
|
|
{
|
|
|
|
char *fstab;
|
1997-11-03 05:38:41 +03:00
|
|
|
int fstabsize;
|
1997-11-05 10:28:20 +03:00
|
|
|
int error;
|
1997-11-03 05:38:41 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
static struct lookfor fstabbuf[] = {
|
|
|
|
{"/dev/", "/dev/%s %s ffs %s", "c", NULL, 0, 0, foundffs},
|
|
|
|
{"/dev/", "/dev/%s %s ufs %s", "c", NULL, 0, 0, foundffs},
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
{"/dev/", "/dev/%s %s sysvbfs %s", "c", NULL, 0, 0,
|
|
|
|
foundsysvbfs},
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
};
|
|
|
|
static size_t numfstabbuf = sizeof(fstabbuf) / sizeof(struct lookfor);
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* First the root device. */
|
2006-01-13 01:02:44 +03:00
|
|
|
if (target_already_root())
|
|
|
|
/* avoid needing to call target_already_root() again */
|
|
|
|
targetroot_mnt[0] = 0;
|
|
|
|
else {
|
2003-11-30 17:36:43 +03:00
|
|
|
error = mount_root();
|
2003-05-19 00:04:21 +04:00
|
|
|
if (error != 0 && error != EBUSY)
|
2012-05-22 02:38:25 +04:00
|
|
|
return -1;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* Check the target /etc/fstab exists before trying to parse it. */
|
2003-05-19 00:04:21 +04:00
|
|
|
if (target_dir_exists_p("/etc") == 0 ||
|
1997-12-05 17:00:59 +03:00
|
|
|
target_file_exists_p("/etc/fstab") == 0) {
|
2014-08-03 20:09:38 +04:00
|
|
|
msg_display(MSG_noetcfstab, pm->diskdev);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
2012-05-22 02:38:25 +04:00
|
|
|
return -1;
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* Get fstab entries from the target-root /etc/fstab. */
|
1999-03-31 04:44:48 +04:00
|
|
|
fstabsize = target_collect_file(T_FILE, &fstab, "/etc/fstab");
|
1997-10-01 09:04:24 +04:00
|
|
|
if (fstabsize < 0) {
|
|
|
|
/* error ! */
|
2014-08-03 20:09:38 +04:00
|
|
|
msg_display(MSG_badetcfstab, pm->diskdev);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
2014-08-03 20:09:38 +04:00
|
|
|
return -2;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
error = walk(fstab, (size_t)fstabsize, fstabbuf, numfstabbuf);
|
1997-10-01 09:04:24 +04:00
|
|
|
free(fstab);
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
return error;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
2000-09-27 16:42:04 +04:00
|
|
|
|
2015-01-02 22:43:13 +03:00
|
|
|
int
|
2015-07-25 10:12:30 +03:00
|
|
|
set_swap_if_low_ram(const char *disk, partinfo *pp)
|
|
|
|
{
|
|
|
|
if (get_ramsize() <= 32)
|
|
|
|
return set_swap(disk, pp);
|
|
|
|
return 0;
|
2015-01-02 22:43:13 +03:00
|
|
|
}
|
|
|
|
|
2000-09-27 16:42:04 +04:00
|
|
|
int
|
2003-07-25 12:26:21 +04:00
|
|
|
set_swap(const char *disk, partinfo *pp)
|
2000-09-27 16:42:04 +04:00
|
|
|
{
|
2003-07-07 16:30:19 +04:00
|
|
|
int i;
|
2003-06-16 14:42:47 +04:00
|
|
|
char *cp;
|
|
|
|
int rval;
|
2000-09-27 16:42:04 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
if (pp == NULL)
|
2014-08-03 20:09:38 +04:00
|
|
|
pp = pm->oldlabel;
|
2000-09-27 16:42:04 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
2003-06-16 14:42:47 +04:00
|
|
|
if (pp[i].pi_fstype != FS_SWAP)
|
|
|
|
continue;
|
2003-07-25 12:26:21 +04:00
|
|
|
asprintf(&cp, "/dev/%s%c", disk, 'a' + i);
|
2003-06-16 14:42:47 +04:00
|
|
|
rval = swapctl(SWAP_ON, cp, 0);
|
|
|
|
free(cp);
|
|
|
|
if (rval != 0)
|
|
|
|
return -1;
|
2000-09-27 16:42:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-16 14:42:47 +04:00
|
|
|
|
|
|
|
int
|
2003-07-25 12:26:21 +04:00
|
|
|
check_swap(const char *disk, int remove_swap)
|
2003-06-16 14:42:47 +04:00
|
|
|
{
|
|
|
|
struct swapent *swap;
|
|
|
|
char *cp;
|
|
|
|
int nswap;
|
|
|
|
int l;
|
|
|
|
int rval = 0;
|
|
|
|
|
|
|
|
nswap = swapctl(SWAP_NSWAP, 0, 0);
|
|
|
|
if (nswap <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
swap = malloc(nswap * sizeof *swap);
|
|
|
|
if (swap == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nswap = swapctl(SWAP_STATS, swap, nswap);
|
|
|
|
if (nswap < 0)
|
|
|
|
goto bad_swap;
|
|
|
|
|
2003-07-25 12:26:21 +04:00
|
|
|
l = strlen(disk);
|
2003-06-16 14:42:47 +04:00
|
|
|
while (--nswap >= 0) {
|
|
|
|
/* Should we check the se_dev or se_path? */
|
|
|
|
cp = swap[nswap].se_path;
|
|
|
|
if (memcmp(cp, "/dev/", 5) != 0)
|
|
|
|
continue;
|
2003-07-25 12:26:21 +04:00
|
|
|
if (memcmp(cp + 5, disk, l) != 0)
|
2003-06-16 14:42:47 +04:00
|
|
|
continue;
|
|
|
|
if (!isalpha(*(unsigned char *)(cp + 5 + l)))
|
|
|
|
continue;
|
|
|
|
if (cp[5 + l + 1] != 0)
|
|
|
|
continue;
|
|
|
|
/* ok path looks like it is for this device */
|
2003-07-25 12:26:21 +04:00
|
|
|
if (!remove_swap) {
|
2003-06-16 14:42:47 +04:00
|
|
|
/* count active swap areas */
|
|
|
|
rval++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (swapctl(SWAP_OFF, cp, 0) == -1)
|
|
|
|
rval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
free(swap);
|
|
|
|
return rval;
|
|
|
|
|
|
|
|
bad_swap:
|
|
|
|
rval = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
2009-04-07 14:45:04 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_BOOTXX_xFS
|
|
|
|
char *
|
|
|
|
bootxx_name(void)
|
|
|
|
{
|
|
|
|
int fstype;
|
|
|
|
const char *bootxxname;
|
|
|
|
char *bootxx;
|
|
|
|
|
|
|
|
/* check we have boot code for the root partition type */
|
2014-08-03 20:09:38 +04:00
|
|
|
fstype = pm->bsdlabel[pm->rootpart].pi_fstype;
|
2009-04-07 14:45:04 +04:00
|
|
|
switch (fstype) {
|
|
|
|
#if defined(BOOTXX_FFSV1) || defined(BOOTXX_FFSV2)
|
|
|
|
case FS_BSDFFS:
|
2014-08-03 20:09:38 +04:00
|
|
|
if (pm->bsdlabel[pm->rootpart].pi_flags & PIF_FFSv2) {
|
2009-04-07 14:45:04 +04:00
|
|
|
#ifdef BOOTXX_FFSV2
|
|
|
|
bootxxname = BOOTXX_FFSV2;
|
|
|
|
#else
|
|
|
|
bootxxname = NULL;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#ifdef BOOTXX_FFSV1
|
|
|
|
bootxxname = BOOTXX_FFSV1;
|
|
|
|
#else
|
|
|
|
bootxxname = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2015-11-15 02:00:17 +03:00
|
|
|
#ifdef BOOTXX_LFSV2
|
2009-04-07 14:45:04 +04:00
|
|
|
case FS_BSDLFS:
|
2015-11-15 02:00:17 +03:00
|
|
|
bootxxname = BOOTXX_LFSV2;
|
2009-04-07 14:45:04 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
bootxxname = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bootxxname == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
asprintf(&bootxx, "%s/%s", BOOTXXDIR, bootxxname);
|
|
|
|
return bootxx;
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-03 20:09:38 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
get_fsid_by_gptuuid(const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uuid_t uuid;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
uuid_from_string(str, &uuid, &status);
|
|
|
|
if (status == uuid_s_ok) {
|
|
|
|
for (i = 0; gpt_filesystems[i].id > 0; i++)
|
|
|
|
if (uuid_equal(&uuid, &(gpt_filesystems[i].uuid), NULL))
|
|
|
|
return gpt_filesystems[i].id;
|
|
|
|
}
|
|
|
|
return FS_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
get_gptfs_by_id(int filesystem)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; gpt_filesystems[i].id > 0; i++)
|
|
|
|
if (filesystem == gpt_filesystems[i].id)
|
|
|
|
return gpt_filesystems[i].name;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* from dkctl.c */
|
|
|
|
static int
|
|
|
|
get_dkwedges_sort(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct dkwedge_info *dkwa = a, *dkwb = b;
|
|
|
|
const daddr_t oa = dkwa->dkw_offset, ob = dkwb->dkw_offset;
|
|
|
|
return (oa < ob) ? -1 : (oa > ob) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
get_dkwedges(struct dkwedge_info **dkw, const char *diskdev)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char buf[STRSIZE];
|
|
|
|
size_t bufsize;
|
|
|
|
struct dkwedge_list dkwl;
|
|
|
|
|
|
|
|
*dkw = NULL;
|
|
|
|
dkwl.dkwl_buf = *dkw;
|
|
|
|
dkwl.dkwl_bufsize = 0;
|
|
|
|
fd = opendisk(diskdev, O_RDONLY, buf, STRSIZE, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (ioctl(fd, DIOCLWEDGES, &dkwl) == -1)
|
|
|
|
return -2;
|
|
|
|
if (dkwl.dkwl_nwedges == dkwl.dkwl_ncopied)
|
|
|
|
break;
|
|
|
|
bufsize = dkwl.dkwl_nwedges * sizeof(**dkw);
|
|
|
|
if (dkwl.dkwl_bufsize < bufsize) {
|
|
|
|
*dkw = realloc(dkwl.dkwl_buf, bufsize);
|
|
|
|
if (*dkw == NULL)
|
|
|
|
return -3;
|
|
|
|
dkwl.dkwl_buf = *dkw;
|
|
|
|
dkwl.dkwl_bufsize = bufsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 17:26:27 +04:00
|
|
|
if (dkwl.dkwl_nwedges > 0 && *dkw != NULL)
|
2014-08-03 20:09:38 +04:00
|
|
|
qsort(*dkw, dkwl.dkwl_nwedges, sizeof(**dkw), get_dkwedges_sort);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return dkwl.dkwl_nwedges;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: rewrite */
|
|
|
|
static int
|
|
|
|
incoregpt(pm_devs_t *pm_cur, partinfo *lp)
|
|
|
|
{
|
|
|
|
int i, num;
|
2014-08-09 00:24:27 +04:00
|
|
|
unsigned int p_num;
|
|
|
|
uint64_t p_start, p_size;
|
2014-08-03 20:09:38 +04:00
|
|
|
char *textbuf, *t, *tt, p_type[STRSIZE];
|
|
|
|
struct dkwedge_info *dkw;
|
|
|
|
|
|
|
|
num = get_dkwedges(&dkw, pm_cur->diskdev);
|
|
|
|
if (dkw != NULL) {
|
|
|
|
for (i = 0; i < num && i < MAX_WEDGES; i++)
|
|
|
|
run_program(RUN_SILENT, "dkctl %s delwedge %s",
|
|
|
|
pm_cur->diskdev, dkw[i].dkw_devname);
|
|
|
|
free (dkw);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collect(T_OUTPUT, &textbuf, "gpt show -u %s 2>/dev/null", pm_cur->diskdev) < 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
(void)strtok(textbuf, "\n"); /* ignore first line */
|
|
|
|
while ((t = strtok(NULL, "\n")) != NULL) {
|
2014-08-09 00:24:27 +04:00
|
|
|
i = 0; p_start = 0; p_size = 0; p_num = 0; strcpy(p_type, ""); /* init */
|
2014-08-03 20:09:38 +04:00
|
|
|
while ((tt = strsep(&t, " \t")) != NULL) {
|
2014-08-09 00:24:27 +04:00
|
|
|
if (strlen(tt) == 0)
|
2014-08-03 20:09:38 +04:00
|
|
|
continue;
|
|
|
|
if (i == 0)
|
2014-08-09 00:24:27 +04:00
|
|
|
p_start = strtouq(tt, NULL, 10);
|
2014-08-03 20:09:38 +04:00
|
|
|
if (i == 1)
|
2014-08-09 00:24:27 +04:00
|
|
|
p_size = strtouq(tt, NULL, 10);
|
2014-08-03 20:09:38 +04:00
|
|
|
if (i == 2)
|
2014-08-09 00:24:27 +04:00
|
|
|
p_num = strtouq(tt, NULL, 10);
|
2014-08-03 20:09:38 +04:00
|
|
|
if (i > 2 || (i == 2 && p_num == 0))
|
|
|
|
if (
|
|
|
|
strcmp(tt, "GPT") &&
|
|
|
|
strcmp(tt, "part") &&
|
|
|
|
strcmp(tt, "-")
|
|
|
|
)
|
|
|
|
strncat(p_type, tt, STRSIZE);
|
|
|
|
i++;
|
|
|
|
}
|
2014-08-09 00:24:27 +04:00
|
|
|
if (p_start == 0 || p_size == 0)
|
2014-08-03 20:09:38 +04:00
|
|
|
continue;
|
|
|
|
else if (! strcmp(p_type, "Pritable"))
|
|
|
|
pm_cur->ptstart = p_start + p_size;
|
|
|
|
else if (! strcmp(p_type, "Sectable"))
|
|
|
|
pm_cur->ptsize = p_start - pm_cur->ptstart - 1;
|
2014-08-09 00:24:27 +04:00
|
|
|
else if (p_num == 0 && strlen(p_type) > 0)
|
2014-08-03 20:09:38 +04:00
|
|
|
/* Utilitary entry (PMBR, etc) */
|
|
|
|
continue;
|
2014-08-09 00:24:27 +04:00
|
|
|
else if (p_num == 0) {
|
2014-08-03 20:09:38 +04:00
|
|
|
/* Free space */
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Usual partition */
|
|
|
|
lp[p_num].pi_size = p_size;
|
|
|
|
lp[p_num].pi_offset = p_start;
|
|
|
|
lp[p_num].pi_fstype = get_fsid_by_gptuuid(p_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(textbuf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-28 15:05:27 +03:00
|
|
|
static bool
|
2014-08-03 20:09:38 +04:00
|
|
|
is_gpt(const char *dev)
|
|
|
|
{
|
2015-05-09 15:06:31 +03:00
|
|
|
check_available_binaries();
|
|
|
|
|
|
|
|
if (!have_gpt)
|
2014-12-28 15:05:27 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return !run_program(RUN_SILENT | RUN_ERROR_OK,
|
2014-08-03 20:09:38 +04:00
|
|
|
"sh -c 'gpt show %s |grep -e Pri\\ GPT\\ table'", dev);
|
|
|
|
}
|