xref: /titanic_44/usr/src/cmd/format/global.h (revision 95efa359b507db290a2484b8f615822b1e06096f)
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 2008 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 struct	disk_info *cur_disk;		/* current disk */
111 struct	disk_type *cur_dtype;		/* current dtype */
112 struct	ctlr_info *cur_ctlr;		/* current ctlr */
113 struct	ctlr_type *cur_ctype;		/* current ctype */
114 struct	ctlr_ops *cur_ops;		/* current ctlr's ops vector */
115 struct	partition_info *cur_parts;	/* current disk's partitioning */
116 struct	defect_list cur_list;		/* current disk's defect list */
117 void	*cur_buf;			/* current disk's I/O buffer */
118 void	*pattern_buf;			/* current disk's pattern buffer */
119 uint_t	pcyl;				/* # physical cyls */
120 uint_t	ncyl;				/* # data cyls */
121 uint_t	acyl;				/* # alt cyls */
122 uint_t	nhead;				/* # heads */
123 uint_t	phead;				/* # physical heads */
124 uint_t	nsect;				/* # data sects/track */
125 uint_t	psect;				/* # physical sects/track */
126 uint_t	apc;				/* # alternates/cyl */
127 uint_t	solaris_offset;			/* Solaris offset, this value is zero */
128 					/* for non-fdisk machines. */
129 #if defined(_SUNOS_VTOC_16)
130 uint_t	bcyl;				/* # other cyls */
131 #endif		/* defined(_SUNOS_VTOC_16) */
132 
133 struct	mboot boot_sec;			/* fdisk partition info */
134 uint_t	xstart;				/* solaris partition start */
135 char	x86_devname[MAXNAMELEN];	/* saved device name for fdisk */
136 					/* information accesses */
137 struct	mctlr_list	*controlp;	/* master controller list ptr */
138 
139 
140 /*
141  * These defines are used to manipulate the physical characteristics of
142  * the current disk.
143  */
144 #define	sectors(h)	((h) == nhead - 1 ? nsect - apc : nsect)
145 #define	spc()		(nhead * nsect - apc)
146 #define	chs2bn(c, h, s)	(((diskaddr_t)(c) * spc() + (h) * nsect + (s)))
147 #define	bn2c(bn)	(uint_t)((diskaddr_t)(bn) / spc())
148 #define	bn2h(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) / nsect)
149 #define	bn2s(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) % nsect)
150 #define	datasects()	(ncyl * spc())
151 #define	totalsects()	((ncyl + acyl) * spc())
152 #define	physsects()	(pcyl * spc())
153 
154 /*
155  * Macro to convert a device number into a partition number
156  */
157 #define	PARTITION(dev)	(minor(dev) & 0x07)
158 
159 /*
160  * These values define flags for the current disk (cur_flags).
161  */
162 #define	DISK_FORMATTED		0x01	/* disk is formatted */
163 #define	LABEL_DIRTY		0x02	/* label has been scribbled */
164 
165 /*
166  * These flags are for the controller type flags field.
167  */
168 #define	CF_NONE		0x0000		/* NO FLAGS */
169 #define	CF_BLABEL	0x0001		/* backup labels in funny place */
170 #define	CF_DEFECTS	0x0002		/* disk has manuf. defect list */
171 #define	CF_APC		0x0004		/* ctlr uses alternates per cyl */
172 #define	CF_SMD_DEFS	0x0008		/* ctlr does smd defect handling */
173 
174 #define	CF_SCSI		0x0040		/* ctlr is for SCSI disks */
175 #define	CF_EMBEDDED	0x0080		/* ctlr is for embedded SCSI disks */
176 
177 #define	CF_IPI		0x0100		/* ctlr is for IPI disks */
178 #define	CF_WLIST	0x0200		/* ctlt handles working list */
179 #define	CF_NOFORMAT	0x0400		/* Manufacture formatting only */
180 /*
181  * This flag has been introduced only for SPARC ATA. Which has been approved
182  * at that time with the agreement in the next fix it will be removed and the
183  * format will be revamped with controller Ops structure not to  have
184  * any operation to be NULL. As it makes things more modular.
185  *
186  * This flag is also used for PCMCIA pcata driver.
187  * The flag prevents reading or writing a defect list on the disk
188  * testing and console error reporting still work normally.
189  * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems
190  * and have not allocated any space for alternate cylinders to keep
191  * the bab block lists.
192  */
193 #define	CF_NOWLIST	0x0800		/* Ctlr doesnot handle working list */
194 
195 
196 /*
197  * Do not require confirmation to extract defect lists on SCSI
198  * and IPI drives, since this operation is instantaneous
199  */
200 #define	CF_CONFIRM	(CF_SCSI|CF_IPI)
201 
202 /*
203  * Macros to make life easier
204  */
205 #define	SMD		(cur_ctype->ctype_flags & CF_SMD_DEFS)
206 #define	SCSI		(cur_ctype->ctype_flags & CF_SCSI)
207 #define	EMBEDDED_SCSI	((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \
208 				(CF_SCSI|CF_EMBEDDED))
209 
210 /*
211  * These flags are for the disk type flags field.
212  */
213 #define	DT_NEED_SPEFS	0x01		/* specifics fields are uninitialized */
214 
215 /*
216  * These defines are used to access the ctlr specific
217  * disk type fields (based on ctlr flags).
218  */
219 #define	dtype_bps	dtype_specifics[0]	/* bytes/sector */
220 #define	dtype_dr_type	dtype_specifics[1]	/* drive type */
221 #define	dtype_dr_type_data dtype_specifics[2]	/* drive type in data file */
222 
223 /*
224  * These flags are for the disk info flags field.
225  */
226 #define	DSK_LABEL	0x01		/* disk is currently labelled */
227 #define	DSK_LABEL_DIRTY	0x02		/* disk auto-sensed, but not */
228 					/* labeled yet. */
229 #define	DSK_AUTO_CONFIG	0x04		/* disk was auto-configured */
230 #define	DSK_RESERVED	0x08		/* disk is reserved by other host */
231 #define	DSK_UNAVAILABLE	0x10		/* disk not available, could be */
232 					/* currently formatting */
233 
234 /*
235  * These flags are used to control disk command execution.
236  */
237 #define	F_NORMAL	0x00		/* normal operation */
238 #define	F_SILENT	0x01		/* no error msgs at all */
239 #define	F_ALLERRS	0x02		/* return any error, not just fatal */
240 #define	F_RQENABLE	0x04		/* no error msgs at all */
241 
242 /*
243  * Directional parameter for the op_rdwr controller op.
244  */
245 #define	DIR_READ	0
246 #define	DIR_WRITE	1
247 
248 /*
249  * These defines are the mode parameter for the checksum routines.
250  */
251 #define	CK_CHECKSUM		0		/* check checksum */
252 #define	CK_MAKESUM		1		/* generate checksum */
253 
254 /*
255  * This is the base character for partition identifiers
256  */
257 #define	PARTITION_BASE		'0'
258 
259 /*
260  * Base pathname for devfs names to be stripped from physical name.
261  */
262 #define	DEVFS_PREFIX	"/devices"
263 
264 /*
265  * Function prototypes ... Both for ANSI and non-ANSI C compilers
266  */
267 #ifdef	__STDC__
268 
269 int copy_solaris_part(struct ipart *);
270 int good_fdisk(void);
271 int fdisk_physical_name(char *);
272 
273 #else	/* __STDC__ */
274 
275 int copy_solaris_part();
276 int good_fdisk();
277 int fdisk_physical_name();
278 
279 #endif	/* __STDC__ */
280 
281 #ifdef	__cplusplus
282 }
283 #endif
284 
285 #endif	/* _GLOBAL_H */
286