2022-02-14 09:45:34 +03:00
|
|
|
/* $NetBSD: target.c,v 1.8.2.7 2022/02/14 06:45:34 msaitoh Exp $ */
|
1997-11-02 11:12:06 +03:00
|
|
|
|
|
|
|
/*
|
1997-11-02 11:30:39 +03:00
|
|
|
* Copyright 1997 Jonathan Stone
|
1997-11-02 11:12:06 +03:00
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-11-02 11:30:39 +03:00
|
|
|
* Jonathan Stone.
|
|
|
|
* 4. The name of Jonathan Stone may not be used to endorse
|
1997-11-02 11:12:06 +03:00
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
1997-11-02 11:30:39 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY JONATHAN STONE ``AS IS''
|
1997-11-02 11:12:06 +03:00
|
|
|
* 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 PIERMONT INFORMATION SYSTEMS INC. 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, 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-10-11 15:10:11 +04:00
|
|
|
/* Copyright below applies to the realpath() code */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1989, 1991, 1993, 1995
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:27:56 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-10-11 15:10:11 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1997-11-03 12:47:00 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2022-02-14 09:45:34 +03:00
|
|
|
__RCSID("$NetBSD: target.c,v 1.8.2.7 2022/02/14 06:45:34 msaitoh Exp $");
|
1997-11-03 12:47:00 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* target.c -- path-prefixing routines to access the target installation
|
2000-12-05 01:47:02 +03:00
|
|
|
* filesystems. Makes the install tools more independent of whether
|
2003-07-07 16:30:19 +04:00
|
|
|
* we're installing into a separate filesystem hierarchy mounted under
|
|
|
|
* /targetroot, or into the currently active root mounted on /.
|
1997-11-03 12:47:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h> /* XXX vm_param.h always defines TRUE*/
|
1997-11-09 15:47:06 +03:00
|
|
|
#include <sys/types.h>
|
2022-02-02 07:25:36 +03:00
|
|
|
#include <sys/ioctl.h>
|
1997-11-03 12:47:00 +03:00
|
|
|
#include <sys/sysctl.h>
|
1997-11-09 15:47:06 +03:00
|
|
|
#include <sys/stat.h> /* stat() */
|
|
|
|
#include <sys/mount.h> /* statfs() */
|
1997-11-02 11:12:06 +03:00
|
|
|
|
2000-10-19 18:42:57 +04:00
|
|
|
#include <fcntl.h>
|
1997-11-02 11:12:06 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
1997-11-03 12:47:00 +03:00
|
|
|
#include <curses.h> /* defines TRUE, but checks */
|
1997-11-05 10:28:20 +03:00
|
|
|
#include <errno.h>
|
2022-02-02 07:25:36 +03:00
|
|
|
#include <util.h>
|
1997-11-03 12:47:00 +03:00
|
|
|
|
1997-11-02 11:12:06 +03:00
|
|
|
#include "defs.h"
|
|
|
|
#include "md.h"
|
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* local prototypes
|
|
|
|
*/
|
1997-11-09 15:47:06 +03:00
|
|
|
|
2000-12-22 13:12:12 +03:00
|
|
|
static void make_prefixed_dir (const char *prefix, const char *path);
|
|
|
|
static int do_target_chdir (const char *dir, int flag);
|
2000-09-26 17:26:02 +04:00
|
|
|
int target_test(unsigned int mode, const char *path);
|
2000-12-22 13:12:12 +03:00
|
|
|
int target_test_dir (const char *path); /* deprecated */
|
|
|
|
int target_test_file (const char *path); /* deprecated */
|
|
|
|
int target_test_symlink (const char *path); /* deprecated */
|
1997-11-02 11:12:06 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
void unwind_mounts(void);
|
1997-12-04 12:05:35 +03:00
|
|
|
|
|
|
|
/* Record a mount for later unwinding of target mounts. */
|
|
|
|
struct unwind_mount {
|
|
|
|
struct unwind_mount *um_prev;
|
2003-11-30 17:36:43 +03:00
|
|
|
char um_mountpoint[4]; /* Allocated longer... */
|
1997-12-04 12:05:35 +03:00
|
|
|
};
|
|
|
|
|
2022-02-02 07:25:36 +03:00
|
|
|
/* Record a wedge for later deletion after all file systems have been unmounted */
|
|
|
|
struct umount_delwedge {
|
|
|
|
struct umount_delwedge *next;
|
|
|
|
char disk[DISKNAMESIZE], wedge[DISKNAMESIZE];
|
|
|
|
};
|
|
|
|
struct umount_delwedge *post_umount_dwlist = NULL;
|
|
|
|
|
1997-12-04 12:05:35 +03:00
|
|
|
/* Unwind-mount stack */
|
1998-06-20 17:05:48 +04:00
|
|
|
struct unwind_mount *unwind_mountlist = NULL;
|
1997-12-04 12:05:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging options
|
|
|
|
*/
|
|
|
|
/*#define DEBUG_ROOT*/ /* turn on what-is-root? debugging. */
|
|
|
|
/*#define DEBUG_UNWIND*/ /* turn on unwind-target-mount debugging. */
|
|
|
|
|
1997-11-09 15:47:06 +03:00
|
|
|
/*
|
|
|
|
* debugging helper. curses...
|
|
|
|
*/
|
2003-01-10 23:00:27 +03:00
|
|
|
#if defined(DEBUG) || defined(DEBUG_ROOT)
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
backtowin(void)
|
1997-11-09 15:47:06 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
fflush(stdout); /* curses does not leave stdout linebuffered. */
|
|
|
|
getchar(); /* wait for user to press return */
|
|
|
|
wrefresh(stdscr);
|
|
|
|
}
|
2003-01-10 23:00:27 +03:00
|
|
|
#endif
|
1997-11-09 15:47:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-05 01:47:02 +03:00
|
|
|
* Is the root partition we're running from the same as the root
|
|
|
|
* which the user has selected to install/upgrade?
|
2014-08-03 20:09:38 +04:00
|
|
|
* Uses global variable "pm->diskdev" to find the selected device for
|
1997-11-09 15:47:06 +03:00
|
|
|
* install/upgrade.
|
1997-11-03 12:47:00 +03:00
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_already_root(void)
|
1997-11-03 12:47:00 +03:00
|
|
|
{
|
2019-06-12 09:20:17 +03:00
|
|
|
char dev[PATH_MAX];
|
|
|
|
int rootpart = -1;
|
|
|
|
static struct pm_devs *last_pm;
|
|
|
|
static int last_res;
|
|
|
|
part_id ptn;
|
2020-02-11 00:39:37 +03:00
|
|
|
struct disk_partitions *parts, *inner;
|
2019-06-12 09:20:17 +03:00
|
|
|
struct disk_part_info info;
|
|
|
|
|
Pull up following revision(s) (requested by martin in ticket #1113):
usr.sbin/sysinst/bsddisklabel.c: revision 1.46
usr.sbin/sysinst/bsddisklabel.c: revision 1.47
usr.sbin/sysinst/disklabel.c: revision 1.40
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.13
usr.sbin/sysinst/bsddisklabel.c: revision 1.48
usr.sbin/sysinst/disklabel.c: revision 1.41
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.14
usr.sbin/sysinst/bsddisklabel.c: revision 1.49
usr.sbin/sysinst/disklabel.c: revision 1.42
usr.sbin/sysinst/Makefile.inc: revision 1.34
usr.sbin/sysinst/disks.c: revision 1.70
usr.sbin/sysinst/arch/hp300/md.c: revision 1.11
usr.sbin/sysinst/disks.c: revision 1.71
usr.sbin/sysinst/arch/i386/md.h: revision 1.8
usr.sbin/sysinst/arch/arc/md.c: revision 1.13
usr.sbin/sysinst/mbr.h: revision 1.5
usr.sbin/sysinst/mbr.h: revision 1.6
usr.sbin/sysinst/arch/mac68k/md.c: revision 1.10
usr.sbin/sysinst/bsddisklabel.c: revision 1.50
usr.sbin/sysinst/arch/acorn32/md.c: revision 1.7
usr.sbin/sysinst/bsddisklabel.c: revision 1.51
usr.sbin/sysinst/bsddisklabel.c: revision 1.52
usr.sbin/sysinst/bsddisklabel.c: revision 1.53
usr.sbin/sysinst/bsddisklabel.c: revision 1.54
usr.sbin/sysinst/bsddisklabel.c: revision 1.55
usr.sbin/sysinst/bsddisklabel.c: revision 1.56
usr.sbin/sysinst/arch/dummy/md.c: revision 1.6
usr.sbin/sysinst/arch/amd64/md.h: revision 1.9
usr.sbin/sysinst/arch/evbsh3/md.c: revision 1.6
usr.sbin/sysinst/arch/sparc/md.c: revision 1.6
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.10
usr.sbin/sysinst/arch/x68k/md.c: revision 1.11
usr.sbin/sysinst/arch/sandpoint/md.c: revision 1.9
usr.sbin/sysinst/arch/vax/md.c: revision 1.7
usr.sbin/sysinst/arch/luna68k/md.c: revision 1.9
usr.sbin/sysinst/gpt.c: revision 1.19
usr.sbin/sysinst/arch/i386/md.c: revision 1.31
usr.sbin/sysinst/arch/i386/md.c: revision 1.32
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.17
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.18
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.19
usr.sbin/sysinst/arch/shark/md.c: revision 1.6
usr.sbin/sysinst/arch/landisk/md.c: revision 1.14
usr.sbin/sysinst/util.c: revision 1.43
usr.sbin/sysinst/gpt.c: revision 1.20
usr.sbin/sysinst/util.c: revision 1.44
usr.sbin/sysinst/gpt.c: revision 1.21
usr.sbin/sysinst/gpt.c: revision 1.22
usr.sbin/sysinst/arch/evbarm/msg.md.en: revision 1.2
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.11
usr.sbin/sysinst/util.c: revision 1.46
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.12
usr.sbin/sysinst/util.c: revision 1.47
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.6
usr.sbin/sysinst/util.c: revision 1.48
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.7
usr.sbin/sysinst/arch/evbmips/md.c: revision 1.9
usr.sbin/sysinst/msg.mi.fr: revision 1.28
usr.sbin/sysinst/msg.mi.fr: revision 1.29
usr.sbin/sysinst/arch/sgimips/md.c: revision 1.9
usr.sbin/sysinst/arch/evbarm/Makefile: revision 1.3
usr.sbin/sysinst/msg.mi.de: revision 1.23
usr.sbin/sysinst/arch/hpcsh/md.c: revision 1.10
usr.sbin/sysinst/msg.mi.de: revision 1.24
usr.sbin/sysinst/install.c: revision 1.15
usr.sbin/sysinst/install.c: revision 1.16
usr.sbin/sysinst/arch/sparc64/md.c: revision 1.6
usr.sbin/sysinst/install.c: revision 1.17
usr.sbin/sysinst/install.c: revision 1.18
usr.sbin/sysinst/partitions.h: revision 1.16
usr.sbin/sysinst/install.c: revision 1.19
usr.sbin/sysinst/partitions.h: revision 1.17
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.9
usr.sbin/sysinst/arch/playstation2/md.c: revision 1.9
usr.sbin/sysinst/partitions.h: revision 1.18
usr.sbin/sysinst/arch/hpcarm/md.c: revision 1.9
usr.sbin/sysinst/partitions.h: revision 1.19
usr.sbin/sysinst/msg.mi.es: revision 1.24
usr.sbin/sysinst/msg.mi.es: revision 1.25
usr.sbin/sysinst/msg.mi.es: revision 1.26
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.9
usr.sbin/sysinst/target.c: revision 1.13
usr.sbin/sysinst/target.c: revision 1.14
usr.sbin/sysinst/part_edit.c: revision 1.17
usr.sbin/sysinst/part_edit.c: revision 1.18
usr.sbin/sysinst/msg.mi.fr: revision 1.30
usr.sbin/sysinst/arch/mvme68k/md.c: revision 1.11
usr.sbin/sysinst/part_edit.c: revision 1.19
usr.sbin/sysinst/msg.mi.fr: revision 1.31
usr.sbin/sysinst/arch/alpha/md.c: revision 1.9
usr.sbin/sysinst/msg.mi.en: revision 1.30
usr.sbin/sysinst/defs.h: revision 1.56
usr.sbin/sysinst/msg.mi.en: revision 1.31
usr.sbin/sysinst/defs.h: revision 1.57
usr.sbin/sysinst/msg.mi.en: revision 1.32
usr.sbin/sysinst/arch/amiga/md.c: revision 1.6
usr.sbin/sysinst/arch/hpcmips/md.c: revision 1.9
usr.sbin/sysinst/defs.h: revision 1.58
usr.sbin/sysinst/arch/cats/md.c: revision 1.5
usr.sbin/sysinst/defs.h: revision 1.59
usr.sbin/sysinst/arch/newsmips/md.c: revision 1.6
usr.sbin/sysinst/arch/pmax/md.c: revision 1.8
usr.sbin/sysinst/arch/mipsco/md.c: revision 1.8
usr.sbin/sysinst/part_edit.c: revision 1.20
usr.sbin/sysinst/part_edit.c: revision 1.21
usr.sbin/sysinst/arch/macppc/md.c: revision 1.6
usr.sbin/sysinst/part_edit.c: revision 1.22
usr.sbin/sysinst/part_edit.c: revision 1.23
usr.sbin/sysinst/part_edit.c: revision 1.24
usr.sbin/sysinst/defs.h: revision 1.60
usr.sbin/sysinst/arch/mac68k/Makefile: revision 1.3
usr.sbin/sysinst/defs.h: revision 1.61
usr.sbin/sysinst/defs.h: revision 1.63
usr.sbin/sysinst/defs.h: revision 1.64
usr.sbin/sysinst/defs.h: revision 1.65
usr.sbin/sysinst/label.c: revision 1.21
usr.sbin/sysinst/defs.h: revision 1.66
usr.sbin/sysinst/label.c: revision 1.22
usr.sbin/sysinst/defs.h: revision 1.67
usr.sbin/sysinst/label.c: revision 1.23
usr.sbin/sysinst/label.c: revision 1.24
usr.sbin/sysinst/label.c: revision 1.25
usr.sbin/sysinst/label.c: revision 1.26
usr.sbin/sysinst/label.c: revision 1.27
usr.sbin/sysinst/msg.mi.pl: revision 1.31
usr.sbin/sysinst/label.c: revision 1.28
usr.sbin/sysinst/msg.mi.pl: revision 1.32
usr.sbin/sysinst/label.c: revision 1.29
usr.sbin/sysinst/arch/atari/md.c: revision 1.7
usr.sbin/sysinst/disklabel.c: revision 1.36
usr.sbin/sysinst/disklabel.c: revision 1.37
usr.sbin/sysinst/disklabel.c: revision 1.38
usr.sbin/sysinst/disklabel.c: revision 1.39
usr.sbin/sysinst/arch/bebox/md.c: revision 1.9
usr.sbin/sysinst/mbr.c: revision 1.32
usr.sbin/sysinst/disks.c: revision 1.66
usr.sbin/sysinst/mbr.c: revision 1.33
usr.sbin/sysinst/disks.c: revision 1.67
usr.sbin/sysinst/mbr.c: revision 1.34
usr.sbin/sysinst/arch/emips/md.c: revision 1.9
usr.sbin/sysinst/disks.c: revision 1.68
usr.sbin/sysinst/partitions.c: revision 1.11
usr.sbin/sysinst/mbr.c: revision 1.35
usr.sbin/sysinst/disks.c: revision 1.69
usr.sbin/sysinst/mbr.c: revision 1.36
usr.sbin/sysinst/arch/hppa/md.c: revision 1.8
usr.sbin/sysinst/arch/prep/md.c: revision 1.13
usr.sbin/sysinst/label.c: revision 1.30
usr.sbin/sysinst/arch/ews4800mips/md.c: revision 1.7
usr.sbin/sysinst/main.c: revision 1.21
usr.sbin/sysinst/main.c: revision 1.22
usr.sbin/sysinst/main.c: revision 1.23
usr.sbin/sysinst/bsddisklabel.c: revision 1.40
usr.sbin/sysinst/main.c: revision 1.24
usr.sbin/sysinst/arch/cobalt/md.h: revision 1.6
usr.sbin/sysinst/bsddisklabel.c: revision 1.41
usr.sbin/sysinst/main.c: revision 1.25
usr.sbin/sysinst/arch/news68k/md.c: revision 1.7
usr.sbin/sysinst/bsddisklabel.c: revision 1.42
usr.sbin/sysinst/bsddisklabel.c: revision 1.43
usr.sbin/sysinst/bsddisklabel.c: revision 1.44
usr.sbin/sysinst/bsddisklabel.c: revision 1.45
Use strlcpy in a few places to guarnatee 0-terminated strings
Rever previous: the d_packname in struct disklabel is not NUL terminated.
Disable the warning instead.
Do not force -Os optimization (unless SMALLPROG)
Remove unused "rel" global variable and make the -r option a no-op.
PR 55045: strlcpy(NULL, ..., 0) considered harmfull in some implementations.
PR misc/54886: bump threshold for automatic/default creation of a tmpfs /tmp
up slightly (to 384 MB ram). This will make sure the default install has
a > 64 MB /tmp available (number pulled out of thin air, 64 MB is the minimum
required by the ZFS tests).
Don't depend on common symbol definitions.
boardype should not be common.
Redo the root-size-limit check again after we grew the root partition
for kernel dumps. Auto-enable the /usr partition if it overflows.
For all non-root partitions, default to FFSv2.
When extending a partition (to fill the total disk size) do respect
size limits.
Do not suggest a size limited partition for extension by default.
Minor tweak to previous: when forcing a /usr partition just to have an
arbitrary extendable partition, still use its default size initially.
At the end of a new installation save entropy.
Ooops, backout previous - twice the entropy saving is not needed.
Instead slightly improve the (slightly) hidden other code that already
did it.
PR 55202: disable swapping if we started it due to low ram
it's "its"
Remove "If you booted from a floppy" message
Set HAVE_INSTALL_IMAGE for evbarm
Change mountpoint of boot ext2fs from /stand to /ext2 to avoid conflict.
Should be pulled up to netbsd-9, with fixes of PR/55060.
MBR type for Ext2 should be MBR_PTYPE_LNXEXT2, not MBR_PTYPE_FAT12.
Silence -Wstringop-truncation for ``name'' in disp_selected_part().
This variable is used only for display, and truncation seems harmless.
PR 55572: avoid crash when answering the mount point prompt for a previously
empty mount point with an emptry sting.
When adding a new partition in the concrete partition editor, make sure
to set a pointer to the partition table interface in the new entry.
Otherwise we may end up not writing back the partitions at all, leading
to further fallout later.
Receipe to reproduce the issue from Frederic Fauberteau, thanks!
In the concrete partitions editor, after deleting the last partition move
the menu selection to the "add a partition" entry (instead of the sentinel
line which is not an active menu entry).
Typo in comment
Keep a list of all partition tables from which we have deleted partitions
and make sure we update those partition tables when writing partitions,
even if no install related partition remains on them.
Fix display of timezone selection menu
If there is no current partitioning manager assume we are editing the
current system and make target_already_root() return true.
Fixes various fallout when using sysinst post installation.
PR 55377: mark boot partitions in the partition size display, as suggested
by Izumi Tsutsui (minor modifications + all bugs by me)
PR 55378: do not assume RAW_PART to be either 2 or 3
PR 55379: avoid creating bogus /etc/fstab lines for /dev/cd* if no
cdrom is available.
PR 55381: try to deal with moved (but not yet saved) partitions when
calculating free space
Apply patch provided by Izumi Tsutsui in PR 55382: make ext2 partitions
show up in the outer (MBR) partition table, needed for example on Cobalt
where firmware boots from that partition.
PR 55384: detangle pm->ptstart from the "install" flag (selecting a
target partition). Instead introduce a new PTI_INSTALL_TARGET per partition
flag and deal with it in the partitioning backends.
Honour pm->ptstart when allocating new partitions - it is supposed to be
the first sector usable by NetBSD.
If we have no explicitly marke target root partition, make sure to set
the proper flag on the implicit one.
When merging existing partitions with desired target system layout
information, only force the "mount" flag if the existing partitions
has a valid mount point.
Add a heuristic to detect and properly mark EFI system partitions
when re-using pre-existing partitions.
When MD code requests a reserved area (at the start of the disk)
make sure to properly account for the "lost" space during all calculations
and especially when expanding the main partition to fill the disk.
Avoid using the global "pm" or a passed device descriptons when we are
passing disk limits explicitly anyway.
Simplify/fix a few rounding calculations.
When creating new partitions for "full disk" use, pass a install target
hint to the partitioning backend (for the outer NetBSD partition).
Use an install target hint to mark a new partition active.
When compiled with BOOTSEL support, also name the new partition "NetBSD".
Remove more pm->ptstart abuse - calculate values localy where needed
instead.
Fix editing start and size of not yet existing outer partitions.
Previously we abused pm->ptstart / pm->ptsize to pass the bounds of the
NetBSD outer partition to the inner partition editor - but now this is
not a valid assumption any more, so explicitly fix the bounds if an
outer partition exists.
Remove very strange code that special-cased MSDOS file systems and refused
to newfs the partition (despite explicit request to do so) if it was
mountable.
Accidently carried over from a dim and distant past, before we had
fsck_newfs.
PR 55536: when we find existing partition tables and have alternative
formats available, offer to delete partitions and create new ones from
scratch (in some other or the same on-disk format).
Minor fix to previous: fix condition when we offer the partition type
switch - it makes sense even if the disk is partitioned but has no valid
partitions.
Before forcing MBR partitions into our disklabel, make sure they are not
there yet - could happen in various paths when reusing existing partitions
(or parts of that) - previously we would blindly duplicate identical
partitions.
Ooops, part of previous was not meant to be included yet
When renumbering partitions (after deletions) be slightly more lax
in matching, to cope with differences between MBR EFI partitions and
disklabel MSDOS partitions.
PR 55142: on popular demand bring back expert options to adjust the
number of free inodes, block size and fragment size for FFS and LFS.
Fix copy & pasto noticed by Jason Mitchell: change the type of a GPT
partition via "gpt type" - not "gpt label".
Fix copy & pasto (missing "again" label)
Remove dead code
Move MBR writing (if any) post disklabel writing, otherwise strange
interactions happen.
Properly convert partition default sizes in MB to number of sectors
2020-10-15 22:36:50 +03:00
|
|
|
if (pm == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2019-06-12 09:20:17 +03:00
|
|
|
if (pm == last_pm)
|
|
|
|
return last_res;
|
|
|
|
|
2019-07-23 21:13:40 +03:00
|
|
|
if (pm->cur_system)
|
|
|
|
return 1;
|
|
|
|
|
2019-06-12 09:20:17 +03:00
|
|
|
last_pm = pm;
|
2019-07-23 18:23:14 +03:00
|
|
|
last_res = 0;
|
2019-06-12 09:20:17 +03:00
|
|
|
|
|
|
|
parts = pm->parts;
|
2019-07-23 18:23:14 +03:00
|
|
|
if (parts == NULL) {
|
2019-06-12 09:20:17 +03:00
|
|
|
last_res = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-23 18:23:14 +03:00
|
|
|
|
|
|
|
if (pm->no_part) {
|
|
|
|
last_res = is_active_rootpart(pm->diskdev, -1);
|
|
|
|
return last_res;
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:39:37 +03:00
|
|
|
if (pm->parts->pscheme->secondary_partitions != NULL) {
|
|
|
|
inner = pm->parts->pscheme->secondary_partitions(parts,
|
2019-06-15 11:20:33 +03:00
|
|
|
pm->ptstart, false);
|
2020-02-11 00:39:37 +03:00
|
|
|
if (inner != NULL)
|
|
|
|
parts = inner;
|
|
|
|
}
|
2019-06-12 09:20:17 +03:00
|
|
|
|
|
|
|
for (ptn = 0; ptn < parts->num_part; ptn++) {
|
|
|
|
if (!parts->pscheme->get_part_info(parts, ptn, &info))
|
|
|
|
continue;
|
|
|
|
if (info.nat_type->generic_ptype != PT_root)
|
|
|
|
continue;
|
2019-07-23 18:23:14 +03:00
|
|
|
if (!is_root_part_mount(info.last_mounted))
|
2019-06-12 09:20:17 +03:00
|
|
|
continue;
|
|
|
|
if (!parts->pscheme->get_part_device(parts, ptn,
|
Pull up following revision(s) (requested by martin in ticket #668):
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.11
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.12
usr.sbin/sysinst/arch/arc/md.c: revision 1.11
usr.sbin/sysinst/arch/arc/md.c: revision 1.12
usr.sbin/sysinst/partman.c: revision 1.43
usr.sbin/sysinst/partman.c: revision 1.46
usr.sbin/sysinst/partman.c: revision 1.47
usr.sbin/sysinst/partman.c: revision 1.48
usr.sbin/sysinst/partman.c: revision 1.49
usr.sbin/sysinst/msg.pm.fr: revision 1.2
usr.sbin/sysinst/upgrade.c: revision 1.14
usr.sbin/sysinst/arch/i386/md.c: revision 1.28
usr.sbin/sysinst/arch/i386/md.c: revision 1.29
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.9
usr.sbin/sysinst/arch/sandpoint/md.c: revision 1.7
usr.sbin/sysinst/arch/sandpoint/md.c: revision 1.8
usr.sbin/sysinst/gpt.c: revision 1.14
usr.sbin/sysinst/gpt.c: revision 1.15
usr.sbin/sysinst/arch/luna68k/md.c: revision 1.8
usr.sbin/sysinst/gpt.c: revision 1.16
usr.sbin/sysinst/msg.pm.de: revision 1.2
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.11
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.12
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.13
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.14
usr.sbin/sysinst/sizemultname.c: revision 1.4
usr.sbin/sysinst/msg.pm.en: revision 1.2
usr.sbin/sysinst/arch/landisk/md.c: revision 1.12
usr.sbin/sysinst/util.c: revision 1.41
usr.sbin/sysinst/arch/landisk/md.c: revision 1.13
usr.sbin/sysinst/util.c: revision 1.42
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.10
usr.sbin/sysinst/partitions.c: revision 1.9
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.4
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.5
usr.sbin/sysinst/arch/evbmips/md.c: revision 1.7
usr.sbin/sysinst/arch/evbmips/md.c: revision 1.8
usr.sbin/sysinst/msg.mi.fr: revision 1.25
usr.sbin/sysinst/msg.mi.de: revision 1.20
usr.sbin/sysinst/install.c: revision 1.14
usr.sbin/sysinst/partitions.h: revision 1.13
usr.sbin/sysinst/partitions.h: revision 1.14
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.7
usr.sbin/sysinst/arch/playstation2/md.c: revision 1.7
usr.sbin/sysinst/msg.mi.en: revision 1.27
usr.sbin/sysinst/partitions.h: revision 1.15
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.8
usr.sbin/sysinst/arch/hpcarm/md.c: revision 1.7
usr.sbin/sysinst/arch/playstation2/md.c: revision 1.8
usr.sbin/sysinst/msg.pm.pl: revision 1.2
usr.sbin/sysinst/arch/hpcarm/md.c: revision 1.8
usr.sbin/sysinst/msg.mi.es: revision 1.21
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.7
usr.sbin/sysinst/target.c: revision 1.11
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.8
usr.sbin/sysinst/part_edit.c: revision 1.14
usr.sbin/sysinst/part_edit.c: revision 1.15
usr.sbin/sysinst/part_edit.c: revision 1.16
usr.sbin/sysinst/defs.h: revision 1.50
usr.sbin/sysinst/defs.h: revision 1.51
usr.sbin/sysinst/defs.h: revision 1.52
usr.sbin/sysinst/defs.h: revision 1.53
usr.sbin/sysinst/defs.h: revision 1.54
usr.sbin/sysinst/arch/hpcmips/md.c: revision 1.7
usr.sbin/sysinst/arch/hpcmips/md.c: revision 1.8
usr.sbin/sysinst/arch/hpcsh/md.c: revision 1.8
usr.sbin/sysinst/msg.pm.es: revision 1.2
usr.sbin/sysinst/arch/hpcsh/md.c: revision 1.9
usr.sbin/sysinst/label.c: revision 1.18
usr.sbin/sysinst/label.c: revision 1.19
usr.sbin/sysinst/net.c: revision 1.35
usr.sbin/sysinst/msg.mi.pl: revision 1.28
usr.sbin/sysinst/disklabel.c: revision 1.28
usr.sbin/sysinst/disklabel.c: revision 1.29
usr.sbin/sysinst/mbr.c: revision 1.24
usr.sbin/sysinst/disks.c: revision 1.59
usr.sbin/sysinst/mbr.c: revision 1.25
usr.sbin/sysinst/mbr.c: revision 1.26
usr.sbin/sysinst/mbr.c: revision 1.27
usr.sbin/sysinst/mbr.c: revision 1.28
usr.sbin/sysinst/label.c: revision 1.20
usr.sbin/sysinst/mbr.c: revision 1.29
usr.sbin/sysinst/bsddisklabel.c: revision 1.34
usr.sbin/sysinst/bsddisklabel.c: revision 1.35
usr.sbin/sysinst/bsddisklabel.c: revision 1.36
usr.sbin/sysinst/bsddisklabel.c: revision 1.37
usr.sbin/sysinst/disklabel.c: revision 1.30
usr.sbin/sysinst/bsddisklabel.c: revision 1.38
usr.sbin/sysinst/disklabel.c: revision 1.31
usr.sbin/sysinst/disklabel.c: revision 1.32
usr.sbin/sysinst/disklabel.c: revision 1.33
usr.sbin/sysinst/disklabel.c: revision 1.34
usr.sbin/sysinst/disks.c: revision 1.60
usr.sbin/sysinst/disks.c: revision 1.61
usr.sbin/sysinst/arch/bebox/md.c: revision 1.7
usr.sbin/sysinst/disks.c: revision 1.62
usr.sbin/sysinst/arch/bebox/md.c: revision 1.8
usr.sbin/sysinst/mbr.c: revision 1.30
usr.sbin/sysinst/partitions.c: revision 1.10
usr.sbin/sysinst/arch/prep/md.c: revision 1.11
usr.sbin/sysinst/arch/prep/md.c: revision 1.12
usr.sbin/sysinst/menus.pm: revision 1.3
usr.sbin/sysinst/main.c: revision 1.20
usr.sbin/sysinst/menus.mi: revision 1.20
usr.sbin/sysinst/menus.mi: revision 1.21
avoid calling snprintf/strlcat with an input parameter the same
as the output. from martin@. fixes gcc 8 restrict warnings.
Finish conversion of extended partitioning parts to new abstract
backend interface. XXX still could use a lot of polishing.
Instead of a (bogus) attempt to query the model via ofctl, use the (now
fixed) sysctl hw.model instead.
When reading the secondary disklabel partitions from an existing disklabel
set the mbr partitions as parent.
Move the LABELSECTOR check and make it FS type specific - some partition
types (FFS, RAID) are allowed to overlap with the LABELSECTOR.
When asked to create a whole-disk partition for unknown usage, do not only
assert(false), but actually return an error (in case "assert" is a nop).
PR install/54787: when trying to derive proper alignement and first offset
from exisiting partitions, use the first partition offset if it is already
closer to the start of the disk than the prefered alignment - we can not
move existing partitions around.
Fix handling of inner/outer partitions (e.g. MBR and disklabel) in
extended partitioning:
- when editing a disk with such a schme, offer both partitions in two
steps
- when commiting changes save the inner partitions after the outer ones
Add a method to query the partitioning schemes "internal idea" of a
cylinder size - whatever that means in the real world.
Avoid using the global "pm" variable in utility functions - during
extended partitioning they may point to a different device.
Remove useless calls to get_ramsize() - return value is ignored and
the function has no side effects.
Fix /tmp tmpfs handling and on machines with enough RAM default to
creating a /tmp tmpfs with 25% of ram size limit. Suggested by ad@.
PR install/54872: fix printf argument order, sectors and heads were
swapped in the bios geometry display.
First try to bring evbarm installation closer to current reality.
hide disklabel_non_bootable() under NO_DISKLABEL_BOOT like the usage.
should fix most builds.
Deal with even stranger fictious empty disklabels (PR kern/54882).
Factor out all RAM size thresholds as defines to avoid magic numbers.
To work around PR misc/54886 bump the threshold for a tmpfs /tmp mount
up to 256 MB.
When retrying sets during extraction, reset the relevant statistics
to avoid counting retried sets multiple times.
Reported by kim.
Fix support for non-512-byte/sector disks again after I broke it when
introducing the abstract partition backends.
Use a few strlcpy() instead of strncpy() for network ioctl structs.
We seem to have no formal documentation stating the various
char if*_name[IFNAMSIZ]; /* if name, e.g. "en0" */
elements in ioctls are nul terminated, but the peanut gallery claims
it is so - and at least half of the code in-tree touching them agrees.
Too much disklabel magic happening in the kernel - to compensate force
MBR first when trying to identify the existing partitioning scheme of
a disk.
2020-01-28 13:17:57 +03:00
|
|
|
dev, sizeof dev, &rootpart, plain_name, false, true))
|
2019-06-12 09:20:17 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
last_res = is_active_rootpart(dev, rootpart);
|
2019-07-23 18:23:14 +03:00
|
|
|
break;
|
|
|
|
}
|
1997-11-03 12:47:00 +03:00
|
|
|
|
2019-07-23 18:23:14 +03:00
|
|
|
return last_res;
|
1997-11-09 15:47:06 +03:00
|
|
|
}
|
|
|
|
|
2019-07-23 18:23:14 +03:00
|
|
|
/*
|
|
|
|
* Could something with this "last mounted on" information be a potential
|
|
|
|
* root partition?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
is_root_part_mount(const char *last_mounted)
|
|
|
|
{
|
2019-08-02 08:41:46 +03:00
|
|
|
if (last_mounted == NULL)
|
|
|
|
return false;
|
|
|
|
|
2019-07-23 18:23:14 +03:00
|
|
|
return strcmp(last_mounted, "/") == 0 ||
|
|
|
|
strcmp(last_mounted, "/targetroot") == 0 ||
|
|
|
|
strcmp(last_mounted, "/altroot") == 0;
|
|
|
|
}
|
2003-09-27 14:47:17 +04:00
|
|
|
|
1997-11-09 15:47:06 +03:00
|
|
|
/*
|
|
|
|
* Is this device partition (e.g., "sd0a") mounted as root?
|
|
|
|
*/
|
|
|
|
int
|
2003-09-27 14:47:17 +04:00
|
|
|
is_active_rootpart(const char *dev, int ptn)
|
1997-11-09 15:47:06 +03:00
|
|
|
{
|
2003-09-27 14:47:17 +04:00
|
|
|
int mib[2];
|
|
|
|
char rootdev[SSTRSIZE];
|
|
|
|
int rootptn;
|
|
|
|
size_t varlen;
|
1997-11-09 15:47:06 +03:00
|
|
|
|
2003-09-27 14:47:17 +04:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_ROOT_DEVICE;
|
|
|
|
varlen = sizeof(rootdev);
|
|
|
|
if (sysctl(mib, 2, rootdev, &varlen, NULL, 0) < 0)
|
|
|
|
return 1;
|
1997-12-02 06:02:29 +03:00
|
|
|
|
2003-09-27 14:47:17 +04:00
|
|
|
if (strcmp(dev, rootdev) != 0)
|
|
|
|
return 0;
|
1997-12-02 06:02:29 +03:00
|
|
|
|
2018-11-09 18:20:36 +03:00
|
|
|
if (ptn < 0)
|
|
|
|
return 1; /* device only check, or wedge */
|
|
|
|
|
2003-09-27 14:47:17 +04:00
|
|
|
mib[1] = KERN_ROOT_PARTITION;
|
|
|
|
varlen = sizeof rootptn;
|
2018-11-09 18:20:36 +03:00
|
|
|
rootptn = -1;
|
2003-09-27 14:47:17 +04:00
|
|
|
if (sysctl(mib, 2, &rootptn, &varlen, NULL, 0) < 0)
|
|
|
|
return 1;
|
1997-11-09 15:47:06 +03:00
|
|
|
|
2003-09-27 14:47:17 +04:00
|
|
|
return ptn == rootptn;
|
1997-11-03 12:47:00 +03:00
|
|
|
}
|
|
|
|
|
1997-11-02 11:12:06 +03:00
|
|
|
/*
|
|
|
|
* Pathname prefixing glue to support installation either
|
|
|
|
* from in-ramdisk miniroots or on-disk diskimages.
|
|
|
|
* If our root is on the target disk, the install target is mounted
|
2003-07-07 16:30:19 +04:00
|
|
|
* on /targetroot and we need to prefix installed pathnames with /targetroot.
|
1997-11-02 11:12:06 +03:00
|
|
|
* otherwise we are installing to the currently-active root and
|
|
|
|
* no prefix is needed.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
const char *
|
2003-06-16 23:42:13 +04:00
|
|
|
target_prefix(void)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX fetch sysctl variable for current root, and compare
|
1998-06-20 17:05:48 +04:00
|
|
|
* to the devicename of the install target disk.
|
1997-11-02 11:12:06 +03:00
|
|
|
*/
|
2003-07-07 16:30:19 +04:00
|
|
|
return(target_already_root() ? "" : targetroot_mnt);
|
1997-11-02 11:12:06 +03:00
|
|
|
}
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/*
|
|
|
|
* concatenate two pathnames.
|
|
|
|
* XXX returns either input args or result in a static buffer.
|
|
|
|
* The caller must copy if it wants to use the pathname past the
|
|
|
|
* next call to a target-prefixing function, or to modify the inputs..
|
|
|
|
* Used only internally so this is probably safe.
|
|
|
|
*/
|
2003-06-16 23:42:13 +04:00
|
|
|
const char *
|
|
|
|
concat_paths(const char *prefix, const char *suffix)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
2003-01-10 23:00:27 +03:00
|
|
|
static char real_path[MAXPATHLEN];
|
1997-11-03 05:38:41 +03:00
|
|
|
|
|
|
|
/* absolute prefix and null suffix? */
|
|
|
|
if (prefix[0] == '/' && suffix[0] == 0)
|
|
|
|
return prefix;
|
|
|
|
|
|
|
|
/* null prefix and absolute suffix? */
|
|
|
|
if (prefix[0] == 0 && suffix[0] == '/')
|
|
|
|
return suffix;
|
|
|
|
|
|
|
|
/* avoid "//" */
|
|
|
|
if (suffix[0] == '/' || suffix[0] == 0)
|
2003-01-10 23:00:27 +03:00
|
|
|
snprintf(real_path, sizeof(real_path), "%s%s", prefix, suffix);
|
1997-11-03 05:38:41 +03:00
|
|
|
else
|
2003-01-10 23:00:27 +03:00
|
|
|
snprintf(real_path, sizeof(real_path), "%s/%s",
|
|
|
|
prefix, suffix);
|
|
|
|
return (real_path);
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do target prefix expansion on a pathname.
|
|
|
|
* XXX uses concat_paths and so returns result in a static buffer.
|
|
|
|
* The caller must copy if it wants to use the pathname past the
|
|
|
|
* next call to a target-prefixing function, or to modify the inputs..
|
|
|
|
* Used only internally so this is probably safe.
|
1997-11-04 04:39:03 +03:00
|
|
|
*
|
|
|
|
* Not static so other functions can generate target related file names.
|
1997-11-03 05:38:41 +03:00
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
const char *
|
2003-06-16 23:42:13 +04:00
|
|
|
target_expand(const char *tgtpath)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
return concat_paths(target_prefix(), tgtpath);
|
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
/* Make a directory, with a prefix like "/targetroot" or possibly just "". */
|
1997-11-02 11:12:06 +03:00
|
|
|
static void
|
2003-06-16 23:42:13 +04:00
|
|
|
make_prefixed_dir(const char *prefix, const char *path)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/bin/mkdir -p %s", concat_paths(prefix, path));
|
1997-11-02 11:12:06 +03:00
|
|
|
}
|
|
|
|
|
2000-12-05 01:47:02 +03:00
|
|
|
/* Make a directory with a pathname relative to the installation target. */
|
1997-11-02 11:12:06 +03:00
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
make_target_dir(const char *path)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-02 11:12:06 +03:00
|
|
|
make_prefixed_dir(target_prefix(), path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
static int
|
2003-06-16 23:42:13 +04:00
|
|
|
do_target_chdir(const char *dir, int must_succeed)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
1997-11-03 05:38:41 +03:00
|
|
|
const char *tgt_dir;
|
1997-11-11 03:43:31 +03:00
|
|
|
int error;
|
1997-11-02 11:12:06 +03:00
|
|
|
|
1997-11-11 03:43:31 +03:00
|
|
|
error = 0;
|
1997-11-03 05:38:41 +03:00
|
|
|
tgt_dir = target_expand(dir);
|
1997-11-02 11:12:06 +03:00
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("target_chdir (%s)\n", tgt_dir);
|
|
|
|
//return (0);
|
|
|
|
#endif
|
1997-11-05 10:28:20 +03:00
|
|
|
/* chdir returns -1 on error and sets errno. */
|
1998-06-20 17:05:48 +04:00
|
|
|
if (chdir(tgt_dir) < 0)
|
1997-11-05 10:28:20 +03:00
|
|
|
error = errno;
|
2012-01-06 01:29:24 +04:00
|
|
|
if (logfp) {
|
2002-12-05 04:17:15 +03:00
|
|
|
fprintf(logfp, "cd to %s\n", tgt_dir);
|
|
|
|
fflush(logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
2012-01-06 01:29:24 +04:00
|
|
|
if (script) {
|
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, "cd %s\n", tgt_dir);
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(script);
|
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-02 11:12:06 +03:00
|
|
|
if (error && must_succeed) {
|
2019-06-12 09:20:17 +03:00
|
|
|
const char *args[] = { target_prefix(), strerror(error) };
|
|
|
|
char *err = str_arg_subst(msg_string(MSG_realdir),
|
|
|
|
__arraycount(args), args);
|
|
|
|
fprintf(stderr, "%s\n", err);
|
2012-01-06 01:29:24 +04:00
|
|
|
if (logfp)
|
2019-06-12 09:20:17 +03:00
|
|
|
fprintf(logfp, "%s\n", err);
|
|
|
|
free(err);
|
1997-11-02 11:12:06 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
2006-01-13 01:02:44 +03:00
|
|
|
errno = error;
|
1997-11-02 11:12:06 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
target_chdir_or_die(const char *dir)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2003-06-16 23:42:13 +04:00
|
|
|
(void)do_target_chdir(dir, 1);
|
1997-11-02 11:12:06 +03:00
|
|
|
}
|
|
|
|
|
2003-01-10 23:00:27 +03:00
|
|
|
#ifdef notdef
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_chdir(const char *dir)
|
1997-11-02 11:12:06 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2003-06-16 23:42:13 +04:00
|
|
|
return do_target_chdir(dir, 0);
|
1997-11-02 11:12:06 +03:00
|
|
|
}
|
2003-01-10 23:00:27 +03:00
|
|
|
#endif
|
1997-11-03 02:43:11 +03:00
|
|
|
|
1998-02-20 05:33:51 +03:00
|
|
|
/*
|
|
|
|
* Copy a file from the current root into the target system,
|
|
|
|
* where the destination pathname is relative to the target root.
|
|
|
|
* Does not check for copy-to-self when target is current root.
|
|
|
|
*/
|
1999-04-09 14:24:38 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
cp_to_target(const char *srcpath, const char *tgt_path)
|
1998-02-20 05:33:51 +03:00
|
|
|
{
|
2003-01-10 23:00:27 +03:00
|
|
|
const char *real_path = target_expand(tgt_path);
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
return run_program(0, "/bin/cp %s %s", srcpath, real_path);
|
1998-02-20 05:33:51 +03:00
|
|
|
}
|
|
|
|
|
1997-11-03 02:43:11 +03:00
|
|
|
/*
|
|
|
|
* Duplicate a file from the current root to the same pathname
|
1998-02-20 05:33:51 +03:00
|
|
|
* in the target system. Pathname must be an absolute pathname.
|
1997-11-03 02:43:11 +03:00
|
|
|
* If we're running in the target, do nothing.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
dup_file_into_target(const char *filename)
|
1997-11-03 02:43:11 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
|
|
|
if (!target_already_root())
|
1998-02-20 05:33:51 +03:00
|
|
|
cp_to_target(filename, filename);
|
1997-11-03 02:43:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
2003-11-30 17:36:43 +03:00
|
|
|
* Do a mv where both pathnames are within the target filesystem.
|
1998-06-20 17:05:48 +04:00
|
|
|
*/
|
2000-09-08 06:50:42 +04:00
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
mv_within_target_or_die(const char *frompath, const char *topath)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
|
|
|
char realfrom[STRSIZE];
|
|
|
|
char realto[STRSIZE];
|
|
|
|
|
2006-01-13 01:02:44 +03:00
|
|
|
strlcpy(realfrom, target_expand(frompath), sizeof realfrom);
|
|
|
|
strlcpy(realto, target_expand(topath), sizeof realto);
|
1997-11-03 05:38:41 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(RUN_FATAL, "mv %s %s", realfrom, realto);
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
/* Do a cp where both pathnames are within the target filesystem. */
|
2003-06-25 19:45:21 +04:00
|
|
|
int
|
2003-12-28 08:30:47 +03:00
|
|
|
cp_within_target(const char *frompath, const char *topath, int optional)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
|
|
|
char realfrom[STRSIZE];
|
|
|
|
char realto[STRSIZE];
|
|
|
|
|
Pull up following revision(s) (requested by martin in ticket #1113):
usr.sbin/sysinst/bsddisklabel.c: revision 1.46
usr.sbin/sysinst/bsddisklabel.c: revision 1.47
usr.sbin/sysinst/disklabel.c: revision 1.40
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.13
usr.sbin/sysinst/bsddisklabel.c: revision 1.48
usr.sbin/sysinst/disklabel.c: revision 1.41
usr.sbin/sysinst/arch/cobalt/md.c: revision 1.14
usr.sbin/sysinst/bsddisklabel.c: revision 1.49
usr.sbin/sysinst/disklabel.c: revision 1.42
usr.sbin/sysinst/Makefile.inc: revision 1.34
usr.sbin/sysinst/disks.c: revision 1.70
usr.sbin/sysinst/arch/hp300/md.c: revision 1.11
usr.sbin/sysinst/disks.c: revision 1.71
usr.sbin/sysinst/arch/i386/md.h: revision 1.8
usr.sbin/sysinst/arch/arc/md.c: revision 1.13
usr.sbin/sysinst/mbr.h: revision 1.5
usr.sbin/sysinst/mbr.h: revision 1.6
usr.sbin/sysinst/arch/mac68k/md.c: revision 1.10
usr.sbin/sysinst/bsddisklabel.c: revision 1.50
usr.sbin/sysinst/arch/acorn32/md.c: revision 1.7
usr.sbin/sysinst/bsddisklabel.c: revision 1.51
usr.sbin/sysinst/bsddisklabel.c: revision 1.52
usr.sbin/sysinst/bsddisklabel.c: revision 1.53
usr.sbin/sysinst/bsddisklabel.c: revision 1.54
usr.sbin/sysinst/bsddisklabel.c: revision 1.55
usr.sbin/sysinst/bsddisklabel.c: revision 1.56
usr.sbin/sysinst/arch/dummy/md.c: revision 1.6
usr.sbin/sysinst/arch/amd64/md.h: revision 1.9
usr.sbin/sysinst/arch/evbsh3/md.c: revision 1.6
usr.sbin/sysinst/arch/sparc/md.c: revision 1.6
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.10
usr.sbin/sysinst/arch/x68k/md.c: revision 1.11
usr.sbin/sysinst/arch/sandpoint/md.c: revision 1.9
usr.sbin/sysinst/arch/vax/md.c: revision 1.7
usr.sbin/sysinst/arch/luna68k/md.c: revision 1.9
usr.sbin/sysinst/gpt.c: revision 1.19
usr.sbin/sysinst/arch/i386/md.c: revision 1.31
usr.sbin/sysinst/arch/i386/md.c: revision 1.32
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.17
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.18
usr.sbin/sysinst/arch/evbarm/md.c: revision 1.19
usr.sbin/sysinst/arch/shark/md.c: revision 1.6
usr.sbin/sysinst/arch/landisk/md.c: revision 1.14
usr.sbin/sysinst/util.c: revision 1.43
usr.sbin/sysinst/gpt.c: revision 1.20
usr.sbin/sysinst/util.c: revision 1.44
usr.sbin/sysinst/gpt.c: revision 1.21
usr.sbin/sysinst/gpt.c: revision 1.22
usr.sbin/sysinst/arch/evbarm/msg.md.en: revision 1.2
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.11
usr.sbin/sysinst/util.c: revision 1.46
usr.sbin/sysinst/arch/ofppc/md.c: revision 1.12
usr.sbin/sysinst/util.c: revision 1.47
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.6
usr.sbin/sysinst/util.c: revision 1.48
usr.sbin/sysinst/arch/evbarm/md.h: revision 1.7
usr.sbin/sysinst/arch/evbmips/md.c: revision 1.9
usr.sbin/sysinst/msg.mi.fr: revision 1.28
usr.sbin/sysinst/msg.mi.fr: revision 1.29
usr.sbin/sysinst/arch/sgimips/md.c: revision 1.9
usr.sbin/sysinst/arch/evbarm/Makefile: revision 1.3
usr.sbin/sysinst/msg.mi.de: revision 1.23
usr.sbin/sysinst/arch/hpcsh/md.c: revision 1.10
usr.sbin/sysinst/msg.mi.de: revision 1.24
usr.sbin/sysinst/install.c: revision 1.15
usr.sbin/sysinst/install.c: revision 1.16
usr.sbin/sysinst/arch/sparc64/md.c: revision 1.6
usr.sbin/sysinst/install.c: revision 1.17
usr.sbin/sysinst/install.c: revision 1.18
usr.sbin/sysinst/partitions.h: revision 1.16
usr.sbin/sysinst/install.c: revision 1.19
usr.sbin/sysinst/partitions.h: revision 1.17
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.9
usr.sbin/sysinst/arch/playstation2/md.c: revision 1.9
usr.sbin/sysinst/partitions.h: revision 1.18
usr.sbin/sysinst/arch/hpcarm/md.c: revision 1.9
usr.sbin/sysinst/partitions.h: revision 1.19
usr.sbin/sysinst/msg.mi.es: revision 1.24
usr.sbin/sysinst/msg.mi.es: revision 1.25
usr.sbin/sysinst/msg.mi.es: revision 1.26
usr.sbin/sysinst/arch/zaurus/md.c: revision 1.9
usr.sbin/sysinst/target.c: revision 1.13
usr.sbin/sysinst/target.c: revision 1.14
usr.sbin/sysinst/part_edit.c: revision 1.17
usr.sbin/sysinst/part_edit.c: revision 1.18
usr.sbin/sysinst/msg.mi.fr: revision 1.30
usr.sbin/sysinst/arch/mvme68k/md.c: revision 1.11
usr.sbin/sysinst/part_edit.c: revision 1.19
usr.sbin/sysinst/msg.mi.fr: revision 1.31
usr.sbin/sysinst/arch/alpha/md.c: revision 1.9
usr.sbin/sysinst/msg.mi.en: revision 1.30
usr.sbin/sysinst/defs.h: revision 1.56
usr.sbin/sysinst/msg.mi.en: revision 1.31
usr.sbin/sysinst/defs.h: revision 1.57
usr.sbin/sysinst/msg.mi.en: revision 1.32
usr.sbin/sysinst/arch/amiga/md.c: revision 1.6
usr.sbin/sysinst/arch/hpcmips/md.c: revision 1.9
usr.sbin/sysinst/defs.h: revision 1.58
usr.sbin/sysinst/arch/cats/md.c: revision 1.5
usr.sbin/sysinst/defs.h: revision 1.59
usr.sbin/sysinst/arch/newsmips/md.c: revision 1.6
usr.sbin/sysinst/arch/pmax/md.c: revision 1.8
usr.sbin/sysinst/arch/mipsco/md.c: revision 1.8
usr.sbin/sysinst/part_edit.c: revision 1.20
usr.sbin/sysinst/part_edit.c: revision 1.21
usr.sbin/sysinst/arch/macppc/md.c: revision 1.6
usr.sbin/sysinst/part_edit.c: revision 1.22
usr.sbin/sysinst/part_edit.c: revision 1.23
usr.sbin/sysinst/part_edit.c: revision 1.24
usr.sbin/sysinst/defs.h: revision 1.60
usr.sbin/sysinst/arch/mac68k/Makefile: revision 1.3
usr.sbin/sysinst/defs.h: revision 1.61
usr.sbin/sysinst/defs.h: revision 1.63
usr.sbin/sysinst/defs.h: revision 1.64
usr.sbin/sysinst/defs.h: revision 1.65
usr.sbin/sysinst/label.c: revision 1.21
usr.sbin/sysinst/defs.h: revision 1.66
usr.sbin/sysinst/label.c: revision 1.22
usr.sbin/sysinst/defs.h: revision 1.67
usr.sbin/sysinst/label.c: revision 1.23
usr.sbin/sysinst/label.c: revision 1.24
usr.sbin/sysinst/label.c: revision 1.25
usr.sbin/sysinst/label.c: revision 1.26
usr.sbin/sysinst/label.c: revision 1.27
usr.sbin/sysinst/msg.mi.pl: revision 1.31
usr.sbin/sysinst/label.c: revision 1.28
usr.sbin/sysinst/msg.mi.pl: revision 1.32
usr.sbin/sysinst/label.c: revision 1.29
usr.sbin/sysinst/arch/atari/md.c: revision 1.7
usr.sbin/sysinst/disklabel.c: revision 1.36
usr.sbin/sysinst/disklabel.c: revision 1.37
usr.sbin/sysinst/disklabel.c: revision 1.38
usr.sbin/sysinst/disklabel.c: revision 1.39
usr.sbin/sysinst/arch/bebox/md.c: revision 1.9
usr.sbin/sysinst/mbr.c: revision 1.32
usr.sbin/sysinst/disks.c: revision 1.66
usr.sbin/sysinst/mbr.c: revision 1.33
usr.sbin/sysinst/disks.c: revision 1.67
usr.sbin/sysinst/mbr.c: revision 1.34
usr.sbin/sysinst/arch/emips/md.c: revision 1.9
usr.sbin/sysinst/disks.c: revision 1.68
usr.sbin/sysinst/partitions.c: revision 1.11
usr.sbin/sysinst/mbr.c: revision 1.35
usr.sbin/sysinst/disks.c: revision 1.69
usr.sbin/sysinst/mbr.c: revision 1.36
usr.sbin/sysinst/arch/hppa/md.c: revision 1.8
usr.sbin/sysinst/arch/prep/md.c: revision 1.13
usr.sbin/sysinst/label.c: revision 1.30
usr.sbin/sysinst/arch/ews4800mips/md.c: revision 1.7
usr.sbin/sysinst/main.c: revision 1.21
usr.sbin/sysinst/main.c: revision 1.22
usr.sbin/sysinst/main.c: revision 1.23
usr.sbin/sysinst/bsddisklabel.c: revision 1.40
usr.sbin/sysinst/main.c: revision 1.24
usr.sbin/sysinst/arch/cobalt/md.h: revision 1.6
usr.sbin/sysinst/bsddisklabel.c: revision 1.41
usr.sbin/sysinst/main.c: revision 1.25
usr.sbin/sysinst/arch/news68k/md.c: revision 1.7
usr.sbin/sysinst/bsddisklabel.c: revision 1.42
usr.sbin/sysinst/bsddisklabel.c: revision 1.43
usr.sbin/sysinst/bsddisklabel.c: revision 1.44
usr.sbin/sysinst/bsddisklabel.c: revision 1.45
Use strlcpy in a few places to guarnatee 0-terminated strings
Rever previous: the d_packname in struct disklabel is not NUL terminated.
Disable the warning instead.
Do not force -Os optimization (unless SMALLPROG)
Remove unused "rel" global variable and make the -r option a no-op.
PR 55045: strlcpy(NULL, ..., 0) considered harmfull in some implementations.
PR misc/54886: bump threshold for automatic/default creation of a tmpfs /tmp
up slightly (to 384 MB ram). This will make sure the default install has
a > 64 MB /tmp available (number pulled out of thin air, 64 MB is the minimum
required by the ZFS tests).
Don't depend on common symbol definitions.
boardype should not be common.
Redo the root-size-limit check again after we grew the root partition
for kernel dumps. Auto-enable the /usr partition if it overflows.
For all non-root partitions, default to FFSv2.
When extending a partition (to fill the total disk size) do respect
size limits.
Do not suggest a size limited partition for extension by default.
Minor tweak to previous: when forcing a /usr partition just to have an
arbitrary extendable partition, still use its default size initially.
At the end of a new installation save entropy.
Ooops, backout previous - twice the entropy saving is not needed.
Instead slightly improve the (slightly) hidden other code that already
did it.
PR 55202: disable swapping if we started it due to low ram
it's "its"
Remove "If you booted from a floppy" message
Set HAVE_INSTALL_IMAGE for evbarm
Change mountpoint of boot ext2fs from /stand to /ext2 to avoid conflict.
Should be pulled up to netbsd-9, with fixes of PR/55060.
MBR type for Ext2 should be MBR_PTYPE_LNXEXT2, not MBR_PTYPE_FAT12.
Silence -Wstringop-truncation for ``name'' in disp_selected_part().
This variable is used only for display, and truncation seems harmless.
PR 55572: avoid crash when answering the mount point prompt for a previously
empty mount point with an emptry sting.
When adding a new partition in the concrete partition editor, make sure
to set a pointer to the partition table interface in the new entry.
Otherwise we may end up not writing back the partitions at all, leading
to further fallout later.
Receipe to reproduce the issue from Frederic Fauberteau, thanks!
In the concrete partitions editor, after deleting the last partition move
the menu selection to the "add a partition" entry (instead of the sentinel
line which is not an active menu entry).
Typo in comment
Keep a list of all partition tables from which we have deleted partitions
and make sure we update those partition tables when writing partitions,
even if no install related partition remains on them.
Fix display of timezone selection menu
If there is no current partitioning manager assume we are editing the
current system and make target_already_root() return true.
Fixes various fallout when using sysinst post installation.
PR 55377: mark boot partitions in the partition size display, as suggested
by Izumi Tsutsui (minor modifications + all bugs by me)
PR 55378: do not assume RAW_PART to be either 2 or 3
PR 55379: avoid creating bogus /etc/fstab lines for /dev/cd* if no
cdrom is available.
PR 55381: try to deal with moved (but not yet saved) partitions when
calculating free space
Apply patch provided by Izumi Tsutsui in PR 55382: make ext2 partitions
show up in the outer (MBR) partition table, needed for example on Cobalt
where firmware boots from that partition.
PR 55384: detangle pm->ptstart from the "install" flag (selecting a
target partition). Instead introduce a new PTI_INSTALL_TARGET per partition
flag and deal with it in the partitioning backends.
Honour pm->ptstart when allocating new partitions - it is supposed to be
the first sector usable by NetBSD.
If we have no explicitly marke target root partition, make sure to set
the proper flag on the implicit one.
When merging existing partitions with desired target system layout
information, only force the "mount" flag if the existing partitions
has a valid mount point.
Add a heuristic to detect and properly mark EFI system partitions
when re-using pre-existing partitions.
When MD code requests a reserved area (at the start of the disk)
make sure to properly account for the "lost" space during all calculations
and especially when expanding the main partition to fill the disk.
Avoid using the global "pm" or a passed device descriptons when we are
passing disk limits explicitly anyway.
Simplify/fix a few rounding calculations.
When creating new partitions for "full disk" use, pass a install target
hint to the partitioning backend (for the outer NetBSD partition).
Use an install target hint to mark a new partition active.
When compiled with BOOTSEL support, also name the new partition "NetBSD".
Remove more pm->ptstart abuse - calculate values localy where needed
instead.
Fix editing start and size of not yet existing outer partitions.
Previously we abused pm->ptstart / pm->ptsize to pass the bounds of the
NetBSD outer partition to the inner partition editor - but now this is
not a valid assumption any more, so explicitly fix the bounds if an
outer partition exists.
Remove very strange code that special-cased MSDOS file systems and refused
to newfs the partition (despite explicit request to do so) if it was
mountable.
Accidently carried over from a dim and distant past, before we had
fsck_newfs.
PR 55536: when we find existing partition tables and have alternative
formats available, offer to delete partitions and create new ones from
scratch (in some other or the same on-disk format).
Minor fix to previous: fix condition when we offer the partition type
switch - it makes sense even if the disk is partitioned but has no valid
partitions.
Before forcing MBR partitions into our disklabel, make sure they are not
there yet - could happen in various paths when reusing existing partitions
(or parts of that) - previously we would blindly duplicate identical
partitions.
Ooops, part of previous was not meant to be included yet
When renumbering partitions (after deletions) be slightly more lax
in matching, to cope with differences between MBR EFI partitions and
disklabel MSDOS partitions.
PR 55142: on popular demand bring back expert options to adjust the
number of free inodes, block size and fragment size for FFS and LFS.
Fix copy & pasto noticed by Jason Mitchell: change the type of a GPT
partition via "gpt type" - not "gpt label".
Fix copy & pasto (missing "again" label)
Remove dead code
Move MBR writing (if any) post disklabel writing, otherwise strange
interactions happen.
Properly convert partition default sizes in MB to number of sectors
2020-10-15 22:36:50 +03:00
|
|
|
strlcpy(realfrom, target_expand(frompath), sizeof realfrom);
|
|
|
|
strlcpy(realto, target_expand(topath), sizeof realto);
|
1997-11-05 10:28:20 +03:00
|
|
|
|
2003-12-28 08:30:47 +03:00
|
|
|
if (access(realfrom, R_OK) == -1 && optional)
|
|
|
|
return 0;
|
2003-11-30 17:36:43 +03:00
|
|
|
return (run_program(0, "cp -p %s %s", realfrom, realto));
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* fopen a pathname in the target. */
|
1998-06-20 17:05:48 +04:00
|
|
|
FILE *
|
2003-06-16 23:42:13 +04:00
|
|
|
target_fopen(const char *filename, const char *type)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
return fopen(target_expand(filename), type);
|
|
|
|
}
|
|
|
|
|
1997-12-04 12:05:35 +03:00
|
|
|
/*
|
2003-11-30 17:36:43 +03:00
|
|
|
* Do a mount onto a mountpoint in the install target.
|
|
|
|
* Record mountpoint so we can unmount when finished.
|
|
|
|
* NB: does not prefix mount-from, which probably breaks nullfs mounts.
|
1997-12-04 12:05:35 +03:00
|
|
|
*/
|
|
|
|
int
|
2014-08-03 20:09:38 +04:00
|
|
|
target_mount_do(const char *opts, const char *from, const char *on)
|
1997-12-04 12:05:35 +03:00
|
|
|
{
|
2003-11-30 17:36:43 +03:00
|
|
|
struct unwind_mount *m;
|
1997-12-04 12:05:35 +03:00
|
|
|
int error;
|
2003-11-30 17:36:43 +03:00
|
|
|
int len;
|
1997-12-04 12:05:35 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
len = strlen(on);
|
|
|
|
m = malloc(sizeof *m + len);
|
1997-12-04 12:05:35 +03:00
|
|
|
if (m == 0)
|
|
|
|
return (ENOMEM); /* XXX */
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
memcpy(m->um_mountpoint, on, len + 1);
|
1997-12-04 12:05:35 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG_UNWIND
|
|
|
|
endwin();
|
|
|
|
fprintf(stderr, "mounting %s with unwind\n", on);
|
|
|
|
backtowin();
|
|
|
|
#endif
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
error = run_program(0, "/sbin/mount %s %s %s%s",
|
|
|
|
opts, from, target_prefix(), on);
|
2003-11-30 17:36:43 +03:00
|
|
|
if (error) {
|
|
|
|
free(m);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
m->um_prev = unwind_mountlist;
|
|
|
|
unwind_mountlist = m;
|
|
|
|
return 0;
|
1997-12-04 12:05:35 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 08:51:43 +03:00
|
|
|
/*
|
|
|
|
* Special case - we have mounted the target / readonly
|
|
|
|
* to peek at etc/fstab, and now want it undone.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
umount_root(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* verify this is the only mount */
|
|
|
|
if (unwind_mountlist == NULL)
|
|
|
|
return;
|
|
|
|
if (unwind_mountlist->um_prev != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (run_program(0, "/sbin/umount %s", target_prefix()) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(unwind_mountlist);
|
|
|
|
unwind_mountlist = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-03 20:09:38 +04:00
|
|
|
int
|
2019-06-12 09:20:17 +03:00
|
|
|
target_mount(const char *opts, const char *from, const char *on)
|
2014-08-03 20:09:38 +04:00
|
|
|
{
|
2019-06-12 09:20:17 +03:00
|
|
|
return target_mount_do(opts, from, on);
|
2014-08-03 20:09:38 +04:00
|
|
|
}
|
|
|
|
|
2022-02-14 09:45:34 +03:00
|
|
|
int
|
|
|
|
target_unmount(const char *mount_point)
|
|
|
|
{
|
|
|
|
struct unwind_mount *m, *prev = NULL;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
for (m = unwind_mountlist; m != NULL; prev = m, m = m->um_prev)
|
|
|
|
if (strcmp(m->um_mountpoint, mount_point) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
return ENOTDIR;
|
|
|
|
|
|
|
|
error = run_program(0, "/sbin/umount %s%s",
|
|
|
|
target_prefix(), m->um_mountpoint);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (m == unwind_mountlist)
|
|
|
|
unwind_mountlist = m->um_prev;
|
|
|
|
else
|
|
|
|
prev->um_prev = m->um_prev;
|
|
|
|
free(m);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-02 07:25:36 +03:00
|
|
|
static bool
|
|
|
|
delete_wedge(const char *disk, const char *wedge)
|
|
|
|
{
|
|
|
|
struct dkwedge_info dkw;
|
|
|
|
char diskpath[MAXPATHLEN];
|
|
|
|
int fd, error;
|
|
|
|
|
|
|
|
fd = opendisk(disk, O_RDWR, diskpath, sizeof(diskpath), 0);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
memset(&dkw, 0, sizeof(dkw));
|
|
|
|
strlcpy(dkw.dkw_devname, wedge, sizeof(dkw.dkw_devname));
|
|
|
|
error = ioctl(fd, DIOCDWEDGE, &dkw);
|
|
|
|
close(fd);
|
|
|
|
return error == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
register_post_umount_delwedge(const char *disk, const char *wedge)
|
|
|
|
{
|
|
|
|
struct umount_delwedge *dw;
|
|
|
|
|
|
|
|
if (unwind_mountlist == NULL) {
|
|
|
|
/* we have nothing mounted, can delete it right now */
|
|
|
|
delete_wedge(disk, wedge);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dw = calloc(1, sizeof(*dw));
|
|
|
|
dw->next = post_umount_dwlist;
|
|
|
|
strlcpy(dw->disk, disk, sizeof(dw->disk));
|
|
|
|
strlcpy(dw->wedge, wedge, sizeof(dw->wedge));
|
|
|
|
post_umount_dwlist = dw;
|
|
|
|
}
|
|
|
|
|
1997-12-04 12:05:35 +03:00
|
|
|
/*
|
2000-12-05 01:47:02 +03:00
|
|
|
* unwind the mount stack, unmounting mounted filesystems.
|
1997-12-04 12:05:35 +03:00
|
|
|
* For now, ignore any errors in unmount.
|
|
|
|
* (Why would we be unable to unmount? The user has suspended
|
|
|
|
* us and forked shell sitting somewhere in the target root?)
|
|
|
|
*/
|
|
|
|
void
|
2003-06-16 23:42:13 +04:00
|
|
|
unwind_mounts(void)
|
1997-12-04 12:05:35 +03:00
|
|
|
{
|
2003-01-10 23:00:27 +03:00
|
|
|
struct unwind_mount *m;
|
2022-02-02 07:25:36 +03:00
|
|
|
struct umount_delwedge *dw;
|
2006-10-23 23:44:57 +04:00
|
|
|
static volatile int unwind_in_progress = 0;
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
/* signal safety */
|
|
|
|
if (unwind_in_progress)
|
|
|
|
return;
|
|
|
|
unwind_in_progress = 1;
|
1997-12-04 12:05:35 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
while ((m = unwind_mountlist) != NULL) {
|
|
|
|
unwind_mountlist = m->um_prev;
|
1997-12-04 12:05:35 +03:00
|
|
|
#ifdef DEBUG_UNWIND
|
|
|
|
endwin();
|
|
|
|
fprintf(stderr, "unmounting %s\n", m->um_mountpoint);
|
|
|
|
backtowin();
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/sbin/umount %s%s",
|
|
|
|
target_prefix(), m->um_mountpoint);
|
1997-12-04 12:05:35 +03:00
|
|
|
free(m);
|
|
|
|
}
|
2022-02-02 07:25:36 +03:00
|
|
|
while ((dw = post_umount_dwlist) != NULL) {
|
|
|
|
post_umount_dwlist = dw->next;
|
|
|
|
delete_wedge(dw->disk, dw->wedge);
|
|
|
|
free(dw);
|
|
|
|
}
|
1997-12-05 17:00:59 +03:00
|
|
|
unwind_in_progress = 0;
|
1997-12-04 12:05:35 +03:00
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-07-25 12:26:21 +04:00
|
|
|
target_collect_file(int kind, char **buffer, const char *name)
|
1997-11-03 02:43:11 +03:00
|
|
|
{
|
2003-06-16 23:42:13 +04:00
|
|
|
const char *realname = target_expand(name);
|
1997-11-03 12:47:00 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("collect real name %s\n", realname);
|
|
|
|
#endif
|
2012-01-06 01:22:49 +04:00
|
|
|
return collect(kind, buffer, "%s", realname);
|
1997-11-03 02:43:11 +03:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify a pathname already exists in the target root filesystem,
|
|
|
|
* by running test "testflag" on the expanded target pathname.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_test(unsigned int mode, const char *path)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
2003-01-10 23:00:27 +03:00
|
|
|
const char *real_path = target_expand(path);
|
1997-11-05 10:28:20 +03:00
|
|
|
register int result;
|
|
|
|
|
2003-01-10 23:00:27 +03:00
|
|
|
result = !file_mode_match(real_path, mode);
|
|
|
|
scripting_fprintf(NULL, "if [ $? != 0 ]; then echo \"%s does not exist!\"; fi\n", real_path);
|
1997-11-05 10:28:20 +03:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2006-09-29 13:29:12 +04:00
|
|
|
printf("target_test(%o, %s) returning %d\n", mode, real_path, result);
|
1997-11-05 10:28:20 +03:00
|
|
|
#endif
|
1998-06-20 17:05:48 +04:00
|
|
|
return (result);
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify a directory already exists in the target root
|
|
|
|
* filesystem. Do not create the directory if it doesn't exist.
|
|
|
|
* Assumes that sysinst has already mounted the target root.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_test_dir(const char *path)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2000-09-26 17:26:02 +04:00
|
|
|
return target_test(S_IFDIR, path);
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify an ordinary file already exists in the target root
|
|
|
|
* filesystem. Do not create the directory if it doesn't exist.
|
|
|
|
* Assumes that sysinst has already mounted the target root.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_test_file(const char *path)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2000-09-26 17:26:02 +04:00
|
|
|
return target_test(S_IFREG, path);
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
1997-12-05 17:00:59 +03:00
|
|
|
|
2000-09-08 06:50:42 +04:00
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
target_test_symlink(const char *path)
|
2000-09-08 06:50:42 +04:00
|
|
|
{
|
|
|
|
|
2000-09-26 17:26:02 +04:00
|
|
|
return target_test(S_IFLNK, path);
|
2000-09-08 06:50:42 +04:00
|
|
|
}
|
|
|
|
|
2003-06-16 23:42:13 +04:00
|
|
|
int
|
|
|
|
target_file_exists_p(const char *path)
|
1997-12-05 17:00:59 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
return (target_test_file(path) == 0);
|
|
|
|
}
|
|
|
|
|
2003-06-16 23:42:13 +04:00
|
|
|
int
|
|
|
|
target_dir_exists_p(const char *path)
|
1997-12-05 17:00:59 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
return (target_test_dir(path) == 0);
|
|
|
|
}
|
2000-09-08 06:50:42 +04:00
|
|
|
|
2003-06-16 23:42:13 +04:00
|
|
|
int
|
|
|
|
target_symlink_exists_p(const char *path)
|
2000-09-08 06:50:42 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (target_test_symlink(path) == 0);
|
|
|
|
}
|
2012-04-07 03:48:53 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
target_mounted(void)
|
|
|
|
{
|
|
|
|
return (unwind_mountlist != NULL);
|
|
|
|
}
|