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