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