Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: disk_ui.cc | |
4 | // Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
5 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
6 | // | |
7 | // The above named program is free software; you can redistribute it and/or | |
8 | // modify it under the terms of the GNU General Public | |
9 | // License version 2 as published by the Free Software Foundation. | |
10 | // | |
11 | // The above named program is distributed in the hope that it will be | |
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public | |
17 | // License along with this work; if not, write to the Free Software | |
18 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | // | |
20 | // ========== Copyright Header End ============================================ | |
21 | #include "disk.h" | |
22 | ||
23 | void Disk::display_label(){ | |
24 | fprintf(debug_file,"%s:%s Disk Label, Type _SUNOS_VTOC_8\n",disk_name,fake_vtoc?"Fake":"Real"); | |
25 | fprintf(debug_file," dkl_asciilabel %s\n",disk_label.dkl_ascii_label); | |
26 | fprintf(debug_file," dkl_vtoc\n"); | |
27 | fprintf(debug_file," v_version 0x%lx\n",disk_label.dkl_vtoc.v_version); | |
28 | fprintf(debug_file," v_volume %s\n",disk_label.dkl_vtoc.v_volume); | |
29 | fprintf(debug_file," v_nparts 0x%x\n",disk_label.dkl_vtoc.v_nparts); | |
30 | fprintf(debug_file," v_part\n"); | |
31 | for(int i = 0; i < VTOC8_NDKMAP; i++){ | |
32 | if(disk_label.dkl_vtoc.v_part[i].p_tag != 0){ | |
33 | fprintf(debug_file," [%d] p_tag 0x%x\n",i,disk_label.dkl_vtoc.v_part[i].p_tag); | |
34 | fprintf(debug_file," [%d] p_flag 0x%x\n",i,disk_label.dkl_vtoc.v_part[i].p_flag); | |
35 | } | |
36 | } | |
37 | fprintf(debug_file," v_bootinfo (%lx %lx %lx)\n",\ | |
38 | disk_label.dkl_vtoc.v_bootinfo[0],\ | |
39 | disk_label.dkl_vtoc.v_bootinfo[1],\ | |
40 | disk_label.dkl_vtoc.v_bootinfo[2]); | |
41 | ||
42 | fprintf(debug_file," v_sanity 0x%lx\n",disk_label.dkl_vtoc.v_sanity); | |
43 | fprintf(debug_file," v_timestamp\n"); | |
44 | for(int i = 0; i < VTOC8_NDKMAP; i++) | |
45 | if(disk_label.dkl_vtoc.v_timestamp[i] != 0) | |
46 | fprintf(debug_file," [%d] 0x%lx\n",disk_label.dkl_vtoc.v_timestamp[i]); | |
47 | ||
48 | fprintf(debug_file," dkl_write_reinstruct 0x%x\n",disk_label.dkl_write_reinstruct); | |
49 | fprintf(debug_file," dkl_read_reinstruct 0x%x\n",disk_label.dkl_read_reinstruct); | |
50 | fprintf(debug_file," dkl_rpm %d\n",disk_label.dkl_rpm); | |
51 | fprintf(debug_file," dkl_pcyl %d\n",disk_label.dkl_pcyl); | |
52 | fprintf(debug_file," dkl_apc %d\n",disk_label.dkl_apc); | |
53 | fprintf(debug_file," dkl_intrlv %d\n",disk_label.dkl_intrlv); | |
54 | fprintf(debug_file," dkl_ncyl %d\n",disk_label.dkl_ncyl); | |
55 | fprintf(debug_file," dkl_acyl %d\n",disk_label.dkl_acyl); | |
56 | fprintf(debug_file," dkl_nhead %d\n",disk_label.dkl_nhead); | |
57 | fprintf(debug_file," dkl_nsect %d\n",disk_label.dkl_nsect); | |
58 | fprintf(debug_file," dkl_map\n"); | |
59 | for(int i = 0; i < VTOC8_NDKMAP; i++) | |
60 | if(disk_label.dkl_map[i].dkl_nblk != 0){ | |
61 | fprintf(debug_file," [%d] dkl_cylno %ld\n",i,disk_label.dkl_map[i].dkl_cylno); | |
62 | fprintf(debug_file," [%d] dkl_nblk %ld\n",i,disk_label.dkl_map[i].dkl_nblk); | |
63 | } | |
64 | fprintf(debug_file," dkl_magic 0x%x\n",disk_label.dkl_magic); | |
65 | fprintf(debug_file," dkl_cksum 0x%x\n",disk_label.dkl_cksum); | |
66 | ||
67 | fflush(debug_file); | |
68 | return; | |
69 | } | |
70 | ||
71 | void Disk::display_geometry(){ | |
72 | fprintf(debug_file,"%s\n",disk_name); | |
73 | ||
74 | fprintf(debug_file,"bytes/sector %d\n",bytes_per_sector); | |
75 | fprintf(debug_file,"sectors/track %d\n",sectors_per_track); | |
76 | fprintf(debug_file,"tracks/cylinder %d\n",tracks_per_cylinder); | |
77 | fprintf(debug_file,"cylinders %ld\n",num_cylinder); | |
78 | fprintf(debug_file,"total blocks(SAM) %lld\n",num_blks); | |
79 | fprintf(debug_file,"\n\n"); | |
80 | fprintf(debug_file,"SAM's Disk Geometry\n"); | |
81 | fprintf(debug_file," First Sector Last\n"); | |
82 | fprintf(debug_file,"Partition Sector Count Sector\n"); | |
83 | for(int i = 0; i < MAX_PARTITIONS; i++){ | |
84 | if(partitions[i]) | |
85 | fprintf(debug_file,"%4d%12lld%12lld%12lld\n",i,partitions[i]->start_lblk,partitions[i]->nblks,partitions[i]->end_lblk); | |
86 | } | |
87 | ||
88 | if(!fake_vtoc){ | |
89 | fprintf(debug_file,"\n\n"); | |
90 | fprintf(debug_file,"VTOC Disk Geometry\n"); | |
91 | fprintf(debug_file," First Sector Last\n"); | |
92 | fprintf(debug_file,"Partition Sector Count Sector\n"); | |
93 | for(int i = 0; i < VTOC8_NDKMAP; i++) | |
94 | if(disk_label.dkl_map[i].dkl_nblk != 0){ | |
95 | uint64_t first_sector = 1ULL*disk_label.dkl_map[i].dkl_cylno * disk_label.dkl_nsect * disk_label.dkl_nhead; | |
96 | uint32_t num_sectors = disk_label.dkl_map[i].dkl_nblk; | |
97 | fprintf(debug_file,"%4d%12lld%12ld%12lld\n",i,\ | |
98 | first_sector,num_sectors,first_sector+num_sectors-1); | |
99 | } | |
100 | } | |
101 | ||
102 | fflush(debug_file); | |
103 | return; | |
104 | } | |
105 | ||
106 | void Disk::display_stats(){ | |
107 | fprintf(debug_file,"%s:\n",disk_name); | |
108 | for(int i = 0; i < MAX_PARTITIONS; i++) | |
109 | if(partitions[i]){ | |
110 | fprintf(debug_file," %s[%d]\n",partitions[i]->part_name,i); | |
111 | fprintf(debug_file," total reads - %lld\n",partitions[i]->lblk_reads); | |
112 | fprintf(debug_file," total writes - %lld\n",partitions[i]->lblk_writes); | |
113 | fprintf(debug_file," backup reads - %lld\n",partitions[i]->lblk_reads_primary); | |
114 | fprintf(debug_file," backup writes - %lld\n",partitions[i]->lblk_writes_primary); | |
115 | fprintf(debug_file," overlay reads - %lld\n",partitions[i]->lblk_reads_overlay); | |
116 | fprintf(debug_file," overlay writes - %lld\n",partitions[i]->lblk_writes_overlay); | |
117 | fprintf(debug_file," ckpt reads - %lld\n",partitions[i]->lblk_reads_ckpt); | |
118 | } | |
119 | fflush(debug_file); | |
120 | } | |
121 | ||
122 | void Disk::display_partitions(int part_num){ | |
123 | fprintf(debug_file,"Disk %s, target id:%d, debug_file <%s>\n",disk_name,target_id,debug_file_name); | |
124 | ||
125 | if(part_num == -1){ | |
126 | for(int i = 0; i < MAX_PARTITIONS; i++) | |
127 | if(partitions[i]) | |
128 | partitions[i]->info(); | |
129 | fflush(debug_file); | |
130 | return; | |
131 | } | |
132 | ||
133 | if(!partitions[part_num]){ | |
134 | fprintf(debug_file," No partition %d present\n",part_num); | |
135 | }else | |
136 | partitions[part_num]->info(); | |
137 | fflush(debug_file); | |
138 | return; | |
139 | } | |
140 | ||
141 | void Disk::display_disk_delay(){ | |
142 | fprintf(debug_file,"%s: disk delay %u/%u micro seconds\n",disk_name,get_read_delay(),get_write_delay()); | |
143 | } | |
144 | ||
145 | void Disk::display_help(){ | |
146 | fprintf(stderr,"gdisk \n"); | |
147 | fprintf(stderr," - display configured disks \n"); | |
148 | fprintf(stderr,"gdisk help\n"); | |
149 | fprintf(stderr," - display this message\n"); | |
150 | fprintf(stderr,"gdisk <disk_name | all> <command_name> [args]\n"); | |
151 | fprintf(stderr," commands are\n"); | |
152 | fprintf(stderr," label\n"); | |
153 | fprintf(stderr," - display disk label\n"); | |
154 | fprintf(stderr," geometry\n"); | |
155 | fprintf(stderr," - display disk geometry\n"); | |
156 | fprintf(stderr," stat\n"); | |
157 | fprintf(stderr," - display any supported stats\n"); | |
158 | fprintf(stderr," partitions [number]\n"); | |
159 | fprintf(stderr," - display partition[number] info\n"); | |
160 | fprintf(stderr," - display all partitions by default\n"); | |
161 | fprintf(stderr," vpd\n"); | |
162 | fprintf(stderr," - display supported disk VPD data\n"); | |
163 | fprintf(stderr," op [file]\n"); | |
164 | fprintf(stderr," - redirect all o/p to <file>\n"); | |
165 | fprintf(stderr," - by default print current op file\n"); | |
166 | fprintf(stderr," dd [read latency/write latency]\n"); | |
167 | fprintf(stderr," - display disk latency\n"); | |
168 | fprintf(stderr," debug [level]\n"); | |
169 | fprintf(stderr," - set debug vebosity to <level>\n"); | |
170 | fprintf(stderr," - displays current level by default\n"); | |
171 | } | |
172 | ||
173 | void Disk::set_debug_level(int l){ | |
174 | debug_level = l; | |
175 | for(int i = 0; i < MAX_PARTITIONS; i++) | |
176 | if(partitions[i]) | |
177 | partitions[i]->set_debug_level(l); | |
178 | return; | |
179 | } | |
180 | ||
181 | void Disk::set_debug_file(const char * file){ | |
182 | if(!strcmp(file,"stderr")){ | |
183 | debug_file = stderr; | |
184 | strcpy(debug_file_name,"stderr"); | |
185 | }else if(!strcmp(file,"stdout")){ | |
186 | debug_file = stdout; | |
187 | strcpy(debug_file_name,"stdout"); | |
188 | }else{ | |
189 | debug_file = fopen(file,"w+"); | |
190 | if(!debug_file){ | |
191 | fprintf(stderr,"%s Unable to open %s\n",disk_name,file); | |
192 | debug_file = stderr; | |
193 | strcpy(debug_file_name,"stderr"); | |
194 | }else | |
195 | strcpy(debug_file_name,file); | |
196 | } | |
197 | ||
198 | for(int i = 0; i < MAX_PARTITIONS; i++) | |
199 | if(partitions[i]) | |
200 | partitions[i]->set_debug_file(debug_file); | |
201 | ||
202 | return; | |
203 | } | |
204 | ||
205 | ||
206 | void Partition::info(){ | |
207 | fprintf(debug_file," %s\n",part_name); | |
208 | if(has_vtoc) | |
209 | fprintf(debug_file," Contains Disk label\n"); | |
210 | fprintf(debug_file," partition# %d\n",index); | |
211 | fprintf(debug_file," backup_file %s\n",part_filename,rw?"Read/Write":"Read Only"); | |
212 | fprintf(debug_file," %s\n",rw?"Read/Write":"Read Only"); | |
213 | fprintf(debug_file," %s\n",has_vtoc?"Contains Disk Label":"No Disk Label"); | |
214 | if(!rw) | |
215 | fprintf(debug_file," overlay_file %s\n",overlay_filename); | |
216 | if(ckpt_filename) | |
217 | fprintf(debug_file," ckpt_file %s\n",ckpt_filename); | |
218 | fprintf(debug_file," size (bytes) %lld\n",size); | |
219 | fprintf(debug_file," nblks %lld\n",nblks); | |
220 | fprintf(debug_file," padding %lld\n",nblks*BYTES_PER_SECTOR - size); | |
221 | fprintf(debug_file," start_lblk %lld\n",start_lblk); | |
222 | fprintf(debug_file," end_lblk %lld\n",end_lblk); | |
223 | fprintf(debug_file," debug_level %d\n",debug_level); | |
224 | ||
225 | fflush(debug_file); | |
226 | } | |
227 | ||
228 | ||
229 | ||
230 | void SCSIDisk::display_vpd(){ | |
231 | fprintf(debug_file,"%s\n",disk_name); | |
232 | ||
233 | fprintf(debug_file," vendorid - "); | |
234 | fwrite(vendorid,sizeof_vendorid,1,debug_file); | |
235 | fprintf(debug_file,"\n"); | |
236 | ||
237 | fprintf(debug_file," productid - "); | |
238 | fwrite(productid,sizeof_productid,1,debug_file); | |
239 | fprintf(debug_file,"\n"); | |
240 | ||
241 | fprintf(debug_file," revisionid - "); | |
242 | fwrite(revisionid,sizeof_revisionid,1,debug_file); | |
243 | fprintf(debug_file,"\n"); | |
244 | ||
245 | fprintf(debug_file," serialno - "); | |
246 | fwrite(serialno,sizeof_serialno,1,debug_file); | |
247 | fprintf(debug_file,"\n"); | |
248 | ||
249 | fprintf(debug_file," prodserialno - "); | |
250 | fwrite(prodserialno,sizeof_prodserialno,1,debug_file); | |
251 | fprintf(debug_file,"\n"); | |
252 | ||
253 | fprintf(debug_file," brdserialno - "); | |
254 | fwrite(brdserialno,sizeof_brdserialno,1,debug_file); | |
255 | fprintf(debug_file,"\n"); | |
256 | ||
257 | fprintf(debug_file," portwwn - "); | |
258 | fwrite(portwwn,sizeof_portwwn,1,debug_file); | |
259 | fprintf(debug_file,"\n"); | |
260 | ||
261 | fprintf(debug_file," nodewwn - "); | |
262 | fwrite(nodewwn,sizeof_nodewwn,1,debug_file); | |
263 | fprintf(debug_file,"\n"); | |
264 | ||
265 | fflush(debug_file); | |
266 | return; | |
267 | } |