defs.h revision 1.73 1 /* $NetBSD: defs.h,v 1.73 2021/09/25 08:54:31 maya 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_GPUFW, /* GPU firmware files */
145 SET_MAN_PAGES, /* online manual pages */
146 SET_MISC, /* miscellaneuous */
147 SET_MODULES, /* kernel modules */
148 SET_RESCUE, /* /rescue recovery tools */
149 SET_TESTS, /* tests */
150 SET_TEXT_TOOLS, /* text processing tools */
151
152 /* X11 sets */
153 SET_X11_FIRST,
154 SET_X11_BASE, /* X11 base and clients */
155 SET_X11_FONTS, /* X11 fonts */
156 SET_X11_SERVERS, /* X11 servers */
157 SET_X11_PROG, /* X11 programming */
158 SET_X11_ETC, /* X11 config */
159 SET_X11_LAST,
160
161 /* Machine dependent sets */
162 SET_MD_1, /* Machine dependent set */
163 SET_MD_2, /* Machine dependent set */
164 SET_MD_3, /* Machine dependent set */
165 SET_MD_4, /* Machine dependent set */
166
167 /* Source sets */
168 SET_SYSSRC,
169 SET_SRC,
170 SET_SHARESRC,
171 SET_GNUSRC,
172 SET_XSRC,
173
174 /* Debug sets */
175 SET_DEBUG,
176 SET_X11_DEBUG,
177
178 SET_LAST,
179 SET_GROUP, /* Start of submenu */
180 SET_GROUP_END, /* End of submenu */
181 SET_PKGSRC, /* pkgsrc, not counted as regular set */
182 };
183
184 /* Initialisers to select sets */
185 /* All kernels */
186 #define SET_KERNEL SET_KERNEL_1, SET_KERNEL_2, SET_KERNEL_3, SET_KERNEL_4, \
187 SET_KERNEL_5, SET_KERNEL_6, SET_KERNEL_7, SET_KERNEL_8
188 #ifdef HAVE_MODULES
189 #define WITH_MODULES SET_MODULES,
190 #else
191 #define WITH_MODULES
192 #endif
193 /* Core system sets */
194 #ifdef HAVE_DTB
195 #define WITH_DTB SET_DTB,
196 #else
197 #define WITH_DTB
198 #endif
199 #ifdef HAVE_GPUFW
200 #define WITH_GPUFW SET_GPUFW,
201 #else
202 #define WITH_GPUFW
203 #endif
204 #define SET_CORE WITH_MODULES SET_BASE, WITH_DTB WITH_GPUFW SET_ETC
205 /* All system sets */
206 #define SET_SYSTEM SET_CORE, SET_COMPILER, SET_GAMES, \
207 SET_MAN_PAGES, SET_MISC, SET_RESCUE, \
208 SET_TESTS, SET_TEXT_TOOLS
209 /* All X11 sets */
210 #define SET_X11_NOSERVERS SET_X11_BASE, SET_X11_FONTS, SET_X11_PROG, SET_X11_ETC
211 #define SET_X11 SET_X11_NOSERVERS, SET_X11_SERVERS
212
213 /* All machine dependent sets */
214 #define SET_MD SET_MD_1, SET_MD_2, SET_MD_3, SET_MD_4
215
216 /* All source sets */
217 #define SET_SOURCE SET_SYSSRC, SET_SRC, SET_SHARESRC, SET_GNUSRC, SET_XSRC
218
219 /* All debug sets */
220 #define SET_DEBUGGING SET_DEBUG, SET_X11_DEBUG
221
222 /* Set list flags */
223 #define SFLAG_MINIMAL 1
224 #define SFLAG_NOX 2
225
226 /* Round up to the next full cylinder size */
227 #define NUMSEC(size, sizemult, cylsize) \
228 ((sizemult) == 1 ? (size) : \
229 roundup((size) * (sizemult), (cylsize)))
230
231 /* What FS type? */
232 #define PI_ISBSDFS(PI) (PI_FSTYPE(PI) == FS_BSDLFS || \
233 PI_FSTYPE(PI) == FS_BSDFFS)
234
235 /*
236 * We do not offer CDs or floppies as installation target usually.
237 * Architectures might want to undefine if they want to allow
238 * these devices or redefine if they have unusual CD device names.
239 * Do not define to empty or an empty string, undefine instead.
240 */
241 #define CD_NAMES "cd*"
242 #define FLOPPY_NAMES "fd*"
243
244 /* Types */
245
246 /* pass a void* argument into a menu and also provide a int return value */
247 typedef struct arg_rv {
248 void *arg;
249 int rv;
250 } arg_rv;
251
252 /*
253 * A minimal argument for menus using string replacements
254 */
255 typedef struct arg_replace {
256 const char **argv;
257 size_t argc;
258 } arg_replace;
259
260 /*
261 * pass a parameter array (for string replacements) into a menu and provide
262 * an integer return value
263 */
264 typedef struct arg_rep_int {
265 arg_replace args;
266 int rv;
267 } arg_rep_int;
268
269 typedef struct distinfo {
270 const char *name;
271 uint set;
272 bool force_tgz; /* this set is always in .tgz format */
273 const char *desc;
274 const char *marker_file; /* set assumed installed if exists */
275 } distinfo;
276
277 #define MOUNTLEN 20
278
279
280 /*
281 * A description of a future partition and its usage.
282 * A list of this is the output of the first stage partition
283 * editor, before it gets transformed into a concrete partition
284 * layout according to the partitioning scheme backend.
285 */
286 struct part_usage_info {
287 daddr_t size; /* thumb guestimate of size,
288 * [sec if positive, %-of-ram
289 * if TMPFS and negative]
290 */
291 daddr_t def_size; /* default size */
292 daddr_t limit; /* max size */
293 char mount[MOUNTLEN]; /* where will we mount this? */
294 enum part_type type; /* PT_root/PT_swap/PT_EFI_SYSTEM */
295
296 #define PUIFLAG_EXTEND 1 /* extend this part if free space
297 * is available */
298 #define PUIFLAG_ADD_OUTER 2 /* Add this partition to the outer
299 * partitions (if available) */
300 #define PUIFLG_IS_OUTER 4 /* this is an existing outer one */
301 #define PUIFLG_ADD_INNER 8 /* add outer also to inner */
302 #define PUIFLG_JUST_MOUNTPOINT 16 /* tmpfs of mfs mountpoints */
303 #define PUIFLG_CLONE_PARTS 32 /* clone external partitions */
304 uint flags;
305 struct disk_partitions *parts; /* Where does this partition live?
306 * We currently only support
307 * a single disk, but we plan to
308 * extend that.
309 * Use pm->parts to access
310 * the partitions. */
311 part_id cur_part_id; /* this may change, but we try to
312 * fix it up after all changes */
313 daddr_t cur_start; /* may change during editing, just
314 * used as a unique identifier */
315 uint32_t cur_flags; /* PTI_* flags from disk_part_info */
316
317 #define PUIMNT_ASYNC 0x0001 /* mount -o async */
318 #define PUIMNT_NOATIME 0x0002 /* mount -o noatime */
319 #define PUIMNT_NODEV 0x0004 /* mount -o nodev */
320 #define PUIMNT_NODEVMTIME 0x0008 /* mount -o nodevmtime */
321 #define PUIMNT_NOEXEC 0x0010 /* mount -o noexec */
322 #define PUIMNT_NOSUID 0x0020 /* mount -o nosuid */
323 #define PUIMNT_LOG 0x0040 /* mount -o log */
324 #define PUIMNT_NOAUTO 0x0080 /* "noauto" fstab flag */
325 unsigned int mountflags; /* flags for fstab */
326 #define PUIINST_NEWFS 0x0001 /* need to 'newfs' partition */
327 #define PUIINST_MOUNT 0x0002 /* need to mount partition */
328 #define PUIINST_BOOT 0x0004 /* this is a boot partition */
329 unsigned int instflags; /* installer handling flags */
330 uint fs_type, fs_version; /* e.g. FS_LFS, or FS_BSDFS,
331 * version = 2 for FFSv2 */
332 uint fs_opt1, fs_opt2, fs_opt3; /* FS specific, FFS: block/frag */
333 #ifndef NO_CLONES
334 /*
335 * Only != NULL when PUIFLG_CLONE_PARTS is set, describes the
336 * source partitions to clone here.
337 */
338 struct selected_partitions *clone_src;
339 /*
340 * If clone_src != NULL, this record corresponds to a single
341 * selected source partition, if clone_ndx is a valid index in clone_src
342 * (>= 0 && <= clone_src->num_sel, or all of them if clone_ndx = ~0U.
343 */
344 size_t clone_ndx;
345 #endif
346 };
347
348 /*
349 * A list of partition suggestions, bundled for editing
350 */
351 struct partition_usage_set {
352 struct disk_partitions *parts; /* main partition table */
353 size_t num; /* number of infos */
354 struct part_usage_info *infos; /* 0 .. num-1 */
355 struct disk_partitions **write_back;
356 /* partition tables from which we
357 * did delete some partitions and
358 * that need updating, even if
359 * no active partition remains. */
360 size_t num_write_back; /* number of write_back */
361 daddr_t cur_free_space; /* estimate of free sectors */
362 daddr_t reserved_space; /* space we are not allowed to use */
363 menu_ent *menu_opts; /* 0 .. num+N */
364 int menu; /* the menu to edit this */
365 bool ok; /* ok to continue (all fit) */
366 };
367
368 /*
369 * A structure we pass around in menus that edit a single partition out
370 * of a partition_usage_set.
371 */
372 struct single_part_fs_edit {
373 struct partition_usage_set *pset;
374 size_t index, first_custom_attr, offset, mode;
375 part_id id;
376 struct disk_part_info info; /* current partition data */
377 struct part_usage_info *wanted; /* points at our edit data */
378
379 /*
380 * "Backup" of old data, so we can restore previous values
381 * ("undo").
382 */
383 struct part_usage_info old_usage;
384 struct disk_part_info old_info;
385
386 /* menu return value */
387 int rv;
388 };
389
390 /*
391 * Description of a full target installation, all partitions and
392 * devices (may be accross several struct pm_devs / disks).
393 */
394 struct install_partition_desc {
395 size_t num; /* how many entries in infos */
396 struct part_usage_info *infos; /* individual partitions */
397 struct disk_partitions **write_back; /* partition tables from
398 * which we did delete some
399 * partitions and that need
400 * updating, even if no
401 * active partition remains. */
402 size_t num_write_back; /* number of write_back */
403 bool cur_system; /* target is the life system */
404 };
405
406 /* variables */
407
408 extern int debug; /* set by -D option */
409
410 extern char machine[SSTRSIZE];
411
412 extern int ignorerror;
413 extern int ttysig_ignore;
414 extern pid_t ttysig_forward;
415 extern uint sizemult;
416 extern const char *multname;
417 extern const char *err_outofmem;
418 extern int partman_go; /* run extended partition manager */
419
420 /* logging variables */
421
422 extern FILE *logfp;
423 extern FILE *script;
424
425 #define MAX_DISKS 15
426
427 extern daddr_t root_limit; /* BIOS (etc) read limit */
428
429 enum SHRED_T { SHRED_NONE=0, SHRED_ZEROS, SHRED_RANDOM };
430
431 /* All information that is unique for each drive */
432 extern SLIST_HEAD(pm_head_t, pm_devs) pm_head;
433
434 struct pm_devs {
435 /*
436 * If device is blocked (e.g. part of a raid)
437 * this is a pointers to the parent dev
438 */
439 void *refdev;
440
441 char diskdev[SSTRSIZE]; /* Actual name of the disk. */
442 char diskdev_descr[STRSIZE]; /* e.g. IDENTIFY result */
443
444 /*
445 * What the disk layout should look like.
446 */
447 struct disk_partitions *parts;
448
449 /*
450 * The device does not take a MBR, even if we usually use
451 * MBR master / disklabel secondary partitioning.
452 * Used e.g. for raid* pseudo-disks.
453 */
454 bool no_mbr; /* userd for raid (etc) */
455
456 /*
457 * This device can not be partitioned (in any way).
458 * Used for wedges (dk*) or LVM devices.
459 */
460 bool no_part;
461
462 /*
463 * This is a pseudo-device representing the currently running
464 * system (i.e. all mounted file systems).
465 */
466 bool cur_system;
467
468 /* Actual values for current disk geometry - set by find_disks() or
469 * md_get_info()
470 */
471 uint sectorsize, dlcyl, dlhead, dlsec, dlcylsize, current_cylsize;
472 /*
473 * Total size of the disk - in 'sectorsize' units (!)
474 */
475 daddr_t dlsize; /* total number of disk sectors */
476
477 /* Area of disk we can allocate, start and size in sectors. */
478 daddr_t ptstart, ptsize;
479
480 /* For some bootblocks we need to know the CHS addressable limit */
481 daddr_t max_chs; /* bcyl * bhead * bsec */
482
483 /* If we have an MBR boot partition, start and size in sectors */
484 daddr_t bootstart, bootsize;
485
486 /*
487 * In extended partitioning: all partitions in parts (number of
488 * entries is parts->num_part) may actually be mounted (temporarily)
489 * somewhere, e.g. to access a vnd device on them. This list has
490 * a pointer to the current mount point (strdup()'d) if mounted,
491 * or NULL if not.
492 */
493 char **mounted;
494
495 bool unsaved; /* Flag indicating to partman that device need saving */
496 bool found; /* Flag to delete unplugged and unconfigured devices */
497 int blocked; /* Device is busy and cannot be changed */
498
499 SLIST_ENTRY(pm_devs) l;
500 };
501 extern struct pm_devs *pm; /* Pointer to current device with which we work */
502 extern struct pm_devs *pm_new; /* Pointer for next allocating device in find_disks() */
503
504 /* Generic structure for partman */
505 struct part_entry {
506 part_id id;
507 struct disk_partitions *parts;
508 void *dev_ptr;
509 size_t index; /* e.g. if PM_RAID: this is raids[index] */
510 int dev_ptr_delta;
511 char fullname[SSTRSIZE];
512 enum {PM_DISK=1, PM_PART, PM_SPEC,
513 PM_RAID, PM_CGD, PM_VND, PM_LVM, PM_LVMLV} type;
514 };
515
516 /* Relative file name for storing a distribution. */
517 extern char xfer_dir[STRSIZE];
518 extern int clean_xfer_dir;
519
520 #if !defined(SYSINST_FTP_HOST)
521 #define SYSINST_FTP_HOST "ftp.NetBSD.org"
522 #endif
523
524 #if !defined(SYSINST_HTTP_HOST)
525 #define SYSINST_HTTP_HOST "cdn.NetBSD.org"
526 #endif
527
528 #if !defined(SYSINST_FTP_DIR)
529 #if defined(NETBSD_OFFICIAL_RELEASE)
530 #define SYSINST_FTP_DIR "pub/NetBSD/NetBSD-" REL
531 #elif defined(REL_PATH)
532 #define SYSINST_FTP_DIR "pub/NetBSD-daily/" REL_PATH "/latest"
533 #else
534 #define SYSINST_FTP_DIR "pub/NetBSD/NetBSD-" REL
535 #endif
536 #endif
537
538 #if !defined(ARCH_SUBDIR)
539 #define ARCH_SUBDIR MACH
540 #endif
541 #if !defined(PKG_ARCH_SUBDIR)
542 #define PKG_ARCH_SUBDIR MACH
543 #endif
544
545 #if !defined(SYSINST_PKG_HOST)
546 #define SYSINST_PKG_HOST "ftp.NetBSD.org"
547 #endif
548 #if !defined(SYSINST_PKG_HTTP_HOST)
549 #define SYSINST_PKG_HTTP_HOST "cdn.NetBSD.org"
550 #endif
551
552 #if !defined(SYSINST_PKG_DIR)
553 #define SYSINST_PKG_DIR "pub/pkgsrc/packages/NetBSD"
554 #endif
555
556 #if !defined(PKG_SUBDIR)
557 #define PKG_SUBDIR REL
558 #endif
559
560 #if !defined(SYSINST_PKGSRC_HOST)
561 #define SYSINST_PKGSRC_HOST SYSINST_PKG_HOST
562 #endif
563 #if !defined(SYSINST_PKGSRC_HTTP_HOST)
564 #define SYSINST_PKGSRC_HTTP_HOST SYSINST_PKG_HTTP_HOST
565 #endif
566
567 #ifndef SETS_TAR_SUFF
568 #define SETS_TAR_SUFF "tgz"
569 #endif
570
571 #ifdef USING_PAXASTAR
572 #define TAR_EXTRACT_FLAGS "-xhepf"
573 #else
574 #define TAR_EXTRACT_FLAGS "-xpf"
575 #endif
576
577 /* Abs. path we extract binary sets from */
578 extern char ext_dir_bin[STRSIZE];
579
580 /* Abs. path we extract source sets from */
581 extern char ext_dir_src[STRSIZE];
582
583 /* Abs. path we extract pkgsrc from */
584 extern char ext_dir_pkgsrc[STRSIZE];
585
586 /* Place we look for binary sets in all fs types */
587 extern char set_dir_bin[STRSIZE];
588
589 /* Place we look for source sets in all fs types */
590 extern char set_dir_src[STRSIZE];
591
592 /* Place we look for pkgs in all fs types */
593 extern char pkg_dir[STRSIZE];
594
595 /* Place we look for pkgsrc in all fs types */
596 extern char pkgsrc_dir[STRSIZE];
597
598 /* User shell */
599 extern const char *ushell;
600
601 #define XFER_FTP 0
602 #define XFER_HTTP 1
603 #define XFER_MAX XFER_HTTP
604
605 struct ftpinfo {
606 char xfer_host[XFER_MAX+1][STRSIZE];
607 char dir[STRSIZE] ;
608 char user[SSTRSIZE];
609 char pass[STRSIZE];
610 char proxy[STRSIZE];
611 unsigned int xfer; /* XFER_FTP for "ftp" or XFER_HTTP for "http" */
612 };
613
614 /* use the same struct for sets ftp and to build pkgpath */
615 extern struct ftpinfo ftp, pkg, pkgsrc;
616
617 extern int (*fetch_fn)(const char *);
618 extern char nfs_host[STRSIZE];
619 extern char nfs_dir[STRSIZE];
620 extern char entropy_file[PATH_MAX];
621
622 extern char cdrom_dev[SSTRSIZE]; /* Typically "cd0a" */
623 extern char fd_dev[SSTRSIZE]; /* Typically "/dev/fd0a" */
624 extern const char *fd_type; /* "msdos", "ffs" or maybe "ados" */
625
626 extern char localfs_dev[SSTRSIZE];
627 extern char localfs_fs[SSTRSIZE];
628 extern char localfs_dir[STRSIZE];
629
630 extern char targetroot_mnt[SSTRSIZE];
631
632 extern int mnt2_mounted;
633
634 extern char dist_postfix[SSTRSIZE];
635 extern char dist_tgz_postfix[SSTRSIZE];
636
637 /* needed prototypes */
638 void set_menu_numopts(int, int);
639 void remove_color_options(void);
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*);
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 bool do_check_entropy(void);
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_mount_do(const char *, const char *, const char *);
927 int target_test(unsigned int, const char *);
928 int target_dir_exists_p(const char *);
929 int target_file_exists_p(const char *);
930 int target_symlink_exists_p(const char *);
931 void unwind_mounts(void);
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