xref: /titanic_50/usr/src/cmd/format/global.h (revision e2ca2865a6870e9c6cbef6becbcc68cafde64537)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_GLOBAL_H
27 #define	_GLOBAL_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Definitions for Label types: L_TYPE_SOLORIS is the default Sun label
35  * a.k.a VTOC. L_TYPE_EFI is the EFI label type.
36  */
37 #define	L_TYPE_SOLARIS	0
38 #define	L_TYPE_EFI	1
39 
40 #ifndef	UINT_MAX64
41 #define	UINT_MAX64	0xffffffffffffffffULL
42 #endif
43 
44 #ifndef UINT_MAX32
45 #define	UINT_MAX32	0xffffffffU
46 #endif
47 
48 #if !defined(_EXTVTOC)
49 #define	_EXTVTOC	/* extented vtoc (struct extvtoc) format is used */
50 #endif
51 
52 /*
53  * This file contains global definitions and declarations.  It is intended
54  * to be included by everyone.
55  */
56 #include <stdio.h>
57 #include <assert.h>
58 #include <memory.h>
59 #include <unistd.h>
60 #include <ctype.h>
61 #include <sys/types.h>
62 #include <sys/param.h>
63 #include <sys/isa_defs.h>
64 
65 #include <sys/dklabel.h>
66 #include <sys/vtoc.h>
67 #include <sys/dkio.h>
68 
69 #include "hardware_structs.h"
70 #include "defect.h"
71 #include "io.h"
72 
73 #include <sys/dktp/fdisk.h>
74 #include <sys/fcntl.h>
75 
76 
77 /*
78  * These declarations are global state variables.
79  */
80 struct	disk_info *disk_list;		/* list of found disks */
81 struct	ctlr_info *ctlr_list;		/* list of found ctlrs */
82 char	cur_menu;			/* current menu level */
83 char	last_menu;			/* last menu level */
84 char	option_msg;			/* extended message options */
85 char	diag_msg;			/* extended diagnostic msgs */
86 char	option_s;			/* silent mode option */
87 char	*option_f;			/* input redirect option */
88 char	*option_l;			/* log file option */
89 FILE	*log_file;			/* log file pointer */
90 char	*option_d;			/* forced disk option */
91 char	*option_t;			/* forced disk type option */
92 char	*option_p;			/* forced partition table option */
93 char	*option_x;			/* data file redirection option */
94 FILE	*data_file;			/* data file pointer */
95 char	*file_name;			/* current data file name */
96 					/* for useful error messages */
97 int	expert_mode;			/* enable for expert mode */
98 					/* commands */
99 int	need_newline;			/* for correctly formatted output */
100 int	dev_expert;			/* enable for developer mode */
101 					/* commands */
102 
103 /*
104  * These declarations are used for quick access to information about
105  * the disk being worked on.
106  */
107 int	cur_file;			/* file descriptor for current disk */
108 int	cur_flags;			/* flags for current disk */
109 int	cur_label;			/* current label type */
110 uint_t	cur_blksz;			/* currect disk block size */
111 struct	disk_info *cur_disk;		/* current disk */
112 struct	disk_type *cur_dtype;		/* current dtype */
113 struct	ctlr_info *cur_ctlr;		/* current ctlr */
114 struct	ctlr_type *cur_ctype;		/* current ctype */
115 struct	ctlr_ops *cur_ops;		/* current ctlr's ops vector */
116 struct	partition_info *cur_parts;	/* current disk's partitioning */
117 struct	defect_list cur_list;		/* current disk's defect list */
118 void	*cur_buf;			/* current disk's I/O buffer */
119 void	*pattern_buf;			/* current disk's pattern buffer */
120 uint_t	pcyl;				/* # physical cyls */
121 uint_t	ncyl;				/* # data cyls */
122 uint_t	acyl;				/* # alt cyls */
123 uint_t	nhead;				/* # heads */
124 uint_t	phead;				/* # physical heads */
125 uint_t	nsect;				/* # data sects/track */
126 uint_t	psect;				/* # physical sects/track */
127 uint_t	apc;				/* # alternates/cyl */
128 uint_t	solaris_offset;			/* Solaris offset, this value is zero */
129 					/* for non-fdisk machines. */
130 #if defined(_SUNOS_VTOC_16)
131 uint_t	bcyl;				/* # other cyls */
132 #endif		/* defined(_SUNOS_VTOC_16) */
133 
134 struct	mboot boot_sec;			/* fdisk partition info */
135 uint_t	xstart;				/* solaris partition start */
136 char	x86_devname[MAXNAMELEN];	/* saved device name for fdisk */
137 					/* information accesses */
138 struct	mctlr_list	*controlp;	/* master controller list ptr */
139 
140 
141 /*
142  * These defines are used to manipulate the physical characteristics of
143  * the current disk.
144  */
145 #define	sectors(h)	((h) == nhead - 1 ? nsect - apc : nsect)
146 #define	spc()		(nhead * nsect - apc)
147 #define	chs2bn(c, h, s)	(((diskaddr_t)(c) * spc() + (h) * nsect + (s)))
148 #define	bn2c(bn)	(uint_t)((diskaddr_t)(bn) / spc())
149 #define	bn2h(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) / nsect)
150 #define	bn2s(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) % nsect)
151 #define	datasects()	(ncyl * spc())
152 #define	totalsects()	((ncyl + acyl) * spc())
153 #define	physsects()	(pcyl * spc())
154 
155 /*
156  * Macro to convert a device number into a partition number
157  */
158 #define	PARTITION(dev)	(minor(dev) & 0x07)
159 
160 /*
161  * These values define flags for the current disk (cur_flags).
162  */
163 #define	DISK_FORMATTED		0x01	/* disk is formatted */
164 #define	LABEL_DIRTY		0x02	/* label has been scribbled */
165 
166 /*
167  * These flags are for the controller type flags field.
168  */
169 #define	CF_NONE		0x0000		/* NO FLAGS */
170 #define	CF_BLABEL	0x0001		/* backup labels in funny place */
171 #define	CF_DEFECTS	0x0002		/* disk has manuf. defect list */
172 #define	CF_APC		0x0004		/* ctlr uses alternates per cyl */
173 #define	CF_SMD_DEFS	0x0008		/* ctlr does smd defect handling */
174 
175 #define	CF_SCSI		0x0040		/* ctlr is for SCSI disks */
176 #define	CF_EMBEDDED	0x0080		/* ctlr is for embedded SCSI disks */
177 
178 #define	CF_IPI		0x0100		/* ctlr is for IPI disks */
179 #define	CF_WLIST	0x0200		/* ctlt handles working list */
180 #define	CF_NOFORMAT	0x0400		/* Manufacture formatting only */
181 /*
182  * This flag has been introduced only for SPARC ATA. Which has been approved
183  * at that time with the agreement in the next fix it will be removed and the
184  * format will be revamped with controller Ops structure not to  have
185  * any operation to be NULL. As it makes things more modular.
186  *
187  * This flag is also used for PCMCIA pcata driver.
188  * The flag prevents reading or writing a defect list on the disk
189  * testing and console error reporting still work normally.
190  * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems
191  * and have not allocated any space for alternate cylinders to keep
192  * the bab block lists.
193  */
194 #define	CF_NOWLIST	0x0800		/* Ctlr doesnot handle working list */
195 
196 
197 /*
198  * Do not require confirmation to extract defect lists on SCSI
199  * and IPI drives, since this operation is instantaneous
200  */
201 #define	CF_CONFIRM	(CF_SCSI|CF_IPI)
202 
203 /*
204  * Macros to make life easier
205  */
206 #define	SMD		(cur_ctype->ctype_flags & CF_SMD_DEFS)
207 #define	SCSI		(cur_ctype->ctype_flags & CF_SCSI)
208 #define	EMBEDDED_SCSI	((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \
209 				(CF_SCSI|CF_EMBEDDED))
210 
211 /*
212  * These flags are for the disk type flags field.
213  */
214 #define	DT_NEED_SPEFS	0x01		/* specifics fields are uninitialized */
215 
216 /*
217  * These defines are used to access the ctlr specific
218  * disk type fields (based on ctlr flags).
219  */
220 #define	dtype_bps	dtype_specifics[0]	/* bytes/sector */
221 #define	dtype_dr_type	dtype_specifics[1]	/* drive type */
222 #define	dtype_dr_type_data dtype_specifics[2]	/* drive type in data file */
223 
224 /*
225  * These flags are for the disk info flags field.
226  */
227 #define	DSK_LABEL	0x01		/* disk is currently labelled */
228 #define	DSK_LABEL_DIRTY	0x02		/* disk auto-sensed, but not */
229 					/* labeled yet. */
230 #define	DSK_AUTO_CONFIG	0x04		/* disk was auto-configured */
231 #define	DSK_RESERVED	0x08		/* disk is reserved by other host */
232 #define	DSK_UNAVAILABLE	0x10		/* disk not available, could be */
233 					/* currently formatting */
234 
235 /*
236  * These flags are used to control disk command execution.
237  */
238 #define	F_NORMAL	0x00		/* normal operation */
239 #define	F_SILENT	0x01		/* no error msgs at all */
240 #define	F_ALLERRS	0x02		/* return any error, not just fatal */
241 #define	F_RQENABLE	0x04		/* no error msgs at all */
242 
243 /*
244  * Directional parameter for the op_rdwr controller op.
245  */
246 #define	DIR_READ	0
247 #define	DIR_WRITE	1
248 
249 /*
250  * These defines are the mode parameter for the checksum routines.
251  */
252 #define	CK_CHECKSUM		0		/* check checksum */
253 #define	CK_MAKESUM		1		/* generate checksum */
254 
255 /*
256  * This is the base character for partition identifiers
257  */
258 #define	PARTITION_BASE		'0'
259 
260 /*
261  * Base pathname for devfs names to be stripped from physical name.
262  */
263 #define	DEVFS_PREFIX	"/devices"
264 
265 /*
266  * Function prototypes ... Both for ANSI and non-ANSI C compilers
267  */
268 #ifdef	__STDC__
269 
270 int copy_solaris_part(struct ipart *);
271 int good_fdisk(void);
272 int fdisk_physical_name(char *);
273 
274 #else	/* __STDC__ */
275 
276 int copy_solaris_part();
277 int good_fdisk();
278 int fdisk_physical_name();
279 
280 #endif	/* __STDC__ */
281 
282 #ifdef	__cplusplus
283 }
284 #endif
285 
286 #endif	/* _GLOBAL_H */
287