Home | History | Annotate | Line # | Download | only in sysinst
defs.h revision 1.52
      1 /*	$NetBSD: defs.h,v 1.52 2020/01/20 21:26:35 martin Exp $	*/
      2 
      3 /*
      4  * Copyright 1997 Piermont Information Systems Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Philip A. Nelson for Piermont Information Systems Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
     18  *    or promote products derived from this software without specific prior
     19  *    written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
     25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31  * THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  */
     34 
     35 #ifndef _DEFS_H_
     36 #define _DEFS_H_
     37 
     38 /* defs.h -- definitions for use in the sysinst program. */
     39 
     40 /* System includes needed for this. */
     41 #include <sys/queue.h>
     42 #include <sys/types.h>
     43 #include <sys/disk.h>
     44 #include <uuid.h>
     45 
     46 const char *getfslabelname(uint, uint);
     47 
     48 #include "msg_defs.h"
     49 #include "menu_defs.h"
     50 #include "partitions.h"
     51 
     52 #define min(a,b)	((a) < (b) ? (a) : (b))
     53 #define max(a,b)	((a) > (b) ? (a) : (b))
     54 
     55 /* constants */
     56 #define MEG (1024UL * 1024UL)
     57 #define GIG (1024UL * MEG)
     58 #define STRSIZE		255
     59 #define	MENUSTRSIZE	80
     60 #define SSTRSIZE	30
     61 
     62 #define	HUGE_DISK_SIZE	(daddr_t)(128 * (GIG / 512))
     63 #define	TINY_DISK_SIZE	(daddr_t)(1800 * (MEG / 512))
     64 
     65 /* helper macros to create unique internal error messages */
     66 #define STR_NO(STR)	#STR
     67 #define	TO_STR(NO)	STR_NO(NO)
     68 #define	INTERNAL_ERROR __FILE__ ":" TO_STR(__LINE__) ": internal error"
     69 
     70 /* For run.c: collect() */
     71 #define T_FILE		0
     72 #define T_OUTPUT	1
     73 
     74 /* Some install status/response values */
     75 #define	SET_OK		0		/* Set extracted */
     76 #define	SET_RETRY	1		/* Retry */
     77 #define	SET_SKIP	2		/* Skip this set */
     78 #define	SET_SKIP_GROUP	3		/* Skip this set and rest of group */
     79 #define	SET_ABANDON	4		/* Abandon installation */
     80 #define	SET_CONTINUE	5		/* Continue (copy from floppy loop) */
     81 
     82 /* run_prog flags */
     83 #define RUN_DISPLAY	0x0001		/* Display program output */
     84 #define RUN_FATAL	0x0002		/* errors are fatal */
     85 #define RUN_CHROOT	0x0004		/* chroot to target disk */
     86 #define RUN_FULLSCREEN	0x0008		/* fullscreen (use with RUN_DISPLAY) */
     87 #define RUN_SILENT	0x0010		/* Do not show output */
     88 #define RUN_ERROR_OK	0x0040		/* Don't wait for error confirmation */
     89 #define RUN_PROGRESS	0x0080		/* Output is just progess test */
     90 #define RUN_NO_CLEAR	0x0100		/* Leave program output after error */
     91 #define RUN_XFER_DIR	0x0200		/* cd to xfer_dir in child */
     92 
     93 /* for bsddisklabel.c */
     94 enum layout_type { LY_KEEPEXISTING, LY_SETSIZES, LY_USEDEFAULT, LY_USEFULL };
     95 enum setup_type { SY_NEWRAID, SY_NEWCGD, SY_NEWLVM };
     96 
     97 /* Installation sets */
     98 enum {
     99     SET_NONE,
    100     SET_KERNEL_FIRST,
    101     SET_KERNEL_1,	/* Usually GENERIC */
    102     SET_KERNEL_2,	/* MD kernel... */
    103     SET_KERNEL_3,	/* MD kernel... */
    104     SET_KERNEL_4,	/* MD kernel... */
    105     SET_KERNEL_5,	/* MD kernel... */
    106     SET_KERNEL_6,	/* MD kernel... */
    107     SET_KERNEL_7,	/* MD kernel... */
    108     SET_KERNEL_8,	/* MD kernel... */
    109     SET_KERNEL_9,	/* MD kernel... */
    110     SET_KERNEL_LAST,	/* allow 9 kernels */
    111 
    112     /* System sets */
    113     SET_BASE,		/* base */
    114     SET_ETC,		/* /etc */
    115     SET_COMPILER,	/* compiler tools */
    116     SET_GAMES,		/* text games */
    117     SET_MAN_PAGES,	/* online manual pages */
    118     SET_MISC,		/* miscellaneuous */
    119     SET_MODULES,	/* kernel modules */
    120     SET_RESCUE,		/* /rescue recovery tools */
    121     SET_TESTS,		/* tests */
    122     SET_TEXT_TOOLS,	/* text processing tools */
    123 
    124     /* X11 sets */
    125     SET_X11_FIRST,
    126     SET_X11_BASE,	/* X11 base and clients */
    127     SET_X11_FONTS,	/* X11 fonts */
    128     SET_X11_SERVERS,	/* X11 servers */
    129     SET_X11_PROG,	/* X11 programming */
    130     SET_X11_ETC,	/* X11 config */
    131     SET_X11_LAST,
    132 
    133     /* Machine dependent sets */
    134     SET_MD_1,		/* Machine dependent set */
    135     SET_MD_2,		/* Machine dependent set */
    136     SET_MD_3,		/* Machine dependent set */
    137     SET_MD_4,		/* Machine dependent set */
    138 
    139     /* Source sets */
    140     SET_SYSSRC,
    141     SET_SRC,
    142     SET_SHARESRC,
    143     SET_GNUSRC,
    144     SET_XSRC,
    145 
    146     /* Debug sets */
    147     SET_DEBUG,
    148     SET_X11_DEBUG,
    149 
    150     SET_LAST,
    151     SET_GROUP,		/* Start of submenu */
    152     SET_GROUP_END,	/* End of submenu */
    153     SET_PKGSRC,		/* pkgsrc, not counted as regular set */
    154 };
    155 
    156 /* Initialisers to select sets */
    157 /* All kernels */
    158 #define SET_KERNEL SET_KERNEL_1, SET_KERNEL_2, SET_KERNEL_3, SET_KERNEL_4, \
    159 		    SET_KERNEL_5, SET_KERNEL_6, SET_KERNEL_7, SET_KERNEL_8
    160 /* Core system sets */
    161 #define SET_CORE SET_MODULES, SET_BASE, SET_ETC
    162 /* All system sets */
    163 #define SET_SYSTEM SET_CORE, SET_COMPILER, SET_GAMES, \
    164 		    SET_MAN_PAGES, SET_MISC, SET_RESCUE, \
    165 		    SET_TESTS, SET_TEXT_TOOLS
    166 /* All X11 sets */
    167 #define SET_X11_NOSERVERS SET_X11_BASE, SET_X11_FONTS, SET_X11_PROG, SET_X11_ETC
    168 #define SET_X11 SET_X11_NOSERVERS, SET_X11_SERVERS
    169 
    170 /* All machine dependent sets */
    171 #define SET_MD SET_MD_1, SET_MD_2, SET_MD_3, SET_MD_4
    172 
    173 /* All source sets */
    174 #define SET_SOURCE SET_SYSSRC, SET_SRC, SET_SHARESRC, SET_GNUSRC, SET_XSRC
    175 
    176 /* All debug sets */
    177 #define SET_DEBUGGING SET_DEBUG, SET_X11_DEBUG
    178 
    179 /* Set list flags */
    180 #define SFLAG_MINIMAL	1
    181 #define	SFLAG_NOX	2
    182 
    183 /* Round up to the next full cylinder size */
    184 #define NUMSEC(size, sizemult, cylsize) \
    185 	((sizemult) == 1 ? (size) : \
    186 	 roundup((size) * (sizemult), (cylsize)))
    187 
    188 /* What FS type? */
    189 #define PI_ISBSDFS(PI) (PI_FSTYPE(PI) == FS_BSDLFS || \
    190 		        PI_FSTYPE(PI) == FS_BSDFFS)
    191 
    192 /*
    193  * We do not offer CDs or floppies as installation target usually.
    194  * Architectures might want to undefine if they want to allow
    195  * these devices or redefine if they have unusual CD device names.
    196  * Do not define to empty or an empty string, undefine instead.
    197  */
    198 #define CD_NAMES "cd*"
    199 #define FLOPPY_NAMES "fd*"
    200 
    201 /* Types */
    202 
    203 /* pass a void* argument into a menu and also provide a int return value */
    204 typedef struct arg_rv {
    205 	void *arg;
    206 	int rv;
    207 } arg_rv;
    208 
    209 /*
    210  * A minimal argument for menus using string replacements
    211  */
    212 typedef struct arg_replace {
    213 	const char **argv;
    214 	size_t argc;
    215 } arg_replace;
    216 
    217 /*
    218  * pass a parameter array (for string replacements) into a menu and provide
    219  * an integer return value
    220  */
    221 typedef struct arg_rep_int {
    222 	arg_replace args;
    223 	int rv;
    224 } arg_rep_int;
    225 
    226 typedef struct distinfo {
    227 	const char	*name;
    228 	uint		set;
    229 	bool		force_tgz;	/* this set is always in .tgz format */
    230 	const char	*desc;
    231 	const char	*marker_file;	/* set assumed installed if exists */
    232 } distinfo;
    233 
    234 #define MOUNTLEN 20
    235 
    236 
    237 /*
    238  * A description of a future partition and its usage.
    239  * A list of this is the output of the first stage partition
    240  * editor, before it gets transformed into a concrete partition
    241  * layout according to the partitioning scheme backend.
    242  */
    243 struct part_usage_info {
    244 	daddr_t	size;			/* thumb guestimate of size,
    245 					 * [sec if positive, %-of-ram
    246 					 * if TMPFS and negative]
    247 					 */
    248 	daddr_t def_size;		/* default size */
    249 	daddr_t limit;			/* max size */
    250 	char 	mount[MOUNTLEN];	/* where will we mount this? */
    251 	enum part_type type;		/* PT_root/PT_swap/PT_EFI_SYSTEM */
    252 
    253 #define	PUIFLAG_EXTEND		1	/* extend this part if free space
    254 					 * is available */
    255 #define	PUIFLAG_ADD_OUTER	2	/* Add this partition to the outer
    256 					 * partitions (if available) */
    257 #define	PUIFLG_IS_OUTER		4	/* this is an existing outer one */
    258 #define	PUIFLG_ADD_INNER	8	/* add outer also to inner */
    259 #define	PUIFLG_JUST_MOUNTPOINT	16	/* tmpfs of mfs mountpoints */
    260 #define	PUIFLG_CLONE_PARTS	32	/* clone external partitions */
    261 	uint flags;
    262 	struct disk_partitions *parts;	/* Where does this partition live?
    263 					 * We currently only support
    264 					 * a single disk, but we plan to
    265 					 * extend that.
    266 					 * Use pm->parts to access
    267 					 * the partitions. */
    268 	part_id cur_part_id;		/* this may change, but we try to
    269 					 * fix it up after all changes */
    270 	daddr_t cur_start;		/* may change during editing, just
    271 					 * used as a unique identifier */
    272 	uint32_t cur_flags;		/* PTI_* flags from disk_part_info */
    273 
    274 #define PUIMNT_ASYNC		0x0001	/* mount -o async */
    275 #define PUIMNT_NOATIME		0x0002	/* mount -o noatime */
    276 #define PUIMNT_NODEV		0x0004	/* mount -o nodev */
    277 #define PUIMNT_NODEVMTIME	0x0008	/* mount -o nodevmtime */
    278 #define PUIMNT_NOEXEC		0x0010	/* mount -o noexec */
    279 #define PUIMNT_NOSUID		0x0020	/* mount -o nosuid */
    280 #define PUIMNT_LOG		0x0040	/* mount -o log */
    281 #define PUIMNT_NOAUTO		0x0080	/* "noauto" fstab flag */
    282 	unsigned int mountflags;	/* flags for fstab */
    283 #define PUIINST_NEWFS	0x0001		/* need to 'newfs' partition */
    284 #define PUIINST_MOUNT	0x0002		/* need to mount partition */
    285 #define	PUIINST_BOOT	0x0004		/* this is a boot partition */
    286 	unsigned int instflags;		/* installer handling flags */
    287 	uint fs_type, fs_version;	/* e.g. FS_LFS, or FS_BSDFS,
    288 					 * version = 2 for FFSv2 */
    289 #ifndef	NO_CLONES
    290 	/*
    291 	 * Only != NULL when PUIFLG_CLONE_PARTS is set, describes the
    292 	 * source partitions to clone here.
    293 	 */
    294 	struct selected_partitions *clone_src;
    295 	/*
    296 	 * If clone_src != NULL, this record corresponds to a single
    297 	 * selected source partition, if clone_ndx is a valid index in clone_src
    298 	 * (>= 0 && <= clone_src->num_sel, or all of them if clone_ndx = ~0U.
    299 	 */
    300 	size_t clone_ndx;
    301 #endif
    302 };
    303 
    304 /*
    305  * A list of partition suggestions, bundled for editing
    306  */
    307 struct partition_usage_set {
    308 	struct disk_partitions *parts;
    309 	size_t num;
    310 	struct part_usage_info *infos;	/* 0 .. num-1 */
    311 	daddr_t cur_free_space;		/* estimate of free sectors */
    312 	menu_ent *menu_opts;		/* 0 .. num+N */
    313 	int menu;			/* the menu to edit this */
    314 	bool ok;			/* ok to continue (all fit) */
    315 };
    316 
    317 /*
    318  * A structure we pass around in menus that edit a single partition out
    319  * of a partition_usage_set.
    320  */
    321 struct single_part_fs_edit {
    322  	struct partition_usage_set *pset;
    323 	size_t index, first_custom_attr;
    324 	part_id id;
    325 	struct disk_part_info info;	/* current partition data */
    326 	struct part_usage_info *wanted;	/* points at our edit data */
    327 
    328 	/*
    329 	 * "Backup" of old data, so we can restore previous values
    330 	 * ("undo").
    331 	 */
    332 	struct part_usage_info old_usage;
    333 	struct disk_part_info old_info;
    334 
    335 	/* menu return value */
    336 	int rv;
    337 };
    338 
    339 /*
    340  * Description of a full target installation, all partitions and
    341  * devices (may be accross several struct pm_devs / disks).
    342  */
    343 struct install_partition_desc {
    344 	size_t num;				/* how many entries in infos */
    345 	struct part_usage_info *infos;		/* individual partitions */
    346 	bool cur_system;			/* target is the life system */
    347 };
    348 
    349 /* variables */
    350 
    351 int debug;		/* set by -D option */
    352 
    353 char rel[SSTRSIZE];
    354 char machine[SSTRSIZE];
    355 
    356 int ignorerror;
    357 int ttysig_ignore;
    358 pid_t ttysig_forward;
    359 int sizemult;
    360 extern const char *multname;
    361 extern const char *err_outofmem;
    362 int partman_go; /* run extended partition manager */
    363 
    364 /* logging variables */
    365 
    366 FILE *logfp;
    367 FILE *script;
    368 
    369 #define MAX_DISKS 15
    370 
    371 daddr_t root_limit;    /* BIOS (etc) read limit */
    372 
    373 enum SHRED_T { SHRED_NONE=0, SHRED_ZEROS, SHRED_RANDOM };
    374 
    375 /* All information that is unique for each drive */
    376 SLIST_HEAD(pm_head_t, pm_devs) pm_head;
    377 
    378 struct pm_devs {
    379 	/*
    380 	 * If device is blocked (e.g. part of a raid)
    381 	 * this is a pointers to the  parent dev
    382 	 */
    383 	void *refdev;
    384 
    385 	char diskdev[SSTRSIZE];		/* Actual name of the disk. */
    386 	char diskdev_descr[STRSIZE];	/* e.g. IDENTIFY result */
    387 
    388 	/*
    389 	 * What the disk layout should look like.
    390 	 */
    391 	struct disk_partitions *parts;
    392 
    393 	/*
    394 	 * The device does not take a MBR, even if we usually use
    395 	 * MBR master / disklabel secondary partitioning.
    396 	 * Used e.g. for raid* pseudo-disks.
    397 	 */
    398 	bool no_mbr;	/* userd for raid (etc) */
    399 
    400 	/*
    401 	 * This device can not be partitioned (in any way).
    402 	 * Used for wedges (dk*) or LVM devices.
    403 	 */
    404 	bool no_part;
    405 
    406 	/*
    407 	 * This is a pseudo-device representing the currently running
    408 	 * system (i.e. all mounted file systems).
    409 	 */
    410 	bool cur_system;
    411 
    412 	/* Actual values for current disk - set by find_disks() or
    413 	   md_get_info() */
    414 	int sectorsize, dlcyl, dlhead, dlsec, dlcylsize, current_cylsize;
    415 	daddr_t dlsize;
    416 
    417 	/* Area of disk we can allocate, start and size in disk sectors. */
    418 	daddr_t ptstart, ptsize;
    419 
    420 	/* For some bootblocks we need to know the CHS addressable limit */
    421 	daddr_t max_chs;	/* bcyl * bhead * bsec */
    422 
    423 	/* If we have an MBR boot partition, start and size in sectors */
    424 	daddr_t bootstart, bootsize;
    425 
    426 	/*
    427 	 * In extended partitioning: all partitions in parts (number of
    428 	 * entries is parts->num_part) may actually be mounted (temporarily)
    429 	 * somewhere, e.g. to access a vnd device on them. This list has
    430 	 * a pointer to the current mount point (strdup()'d) if mounted,
    431 	 * or NULL if not.
    432 	 */
    433 	char **mounted;
    434 
    435 	bool unsaved;	/* Flag indicating to partman that device need saving */
    436 	bool found;	/* Flag to delete unplugged and unconfigured devices */
    437 	int blocked;	/* Device is busy and cannot be changed */
    438 
    439 	SLIST_ENTRY(pm_devs) l;
    440 };
    441 struct pm_devs *pm; /* Pointer to current device with which we work */
    442 struct pm_devs *pm_new; /* Pointer for next allocating device in find_disks() */
    443 
    444 /* Generic structure for partman */
    445 struct part_entry {
    446 	part_id id;
    447 	struct disk_partitions *parts;
    448 	void *dev_ptr;
    449 	size_t index;	/* e.g. if PM_RAID: this is raids[index] */
    450 	int dev_ptr_delta;
    451 	char fullname[SSTRSIZE];
    452 	enum {PM_DISK=1, PM_PART, PM_SPEC,
    453 	    PM_RAID, PM_CGD, PM_VND, PM_LVM, PM_LVMLV} type;
    454 };
    455 
    456 /* Relative file name for storing a distribution. */
    457 char xfer_dir[STRSIZE];
    458 int  clean_xfer_dir;
    459 
    460 #if !defined(SYSINST_FTP_HOST)
    461 #define SYSINST_FTP_HOST	"ftp.NetBSD.org"
    462 #endif
    463 
    464 #if !defined(SYSINST_HTTP_HOST)
    465 #define SYSINST_HTTP_HOST	"cdn.NetBSD.org"
    466 #endif
    467 
    468 #if !defined(SYSINST_FTP_DIR)
    469 #if defined(NETBSD_OFFICIAL_RELEASE)
    470 #define SYSINST_FTP_DIR		"pub/NetBSD/NetBSD-" REL
    471 #elif defined(REL_PATH)
    472 #define SYSINST_FTP_DIR		"pub/NetBSD-daily/" REL_PATH "/latest"
    473 #else
    474 #define SYSINST_FTP_DIR		"pub/NetBSD/NetBSD-" REL
    475 #endif
    476 #endif
    477 
    478 #if !defined(ARCH_SUBDIR)
    479 #define	ARCH_SUBDIR	MACH
    480 #endif
    481 #if !defined(PKG_ARCH_SUBDIR)
    482 #define	PKG_ARCH_SUBDIR	MACH
    483 #endif
    484 
    485 #if !defined(SYSINST_PKG_HOST)
    486 #define SYSINST_PKG_HOST	"ftp.NetBSD.org"
    487 #endif
    488 #if !defined(SYSINST_PKG_HTTP_HOST)
    489 #define SYSINST_PKG_HTTP_HOST	"cdn.NetBSD.org"
    490 #endif
    491 
    492 #if !defined(SYSINST_PKG_DIR)
    493 #define SYSINST_PKG_DIR		"pub/pkgsrc/packages/NetBSD"
    494 #endif
    495 
    496 #if !defined(PKG_SUBDIR)
    497 #define	PKG_SUBDIR		REL
    498 #endif
    499 
    500 #if !defined(SYSINST_PKGSRC_HOST)
    501 #define SYSINST_PKGSRC_HOST	SYSINST_PKG_HOST
    502 #endif
    503 #if !defined(SYSINST_PKGSRC_HTTP_HOST)
    504 #define SYSINST_PKGSRC_HTTP_HOST	SYSINST_PKG_HTTP_HOST
    505 #endif
    506 
    507 #ifndef SETS_TAR_SUFF
    508 #define	SETS_TAR_SUFF	 "tgz"
    509 #endif
    510 
    511 #ifdef	USING_PAXASTAR
    512 #define	TAR_EXTRACT_FLAGS	"-xhepf"
    513 #else
    514 #define	TAR_EXTRACT_FLAGS	"-xpPf"
    515 #endif
    516 
    517 /* Abs. path we extract binary sets from */
    518 char ext_dir_bin[STRSIZE];
    519 
    520 /* Abs. path we extract source sets from */
    521 char ext_dir_src[STRSIZE];
    522 
    523 /* Abs. path we extract pkgsrc from */
    524 char ext_dir_pkgsrc[STRSIZE];
    525 
    526 /* Place we look for binary sets in all fs types */
    527 char set_dir_bin[STRSIZE];
    528 
    529 /* Place we look for source sets in all fs types */
    530 char set_dir_src[STRSIZE];
    531 
    532 /* Place we look for pkgs in all fs types */
    533 char pkg_dir[STRSIZE];
    534 
    535 /* Place we look for pkgsrc in all fs types */
    536 char pkgsrc_dir[STRSIZE];
    537 
    538 /* User shell */
    539 const char *ushell;
    540 
    541 #define	XFER_FTP	0
    542 #define	XFER_HTTP	1
    543 #define	XFER_MAX	XFER_HTTP
    544 
    545 struct ftpinfo {
    546 	char xfer_host[XFER_MAX+1][STRSIZE];
    547 	char dir[STRSIZE] ;
    548 	char user[SSTRSIZE];
    549 	char pass[STRSIZE];
    550 	char proxy[STRSIZE];
    551 	unsigned int xfer;	/* XFER_FTP for "ftp" or XFER_HTTP for "http" */
    552 };
    553 
    554 /* use the same struct for sets ftp and to build pkgpath */
    555 struct ftpinfo ftp, pkg, pkgsrc;
    556 
    557 int (*fetch_fn)(const char *);
    558 char nfs_host[STRSIZE];
    559 char nfs_dir[STRSIZE];
    560 
    561 char cdrom_dev[SSTRSIZE];		/* Typically "cd0a" */
    562 char fd_dev[SSTRSIZE];			/* Typically "/dev/fd0a" */
    563 const char *fd_type;			/* "msdos", "ffs" or maybe "ados" */
    564 
    565 char localfs_dev[SSTRSIZE];
    566 char localfs_fs[SSTRSIZE];
    567 char localfs_dir[STRSIZE];
    568 
    569 char targetroot_mnt[SSTRSIZE];
    570 
    571 int  mnt2_mounted;
    572 
    573 char dist_postfix[SSTRSIZE];
    574 char dist_tgz_postfix[SSTRSIZE];
    575 
    576 /* needed prototypes */
    577 void set_menu_numopts(int, int);
    578 void remove_color_options(void);
    579 void remove_raid_options(void);
    580 void remove_lvm_options(void);
    581 void remove_cgd_options(void);
    582 
    583 /* Machine dependent functions .... */
    584 void	md_init(void);
    585 void	md_init_set_status(int); /* SFLAG_foo */
    586 
    587  /* MD functions if user selects install - in order called */
    588 bool	md_get_info(struct install_partition_desc*);
    589 bool	md_make_bsd_partitions(struct install_partition_desc*);
    590 bool	md_check_partitions(struct install_partition_desc*);
    591 #ifdef HAVE_GPT
    592 /*
    593  * New GPT partitions have been written, update bootloader or remember
    594  * data untill needed in md_post_newfs
    595  */
    596 bool	md_gpt_post_write(struct disk_partitions*, part_id root_id,
    597 	    bool root_is_new, part_id efi_id, bool efi_is_new);
    598 #endif
    599 /*
    600  * md_pre_disklabel and md_post_disklabel may be called
    601  * multiple times, for each affected device, with the
    602  * "inner" partitions pointer of the relevant partitions
    603  * passed.
    604  */
    605 bool	md_pre_disklabel(struct install_partition_desc*, struct disk_partitions*);
    606 bool	md_post_disklabel(struct install_partition_desc*, struct disk_partitions*);
    607 int	md_pre_mount(struct install_partition_desc*, size_t);
    608 int	md_post_newfs(struct install_partition_desc*);
    609 int	md_post_extract(struct install_partition_desc*);
    610 void	md_cleanup_install(struct install_partition_desc*);
    611 
    612  /* MD functions if user selects upgrade - in order called */
    613 int	md_pre_update(struct install_partition_desc*);
    614 int	md_update(struct install_partition_desc*);
    615 /* Also calls md_post_extract() */
    616 
    617 /* from main.c */
    618 void	toplevel(void);
    619 
    620 /* from disks.c */
    621 bool	get_default_cdrom(char *, size_t);
    622 int	find_disks(const char *, bool);
    623 bool enumerate_disks(void *state,bool (*func)(void *state, const char *dev));
    624 bool is_cdrom_device(const char *dev, bool as_target);
    625 bool is_bootable_device(const char *dev);
    626 bool is_partitionable_device(const char *dev);
    627 bool convert_scheme(struct pm_devs *p, bool is_boot_drive, const char **err_msg);
    628 
    629 #ifndef	NO_CLONES
    630 /* a single partition selected for cloning (etc) */
    631 struct selected_partition {
    632 	struct disk_partitions *parts;
    633 	part_id id;
    634 };
    635 struct selected_partitions {
    636 	struct selected_partition *selection;
    637 	size_t num_sel;
    638 	bool with_data;		/* partitions and their data selected */
    639 	bool free_parts;	/* caller should free parts */
    640 };
    641 bool select_partitions(struct selected_partitions *res,
    642     const struct disk_partitions *ignore);
    643 daddr_t	selected_parts_size(struct selected_partitions *);
    644 void	free_selected_partitions(struct selected_partitions *);
    645 
    646 struct clone_target_menu_data {
    647 	struct partition_usage_set usage;
    648 	int res;
    649 };
    650 
    651 int	clone_target_select(menudesc *m, void *arg);
    652 bool	clone_partition_data(struct disk_partitions *dest_parts, part_id did,
    653 	struct disk_partitions *src_parts, part_id sid);
    654 #endif
    655 
    656 struct menudesc;
    657 void	disp_cur_fspart(int, int);
    658 int	make_filesystems(struct install_partition_desc *);
    659 int	make_fstab(struct install_partition_desc *);
    660 int	mount_disks(struct install_partition_desc *);
    661 int	set_swap_if_low_ram(struct install_partition_desc *);
    662 int	set_swap(struct install_partition_desc *);
    663 int	check_swap(const char *, int);
    664 char *bootxx_name(struct install_partition_desc *);
    665 int get_dkwedges(struct dkwedge_info **, const char *);
    666 
    667 /* from disks_lfs.c */
    668 int	fs_is_lfs(void *);
    669 
    670 /* from label.c */
    671 /*
    672  * Bits valid for "flags" in get_last_mounted.
    673  * Currently we return the real last mount from FFS, the volume label
    674  * from FAT32, and nothing otherwise. The NTFS support is currently
    675  * restricted to verify the partition has an NTFS (as some partitioning
    676  * schemes do not tell NTFS from FAT).
    677  */
    678 #define GLM_LIKELY_FFS		1U
    679 #define	GLM_MAYBE_FAT32		2U
    680 #define	GLM_MAYBE_NTFS		4U
    681 /*
    682  * possible fs_sub_types are currently:
    683  *  FS_BSDFFS:
    684  *	0	unknown
    685  *	1	FFSv1
    686  *	2	FFSv2
    687  * FS_MSDOS:
    688  *	0	unknown
    689  *	else	MBR_PTYPE_FAT* for the current FAT variant
    690  * FS_NTFS:
    691  *	0	unknown
    692  *	else	MBR_PTYPE_NTFS (if valid NTFS was found)
    693  *
    694  * The fs_type and fs_sub_type pointers may be NULL.
    695  */
    696 const char *get_last_mounted(int fd, daddr_t offset, uint *fs_type,
    697      uint *fs_sub_type, uint flags);
    698 void	canonicalize_last_mounted(char*);
    699 int	edit_and_check_label(struct pm_devs *p, struct partition_usage_set *pset, bool install);
    700 int edit_ptn(menudesc *, void *);
    701 int checkoverlap(struct disk_partitions *parts);
    702 daddr_t getpartsize(struct disk_partitions *parts, daddr_t partstart,
    703     daddr_t defpartsize);
    704 daddr_t getpartoff(struct disk_partitions *parts, daddr_t defpartstart);
    705 
    706 /* from install.c */
    707 void	do_install(void);
    708 
    709 /* from factor.c */
    710 void	factor(long, long *, int, int *);
    711 
    712 /* from fdisk.c */
    713 void	get_disk_info(char *);
    714 void	set_disk_info(char *);
    715 
    716 /* from geom.c */
    717 bool	disk_ioctl(const char *, unsigned long, void *);
    718 bool	get_wedge_list(const char *, struct dkwedge_list *);
    719 bool	get_wedge_info(const char *, struct dkwedge_info *);
    720 bool	get_disk_geom(const char *, struct disk_geom *);
    721 bool	get_label_geom(const char *, struct disklabel *);
    722 
    723 /* from net.c */
    724 extern int network_up;
    725 extern char net_namesvr[STRSIZE];
    726 int	get_via_ftp(unsigned int);
    727 int	get_via_nfs(void);
    728 int	config_network(void);
    729 void	mnt_net_config(void);
    730 void	make_url(char *, struct ftpinfo *, const char *);
    731 int	get_pkgsrc(void);
    732 const char *url_proto(unsigned int);
    733 
    734 /* From run.c */
    735 int	collect(int, char **, const char *, ...) __printflike(3, 4);
    736 int	run_program(int, const char *, ...) __printflike(2, 3);
    737 void	do_logging(void);
    738 int	do_system(const char *);
    739 
    740 /* from upgrade.c */
    741 void	do_upgrade(void);
    742 void	do_reinstall_sets(void);
    743 void	restore_etc(void);
    744 
    745 /* from part_edit.c */
    746 int	err_msg_win(const char*);
    747 const struct disk_partitioning_scheme *select_part_scheme(struct pm_devs *dev,
    748     const struct disk_partitioning_scheme *skip, bool bootable,
    749     const char *title);
    750 bool	edit_outer_parts(struct disk_partitions*);
    751 bool	parts_use_wholedisk(struct disk_partitions*,
    752 	     size_t add_ext_parts, const struct disk_part_info *ext_parts);
    753 
    754 /*
    755  * Machine dependent partitioning function, only used when
    756  * innern/outer partitioning schemes are in use - this sets
    757  * up the outer scheme for maximum NetBSD usage.
    758  */
    759 bool	md_parts_use_wholedisk(struct disk_partitions*);
    760 
    761 /* from util.c */
    762 bool	root_is_read_only(void);
    763 void	get_ptn_alignment(const struct disk_partitions *parts, daddr_t *align, daddr_t *p0off);
    764 struct disk_partitions *get_inner_parts(struct disk_partitions *parts);
    765 char*	str_arg_subst(const char *, size_t, const char **);
    766 void	msg_display_subst(const char *, size_t, ...);
    767 void	msg_display_add_subst(const char *, size_t, ...);
    768 int	ask_yesno(const char *);
    769 int	ask_noyes(const char *);
    770 void	hit_enter_to_continue(const char *msg, const char *title);
    771 /*
    772  * return value:
    773  *  0 -> abort
    774  *  1 -> re-edit
    775  *  2 -> continue installation
    776 */
    777 int	ask_reedit(const struct disk_partitions *);
    778 int	dir_exists_p(const char *);
    779 int	file_exists_p(const char *);
    780 int	file_mode_match(const char *, unsigned int);
    781 uint64_t	get_ramsize(void);	/* in MB! */
    782 void	ask_sizemult(int);
    783 void	run_makedev(void);
    784 int	boot_media_still_needed(void);
    785 int	get_via_floppy(void);
    786 int	get_via_cdrom(void);
    787 int	get_via_localfs(void);
    788 int	get_via_localdir(void);
    789 void	show_cur_distsets(void);
    790 void	make_ramdisk_dir(const char *);
    791 void    set_kernel_set(unsigned int);
    792 void    set_noextract_set(unsigned int);
    793 unsigned int    get_kernel_set(void);
    794 unsigned int    set_X11_selected(void);
    795 int 	get_and_unpack_sets(int, msg, msg, msg);
    796 int	sanity_check(void);
    797 int	set_timezone(void);
    798 void	scripting_fprintf(FILE *, const char *, ...) __printflike(2, 3);
    799 void	scripting_vfprintf(FILE *, const char *, va_list) __printflike(2, 0);
    800 void	add_rc_conf(const char *, ...) __printflike(1, 2);
    801 int	del_rc_conf(const char *);
    802 void	add_sysctl_conf(const char *, ...) __printflike(1, 2);
    803 void	enable_rc_conf(void);
    804 void	set_sizemult(uint secs);
    805 void	set_default_sizemult(uint secs);
    806 int	check_lfs_progs(void);
    807 void	init_set_status(int);
    808 void	customise_sets(void);
    809 void	umount_mnt2(void);
    810 int 	set_is_source(const char *);
    811 const char *set_dir_for_set(const char *);
    812 const char *ext_dir_for_set(const char *);
    813 void	replace(const char *, const char *, ...) __printflike(2, 3);
    814 void	get_tz_default(void);
    815 distinfo*	get_set_distinfo(int);
    816 int	extract_file(distinfo *, int);
    817 int extract_file_to(distinfo *dist, int update, const char *dest_dir,
    818     const char *extr_pattern, bool do_stats);
    819 void	do_coloring (unsigned int, unsigned int);
    820 int set_menu_select(menudesc *, void *);
    821 const char *safectime(time_t *);
    822 bool	use_tgz_for_set(const char*);
    823 const char *set_postfix(const char*);
    824 bool	usage_set_from_parts(struct partition_usage_set*,
    825 	    struct disk_partitions*);
    826 void	free_usage_set(struct partition_usage_set*);
    827 bool	install_desc_from_parts(struct install_partition_desc *,
    828 	    struct disk_partitions*);
    829 void	free_install_desc(struct install_partition_desc*);
    830 bool	may_swap_if_not_sdmmc(const char*);
    831 
    832 /* from target.c */
    833 #if defined(DEBUG)  ||	defined(DEBUG_ROOT)
    834 void	backtowin(void);
    835 #endif
    836 bool	is_root_part_mount(const char *);
    837 const	char *concat_paths(const char *, const char *);
    838 const	char *target_expand(const char *);
    839 bool	needs_expanding(const char *, size_t);
    840 void	make_target_dir(const char *);
    841 void	append_to_target_file(const char *, const char *);
    842 void	echo_to_target_file(const char *, const char *);
    843 void	trunc_target_file(const char *);
    844 const	char *target_prefix(void);
    845 int	target_chdir(const char *);
    846 void	target_chdir_or_die(const char *);
    847 int	target_already_root(void);
    848 FILE	*target_fopen(const char *, const char *);
    849 int	target_collect_file(int, char **, const char *);
    850 int	is_active_rootpart(const char *, int);
    851 int	cp_to_target(const char *, const char *);
    852 void	dup_file_into_target(const char *);
    853 void	mv_within_target_or_die(const char *, const char *);
    854 int	cp_within_target(const char *, const char *, int);
    855 int	target_mount(const char *, const char *, const char *);
    856 int	target_mount_do(const char *, const char *, const char *);
    857 int	target_test(unsigned int, const char *);
    858 int	target_dir_exists_p(const char *);
    859 int	target_file_exists_p(const char *);
    860 int	target_symlink_exists_p(const char *);
    861 void	unwind_mounts(void);
    862 int	target_mounted(void);
    863 void	umount_root(void);
    864 
    865 /* from partman.c */
    866 #ifndef NO_PARTMAN
    867 int partman(void);
    868 int pm_getrefdev(struct pm_devs *);
    869 void update_wedges(const char *);
    870 void pm_destroy_all(void);
    871 #else
    872 static inline int partman(void) { return -1; }
    873 static inline int pm_getrefdev(struct pm_devs *x __unused) { return -1; }
    874 #define update_wedges(x) __nothing
    875 #endif
    876 void pmdiskentry_enable(menudesc*, struct part_entry *);
    877 int pm_partusage(struct pm_devs *, int, int);
    878 void pm_setfstype(struct pm_devs *, part_id, int, int);
    879 void pm_set_lvmpv(struct pm_devs *, part_id, bool);
    880 bool pm_is_lvmpv(struct pm_devs *, part_id, const struct disk_part_info*);
    881 int pm_editpart(int);
    882 void pm_rename(struct pm_devs *);
    883 void pm_shred(struct part_entry *, int);
    884 void pm_umount(struct pm_devs *, int);
    885 int pm_unconfigure(struct pm_devs *);
    886 int pm_cgd_edit_new(struct pm_devs *pm, part_id id);
    887 int pm_cgd_edit_old(struct part_entry *);
    888 void pm_wedges_fill(struct pm_devs *);
    889 void pm_edit_partitions(struct part_entry *);
    890 part_id pm_whole_disk(struct part_entry *, int);
    891 struct pm_devs * pm_from_pe(struct part_entry *);
    892 bool pm_force_parts(struct pm_devs *);
    893 
    894 /*
    895  * Parse a file system position or size in a common way, return
    896  * sector count and multiplicator.
    897  * If "extend" is supported, things like 120+ will be parsed as
    898  * 120 plus "extend this" flag.
    899  * Caller needs to init muliplicator upfront to the default value.
    900  */
    901 daddr_t parse_disk_pos(
    902 	const char *,	/* in: input string */
    903 	daddr_t *,	/* in/out: multiplicator for return value */
    904 	daddr_t,	/* in: cylinder size in blocks */
    905 	bool *);	/* NULL if "extend" is not supported, & of
    906 			 * "extend" flag otherwise */
    907 
    908 /* flags whether to offer the respective options (depending on helper
    909    programs available on install media */
    910 extern int have_raid, have_vnd, have_cgd, have_lvm, have_gpt, have_dk;
    911 /* initialize above variables */
    912 void check_available_binaries(void);
    913 
    914 /* from bsddisklabel.c */
    915 bool	make_bsd_partitions(struct install_partition_desc*);
    916 void	set_ptn_titles(menudesc *, int, void *);
    917 int	set_ptn_size(menudesc *, void *);
    918 bool	get_ptn_sizes(struct partition_usage_set*);
    919 bool	check_partitions(struct install_partition_desc*);
    920 
    921 /* from aout2elf.c */
    922 int move_aout_libs(void);
    923 
    924 #ifdef WSKBD
    925 void	get_kb_encoding(void);
    926 void	save_kb_encoding(void);
    927 #else
    928 #define	get_kb_encoding()
    929 #define	save_kb_encoding()
    930 #endif
    931 
    932 /* from configmenu.c */
    933 void	do_configmenu(struct install_partition_desc*);
    934 
    935 /* from checkrc.c */
    936 int	check_rcvar(const char *);
    937 int	check_rcdefault(const char *);
    938 	WINDOW *mainwin;
    939 
    940 /* in menus.mi */
    941 void expand_all_option_texts(menudesc *menu, void *arg);
    942 void resize_menu_height(menudesc *);
    943 
    944 #endif	/* _DEFS_H_ */
    945