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