xref: /netbsd-src/usr.sbin/sysinst/defs.h (revision f56b29a750628a7095c5912a389a6083a9f727f9)
1 /*	$NetBSD: defs.h,v 1.81 2022/04/21 17:30:15 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 accross 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 	size_t index;	/* e.g. if PM_RAID: this is raids[index] */
507 	int dev_ptr_delta;
508 	char fullname[SSTRSIZE];
509 	enum {PM_DISK=1, PM_PART, PM_SPEC,
510 	    PM_RAID, PM_CGD, PM_VND, PM_LVM, PM_LVMLV} type;
511 };
512 
513 /* Relative file name for storing a distribution. */
514 extern char xfer_dir[STRSIZE];
515 extern int  clean_xfer_dir;
516 
517 #if !defined(SYSINST_FTP_HOST)
518 #define SYSINST_FTP_HOST	"ftp.NetBSD.org"
519 #endif
520 
521 #if !defined(SYSINST_HTTP_HOST)
522 #define SYSINST_HTTP_HOST	"cdn.NetBSD.org"
523 #endif
524 
525 #if !defined(SYSINST_FTP_DIR)
526 #if defined(NETBSD_OFFICIAL_RELEASE)
527 #define SYSINST_FTP_DIR		"pub/NetBSD/NetBSD-" REL
528 #elif defined(REL_PATH)
529 #define SYSINST_FTP_DIR		"pub/NetBSD-daily/" REL_PATH "/latest"
530 #else
531 #define SYSINST_FTP_DIR		"pub/NetBSD/NetBSD-" REL
532 #endif
533 #endif
534 
535 #if !defined(ARCH_SUBDIR)
536 #define	ARCH_SUBDIR	MACH
537 #endif
538 #if !defined(PKG_ARCH_SUBDIR)
539 #define	PKG_ARCH_SUBDIR	MACH
540 #endif
541 
542 #if !defined(SYSINST_PKG_HOST)
543 #define SYSINST_PKG_HOST	"ftp.NetBSD.org"
544 #endif
545 #if !defined(SYSINST_PKG_HTTP_HOST)
546 #define SYSINST_PKG_HTTP_HOST	"cdn.NetBSD.org"
547 #endif
548 
549 #if !defined(SYSINST_PKG_DIR)
550 #define SYSINST_PKG_DIR		"pub/pkgsrc/packages/NetBSD"
551 #endif
552 
553 #if !defined(PKG_SUBDIR)
554 #define	PKG_SUBDIR		REL
555 #endif
556 
557 #if !defined(SYSINST_PKGSRC_HOST)
558 #define SYSINST_PKGSRC_HOST	SYSINST_PKG_HOST
559 #endif
560 #if !defined(SYSINST_PKGSRC_HTTP_HOST)
561 #define SYSINST_PKGSRC_HTTP_HOST	SYSINST_PKG_HTTP_HOST
562 #endif
563 
564 #ifndef SETS_TAR_SUFF
565 #define	SETS_TAR_SUFF	 "tgz"
566 #endif
567 
568 #ifdef	USING_PAXASTAR
569 #define	TAR_EXTRACT_FLAGS	"-xhepf"
570 #else
571 #define	TAR_EXTRACT_FLAGS	"-xpf"
572 #endif
573 
574 /* Abs. path we extract binary sets from */
575 extern char ext_dir_bin[STRSIZE];
576 
577 /* Abs. path we extract source sets from */
578 extern char ext_dir_src[STRSIZE];
579 
580 /* Abs. path we extract pkgsrc from */
581 extern char ext_dir_pkgsrc[STRSIZE];
582 
583 /* Place we look for binary sets in all fs types */
584 extern char set_dir_bin[STRSIZE];
585 
586 /* Place we look for source sets in all fs types */
587 extern char set_dir_src[STRSIZE];
588 
589 /* Place we look for pkgs in all fs types */
590 extern char pkg_dir[STRSIZE];
591 
592 /* Place we look for pkgsrc in all fs types */
593 extern char pkgsrc_dir[STRSIZE];
594 
595 /* User shell */
596 extern const char *ushell;
597 
598 #define	XFER_FTP	0
599 #define	XFER_HTTP	1
600 #define	XFER_MAX	XFER_HTTP
601 
602 struct ftpinfo {
603 	char xfer_host[XFER_MAX+1][STRSIZE];
604 	char dir[STRSIZE] ;
605 	char user[SSTRSIZE];
606 	char pass[STRSIZE];
607 	char proxy[STRSIZE];
608 	unsigned int xfer;	/* XFER_FTP for "ftp" or XFER_HTTP for "http" */
609 };
610 
611 /* use the same struct for sets ftp and to build pkgpath */
612 extern struct ftpinfo ftp, pkg, pkgsrc;
613 
614 extern int (*fetch_fn)(const char *);
615 extern char nfs_host[STRSIZE];
616 extern char nfs_dir[STRSIZE];
617 extern char entropy_file[PATH_MAX];
618 
619 extern char cdrom_dev[SSTRSIZE];		/* Typically "cd0a" */
620 extern char fd_dev[SSTRSIZE];			/* Typically "/dev/fd0a" */
621 extern const char *fd_type;			/* "msdos", "ffs" or maybe "ados" */
622 
623 extern char localfs_dev[SSTRSIZE];
624 extern char localfs_fs[SSTRSIZE];
625 extern char localfs_dir[STRSIZE];
626 
627 extern char targetroot_mnt[SSTRSIZE];
628 
629 extern int  mnt2_mounted;
630 
631 extern char dist_postfix[SSTRSIZE];
632 extern char dist_tgz_postfix[SSTRSIZE];
633 
634 /* needed prototypes */
635 void set_menu_numopts(int, int);
636 void remove_color_options(void);
637 #ifdef CHECK_ENTROPY
638 bool do_add_entropy(void);
639 size_t entropy_needed(void);
640 #endif
641 void remove_raid_options(void);
642 void remove_lvm_options(void);
643 void remove_cgd_options(void);
644 
645 /* Machine dependent functions .... */
646 void	md_init(void);
647 void	md_init_set_status(int); /* SFLAG_foo */
648 
649  /* MD functions if user selects install - in order called */
650 bool	md_get_info(struct install_partition_desc*);
651 /* returns -1 to restart partitioning, 0 for error, 1 for success */
652 int	md_make_bsd_partitions(struct install_partition_desc*);
653 bool	md_check_partitions(struct install_partition_desc*);
654 #ifdef HAVE_GPT
655 /*
656  * New GPT partitions have been written, update bootloader or remember
657  * data untill needed in md_post_newfs
658  */
659 bool	md_gpt_post_write(struct disk_partitions*, part_id root_id,
660 	    bool root_is_new, part_id efi_id, bool efi_is_new);
661 #endif
662 /*
663  * md_pre_disklabel and md_post_disklabel may be called
664  * multiple times, for each affected device, with the
665  * "inner" partitions pointer of the relevant partitions
666  * passed.
667  */
668 bool	md_pre_disklabel(struct install_partition_desc*, struct disk_partitions*);
669 bool	md_post_disklabel(struct install_partition_desc*, struct disk_partitions*);
670 int	md_pre_mount(struct install_partition_desc*, size_t);
671 int	md_post_newfs(struct install_partition_desc*);
672 int	md_post_extract(struct install_partition_desc*, bool upgrade);
673 void	md_cleanup_install(struct install_partition_desc*);
674 
675  /* MD functions if user selects upgrade - in order called */
676 int	md_pre_update(struct install_partition_desc*);
677 int	md_update(struct install_partition_desc*);
678 /* Also calls md_post_extract() */
679 
680 /* from main.c */
681 void	toplevel(void);
682 
683 /* from disks.c */
684 bool	get_default_cdrom(char *, size_t);
685 int	find_disks(const char *, bool);
686 bool enumerate_disks(void *state,bool (*func)(void *state, const char *dev));
687 bool is_cdrom_device(const char *dev, bool as_target);
688 bool is_bootable_device(const char *dev);
689 bool is_partitionable_device(const char *dev);
690 bool convert_scheme(struct pm_devs *p, bool is_boot_drive, const char **err_msg);
691 
692 #ifndef	NO_CLONES
693 /* a single partition selected for cloning (etc) */
694 struct selected_partition {
695 	struct disk_partitions *parts;
696 	part_id id;
697 };
698 struct selected_partitions {
699 	struct selected_partition *selection;
700 	size_t num_sel;
701 	bool with_data;		/* partitions and their data selected */
702 	bool free_parts;	/* caller should free parts */
703 };
704 bool select_partitions(struct selected_partitions *res,
705     const struct disk_partitions *ignore);
706 daddr_t	selected_parts_size(struct selected_partitions *);
707 void	free_selected_partitions(struct selected_partitions *);
708 
709 struct clone_target_menu_data {
710 	struct partition_usage_set usage;
711 	int res;
712 };
713 
714 int	clone_target_select(menudesc *m, void *arg);
715 bool	clone_partition_data(struct disk_partitions *dest_parts, part_id did,
716 	struct disk_partitions *src_parts, part_id sid);
717 #endif
718 
719 struct menudesc;
720 void	disp_cur_fspart(int, int);
721 int	make_filesystems(struct install_partition_desc *);
722 int	make_fstab(struct install_partition_desc *);
723 int	mount_disks(struct install_partition_desc *);
724 void	set_swap_if_low_ram(struct install_partition_desc *);
725 void	set_swap(struct install_partition_desc *);
726 void	clear_swap(void);
727 int	check_swap(const char *, int);
728 char *bootxx_name(struct install_partition_desc *);
729 int get_dkwedges(struct dkwedge_info **, const char *);
730 
731 /* from disks_lfs.c */
732 int	fs_is_lfs(void *);
733 
734 /* from label.c */
735 /*
736  * Bits valid for "flags" in get_last_mounted.
737  * Currently we return the real last mount from FFS, the volume label
738  * from FAT32, and nothing otherwise. The NTFS support is currently
739  * restricted to verify the partition has an NTFS (as some partitioning
740  * schemes do not tell NTFS from FAT).
741  */
742 #define GLM_LIKELY_FFS		1U
743 #define	GLM_MAYBE_FAT32		2U
744 #define	GLM_MAYBE_NTFS		4U
745 /*
746  * possible fs_sub_types are currently:
747  *  FS_BSDFFS:
748  *	0	unknown
749  *	1	FFSv1
750  *	2	FFSv2
751  * FS_MSDOS:
752  *	0	unknown
753  *	else	MBR_PTYPE_FAT* for the current FAT variant
754  * FS_NTFS:
755  *	0	unknown
756  *	else	MBR_PTYPE_NTFS (if valid NTFS was found)
757  *
758  * The fs_type and fs_sub_type pointers may be NULL.
759  */
760 const char *get_last_mounted(int fd, daddr_t offset, uint *fs_type,
761      uint *fs_sub_type, uint flags);
762 void	canonicalize_last_mounted(char*);
763 int	edit_and_check_label(struct pm_devs *p, struct partition_usage_set *pset, bool install);
764 int edit_ptn(menudesc *, void *);
765 int checkoverlap(struct disk_partitions *parts);
766 daddr_t getpartsize(struct disk_partitions *parts, daddr_t orig_start,
767     daddr_t partstart, daddr_t defpartsize);
768 daddr_t getpartoff(struct disk_partitions *parts, daddr_t defpartstart);
769 
770 /* from install.c */
771 void	do_install(void);
772 
773 /* from factor.c */
774 void	factor(long, long *, int, int *);
775 
776 /* from fdisk.c */
777 void	get_disk_info(char *);
778 void	set_disk_info(char *);
779 
780 /* from geom.c */
781 bool	disk_ioctl(const char *, unsigned long, void *);
782 bool	get_wedge_list(const char *, struct dkwedge_list *);
783 bool	get_wedge_info(const char *, struct dkwedge_info *);
784 bool	get_disk_geom(const char *, struct disk_geom *);
785 bool	get_label_geom(const char *, struct disklabel *);
786 
787 /* from net.c */
788 extern int network_up;
789 extern char net_namesvr[STRSIZE];
790 int	get_via_ftp(unsigned int);
791 int	get_via_nfs(void);
792 int	config_network(void);
793 void	mnt_net_config(void);
794 void	make_url(char *, struct ftpinfo *, const char *);
795 int	get_pkgsrc(void);
796 const char *url_proto(unsigned int);
797 
798 /* From run.c */
799 int	collect(int, char **, const char *, ...) __printflike(3, 4);
800 int	run_program(int, const char *, ...) __printflike(2, 3);
801 void	do_logging(void);
802 int	do_system(const char *);
803 
804 /* from upgrade.c */
805 void	do_upgrade(void);
806 void	do_reinstall_sets(void);
807 void	restore_etc(void);
808 
809 /* from part_edit.c */
810 int	err_msg_win(const char*);
811 const struct disk_partitioning_scheme *select_part_scheme(struct pm_devs *dev,
812     const struct disk_partitioning_scheme *skip, bool bootable,
813     const char *title);
814 /*
815  * return value:
816  *  0 -> abort
817  *  1 -> ok, continue
818  *  -1 -> partitions have been deleted, start from scratch
819 */
820 int	edit_outer_parts(struct disk_partitions*);
821 bool	parts_use_wholedisk(struct disk_partitions*,
822 	     size_t add_ext_parts, const struct disk_part_info *ext_parts);
823 
824 /*
825  * Machine dependent partitioning function, only used when
826  * innern/outer partitioning schemes are in use - this sets
827  * up the outer scheme for maximum NetBSD usage.
828  */
829 bool	md_parts_use_wholedisk(struct disk_partitions*);
830 
831 /* from util.c */
832 bool	root_is_read_only(void);
833 void	get_ptn_alignment(const struct disk_partitions *parts, daddr_t *align, daddr_t *p0off);
834 struct disk_partitions *get_inner_parts(struct disk_partitions *parts);
835 char*	str_arg_subst(const char *, size_t, const char **);
836 void	msg_display_subst(const char *, size_t, ...);
837 void	msg_display_add_subst(const char *, size_t, ...);
838 int	ask_yesno(const char *);
839 int	ask_noyes(const char *);
840 void	hit_enter_to_continue(const char *msg, const char *title);
841 /*
842  * return value:
843  *  0 -> abort
844  *  1 -> re-edit
845  *  2 -> continue installation
846 */
847 int	ask_reedit(const struct disk_partitions *);
848 int	dir_exists_p(const char *);
849 int	file_exists_p(const char *);
850 int	file_mode_match(const char *, unsigned int);
851 uint64_t	get_ramsize(void);	/* in MB! */
852 void	ask_sizemult(int);
853 void	run_makedev(void);
854 int	boot_media_still_needed(void);
855 int	get_via_floppy(void);
856 int	get_via_cdrom(void);
857 int	get_via_localfs(void);
858 int	get_via_localdir(void);
859 void	show_cur_distsets(void);
860 void	make_ramdisk_dir(const char *);
861 void    set_kernel_set(unsigned int);
862 void    set_noextract_set(unsigned int);
863 unsigned int    get_kernel_set(void);
864 unsigned int    set_X11_selected(void);
865 int 	get_and_unpack_sets(int, msg, msg, msg);
866 int	sanity_check(void);
867 int	set_timezone(void);
868 void	scripting_fprintf(FILE *, const char *, ...) __printflike(2, 3);
869 void	scripting_vfprintf(FILE *, const char *, va_list) __printflike(2, 0);
870 void	add_rc_conf(const char *, ...) __printflike(1, 2);
871 int	del_rc_conf(const char *);
872 void	add_sysctl_conf(const char *, ...) __printflike(1, 2);
873 void	enable_rc_conf(void);
874 void	set_sizemult(daddr_t, uint bps);
875 void	set_default_sizemult(const char *disk, daddr_t unit, uint bps);
876 int	check_lfs_progs(void);
877 void	init_set_status(int);
878 void	customise_sets(void);
879 void	umount_mnt2(void);
880 int 	set_is_source(const char *);
881 const char *set_dir_for_set(const char *);
882 const char *ext_dir_for_set(const char *);
883 void	replace(const char *, const char *, ...) __printflike(2, 3);
884 void	get_tz_default(void);
885 distinfo*	get_set_distinfo(int);
886 int	extract_file(distinfo *, int);
887 int extract_file_to(distinfo *dist, int update, const char *dest_dir,
888     const char *extr_pattern, bool do_stats);
889 void	do_coloring (unsigned int, unsigned int);
890 int set_menu_select(menudesc *, void *);
891 const char *safectime(time_t *);
892 bool	use_tgz_for_set(const char*);
893 const char *set_postfix(const char*);
894 bool	usage_set_from_parts(struct partition_usage_set*,
895 	    struct disk_partitions*);
896 void	free_usage_set(struct partition_usage_set*);
897 bool	install_desc_from_parts(struct install_partition_desc *,
898 	    struct disk_partitions*);
899 void	free_install_desc(struct install_partition_desc*);
900 bool	may_swap_if_not_sdmmc(const char*);
901 
902 /* from target.c */
903 #if defined(DEBUG)  ||	defined(DEBUG_ROOT)
904 void	backtowin(void);
905 #endif
906 bool	is_root_part_mount(const char *);
907 const	char *concat_paths(const char *, const char *);
908 const	char *target_expand(const char *);
909 bool	needs_expanding(const char *, size_t);
910 void	make_target_dir(const char *);
911 void	append_to_target_file(const char *, const char *);
912 void	echo_to_target_file(const char *, const char *);
913 void	trunc_target_file(const char *);
914 const	char *target_prefix(void);
915 int	target_chdir(const char *);
916 void	target_chdir_or_die(const char *);
917 int	target_already_root(void);
918 FILE	*target_fopen(const char *, const char *);
919 int	target_collect_file(int, char **, const char *);
920 int	is_active_rootpart(const char *, int);
921 int	cp_to_target(const char *, const char *);
922 void	dup_file_into_target(const char *);
923 void	mv_within_target_or_die(const char *, const char *);
924 int	cp_within_target(const char *, const char *, int);
925 int	target_mount(const char *, const char *, const char *);
926 int	target_unmount(const char *);
927 int	target_mount_do(const char *, const char *, const char *);
928 int	target_test(unsigned int, const char *);
929 int	target_dir_exists_p(const char *);
930 int	target_file_exists_p(const char *);
931 int	target_symlink_exists_p(const char *);
932 void	unwind_mounts(void);
933 void	register_post_umount_delwedge(const char *disk, const char *wedge);
934 int	target_mounted(void);
935 void	umount_root(void);
936 
937 /* from partman.c */
938 #ifndef NO_PARTMAN
939 int partman(void);
940 int pm_getrefdev(struct pm_devs *);
941 void update_wedges(const char *);
942 void pm_destroy_all(void);
943 #else
944 static inline int partman(void) { return -1; }
945 static inline int pm_getrefdev(struct pm_devs *x __unused) { return -1; }
946 #define update_wedges(x) __nothing
947 #endif
948 void pmdiskentry_enable(menudesc*, struct part_entry *);
949 int pm_partusage(struct pm_devs *, int, int);
950 void pm_setfstype(struct pm_devs *, part_id, int, int);
951 void pm_set_lvmpv(struct pm_devs *, part_id, bool);
952 bool pm_is_lvmpv(struct pm_devs *, part_id, const struct disk_part_info*);
953 int pm_editpart(int);
954 void pm_rename(struct pm_devs *);
955 void pm_shred(struct part_entry *, int);
956 void pm_umount(struct pm_devs *, int);
957 int pm_unconfigure(struct pm_devs *);
958 int pm_cgd_edit_new(struct pm_devs *pm, part_id id);
959 int pm_cgd_edit_old(struct part_entry *);
960 void pm_wedges_fill(struct pm_devs *);
961 void pm_edit_partitions(struct part_entry *);
962 part_id pm_whole_disk(struct part_entry *, int);
963 struct pm_devs * pm_from_pe(struct part_entry *);
964 bool pm_force_parts(struct pm_devs *);
965 
966 /*
967  * Parse a file system position or size in a common way, return
968  * sector count and multiplicator.
969  * If "extend" is supported, things like 120+ will be parsed as
970  * 120 plus "extend this" flag.
971  * Caller needs to init muliplicator upfront to the default value.
972  */
973 daddr_t parse_disk_pos(
974 	const char *,	/* in: input string */
975 	daddr_t *,	/* in/out: multiplicator for return value */
976 	daddr_t bps,	/* in: sector size in bytes */
977 	daddr_t,	/* in: cylinder size in sectors */
978 	bool *);	/* NULL if "extend" is not supported, & of
979 			 * "extend" flag otherwise */
980 
981 /* flags whether to offer the respective options (depending on helper
982    programs available on install media */
983 extern int have_raid, have_vnd, have_cgd, have_lvm, have_gpt, have_dk;
984 /* initialize above variables */
985 void check_available_binaries(void);
986 
987 /* from bsddisklabel.c */
988 /* returns -1 to restart partitioning, 0 for error, 1 for success */
989 int	make_bsd_partitions(struct install_partition_desc*);
990 void	set_ptn_titles(menudesc *, int, void *);
991 int	set_ptn_size(menudesc *, void *);
992 bool	get_ptn_sizes(struct partition_usage_set*);
993 bool	check_partitions(struct install_partition_desc*);
994 
995 /* from aout2elf.c */
996 int move_aout_libs(void);
997 
998 #ifdef WSKBD
999 void	get_kb_encoding(void);
1000 void	save_kb_encoding(void);
1001 #else
1002 #define	get_kb_encoding()
1003 #define	save_kb_encoding()
1004 #endif
1005 
1006 /* from configmenu.c */
1007 void	do_configmenu(struct install_partition_desc*);
1008 void	root_pw_setup(void);
1009 
1010 /* from checkrc.c */
1011 int	check_rcvar(const char *);
1012 int	check_rcdefault(const char *);
1013 extern	WINDOW *mainwin;
1014 
1015 /* in menus.mi */
1016 void expand_all_option_texts(menudesc *menu, void *arg);
1017 void resize_menu_height(menudesc *);
1018 
1019 #endif	/* _DEFS_H_ */
1020