xref: /titanic_54/usr/src/cmd/format/global.h (revision 8488aeb5df27784d479c16cde06a9e25cd9a1152)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8488aeb5Staylor  * Common Development and Distribution License (the "License").
6*8488aeb5Staylor  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*8488aeb5Staylor  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_GLOBAL_H
277c478bd9Sstevel@tonic-gate #define	_GLOBAL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Definitions for Label types: L_TYPE_SOLORIS is the default Sun label
377c478bd9Sstevel@tonic-gate  * a.k.a VTOC. L_TYPE_EFI is the EFI label type.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #define	L_TYPE_SOLARIS	0
407c478bd9Sstevel@tonic-gate #define	L_TYPE_EFI	1
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifndef	UINT_MAX64
43052b6e8aSbg159949 #define	UINT_MAX64	0xffffffffffffffffULL
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifndef UINT_MAX32
477c478bd9Sstevel@tonic-gate #define	UINT_MAX32	0xffffffff
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * This file contains global definitions and declarations.  It is intended
527c478bd9Sstevel@tonic-gate  * to be included by everyone.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #include <stdio.h>
557c478bd9Sstevel@tonic-gate #include <assert.h>
567c478bd9Sstevel@tonic-gate #include <memory.h>
577c478bd9Sstevel@tonic-gate #include <unistd.h>
587c478bd9Sstevel@tonic-gate #include <ctype.h>
597c478bd9Sstevel@tonic-gate #include <sys/types.h>
607c478bd9Sstevel@tonic-gate #include <sys/param.h>
617c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #include <sys/dklabel.h>
647c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
657c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #include "hardware_structs.h"
687c478bd9Sstevel@tonic-gate #include "defect.h"
697c478bd9Sstevel@tonic-gate #include "io.h"
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
727c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * These declarations are global state variables.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate struct	disk_info *disk_list;		/* list of found disks */
797c478bd9Sstevel@tonic-gate struct	ctlr_info *ctlr_list;		/* list of found ctlrs */
807c478bd9Sstevel@tonic-gate char	cur_menu;			/* current menu level */
817c478bd9Sstevel@tonic-gate char	last_menu;			/* last menu level */
827c478bd9Sstevel@tonic-gate char	option_msg;			/* extended message options */
837c478bd9Sstevel@tonic-gate char	diag_msg;			/* extended diagnostic msgs */
847c478bd9Sstevel@tonic-gate char	option_s;			/* silent mode option */
857c478bd9Sstevel@tonic-gate char	*option_f;			/* input redirect option */
867c478bd9Sstevel@tonic-gate char	*option_l;			/* log file option */
877c478bd9Sstevel@tonic-gate FILE	*log_file;			/* log file pointer */
887c478bd9Sstevel@tonic-gate char	*option_d;			/* forced disk option */
897c478bd9Sstevel@tonic-gate char	*option_t;			/* forced disk type option */
907c478bd9Sstevel@tonic-gate char	*option_p;			/* forced partition table option */
917c478bd9Sstevel@tonic-gate char	*option_x;			/* data file redirection option */
927c478bd9Sstevel@tonic-gate FILE	*data_file;			/* data file pointer */
937c478bd9Sstevel@tonic-gate char	*file_name;			/* current data file name */
947c478bd9Sstevel@tonic-gate 					/* for useful error messages */
957c478bd9Sstevel@tonic-gate int	expert_mode;			/* enable for expert mode */
967c478bd9Sstevel@tonic-gate 					/* commands */
977c478bd9Sstevel@tonic-gate int	need_newline;			/* for correctly formatted output */
987c478bd9Sstevel@tonic-gate int	dev_expert;			/* enable for developer mode */
997c478bd9Sstevel@tonic-gate 					/* commands */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * These declarations are used for quick access to information about
1037c478bd9Sstevel@tonic-gate  * the disk being worked on.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate int	cur_file;			/* file descriptor for current disk */
1067c478bd9Sstevel@tonic-gate int	cur_flags;			/* flags for current disk */
1077c478bd9Sstevel@tonic-gate int	cur_label;			/* current label type */
1087c478bd9Sstevel@tonic-gate struct	disk_info *cur_disk;		/* current disk */
1097c478bd9Sstevel@tonic-gate struct	disk_type *cur_dtype;		/* current dtype */
1107c478bd9Sstevel@tonic-gate struct	ctlr_info *cur_ctlr;		/* current ctlr */
1117c478bd9Sstevel@tonic-gate struct	ctlr_type *cur_ctype;		/* current ctype */
1127c478bd9Sstevel@tonic-gate struct	ctlr_ops *cur_ops;		/* current ctlr's ops vector */
1137c478bd9Sstevel@tonic-gate struct	partition_info *cur_parts;	/* current disk's partitioning */
1147c478bd9Sstevel@tonic-gate struct	defect_list cur_list;		/* current disk's defect list */
1157c478bd9Sstevel@tonic-gate void	*cur_buf;			/* current disk's I/O buffer */
1167c478bd9Sstevel@tonic-gate void	*pattern_buf;			/* current disk's pattern buffer */
1177c478bd9Sstevel@tonic-gate int	pcyl;				/* # physical cyls */
1187c478bd9Sstevel@tonic-gate int	ncyl;				/* # data cyls */
1197c478bd9Sstevel@tonic-gate int	acyl;				/* # alt cyls */
1207c478bd9Sstevel@tonic-gate int	nhead;				/* # heads */
1217c478bd9Sstevel@tonic-gate int	phead;				/* # physical heads */
1227c478bd9Sstevel@tonic-gate int	nsect;				/* # data sects/track */
1237c478bd9Sstevel@tonic-gate int	psect;				/* # physical sects/track */
1247c478bd9Sstevel@tonic-gate int	apc;				/* # alternates/cyl */
1257c478bd9Sstevel@tonic-gate int	solaris_offset;			/* Solaris offset, this value is zero */
1267c478bd9Sstevel@tonic-gate 					/* for non-fdisk machines. */
1277c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
1287c478bd9Sstevel@tonic-gate int	bcyl;				/* # other cyls */
1297c478bd9Sstevel@tonic-gate #endif		/* defined(_SUNOS_VTOC_16) */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate struct	mboot boot_sec;			/* fdisk partition info */
1327c478bd9Sstevel@tonic-gate int	xstart;				/* solaris partition start */
1337c478bd9Sstevel@tonic-gate char	x86_devname[80];		/* saved device name for fdisk */
1347c478bd9Sstevel@tonic-gate 					/* information accesses */
1357c478bd9Sstevel@tonic-gate struct	mctlr_list	*controlp;	/* master controller list ptr */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * These defines are used to manipulate the physical characteristics of
1407c478bd9Sstevel@tonic-gate  * the current disk.
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate #define	sectors(h)	((h) == nhead - 1 ? nsect - apc : nsect)
1437c478bd9Sstevel@tonic-gate #define	spc()		((int)(nhead * nsect - apc))
1447c478bd9Sstevel@tonic-gate #define	chs2bn(c, h, s)	((daddr_t)((c) * spc() + (h) * nsect + (s)))
1457c478bd9Sstevel@tonic-gate #define	bn2c(bn)	((bn) / (int)spc())
1467c478bd9Sstevel@tonic-gate #define	bn2h(bn)	(((bn) % (int)spc()) / (int)nsect)
1477c478bd9Sstevel@tonic-gate #define	bn2s(bn)	(((bn) % (int)spc()) % (int)nsect)
1487c478bd9Sstevel@tonic-gate #define	datasects()	(ncyl * spc())
1497c478bd9Sstevel@tonic-gate #define	totalsects()	((ncyl + acyl) * spc())
1507c478bd9Sstevel@tonic-gate #define	physsects()	(pcyl * spc())
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * Macro to convert a device number into a partition number
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	PARTITION(dev)	(minor(dev) & 0x07)
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * These values define flags for the current disk (cur_flags).
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	DISK_FORMATTED		0x01	/* disk is formatted */
1617c478bd9Sstevel@tonic-gate #define	LABEL_DIRTY		0x02	/* label has been scribbled */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * These flags are for the controller type flags field.
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate #define	CF_NONE		0x0000		/* NO FLAGS */
1677c478bd9Sstevel@tonic-gate #define	CF_BLABEL	0x0001		/* backup labels in funny place */
1687c478bd9Sstevel@tonic-gate #define	CF_DEFECTS	0x0002		/* disk has manuf. defect list */
1697c478bd9Sstevel@tonic-gate #define	CF_APC		0x0004		/* ctlr uses alternates per cyl */
1707c478bd9Sstevel@tonic-gate #define	CF_SMD_DEFS	0x0008		/* ctlr does smd defect handling */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #define	CF_SCSI		0x0040		/* ctlr is for SCSI disks */
1737c478bd9Sstevel@tonic-gate #define	CF_EMBEDDED	0x0080		/* ctlr is for embedded SCSI disks */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #define	CF_IPI		0x0100		/* ctlr is for IPI disks */
1767c478bd9Sstevel@tonic-gate #define	CF_WLIST	0x0200		/* ctlt handles working list */
1777c478bd9Sstevel@tonic-gate #define	CF_NOFORMAT	0x0400		/* Manufacture formatting only */
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * This flag has been introduced only for SPARC ATA. Which has been approved
1807c478bd9Sstevel@tonic-gate  * at that time with the agreement in the next fix it will be removed and the
1817c478bd9Sstevel@tonic-gate  * format will be revamped with controller Ops structure not to  have
1827c478bd9Sstevel@tonic-gate  * any operation to be NULL. As it makes things more modular.
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  * This flag is also used for PCMCIA pcata driver.
1857c478bd9Sstevel@tonic-gate  * The flag prevents reading or writing a defect list on the disk
1867c478bd9Sstevel@tonic-gate  * testing and console error reporting still work normally.
1877c478bd9Sstevel@tonic-gate  * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems
1887c478bd9Sstevel@tonic-gate  * and have not allocated any space for alternate cylinders to keep
1897c478bd9Sstevel@tonic-gate  * the bab block lists.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate #define	CF_NOWLIST	0x0800		/* Ctlr doesnot handle working list */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate  * Do not require confirmation to extract defect lists on SCSI
1967c478bd9Sstevel@tonic-gate  * and IPI drives, since this operation is instantaneous
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate #define	CF_CONFIRM	(CF_SCSI|CF_IPI)
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * Macros to make life easier
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate #define	SMD		(cur_ctype->ctype_flags & CF_SMD_DEFS)
2047c478bd9Sstevel@tonic-gate #define	SCSI		(cur_ctype->ctype_flags & CF_SCSI)
2057c478bd9Sstevel@tonic-gate #define	EMBEDDED_SCSI	((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \
2067c478bd9Sstevel@tonic-gate 				(CF_SCSI|CF_EMBEDDED))
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * These flags are for the disk type flags field.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate #define	DT_NEED_SPEFS	0x01		/* specifics fields are uninitialized */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * These defines are used to access the ctlr specific
2157c478bd9Sstevel@tonic-gate  * disk type fields (based on ctlr flags).
2167c478bd9Sstevel@tonic-gate  */
2177c478bd9Sstevel@tonic-gate #define	dtype_bps	dtype_specifics[0]	/* bytes/sector */
2187c478bd9Sstevel@tonic-gate #define	dtype_dr_type	dtype_specifics[1]	/* drive type */
2197c478bd9Sstevel@tonic-gate #define	dtype_dr_type_data dtype_specifics[2]	/* drive type in data file */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate  * These flags are for the disk info flags field.
2237c478bd9Sstevel@tonic-gate  */
2247c478bd9Sstevel@tonic-gate #define	DSK_LABEL	0x01		/* disk is currently labelled */
2257c478bd9Sstevel@tonic-gate #define	DSK_LABEL_DIRTY	0x02		/* disk auto-sensed, but not */
2267c478bd9Sstevel@tonic-gate 					/* labeled yet. */
2277c478bd9Sstevel@tonic-gate #define	DSK_AUTO_CONFIG	0x04		/* disk was auto-configured */
2287c478bd9Sstevel@tonic-gate #define	DSK_RESERVED	0x08		/* disk is reserved by other host */
2297c478bd9Sstevel@tonic-gate #define	DSK_UNAVAILABLE	0x10		/* disk not available, could be */
2307c478bd9Sstevel@tonic-gate 					/* currently formatting */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * These flags are used to control disk command execution.
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate #define	F_NORMAL	0x00		/* normal operation */
2367c478bd9Sstevel@tonic-gate #define	F_SILENT	0x01		/* no error msgs at all */
2377c478bd9Sstevel@tonic-gate #define	F_ALLERRS	0x02		/* return any error, not just fatal */
2387c478bd9Sstevel@tonic-gate #define	F_RQENABLE	0x04		/* no error msgs at all */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate  * Directional parameter for the op_rdwr controller op.
2427c478bd9Sstevel@tonic-gate  */
2437c478bd9Sstevel@tonic-gate #define	DIR_READ	0
2447c478bd9Sstevel@tonic-gate #define	DIR_WRITE	1
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * These defines are the mode parameter for the checksum routines.
2487c478bd9Sstevel@tonic-gate  */
2497c478bd9Sstevel@tonic-gate #define	CK_CHECKSUM		0		/* check checksum */
2507c478bd9Sstevel@tonic-gate #define	CK_MAKESUM		1		/* generate checksum */
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * This is the base character for partition identifiers
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate #define	PARTITION_BASE		'0'
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * Base pathname for devfs names to be stripped from physical name.
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate #define	DEVFS_PREFIX	"/devices"
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate  * Function prototypes ... Both for ANSI and non-ANSI C compilers
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate #ifdef	__STDC__
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate int copy_solaris_part(struct ipart *);
2687c478bd9Sstevel@tonic-gate int good_fdisk(void);
2697c478bd9Sstevel@tonic-gate int fdisk_physical_name(char *);
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate int copy_solaris_part();
2747c478bd9Sstevel@tonic-gate int good_fdisk();
2757c478bd9Sstevel@tonic-gate int fdisk_physical_name();
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate #endif
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate #endif	/* _GLOBAL_H */
284