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