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