10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57563SPrasad.Singamsetty@Sun.COM * Common Development and Distribution License (the "License"). 67563SPrasad.Singamsetty@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12311SShengliang.Zhang@Sun.COM * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _MISC_H 260Sstevel@tonic-gate #define _MISC_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifdef __cplusplus 290Sstevel@tonic-gate extern "C" { 300Sstevel@tonic-gate #endif 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * This file contains declarations pertaining to the miscellaneous routines. 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate #include <setjmp.h> 360Sstevel@tonic-gate #include <termios.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* 390Sstevel@tonic-gate * Define macros bzero and bcopy for convenience 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate #ifndef bzero 420Sstevel@tonic-gate #define bzero(p, n) (void) memset((p), 0, (n)) 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate #ifndef bcopy 450Sstevel@tonic-gate #define bcopy(src, dst, n) (void) memcpy((dst), (src), (n)) 460Sstevel@tonic-gate #endif 470Sstevel@tonic-gate #ifndef bcmp 480Sstevel@tonic-gate #define bcmp(p1, p2, n) memcmp((p1), (p2), (n)) 490Sstevel@tonic-gate #endif 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * Minimum and maximum macros 530Sstevel@tonic-gate */ 540Sstevel@tonic-gate #ifndef min 550Sstevel@tonic-gate #define min(x, y) ((x) < (y) ? (x) : (y)) 560Sstevel@tonic-gate #endif /* min */ 570Sstevel@tonic-gate #ifndef max 580Sstevel@tonic-gate #define max(x, y) ((x) > (y) ? (x) : (y)) 590Sstevel@tonic-gate #endif /* max */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * This defines the structure of a saved environment. It consists of the 630Sstevel@tonic-gate * environment itself, a pointer to the next environment on the stack, and 640Sstevel@tonic-gate * flags to tell whether the environment is active, etc. 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate struct env { 670Sstevel@tonic-gate jmp_buf env; /* environment buf */ 680Sstevel@tonic-gate struct env *ptr; /* ptr to next on list */ 690Sstevel@tonic-gate char flags; /* flags */ 700Sstevel@tonic-gate }; 710Sstevel@tonic-gate extern struct env *current_env; 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * This macro saves the current environment in the given structure and 740Sstevel@tonic-gate * pushes the structure onto our enivornment stack. It initializes the 750Sstevel@tonic-gate * flags to zero (inactive). 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate #define saveenv(x) { \ 780Sstevel@tonic-gate x.ptr = current_env; \ 790Sstevel@tonic-gate current_env = &x; \ 800Sstevel@tonic-gate (void) setjmp(x.env); \ 810Sstevel@tonic-gate x.flags = 0; \ 820Sstevel@tonic-gate } 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * This macro marks the environment on the top of the stack active. It 850Sstevel@tonic-gate * assumes that there is an environment on the stack. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate #define useenv() (current_env->flags |= ENV_USE) 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * This macro marks the environment on the top of the stack inactive. It 900Sstevel@tonic-gate * assumes that there is an environment on the stack. 910Sstevel@tonic-gate */ 920Sstevel@tonic-gate #define unuseenv() (current_env->flags &= ~ENV_USE) 930Sstevel@tonic-gate /* 940Sstevel@tonic-gate * This macro pops an environment off the top of the stack. It 950Sstevel@tonic-gate * assumes that there is an environment on the stack. 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate #define clearenv() (current_env = current_env->ptr) 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * These are the flags for the environment struct. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate #define ENV_USE 0x01 /* active */ 1020Sstevel@tonic-gate #define ENV_CRITICAL 0x02 /* in critical zone */ 1030Sstevel@tonic-gate #define ENV_ABORT 0x04 /* abort pending */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * This structure is used to keep track of the state of the tty. This 1070Sstevel@tonic-gate * is necessary because some of the commands turn off echoing. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate struct ttystate { 1100Sstevel@tonic-gate struct termios ttystate; /* buffer for ioctls */ 1110Sstevel@tonic-gate int ttyflags; /* changes to tty state */ 1120Sstevel@tonic-gate int ttyfile; /* file for ioctls */ 1130Sstevel@tonic-gate int vmin; /* min read satisfier */ 1140Sstevel@tonic-gate int vtime; /* read timing */ 1150Sstevel@tonic-gate }; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * ttyflags - changes we can make to the tty state. 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate #define TTY_ECHO_OFF 0x01 /* turned echo off */ 1210Sstevel@tonic-gate #define TTY_CBREAK_ON 0x02 /* turned cbreak on */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * This is the number lines assumed for the tty. It is designed to work 1250Sstevel@tonic-gate * on terminals as well as sun monitors. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate #define TTY_LINES 24 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* 1300Sstevel@tonic-gate * format parameter to dump() 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate #define HEX_ONLY 0 /* print hex only */ 1330Sstevel@tonic-gate #define HEX_ASCII 1 /* hex and ascii */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * Prototypes for ANSI C 1380Sstevel@tonic-gate */ 1390Sstevel@tonic-gate void *zalloc(int count); 1400Sstevel@tonic-gate void *rezalloc(void *ptr, int count); 1410Sstevel@tonic-gate void destroy_data(char *data); 1420Sstevel@tonic-gate int check(char *question); 1430Sstevel@tonic-gate void cmdabort(int sig); 1440Sstevel@tonic-gate void onsusp(int sig); 1450Sstevel@tonic-gate void onalarm(int sig); 1461054Smike_s void fullabort(void) __NORETURN; 1470Sstevel@tonic-gate void enter_critical(void); 1480Sstevel@tonic-gate void exit_critical(void); 1490Sstevel@tonic-gate void echo_off(void); 1500Sstevel@tonic-gate void echo_on(void); 1510Sstevel@tonic-gate void charmode_on(void); 1520Sstevel@tonic-gate void charmode_off(void); 1530Sstevel@tonic-gate char *alloc_string(char *s); 1540Sstevel@tonic-gate char **build_argvlist(char **, int *, int *, char *); 1550Sstevel@tonic-gate int conventional_name(char *name); 156*12311SShengliang.Zhang@Sun.COM #ifdef i386 157*12311SShengliang.Zhang@Sun.COM int emcpower_name(char *name); 158*12311SShengliang.Zhang@Sun.COM #endif 159*12311SShengliang.Zhang@Sun.COM 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #if defined(_FIRMWARE_NEEDS_FDISK) 1620Sstevel@tonic-gate int fdisk_physical_name(char *name); 1630Sstevel@tonic-gate #endif /* defined(_FIRMWARE_NEEDS_FDISK) */ 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate int whole_disk_name(char *name); 1660Sstevel@tonic-gate int canonical_name(char *name); 1670Sstevel@tonic-gate int canonical4x_name(char *name); 1680Sstevel@tonic-gate void canonicalize_name(char *dst, char *src); 1690Sstevel@tonic-gate int match_substr(char *s1, char *s2); 1700Sstevel@tonic-gate void dump(char *, caddr_t, int, int); 1710Sstevel@tonic-gate float bn2mb(uint64_t); 1727563SPrasad.Singamsetty@Sun.COM diskaddr_t mb2bn(float); 1730Sstevel@tonic-gate float bn2gb(uint64_t); 1740Sstevel@tonic-gate float bn2tb(uint64_t); 1757563SPrasad.Singamsetty@Sun.COM diskaddr_t gb2bn(float); 1760Sstevel@tonic-gate int get_tty_lines(); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Macro to handle internal programming errors that 1810Sstevel@tonic-gate * should "never happen". 1820Sstevel@tonic-gate */ 1830Sstevel@tonic-gate #define impossible(msg) {err_print("Internal error: file %s, line %d: %s\n", \ 1840Sstevel@tonic-gate __FILE__, __LINE__, msg); \ 1850Sstevel@tonic-gate fullabort(); } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate extern char *confirm_list[]; 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate /* 1910Sstevel@tonic-gate * This defines the size of the blind selection verfication prompt 1920Sstevel@tonic-gate */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #define BLIND_SELECT_VER_PROMPT (43 + MAXNAMELEN) 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate #ifdef __cplusplus 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate #endif 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate #endif /* _MISC_H */ 201