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