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