1/* $NetBSD: defs.h,v 1.161.2.2 2012/07/04 20:48:55 jdc 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/types.h> 42#include <sys/disklabel.h> 43 44const char *getfslabelname(uint8_t); 45 46static inline void * 47deconst(const void *p) 48{ 49 return (char *)0 + ((const char *)p - (const char *)0); 50} 51 52#include "msg_defs.h" 53#include "menu_defs.h" 54 55#define min(a,b) ((a) < (b) ? (a) : (b)) 56#define max(a,b) ((a) > (b) ? (a) : (b)) 57 58/* constants */ 59#define MEG (1024 * 1024) 60#define STRSIZE 255 61#define SSTRSIZE 30 62 63/* For run.c: collect() */ 64#define T_FILE 0 65#define T_OUTPUT 1 66 67/* Some install status/response values */ 68#define SET_OK 0 /* Set extracted */ 69#define SET_RETRY 1 /* Retry */ 70#define SET_SKIP 2 /* Skip this set */ 71#define SET_SKIP_GROUP 3 /* Skip this set and rest of group */ 72#define SET_ABANDON 4 /* Abandon installation */ 73#define SET_CONTINUE 5 /* Continue (copy from floppy loop) */ 74 75/* run_prog flags */ 76#define RUN_DISPLAY 0x0001 /* Display program output */ 77#define RUN_FATAL 0x0002 /* errors are fatal */ 78#define RUN_CHROOT 0x0004 /* chroot to target disk */ 79#define RUN_FULLSCREEN 0x0008 /* fullscreen (use with RUN_DISPLAY) */ 80#define RUN_SILENT 0x0010 /* Do not show output */ 81#define RUN_ERROR_OK 0x0040 /* Don't wait for error confirmation */ 82#define RUN_PROGRESS 0x0080 /* Output is just progess test */ 83#define RUN_NO_CLEAR 0x0100 /* Leave program output after error */ 84#define RUN_XFER_DIR 0x0200 /* cd to xfer_dir in child */ 85 86/* Installation sets */ 87enum { 88 SET_NONE, 89 SET_KERNEL_FIRST, 90 SET_KERNEL_1, /* Usually GENERIC */ 91 SET_KERNEL_2, /* MD kernel... */ 92 SET_KERNEL_3, /* MD kernel... */ 93 SET_KERNEL_4, /* MD kernel... */ 94 SET_KERNEL_5, /* MD kernel... */ 95 SET_KERNEL_6, /* MD kernel... */ 96 SET_KERNEL_7, /* MD kernel... */ 97 SET_KERNEL_8, /* MD kernel... */ 98 SET_KERNEL_LAST, /* allow 8 kernels */ 99 100 /* System sets */ 101 SET_BASE, /* base */ 102 SET_ETC, /* /etc */ 103 SET_COMPILER, /* compiler tools */ 104 SET_GAMES, /* text games */ 105 SET_MAN_PAGES, /* online manual pages */ 106 SET_MISC, /* miscellaneuous */ 107 SET_MODULES, /* kernel modules */ 108 SET_TESTS, /* tests */ 109 SET_TEXT_TOOLS, /* text processing tools */ 110 111 /* X11 sets */ 112 SET_X11_FIRST, 113 SET_X11_BASE, /* X11 base and clients */ 114 SET_X11_FONTS, /* X11 fonts */ 115 SET_X11_SERVERS, /* X11 servers */ 116 SET_X11_PROG, /* X11 programming */ 117 SET_X11_ETC, /* X11 config */ 118 SET_X11_LAST, 119 120 /* Machine dependent sets */ 121 SET_MD_1, /* Machine dependent set */ 122 SET_MD_2, /* Machine dependent set */ 123 SET_MD_3, /* Machine dependent set */ 124 SET_MD_4, /* Machine dependent set */ 125 126 /* Source sets */ 127 SET_SYSSRC, 128 SET_SRC, 129 SET_SHARESRC, 130 SET_GNUSRC, 131 SET_XSRC, 132 133 SET_LAST, 134 SET_GROUP, /* Start of submenu */ 135 SET_GROUP_END, /* End of submenu */ 136 SET_PKGSRC, /* pkgsrc, not counted as regular set */ 137}; 138 139/* Initialisers to select sets */ 140/* All kernels */ 141#define SET_KERNEL SET_KERNEL_1, SET_KERNEL_2, SET_KERNEL_3, SET_KERNEL_4, \ 142 SET_KERNEL_5, SET_KERNEL_6, SET_KERNEL_7, SET_KERNEL_8 143/* Core system sets */ 144#define SET_CORE SET_MODULES, SET_BASE, SET_ETC 145/* All system sets */ 146#define SET_SYSTEM SET_CORE, SET_COMPILER, SET_GAMES, \ 147 SET_MAN_PAGES, SET_MISC, SET_TESTS, SET_TEXT_TOOLS 148/* All X11 sets */ 149#define SET_X11_NOSERVERS SET_X11_BASE, SET_X11_FONTS, SET_X11_PROG, SET_X11_ETC 150#define SET_X11 SET_X11_NOSERVERS, SET_X11_SERVERS 151 152/* All machine dependent sets */ 153#define SET_MD SET_MD_1, SET_MD_2, SET_MD_3, SET_MD_4 154 155/* All source sets */ 156#define SET_SOURCE SET_SYSSRC, SET_SRC, SET_SHARESRC, SET_GNUSRC, SET_XSRC 157 158/* Set list flags */ 159#define SFLAG_MINIMAL 1 160#define SFLAG_NOX 2 161 162/* Macros */ 163#define nelem(x) (sizeof (x) / sizeof *(x)) 164 165/* Round up to the next full cylinder size */ 166#define NUMSEC(size, sizemult, cylsize) \ 167 ((size) == ~0u ? ~0u : (sizemult) == 1 ? (size) : \ 168 roundup((size) * (sizemult), (cylsize))) 169 170/* What FS type? */ 171#define PI_ISBSDFS(p) ((p)->pi_fstype == FS_BSDLFS || \ 172 (p)->pi_fstype == FS_BSDFFS) 173 174/* standard cd0 device */ 175#define CD_NAMES "cd0a" 176 177/* Types */ 178typedef struct distinfo { 179 const char *name; 180 uint set; 181 const char *desc; 182 const char *marker_file; /* set assumed installed if exists */ 183} distinfo; 184 185typedef struct _partinfo { 186 struct partition pi_partition; 187#define pi_size pi_partition.p_size 188#define pi_offset pi_partition.p_offset 189#define pi_fsize pi_partition.p_fsize 190#define pi_fstype pi_partition.p_fstype 191#define pi_frag pi_partition.p_frag 192#define pi_cpg pi_partition.p_cpg 193 char pi_mount[20]; 194 uint pi_isize; /* bytes per inode (for # inodes) */ 195 uint pi_flags; 196#define PIF_NEWFS 0x0001 /* need to 'newfs' partition */ 197#define PIF_FFSv2 0x0002 /* newfs with FFSv2, not FFSv1 */ 198#define PIF_MOUNT 0x0004 /* need to mount partition */ 199#define PIF_ASYNC 0x0010 /* mount -o async */ 200#define PIF_NOATIME 0x0020 /* mount -o noatime */ 201#define PIF_NODEV 0x0040 /* mount -o nodev */ 202#define PIF_NODEVMTIME 0x0080 /* mount -o nodevmtime */ 203#define PIF_NOEXEC 0x0100 /* mount -o noexec */ 204#define PIF_NOSUID 0x0200 /* mount -o nosuid */ 205#define PIF__UNUSED 0x0400 /* unused */ 206#define PIF_LOG 0x0800 /* mount -o log */ 207#define PIF_MOUNT_OPTS 0x0ff0 /* all above mount flags */ 208#define PIF_RESET 0x1000 /* internal - restore previous values */ 209} partinfo; /* Single partition from a disklabel */ 210 211struct ptn_info { 212 int menu_no; 213 struct ptn_size { 214 int ptn_id; 215 char mount[20]; 216 daddr_t dflt_size; 217 daddr_t size; 218 int limit; 219 int changed; 220 } ptn_sizes[MAXPARTITIONS + 1]; /* +1 for delete code */ 221 menu_ent ptn_menus[MAXPARTITIONS + 1]; /* +1 for unit chg */ 222 int free_parts; 223 daddr_t free_space; 224 struct ptn_size *pool_part; 225 char exit_msg[70]; 226}; 227 228/* variables */ 229 230int debug; /* set by -D option */ 231 232char rel[SSTRSIZE]; 233char machine[SSTRSIZE]; 234 235int yesno; 236int ignorerror; 237int ttysig_ignore; 238pid_t ttysig_forward; 239int layoutkind; 240int sizemult; 241const char *multname; 242 243/* loging variables */ 244 245FILE *logfp; 246FILE *script; 247 248/* Actual name of the disk. */ 249char diskdev[SSTRSIZE]; 250int no_mbr; /* set for raid (etc) */ 251int rootpart; /* partition we install into */ 252const char *disktype; /* ST506, SCSI, ... */ 253 254/* Area of disk we can allocate, start and size in disk sectors. */ 255daddr_t ptstart, ptsize; 256/* If we have an MBR boot partition, start and size in sectors */ 257int bootstart, bootsize; 258 259/* Actual values for current disk - set by find_disks() or md_get_info() */ 260int sectorsize; 261int dlcyl, dlhead, dlsec, dlcylsize; 262daddr_t dlsize; 263int current_cylsize; 264unsigned int root_limit; /* BIOS (etc) read limit */ 265 266/* Information for the NetBSD disklabel */ 267enum DLTR { PART_A, PART_B, PART_C, PART_D, PART_E, PART_F, PART_G, PART_H, 268 PART_I, PART_J, PART_K, PART_L, PART_M, PART_N, PART_O, PART_P}; 269#define partition_name(x) ('a' + (x)) 270partinfo oldlabel[MAXPARTITIONS]; /* What we found on the disk */ 271partinfo bsdlabel[MAXPARTITIONS]; /* What we want it to look like */ 272daddr_t tmp_ramdisk_size; 273 274#define DISKNAME_SIZE 16 275char bsddiskname[DISKNAME_SIZE]; 276const char *doessf; 277 278/* Relative file name for storing a distribution. */ 279char xfer_dir[STRSIZE]; 280int clean_xfer_dir; 281 282#if !defined(SYSINST_FTP_HOST) 283#define SYSINST_FTP_HOST "ftp.NetBSD.org" 284#endif 285 286#if !defined(SYSINST_FTP_DIR) 287#define SYSINST_FTP_DIR "pub/NetBSD/NetBSD-" REL 288#endif 289 290#if !defined(SYSINST_PKG_HOST) 291#define SYSINST_PKG_HOST SYSINST_FTP_HOST 292#endif 293 294#if !defined(SYSINST_PKG_DIR) 295#define SYSINST_PKG_DIR "pub/pkgsrc/packages/NetBSD" 296#endif 297 298#if !defined(SYSINST_PKGSRC_HOST) 299#define SYSINST_PKGSRC_HOST SYSINST_PKG_HOST 300#endif 301 302/* Abs. path we extract binary sets from */ 303char ext_dir_bin[STRSIZE]; 304 305/* Abs. path we extract source sets from */ 306char ext_dir_src[STRSIZE]; 307 308/* Abs. path we extract pkgsrc from */ 309char ext_dir_pkgsrc[STRSIZE]; 310 311/* Place we look for binary sets in all fs types */ 312char set_dir_bin[STRSIZE]; 313 314/* Place we look for source sets in all fs types */ 315char set_dir_src[STRSIZE]; 316 317/* Place we look for pkgs in all fs types */ 318char pkg_dir[STRSIZE]; 319 320/* Place we look for pkgsrc in all fs types */ 321char pkgsrc_dir[STRSIZE]; 322 323struct ftpinfo { 324 char host[STRSIZE]; 325 char dir[STRSIZE] ; 326 char user[SSTRSIZE]; 327 char pass[STRSIZE]; 328 char proxy[STRSIZE]; 329 const char *xfer_type; /* "ftp" or "http" */ 330}; 331 332/* use the same struct for sets ftp and to build pkgpath */ 333struct ftpinfo ftp, pkg, pkgsrc; 334 335int (*fetch_fn)(const char *); 336char nfs_host[STRSIZE]; 337char nfs_dir[STRSIZE]; 338 339char cdrom_dev[SSTRSIZE]; /* Typically "cd0a" */ 340char fd_dev[SSTRSIZE]; /* Typically "/dev/fd0a" */ 341const char *fd_type; /* "msdos", "ffs" or maybe "ados" */ 342 343char localfs_dev[SSTRSIZE]; 344char localfs_fs[SSTRSIZE]; 345char localfs_dir[STRSIZE]; 346 347char targetroot_mnt[SSTRSIZE]; 348 349int mnt2_mounted; 350 351char dist_postfix[SSTRSIZE]; 352 353/* needed prototypes */ 354void set_menu_numopts(int, int); 355 356/* Machine dependent functions .... */ 357void md_init(void); 358void md_init_set_status(int); /* SFLAG_foo */ 359 360 /* MD functions if user selects install - in order called */ 361int md_get_info(void); 362int md_make_bsd_partitions(void); 363int md_check_partitions(void); 364int md_pre_disklabel(void); 365int md_post_disklabel(void); 366int md_pre_mount(void); 367int md_post_newfs(void); 368int md_post_extract(void); 369void md_cleanup_install(void); 370 371 /* MD functions if user selects upgrade - in order called */ 372int md_pre_update(void); 373int md_update(void); 374/* Also calls md_post_extract() */ 375 376/* from main.c */ 377void toplevel(void); 378 379/* from disks.c */ 380const char *get_default_cdrom(void); 381int find_disks(const char *); 382struct menudesc; 383void fmt_fspart(struct menudesc *, int, void *); 384void disp_cur_fspart(int, int); 385int write_disklabel(void); 386int make_filesystems(void); 387int make_fstab(void); 388int mount_disks(void); 389int set_swap(const char *, partinfo *); 390int check_swap(const char *, int); 391char *bootxx_name(void); 392 393/* from disks_lfs.c */ 394int fs_is_lfs(void *); 395 396/* from label.c */ 397const char *get_last_mounted(int, int, partinfo *); 398int savenewlabel(partinfo *, int); 399int incorelabel(const char *, partinfo *); 400int edit_and_check_label(partinfo *, int, int, int); 401void set_bsize(partinfo *, int); 402void set_fsize(partinfo *, int); 403void set_ptype(partinfo *, int, int); 404 405/* from install.c */ 406void do_install(void); 407 408/* from factor.c */ 409void factor(long, long *, int, int *); 410 411/* from fdisk.c */ 412void get_disk_info(char *); 413void set_disk_info(char *); 414 415/* from geom.c */ 416int get_geom(const char *, struct disklabel *); 417int get_real_geom(const char *, struct disklabel *); 418 419/* from net.c */ 420extern int network_up; 421extern char net_namesvr6[STRSIZE]; 422int get_via_ftp(const char *); 423int get_via_nfs(void); 424int config_network(void); 425void mnt_net_config(void); 426void make_url(char *, struct ftpinfo *, const char *); 427int get_pkgsrc(void); 428 429/* From run.c */ 430int collect(int, char **, const char *, ...) __printflike(3, 4); 431int run_program(int, const char *, ...) __printflike(2, 3); 432void do_logging(void); 433int do_system(const char *); 434 435/* from upgrade.c */ 436void do_upgrade(void); 437void do_reinstall_sets(void); 438void restore_etc(void); 439 440/* from util.c */ 441int dir_exists_p(const char *); 442int file_exists_p(const char *); 443int file_mode_match(const char *, unsigned int); 444uint get_ramsize(void); 445void ask_sizemult(int); 446void run_makedev(void); 447int boot_media_still_needed(void); 448int get_via_floppy(void); 449int get_via_cdrom(void); 450int get_via_localfs(void); 451int get_via_localdir(void); 452void show_cur_distsets(void); 453void make_ramdisk_dir(const char *); 454void set_kernel_set(unsigned int); 455unsigned int get_kernel_set(void); 456unsigned int set_X11_selected(void); 457int get_and_unpack_sets(int, msg, msg, msg); 458int sanity_check(void); 459int set_timezone(void); 460void scripting_fprintf(FILE *, const char *, ...) __printflike(2, 3); 461void scripting_vfprintf(FILE *, const char *, va_list) __printflike(2, 0); 462void add_rc_conf(const char *, ...); 463int del_rc_conf(const char *); 464void add_sysctl_conf(const char *, ...) __printflike(1, 2); 465void enable_rc_conf(void); 466void set_sizemultname_cyl(void); 467void set_sizemultname_meg(void); 468int check_lfs_progs(void); 469void init_set_status(int); 470void customise_sets(void); 471void umount_mnt2(void); 472int set_is_source(const char *); 473const char *set_dir_for_set(const char *); 474const char *ext_dir_for_set(const char *); 475void replace(const char *, const char *, ...); 476void get_tz_default(void); 477int extract_file(distinfo *, int); 478 479/* from target.c */ 480#if defined(DEBUG) || defined(DEBUG_ROOT) 481void backtowin(void); 482#endif 483const char *concat_paths(const char *, const char *); 484const char *target_expand(const char *); 485void make_target_dir(const char *); 486void append_to_target_file(const char *, const char *); 487void echo_to_target_file(const char *, const char *); 488void sprintf_to_target_file(const char *, const char *, ...) 489 __printflike(2, 3); 490void trunc_target_file(const char *); 491const char *target_prefix(void); 492int target_chdir(const char *); 493void target_chdir_or_die(const char *); 494int target_already_root(void); 495FILE *target_fopen(const char *, const char *); 496int target_collect_file(int, char **, const char *); 497int is_active_rootpart(const char *, int); 498int cp_to_target(const char *, const char *); 499void dup_file_into_target(const char *); 500void mv_within_target_or_die(const char *, const char *); 501int cp_within_target(const char *, const char *, int); 502int target_mount(const char *, const char *, int, const char *); 503int target_test(unsigned int, const char *); 504int target_dir_exists_p(const char *); 505int target_file_exists_p(const char *); 506int target_symlink_exists_p(const char *); 507void unwind_mounts(void); 508int target_mounted(void); 509 510/* from bsddisklabel.c */ 511int make_bsd_partitions(void); 512int save_ptn(int, daddr_t, daddr_t, int, const char *); 513void set_ptn_titles(menudesc *, int, void *); 514void set_ptn_menu(struct ptn_info *); 515int set_ptn_size(menudesc *, void *); 516void get_ptn_sizes(daddr_t, daddr_t, int); 517 518/* from aout2elf.c */ 519int move_aout_libs(void); 520 521#ifdef WSKBD 522void get_kb_encoding(void); 523void save_kb_encoding(void); 524#else 525#define get_kb_encoding() 526#define save_kb_encoding() 527#endif 528 529/* from configmenu.c */ 530void do_configmenu(void); 531 532/* from checkrc.c */ 533int check_rcvar(const char *); 534int check_rcdefault(const char *); 535#endif /* _DEFS_H_ */ 536