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