xref: /onnv-gate/usr/src/cmd/format/global.h (revision 12594:d6a845bf8951)
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
54276Staylor  * Common Development and Distribution License (the "License").
64276Staylor  * 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*12594SShengliang.Zhang@Sun.COM  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_GLOBAL_H
260Sstevel@tonic-gate #define	_GLOBAL_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  * Definitions for Label types: L_TYPE_SOLORIS is the default Sun label
340Sstevel@tonic-gate  * a.k.a VTOC. L_TYPE_EFI is the EFI label type.
350Sstevel@tonic-gate  */
360Sstevel@tonic-gate #define	L_TYPE_SOLARIS	0
370Sstevel@tonic-gate #define	L_TYPE_EFI	1
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef	UINT_MAX64
40362Sbg159949 #define	UINT_MAX64	0xffffffffffffffffULL
410Sstevel@tonic-gate #endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #ifndef UINT_MAX32
447563SPrasad.Singamsetty@Sun.COM #define	UINT_MAX32	0xffffffffU
457563SPrasad.Singamsetty@Sun.COM #endif
467563SPrasad.Singamsetty@Sun.COM 
477563SPrasad.Singamsetty@Sun.COM #if !defined(_EXTVTOC)
487563SPrasad.Singamsetty@Sun.COM #define	_EXTVTOC	/* extented vtoc (struct extvtoc) format is used */
490Sstevel@tonic-gate #endif
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * This file contains global definitions and declarations.  It is intended
530Sstevel@tonic-gate  * to be included by everyone.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate #include <stdio.h>
560Sstevel@tonic-gate #include <assert.h>
570Sstevel@tonic-gate #include <memory.h>
580Sstevel@tonic-gate #include <unistd.h>
590Sstevel@tonic-gate #include <ctype.h>
600Sstevel@tonic-gate #include <sys/types.h>
610Sstevel@tonic-gate #include <sys/param.h>
620Sstevel@tonic-gate #include <sys/isa_defs.h>
630Sstevel@tonic-gate 
640Sstevel@tonic-gate #include <sys/dklabel.h>
650Sstevel@tonic-gate #include <sys/vtoc.h>
660Sstevel@tonic-gate #include <sys/dkio.h>
670Sstevel@tonic-gate 
680Sstevel@tonic-gate #include "hardware_structs.h"
690Sstevel@tonic-gate #include "defect.h"
700Sstevel@tonic-gate #include "io.h"
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
730Sstevel@tonic-gate #include <sys/fcntl.h>
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * These declarations are global state variables.
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate struct	disk_info *disk_list;		/* list of found disks */
800Sstevel@tonic-gate struct	ctlr_info *ctlr_list;		/* list of found ctlrs */
810Sstevel@tonic-gate char	cur_menu;			/* current menu level */
820Sstevel@tonic-gate char	last_menu;			/* last menu level */
830Sstevel@tonic-gate char	option_msg;			/* extended message options */
840Sstevel@tonic-gate char	diag_msg;			/* extended diagnostic msgs */
850Sstevel@tonic-gate char	option_s;			/* silent mode option */
860Sstevel@tonic-gate char	*option_f;			/* input redirect option */
870Sstevel@tonic-gate char	*option_l;			/* log file option */
880Sstevel@tonic-gate FILE	*log_file;			/* log file pointer */
890Sstevel@tonic-gate char	*option_d;			/* forced disk option */
900Sstevel@tonic-gate char	*option_t;			/* forced disk type option */
910Sstevel@tonic-gate char	*option_p;			/* forced partition table option */
920Sstevel@tonic-gate char	*option_x;			/* data file redirection option */
930Sstevel@tonic-gate FILE	*data_file;			/* data file pointer */
940Sstevel@tonic-gate char	*file_name;			/* current data file name */
950Sstevel@tonic-gate 					/* for useful error messages */
960Sstevel@tonic-gate int	expert_mode;			/* enable for expert mode */
970Sstevel@tonic-gate 					/* commands */
980Sstevel@tonic-gate int	need_newline;			/* for correctly formatted output */
990Sstevel@tonic-gate int	dev_expert;			/* enable for developer mode */
1000Sstevel@tonic-gate 					/* commands */
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * These declarations are used for quick access to information about
1040Sstevel@tonic-gate  * the disk being worked on.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate int	cur_file;			/* file descriptor for current disk */
1070Sstevel@tonic-gate int	cur_flags;			/* flags for current disk */
1080Sstevel@tonic-gate int	cur_label;			/* current label type */
1099889SLarry.Liu@Sun.COM uint_t	cur_blksz;			/* currect disk block size */
1100Sstevel@tonic-gate struct	disk_info *cur_disk;		/* current disk */
1110Sstevel@tonic-gate struct	disk_type *cur_dtype;		/* current dtype */
1120Sstevel@tonic-gate struct	ctlr_info *cur_ctlr;		/* current ctlr */
1130Sstevel@tonic-gate struct	ctlr_type *cur_ctype;		/* current ctype */
1140Sstevel@tonic-gate struct	ctlr_ops *cur_ops;		/* current ctlr's ops vector */
1150Sstevel@tonic-gate struct	partition_info *cur_parts;	/* current disk's partitioning */
1160Sstevel@tonic-gate struct	defect_list cur_list;		/* current disk's defect list */
1170Sstevel@tonic-gate void	*cur_buf;			/* current disk's I/O buffer */
1180Sstevel@tonic-gate void	*pattern_buf;			/* current disk's pattern buffer */
1197563SPrasad.Singamsetty@Sun.COM uint_t	pcyl;				/* # physical cyls */
1207563SPrasad.Singamsetty@Sun.COM uint_t	ncyl;				/* # data cyls */
1217563SPrasad.Singamsetty@Sun.COM uint_t	acyl;				/* # alt cyls */
1227563SPrasad.Singamsetty@Sun.COM uint_t	nhead;				/* # heads */
1237563SPrasad.Singamsetty@Sun.COM uint_t	phead;				/* # physical heads */
1247563SPrasad.Singamsetty@Sun.COM uint_t	nsect;				/* # data sects/track */
1257563SPrasad.Singamsetty@Sun.COM uint_t	psect;				/* # physical sects/track */
1267563SPrasad.Singamsetty@Sun.COM uint_t	apc;				/* # alternates/cyl */
1277563SPrasad.Singamsetty@Sun.COM uint_t	solaris_offset;			/* Solaris offset, this value is zero */
1280Sstevel@tonic-gate 					/* for non-fdisk machines. */
129*12594SShengliang.Zhang@Sun.COM int	prot_type;			/* protection type to format disk */
130*12594SShengliang.Zhang@Sun.COM 
1310Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
1327563SPrasad.Singamsetty@Sun.COM uint_t	bcyl;				/* # other cyls */
1330Sstevel@tonic-gate #endif		/* defined(_SUNOS_VTOC_16) */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate struct	mboot boot_sec;			/* fdisk partition info */
1367563SPrasad.Singamsetty@Sun.COM uint_t	xstart;				/* solaris partition start */
1374865Sqd208687 char	x86_devname[MAXNAMELEN];	/* saved device name for fdisk */
1380Sstevel@tonic-gate 					/* information accesses */
1390Sstevel@tonic-gate struct	mctlr_list	*controlp;	/* master controller list ptr */
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate /*
1430Sstevel@tonic-gate  * These defines are used to manipulate the physical characteristics of
1440Sstevel@tonic-gate  * the current disk.
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate #define	sectors(h)	((h) == nhead - 1 ? nsect - apc : nsect)
1477563SPrasad.Singamsetty@Sun.COM #define	spc()		(nhead * nsect - apc)
1487563SPrasad.Singamsetty@Sun.COM #define	chs2bn(c, h, s)	(((diskaddr_t)(c) * spc() + (h) * nsect + (s)))
1497563SPrasad.Singamsetty@Sun.COM #define	bn2c(bn)	(uint_t)((diskaddr_t)(bn) / spc())
1507563SPrasad.Singamsetty@Sun.COM #define	bn2h(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) / nsect)
1517563SPrasad.Singamsetty@Sun.COM #define	bn2s(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) % nsect)
1520Sstevel@tonic-gate #define	datasects()	(ncyl * spc())
1530Sstevel@tonic-gate #define	totalsects()	((ncyl + acyl) * spc())
1540Sstevel@tonic-gate #define	physsects()	(pcyl * spc())
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate /*
1570Sstevel@tonic-gate  * Macro to convert a device number into a partition number
1580Sstevel@tonic-gate  */
1590Sstevel@tonic-gate #define	PARTITION(dev)	(minor(dev) & 0x07)
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * These values define flags for the current disk (cur_flags).
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate #define	DISK_FORMATTED		0x01	/* disk is formatted */
1650Sstevel@tonic-gate #define	LABEL_DIRTY		0x02	/* label has been scribbled */
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate /*
1680Sstevel@tonic-gate  * These flags are for the controller type flags field.
1690Sstevel@tonic-gate  */
1700Sstevel@tonic-gate #define	CF_NONE		0x0000		/* NO FLAGS */
1710Sstevel@tonic-gate #define	CF_BLABEL	0x0001		/* backup labels in funny place */
1720Sstevel@tonic-gate #define	CF_DEFECTS	0x0002		/* disk has manuf. defect list */
1730Sstevel@tonic-gate #define	CF_APC		0x0004		/* ctlr uses alternates per cyl */
1740Sstevel@tonic-gate #define	CF_SMD_DEFS	0x0008		/* ctlr does smd defect handling */
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate #define	CF_SCSI		0x0040		/* ctlr is for SCSI disks */
1770Sstevel@tonic-gate #define	CF_EMBEDDED	0x0080		/* ctlr is for embedded SCSI disks */
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #define	CF_IPI		0x0100		/* ctlr is for IPI disks */
1800Sstevel@tonic-gate #define	CF_WLIST	0x0200		/* ctlt handles working list */
1810Sstevel@tonic-gate #define	CF_NOFORMAT	0x0400		/* Manufacture formatting only */
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate  * This flag has been introduced only for SPARC ATA. Which has been approved
1840Sstevel@tonic-gate  * at that time with the agreement in the next fix it will be removed and the
1850Sstevel@tonic-gate  * format will be revamped with controller Ops structure not to  have
1860Sstevel@tonic-gate  * any operation to be NULL. As it makes things more modular.
1870Sstevel@tonic-gate  *
1880Sstevel@tonic-gate  * This flag is also used for PCMCIA pcata driver.
1890Sstevel@tonic-gate  * The flag prevents reading or writing a defect list on the disk
1900Sstevel@tonic-gate  * testing and console error reporting still work normally.
1910Sstevel@tonic-gate  * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems
1920Sstevel@tonic-gate  * and have not allocated any space for alternate cylinders to keep
1930Sstevel@tonic-gate  * the bab block lists.
1940Sstevel@tonic-gate  */
1950Sstevel@tonic-gate #define	CF_NOWLIST	0x0800		/* Ctlr doesnot handle working list */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate /*
1990Sstevel@tonic-gate  * Do not require confirmation to extract defect lists on SCSI
2000Sstevel@tonic-gate  * and IPI drives, since this operation is instantaneous
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate #define	CF_CONFIRM	(CF_SCSI|CF_IPI)
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate /*
2050Sstevel@tonic-gate  * Macros to make life easier
2060Sstevel@tonic-gate  */
2070Sstevel@tonic-gate #define	SMD		(cur_ctype->ctype_flags & CF_SMD_DEFS)
2080Sstevel@tonic-gate #define	SCSI		(cur_ctype->ctype_flags & CF_SCSI)
2090Sstevel@tonic-gate #define	EMBEDDED_SCSI	((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \
2100Sstevel@tonic-gate 				(CF_SCSI|CF_EMBEDDED))
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate  * These flags are for the disk type flags field.
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate #define	DT_NEED_SPEFS	0x01		/* specifics fields are uninitialized */
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate /*
2180Sstevel@tonic-gate  * These defines are used to access the ctlr specific
2190Sstevel@tonic-gate  * disk type fields (based on ctlr flags).
2200Sstevel@tonic-gate  */
2210Sstevel@tonic-gate #define	dtype_bps	dtype_specifics[0]	/* bytes/sector */
2220Sstevel@tonic-gate #define	dtype_dr_type	dtype_specifics[1]	/* drive type */
2230Sstevel@tonic-gate #define	dtype_dr_type_data dtype_specifics[2]	/* drive type in data file */
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate /*
2260Sstevel@tonic-gate  * These flags are for the disk info flags field.
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate #define	DSK_LABEL	0x01		/* disk is currently labelled */
2290Sstevel@tonic-gate #define	DSK_LABEL_DIRTY	0x02		/* disk auto-sensed, but not */
2300Sstevel@tonic-gate 					/* labeled yet. */
2310Sstevel@tonic-gate #define	DSK_AUTO_CONFIG	0x04		/* disk was auto-configured */
2320Sstevel@tonic-gate #define	DSK_RESERVED	0x08		/* disk is reserved by other host */
2330Sstevel@tonic-gate #define	DSK_UNAVAILABLE	0x10		/* disk not available, could be */
2340Sstevel@tonic-gate 					/* currently formatting */
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate /*
2370Sstevel@tonic-gate  * These flags are used to control disk command execution.
2380Sstevel@tonic-gate  */
2390Sstevel@tonic-gate #define	F_NORMAL	0x00		/* normal operation */
2400Sstevel@tonic-gate #define	F_SILENT	0x01		/* no error msgs at all */
2410Sstevel@tonic-gate #define	F_ALLERRS	0x02		/* return any error, not just fatal */
2420Sstevel@tonic-gate #define	F_RQENABLE	0x04		/* no error msgs at all */
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate /*
2450Sstevel@tonic-gate  * Directional parameter for the op_rdwr controller op.
2460Sstevel@tonic-gate  */
2470Sstevel@tonic-gate #define	DIR_READ	0
2480Sstevel@tonic-gate #define	DIR_WRITE	1
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate  * These defines are the mode parameter for the checksum routines.
2520Sstevel@tonic-gate  */
2530Sstevel@tonic-gate #define	CK_CHECKSUM		0		/* check checksum */
2540Sstevel@tonic-gate #define	CK_MAKESUM		1		/* generate checksum */
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate /*
2570Sstevel@tonic-gate  * This is the base character for partition identifiers
2580Sstevel@tonic-gate  */
2590Sstevel@tonic-gate #define	PARTITION_BASE		'0'
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate /*
2620Sstevel@tonic-gate  * Base pathname for devfs names to be stripped from physical name.
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate #define	DEVFS_PREFIX	"/devices"
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /*
267*12594SShengliang.Zhang@Sun.COM  *  Protection type by SCSI-3
268*12594SShengliang.Zhang@Sun.COM  */
269*12594SShengliang.Zhang@Sun.COM #define	PROT_TYPE_0	0
270*12594SShengliang.Zhang@Sun.COM #define	PROT_TYPE_1	1
271*12594SShengliang.Zhang@Sun.COM #define	PROT_TYPE_2	2
272*12594SShengliang.Zhang@Sun.COM #define	PROT_TYPE_3	3
273*12594SShengliang.Zhang@Sun.COM #define	NUM_PROT_TYPE	4
274*12594SShengliang.Zhang@Sun.COM 
275*12594SShengliang.Zhang@Sun.COM /*
2760Sstevel@tonic-gate  * Function prototypes ... Both for ANSI and non-ANSI C compilers
2770Sstevel@tonic-gate  */
2780Sstevel@tonic-gate #ifdef	__STDC__
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate int copy_solaris_part(struct ipart *);
2810Sstevel@tonic-gate int good_fdisk(void);
2820Sstevel@tonic-gate int fdisk_physical_name(char *);
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate #else	/* __STDC__ */
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate int copy_solaris_part();
2870Sstevel@tonic-gate int good_fdisk();
2880Sstevel@tonic-gate int fdisk_physical_name();
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate #endif	/* __STDC__ */
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate #ifdef	__cplusplus
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate #endif
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate #endif	/* _GLOBAL_H */
297