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