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