/*
* Copyright 1997 Piermont Information Systems Inc.
* All rights reserved.
*
* Written by Philip A. Nelson for Piermont Information Systems Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _DEFS_H_
#define _DEFS_H_
/* defs.h -- definitions for use in the sysinst program. */
/* System includes needed for this. */
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/disk.h>
#include <limits.h>
#include <uuid.h>
/* these are used for different alignment defaults */
#define HUGE_DISK_SIZE (daddr_t)(128 * (GIG / 512))
#define TINY_DISK_SIZE (daddr_t)(1800 * (MEG / 512))
/*
* if a system does not have more ram (in MB) than this, swap will be enabled
* very early (as soon as the swap partition has been created)
*/
#ifdef EXTRACT_NEEDS_BIG_RAM /* we use an expensive decompressor */
#define TINY_RAM_SIZE 256
#else
#define TINY_RAM_SIZE 32
#endif
/*
* if a system has less ram (in MB) than this, we will not create a
* tmpfs /tmp by default (to workaround PR misc/54886)
*/
#define SMALL_RAM_SIZE 384
/* Some install status/response values */
#define SET_OK 0 /* Set extracted */
#define SET_RETRY 1 /* Retry */
#define SET_SKIP 2 /* Skip this set */
#define SET_SKIP_GROUP 3 /* Skip this set and rest of group */
#define SET_ABANDON 4 /* Abandon installation */
#define SET_CONTINUE 5 /* Continue (copy from floppy loop) */
/* run_prog flags */
#define RUN_DISPLAY 0x0001 /* Display program output */
#define RUN_FATAL 0x0002 /* errors are fatal */
#define RUN_CHROOT 0x0004 /* chroot to target disk */
#define RUN_FULLSCREEN 0x0008 /* fullscreen (use with RUN_DISPLAY) */
#define RUN_SILENT 0x0010 /* Do not show output */
#define RUN_ERROR_OK 0x0040 /* Don't wait for error confirmation */
#define RUN_PROGRESS 0x0080 /* Output is just progess test */
#define RUN_NO_CLEAR 0x0100 /* Leave program output after error */
#define RUN_XFER_DIR 0x0200 /* cd to xfer_dir in child */
#define RUN_STDSCR 0x0400 /* run program in standard screen */
/* for bsddisklabel.c */
enum layout_type {
LY_KEEPEXISTING, /* keep existing partitions */
LY_OTHERSCHEME, /* delete all, select new partitioning scheme */
LY_SETSIZES, /* edit sizes */
LY_USEDEFAULT, /* use default sizes */
LY_USEFULL, /* use full disk for NetBSD */
LY_USENONE, /* start with empty partitions, manual mode */
LY_ERROR /* used for "abort" in menu */
};
/*
* We do not offer CDs or floppies as installation target usually.
* Architectures might want to undefine if they want to allow
* these devices or redefine if they have unusual CD device names.
* Do not define to empty or an empty string, undefine instead.
*/
#define CD_NAMES "cd*"
#define FLOPPY_NAMES "fd*"
/* Types */
/* pass a void* argument into a menu and also provide a int return value */
typedef struct arg_rv {
void *arg;
int rv;
} arg_rv;
/*
* A minimal argument for menus using string replacements
*/
typedef struct arg_replace {
const char **argv;
size_t argc;
} arg_replace;
/*
* pass a parameter array (for string replacements) into a menu and provide
* an integer return value
*/
typedef struct arg_rep_int {
arg_replace args;
int rv;
} arg_rep_int;
typedef struct distinfo {
const char *name;
uint set;
bool force_tgz; /* this set is always in .tgz format */
const char *desc;
const char *marker_file; /* set assumed installed if exists */
} distinfo;
#define MOUNTLEN 20
/*
* A description of a future partition and its usage.
* A list of this is the output of the first stage partition
* editor, before it gets transformed into a concrete partition
* layout according to the partitioning scheme backend.
*/
struct part_usage_info {
daddr_t size; /* thumb guestimate of size,
* [sec if positive, %-of-ram
* if TMPFS and negative]
*/
daddr_t def_size; /* default size */
daddr_t limit; /* max size */
char mount[MOUNTLEN]; /* where will we mount this? */
enum part_type type; /* PT_root/PT_swap/PT_EFI_SYSTEM */
#define PUIFLAG_EXTEND 1 /* extend this part if free space
* is available */
#define PUIFLAG_ADD_OUTER 2 /* Add this partition to the outer
* partitions (if available) */
#define PUIFLG_IS_OUTER 4 /* this is an existing outer one */
#define PUIFLG_ADD_INNER 8 /* add outer also to inner */
#define PUIFLG_JUST_MOUNTPOINT 16 /* tmpfs of mfs mountpoints */
#define PUIFLG_CLONE_PARTS 32 /* clone external partitions */
uint flags;
struct disk_partitions *parts; /* Where does this partition live?
* We currently only support
* a single disk, but we plan to
* extend that.
* Use pm->parts to access
* the partitions. */
part_id cur_part_id; /* this may change, but we try to
* fix it up after all changes */
daddr_t cur_start; /* may change during editing, just
* used as a unique identifier */
uint32_t cur_flags; /* PTI_* flags from disk_part_info */
#define PUIMNT_ASYNC 0x0001 /* mount -o async */
#define PUIMNT_NOATIME 0x0002 /* mount -o noatime */
#define PUIMNT_NODEV 0x0004 /* mount -o nodev */
#define PUIMNT_NODEVMTIME 0x0008 /* mount -o nodevmtime */
#define PUIMNT_NOEXEC 0x0010 /* mount -o noexec */
#define PUIMNT_NOSUID 0x0020 /* mount -o nosuid */
#define PUIMNT_LOG 0x0040 /* mount -o log */
#define PUIMNT_NOAUTO 0x0080 /* "noauto" fstab flag */
unsigned int mountflags; /* flags for fstab */
#define PUIINST_NEWFS 0x0001 /* need to 'newfs' partition */
#define PUIINST_MOUNT 0x0002 /* need to mount partition */
#define PUIINST_BOOT 0x0004 /* this is a boot partition */
unsigned int instflags; /* installer handling flags */
uint fs_type, fs_version; /* e.g. FS_LFS, or FS_BSDFS,
* version = 2 for FFSv2 */
uint fs_opt1, fs_opt2, fs_opt3; /* FS specific, FFS: block/frag */
#ifndef NO_CLONES
/*
* Only != NULL when PUIFLG_CLONE_PARTS is set, describes the
* source partitions to clone here.
*/
struct selected_partitions *clone_src;
/*
* If clone_src != NULL, this record corresponds to a single
* selected source partition, if clone_ndx is a valid index in clone_src
* (>= 0 && <= clone_src->num_sel, or all of them if clone_ndx = ~0U.
*/
size_t clone_ndx;
#endif
};
/*
* A list of partition suggestions, bundled for editing
*/
struct partition_usage_set {
struct disk_partitions *parts; /* main partition table */
size_t num; /* number of infos */
struct part_usage_info *infos; /* 0 .. num-1 */
struct disk_partitions **write_back;
/* partition tables from which we
* did delete some partitions and
* that need updating, even if
* no active partition remains. */
size_t num_write_back; /* number of write_back */
daddr_t cur_free_space; /* estimate of free sectors */
daddr_t reserved_space; /* space we are not allowed to use */
menu_ent *menu_opts; /* 0 .. num+N */
int menu; /* the menu to edit this */
bool ok; /* ok to continue (all fit) */
};
/*
* A structure we pass around in menus that edit a single partition out
* of a partition_usage_set.
*/
struct single_part_fs_edit {
struct partition_usage_set *pset;
size_t index, first_custom_attr, offset, mode;
part_id id;
struct disk_part_info info; /* current partition data */
struct part_usage_info *wanted; /* points at our edit data */
/*
* "Backup" of old data, so we can restore previous values
* ("undo").
*/
struct part_usage_info old_usage;
struct disk_part_info old_info;
/* menu return value */
int rv;
};
/*
* Description of a full target installation, all partitions and
* devices (may be across several struct pm_devs / disks).
*/
struct install_partition_desc {
size_t num; /* how many entries in infos */
struct part_usage_info *infos; /* individual partitions */
struct disk_partitions **write_back; /* partition tables from
* which we did delete some
* partitions and that need
* updating, even if no
* active partition remains. */
size_t num_write_back; /* number of write_back */
bool cur_system; /* target is the live system */
};
/* variables */
extern int debug; /* set by -D option */
extern char machine[SSTRSIZE];
extern int ignorerror;
extern int ttysig_ignore;
extern pid_t ttysig_forward;
extern uint sizemult;
extern const char *multname;
extern const char *err_outofmem;
extern int partman_go; /* run extended partition manager */
/* All information that is unique for each drive */
extern SLIST_HEAD(pm_head_t, pm_devs) pm_head;
struct pm_devs {
/*
* If device is blocked (e.g. part of a raid)
* this is a pointers to the parent dev
*/
void *refdev;
char diskdev[SSTRSIZE]; /* Actual name of the disk. */
char diskdev_descr[STRSIZE]; /* e.g. IDENTIFY result */
/*
* What the disk layout should look like.
*/
struct disk_partitions *parts;
/*
* The device does not take a MBR, even if we usually use
* MBR master / disklabel secondary partitioning.
* Used e.g. for raid* pseudo-disks.
*/
bool no_mbr; /* userd for raid (etc) */
/*
* This device can not be partitioned (in any way).
* Used for wedges (dk*) or LVM devices.
*/
bool no_part;
/*
* This is a pseudo-device representing the currently running
* system (i.e. all mounted file systems).
*/
bool cur_system;
/* Actual values for current disk geometry - set by find_disks() or
* md_get_info()
*/
uint sectorsize, dlcyl, dlhead, dlsec, dlcylsize, current_cylsize;
/*
* Total size of the disk - in 'sectorsize' units (!)
*/
daddr_t dlsize; /* total number of disk sectors */
/* Area of disk we can allocate, start and size in sectors. */
daddr_t ptstart, ptsize;
/* For some bootblocks we need to know the CHS addressable limit */
daddr_t max_chs; /* bcyl * bhead * bsec */
/* If we have an MBR boot partition, start and size in sectors */
daddr_t bootstart, bootsize;
/*
* In extended partitioning: all partitions in parts (number of
* entries is parts->num_part) may actually be mounted (temporarily)
* somewhere, e.g. to access a vnd device on them. This list has
* a pointer to the current mount point (strdup()'d) if mounted,
* or NULL if not.
*/
char **mounted;
bool unsaved; /* Flag indicating to partman that device need saving */
bool found; /* Flag to delete unplugged and unconfigured devices */
int blocked; /* Device is busy and cannot be changed */
SLIST_ENTRY(pm_devs) l;
};
extern struct pm_devs *pm; /* Pointer to current device with which we work */
extern struct pm_devs *pm_new; /* Pointer for next allocating device in find_disks() */
/* Generic structure for partman */
struct part_entry {
part_id id;
struct disk_partitions *parts;
void *dev_ptr;
struct install_partition_desc *install;
size_t index; /* e.g. if PM_RAID: this is raids[index] */
int dev_ptr_delta;
char fullname[SSTRSIZE];
enum {PM_DISK=1, PM_PART, PM_SPEC,
PM_RAID, PM_CGD, PM_VND, PM_LVM, PM_LVMLV} type;
};
/* Relative file name for storing a distribution. */
extern char xfer_dir[STRSIZE];
extern int clean_xfer_dir;
/* MD functions if user selects install - in order called */
bool md_get_info(struct install_partition_desc*);
/* returns -1 to restart partitioning, 0 for error, 1 for success */
int md_make_bsd_partitions(struct install_partition_desc*);
bool md_check_partitions(struct install_partition_desc*);
#ifdef HAVE_GPT
/*
* New GPT partitions have been written, update bootloader or remember
* data untill needed in md_post_newfs
*/
bool md_gpt_post_write(struct disk_partitions*, part_id root_id,
bool root_is_new, part_id efi_id, bool efi_is_new);
#endif
/*
* md_pre_disklabel and md_post_disklabel may be called
* multiple times, for each affected device, with the
* "inner" partitions pointer of the relevant partitions
* passed.
*/
bool md_pre_disklabel(struct install_partition_desc*, struct disk_partitions*);
bool md_post_disklabel(struct install_partition_desc*, struct disk_partitions*);
bool md_disklabel_is_default(const struct disklabel *);
int md_pre_mount(struct install_partition_desc*, size_t);
int md_post_newfs(struct install_partition_desc*);
int md_post_extract(struct install_partition_desc*, bool upgrade);
void md_cleanup_install(struct install_partition_desc*);
/* MD functions if user selects upgrade - in order called */
int md_pre_update(struct install_partition_desc*);
int md_update(struct install_partition_desc*);
/* Also calls md_post_extract() */
struct menudesc;
void disp_cur_fspart(int, int);
bool can_newfs_fstype(unsigned int);
int make_filesystems(struct install_partition_desc *);
int make_fstab(struct install_partition_desc *);
int mount_disks(struct install_partition_desc *);
void set_swap_if_low_ram(struct install_partition_desc *);
void set_swap(struct install_partition_desc *);
void clear_swap(void);
int check_swap(const char *, int);
char *bootxx_name(struct install_partition_desc *);
int get_dkwedges(struct dkwedge_info **, const char *);
/* from disks_lfs.c */
int fs_is_lfs(void *);
/* from label.c */
/*
* Bits valid for "flags" in get_last_mounted.
* Currently we return the real last mount from FFS, the volume label
* from FAT32, and nothing otherwise. The NTFS support is currently
* restricted to verify the partition has an NTFS (as some partitioning
* schemes do not tell NTFS from FAT).
*/
#define GLM_LIKELY_FFS 1U
#define GLM_MAYBE_FAT32 2U
#define GLM_MAYBE_NTFS 4U
/*
* possible fs_sub_types are currently:
* FS_BSDFFS:
* 0 unknown
* 1 FFSv1
* 2 FFSv2
* FS_MSDOS:
* 0 unknown
* else MBR_PTYPE_FAT* for the current FAT variant
* FS_NTFS:
* 0 unknown
* else MBR_PTYPE_NTFS (if valid NTFS was found)
*
* The fs_type and fs_sub_type pointers may be NULL.
*/
const char *get_last_mounted(int fd, daddr_t offset, uint *fs_type,
uint *fs_sub_type, uint flags);
void canonicalize_last_mounted(char*);
int edit_and_check_label(struct pm_devs *p, struct partition_usage_set *pset, bool install);
int edit_ptn(menudesc *, void *);
int checkoverlap(struct disk_partitions *parts);
daddr_t getpartsize(struct disk_partitions *parts, daddr_t orig_start,
daddr_t partstart, daddr_t defpartsize);
daddr_t getpartoff(struct disk_partitions *parts, daddr_t defpartstart);
/* from install.c */
void do_install(void);
/* from factor.c */
void factor(long, long *, int, int *);
/* from fdisk.c */
void get_disk_info(char *);
void set_disk_info(char *);
/* from net.c */
extern int network_up;
extern char net_namesvr[STRSIZE];
int get_via_ftp(unsigned int);
int get_via_nfs(void);
int config_network(int force);
void mnt_net_config(void);
void make_url(char *, struct ftpinfo *, const char *);
int get_pkgsrc(void);
const char *url_proto(unsigned int);
/* From run.c */
int collect(int, char **, const char *, ...) __printflike(3, 4);
int run_program(int, const char *, ...) __printflike(2, 3);
void do_logging(void);
int do_system(const char *);
/* from upgrade.c */
void do_upgrade(void);
void do_reinstall_sets(void);
void restore_etc(void);
/* from part_edit.c */
int err_msg_win(const char*);
const struct disk_partitioning_scheme *select_part_scheme(struct pm_devs *dev,
const struct disk_partitioning_scheme *skip, bool bootable,
const char *title);
/*
* return value:
* 0 -> abort
* 1 -> ok, continue
* -1 -> partitions have been deleted, start from scratch
*/
int edit_outer_parts(struct disk_partitions*);
bool parts_use_wholedisk(struct disk_partitions*,
size_t add_ext_parts, const struct disk_part_info *ext_parts);
/*
* Machine dependent partitioning function, only used when
* innern/outer partitioning schemes are in use - this sets
* up the outer scheme for maximum NetBSD usage.
*/
bool md_parts_use_wholedisk(struct disk_partitions*);
/*
* Parse a file system position or size in a common way, return
* sector count and multiplicator.
* If "extend" is supported, things like 120+ will be parsed as
* 120 plus "extend this" flag.
* Caller needs to init muliplicator upfront to the default value.
*/
daddr_t parse_disk_pos(
const char *, /* in: input string */
daddr_t *, /* in/out: multiplicator for return value */
daddr_t bps, /* in: sector size in bytes */
daddr_t, /* in: cylinder size in sectors */
bool *); /* NULL if "extend" is not supported, & of
* "extend" flag otherwise */
/* flags whether to offer the respective options (depending on helper
programs available on install media */
extern int have_raid, have_vnd, have_cgd, have_lvm, have_gpt, have_dk;
/* initialize above variables */
void check_available_binaries(void);
/* from bsddisklabel.c */
/* returns -1 to restart partitioning, 0 for error, 1 for success */
int make_bsd_partitions(struct install_partition_desc*);
void set_ptn_titles(menudesc *, int, void *);
int set_ptn_size(menudesc *, void *);
bool get_ptn_sizes(struct partition_usage_set*);
bool check_partitions(struct install_partition_desc*);