This file is indexed.

/usr/sbin/tk_scsiformat is in scsitools 0.12-3ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
#!/bin/sh
# the next lines restarts using wish or abort with a message \
type wish > /dev/null 2>&1 && exec wish -f "$0" "$@" || \
echo "no /usr/bin/wish found: please install the tk package." && exit 1
#!/usr/bin/wish -f
# Based in parts on scsi-config by:
#     Copyright 1993 Yggdrasil Computing, Incorporated
# Copyright 1997 Michael Weller (eowmob@exp-math.uni-essen.de)
# You may copy this file according to the terms and conditions of version 2
# of the GNU General Public License as published by the Free Software
# Foundation.

# This variable is set if WE issued a format command. Only when set, we will
# issue an mkfs command if a format completes.
set format_initiator 0

set textwidth 28
set winwidth 64
set butwidth 18
set butwidth2 25
set sdevice $argv
set par_fov "-o"
set par_inter "0"
set par_query ""
set par_estim 600
set par_initpat ""
set par_initmode "none"
set par_defform "-d"
set par_erase ""
set par_defects ""
set par_partstyle "-fdos"
set par_parttype "-y83"
set par_partmin "99999"
set par_geomdetect ""
set par_heads "64"
set par_sectors "32"
set par_mkfs "mke2fs -m0 -q <DEVICE>1"

set par_mkfsnames [list \
    "None" \
    "Ext2 (standard)" \
    "Ext2 (no reserved blocks)" \
    "DOS-FAT (1K clusters, up to 32MB)" \
    "DOS-FAT (2K clusters, up to 64MB)" \
    "DOS-FAT (4K clusters, up to 128MB)" \
    "DOS-FAT (8K clusters), up to 256MB)" \
    "DOS-FAT (16K clusters, up to 512MB)" \
    ]
# Value for None is not a valid command at all:
set par_mkfscmds [list \
    "<DEVICE>1" \
    "mke2fs -q <DEVICE>1" \
    "mke2fs -m0 -q <DEVICE>1" \
    "mkdosfs -s2 <DEVICE>1" \
    "mkdosfs -s4 <DEVICE>1" \
    "mkdosfs -s8 <DEVICE>1" \
    "mkdosfs -s16 <DEVICE>1" \
    "mkdosfs -s32 <DEVICE>1" \
    ]
set vars2save [list par_fov par_inter par_query par_estim par_initpat par_initmode \
    par_defform par_erase par_partstyle par_parttype par_partmin par_geomdetect par_heads \
    par_sectors par_disprim par_nvram par_discert par_stop par_mkfs\
    ]

set whoami [exec whoami]

proc save_var {fd var} {
   upvar #0 $var myval
   puts $fd "set $var \"$myval\""
}

proc change_fov {} {
   global par_fov

   if { [string compare $par_fov -o] != 0 } then {
       if { [winfo exists .init_win] == 1 } then {
	  destroy .init_win
       }
       .f_opt.col1.init configure -state disabled
       .f_opt.col1.disprim configure -state disabled
       .f_opt.col1.nvram configure -state disabled
       .f_opt.col2.discert configure -state disabled
       .f_opt.col2.stop configure -state disabled
   } else {
       .f_opt.col1.init configure -state normal
       .f_opt.col1.disprim configure -state normal
       .f_opt.col1.nvram configure -state normal
       .f_opt.col2.discert configure -state normal
       .f_opt.col2.stop configure -state normal
   }
}

proc simple {} {
   global par_inter par_fov par_erase par_defform par_defects par_query

   set par_inter "0"
   set par_fov ""
   set par_erase ""
   change_fov
   if { [winfo exists .defs_win] == 1 } {
	destroy .defs_win
   }
   set par_defform "-d"
   set par_defects ""
   set par_query "-b"
   block_change $par_query
}

proc change_partmin {} {
   global par_partmin

   if { [string compare $par_partmin ""] == 0} then {
	set par_partmin 0
   }
   .f_def.part.menu entryconfigure 9 -label "Maximal Partition Size ${par_partmin}MB"
}

proc change_geom {geomdetect heads sectors} {
   if { [string compare $geomdetect "-G"] == 0} then {
	.f_def.part.menu entryconfigure 8 -label \
	     "Disk Geometry is ${heads} Heads and ${sectors} Sectors"
   } else {
	.f_def.part.menu entryconfigure 8 -label "Autodetect Disk Geometry"
   }
}

proc change_mkfs {} {
    global par_mkfscmds par_mkfs

    if { [lsearch -exact $par_mkfscmds "$par_mkfs"] >= 0 } then {
	set label "Other"
    } else {
	set label "Other ($par_mkfs)"
    }
    .f_def.part.menu.mkfs entryconfigure [expr [llength $par_mkfscmds] + 2] -label "$label"
}

proc bind_eedit {w} {
    bind $w <Key-Delete> {
	%W select clear
	%W delete insert insert
    }
    bind $w <Key-BackSpace> {
	%W select clear
	%W delete [expr [%W index insert] - 1] \
		[expr [%W index insert] - 1]
    }
    bind $w <Key-Left> {
	%W select clear
	%W icursor [expr [%W index insert] - 1]
    }
    bind $w <Key-Right> {
	%W select clear
	%W icursor [expr [%W index insert] + 1]
    }
    bind $w <Button-2> {
	catch {
		%W insert insert [selection get]
	}
    }
}

proc bind_entry {w} {
    bind_eedit $w
    bind $w <Key> {
	if { [ string length [%W get] ] < 5 } {
	    if { [ string first %A "0123456789" ] >= 0 } then {
	        %W insert insert %A
	    }
	}
    }
    bind $w <Control-Key> {set x 1}
    bind $w <Meta-Key> {set x 1}
    bind $w <Alt-Key> {set x 1}
    bind $w <Control-Meta-Key> {set x 1}
    bind $w <Control-Alt-Key> {set x 1}
    bind $w <Meta-Alt-Control-Key> {set x 1}
    bind $w <Button-2> {
	catch {
		set sel [selection get]
		regsub -all "\[^0-9\]" $sel "" sel2
		%W insert insert $sel2
		%W delete 5 end
	}
    }
}

proc bind_text {w} {
   bind $w <Control-Key> {set x 1}
   bind $w <Meta-Key> {set x 1}
   bind $w <Alt-Key> {set x 1}
   bind $w <Control-Meta-Key> {set x 1}
   bind $w <Control-Alt-Key> {set x 1}
   bind $w <Meta-Alt-Control-Key> {set x 1}
   bind $w <Key-Delete> {
	%W delete insert {insert + 1 chars}
	%W yview -pickplace insert
   }
   bind $w <Key-BackSpace> {
	%W delete {insert - 1 chars} insert
	%W yview -pickplace insert
   }
   bind $w <Key-Left> {
	%W mark set insert {insert - 1 chars}
	%W yview -pickplace insert
   }
   bind $w <Key-Right> {
	%W mark set insert {insert + 1 chars}
	%W yview -pickplace insert
   }
   bind $w <Key-Up> {
	%W mark set insert {insert - 1 lines}
	%W yview -pickplace insert
   }
   bind $w <Key-Down> {
	%W mark set insert {insert + 1 lines}
	%W yview -pickplace insert
   }
}

proc block_change { block } {
    if { [ string compare $block "-b" ] == 0 } then {
	.f_block.f_estim configure -foreground black
	.f_block.f_estim.t configure -state normal
	.f_block.f_estim.t configure -background white
    } else {
	.f_block.f_estim configure -foreground gray70
	.f_block.f_estim.t configure -state disabled
	.f_block.f_estim.t configure -background bisque
    }
}

proc copyrights {} {
  global butwidth butwidth2
  if { [winfo exists .version] == 1 } {
	raise .version
	return;
  }
  toplevel .version
  wm title .version "TkScsiformat Version Information"
  wm group .
  frame .version.header
  label .version.header.label -bitmap info -bg pink
  message .version.header.message -width 400 -bg pink -text \
	"Version Information." 

  pack .version.header.label .version.header.message -side left -padx 15
  message .version.copy0 -width 400 -background yellow -justify center -text \
     { This is version 1.0, 20th Aug 1997 of tk_scsiformat.}
  pack .version.header .version.copy0\
         -side top -pady 10 -padx 15

  message .version.copy1 -width 400 -background green -justify left -text\
     {Copyright 1993 Yggdrasil Computing, Incorporated.
Copyright 1997 Michael Weller (eowmob@exp-math.uni-essen.de).}

  message .version.copy2 -width 400 -justify center -text {This configuration\
     script may be copied and modified according to the terms and conditions\
     of version 2 of the GNU General Public License as published by the\
     Free Software Foundation (Cambridge, Massachusetts),\
     provided that this notice is not removed.

     This script was originally the control panel from the Yggdrasil\
     distribution.  Eric Youngdale thought it looked pretty keen, and it was easy\
     to adapt, so he used it as the basis for the SCSI configuration manager.\

     The configuration manager was extended by Michael Weller, and finally \
     this utility was written and based on it.

     Well, honestly, not more than ten or twenty lines are copied from scsi-config. \
     Thus repeating the copyrights above is probably not required. This is released \
     under GPL nevertheless, though.
}


   button .version.dismiss -text "Dismiss" -activebackground green \
	-command {destroy .version} -width $butwidth2
   pack .version.copy1 .version.copy2 .version.dismiss\
         -side top -pady 10 -padx 15

   tkwait window .version
}

proc enter_init {} {
   global butwidth2 par_initpat par_initmode textwidth winwidth
   global my_initmode

   set my_initmode ${par_initmode}

   if { [winfo exists .init_win] == 1 } {
	raise .init_win
	return;
   }
   toplevel .init_win
   wm title .init_win "Initialization of Logical Blocks"
   wm group .

   frame .init_win.header
   label .init_win.header.label -bitmap questhead -bg pink
   message .init_win.header.message -width 400 -bg pink -text \
	"Initialization Pattern for the Logical Blocks." 

   pack .init_win.header.label .init_win.header.message \
	 -side left -padx 15
   pack .init_win.header -side top -pady 10 -padx 15

   frame .init_win.row1
   frame .init_win.row2
   radiobutton .init_win.row1.log -text "of each logical block" \
	-variable my_initmode -value "-L" -width $textwidth
   radiobutton .init_win.row1.phy -text "of each physical block" \
	-variable my_initmode -value "-P" -width $textwidth
   radiobutton .init_win.row2.def -text "Don't write them anywhere" \
	-variable my_initmode -value "none" -width $textwidth

   pack .init_win.row1.log .init_win.row1.phy \
	 -side left -pady 5 -padx 15 -ipadx 2 -pady 2
   pack .init_win.row2.def \
	 -side left -pady 5 -padx 15 -ipadx 2 -pady 2

   label .init_win.mess1 -width $winwidth -text \
	"Write the corresponding logical block number in the first 4 bytes:"
   pack .init_win.mess1 -side top -pady 5 -padx 15
   pack .init_win.row1 -side top -pady 5 -padx 15
   pack .init_win.row2 -side top -pady 5 -padx 15

   label .init_win.mess2 -width $winwidth -text \
	"Enter an (optional) sequence of hexnumbers to fill the blocks with:"
   pack .init_win.mess2 -side top -pady 5 -padx 15

   frame .init_win.frame
   scrollbar .init_win.frame.yscroll -relief sunken \
        -command ".init_win.frame.page yview"
   text .init_win.frame.page -width $winwidth -background white -relief sunken \
	-borderwidth 2 -height 8 -wrap char -exportselection 1 \
	-yscrollcommand ".init_win.frame.yscroll set"
   .init_win.frame.page insert 1.0 $par_initpat
   pack .init_win.frame.yscroll -side right -fill y
   pack .init_win.frame.page -side top -expand 1 -fill both

   bind .init_win.frame.page <Key> {
	if { [ string first %A " 0123456789abcdefgABCDEF" ] >= 0 } then {
	    .init_win.frame.page insert insert [string toupper %A]
	    .init_win.frame.page yview -pickplace insert
	}
	if { [ string first %A "
" ] >= 0 } then {
	    .init_win.frame.page insert insert "\x0a"
	    .init_win.frame.page yview -pickplace insert
	}
   }
   bind .init_win.frame.page <Button-2> {
	catch {
		set sel [string toupper [selection get]]
		regsub -all "\[^ 0123456789ABCDEF\x0a\]" $sel "" sel2
		%W insert insert $sel2
	}
   }
   bind_text .init_win.frame.page
   pack .init_win.frame -side top -pady 5 -padx 15
   frame .init_win.f_bot
   button .init_win.f_bot.ok -text "Ok" \
        -activebackground green -command {
		set par_initpat [ .init_win.frame.page get 1.0 end ]
		set par_initmode $my_initmode
		destroy .init_win
        } -width $butwidth2
   button .init_win.f_bot.dismiss -text "Abort" \
        -activebackground red -activeforeground white \
	-command {destroy .init_win} -width $butwidth2
   pack .init_win.f_bot.ok .init_win.f_bot.dismiss \
	 -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   pack .init_win.f_bot -side top -pady 10 -padx 15

   tkwait window .init_win
}

proc set_msg { form } {
    switch -- $form {
	-D { .defs_win.mess3 configure -text \
	    {Enter defects in the format <integer>:<integer>:<integer> with three numbers \
             for cylinder, head, physical sector. Specifying sector -1 marks the whole \
             track as defect. You may preceed numbers with 0x or 0 for hexadecimal or \
	     octal representation }
	}
	-B { .defs_win.mess3 configure -text \
	    {Enter defects in the format <integer>:<integer>:<integer> with three numbers \
             for cylinder, head, bytes from index. This marks that number of bytes from \
	     the index mark as bad. Specifying -1 marks the whole \
             track as defect. You may preceed numbers with 0x or 0 for hexadecimal or \
	     octal representation }
	}
	-d { .defs_win.mess3 configure -text \
	    {Enter defects in the format <integer> where <integer> is the number of the \
	     defect logical block. You may preceed numbers with 0x or 0 for hexadecimal or \
	     octal representation }
	}
    }
}

proc enter_defs {} {
   global butwidth2 par_defform par_defects textwidth winwidth
   global my_defform

   set my_defform $par_defform
   if { [winfo exists .defs_win] == 1 } {
	raise .defs_win
	return;
   }
   toplevel .defs_win
   wm title .defs_win "Manual Defects Addition"
   wm group .
   frame .defs_win.header
   label .defs_win.header.label -bitmap questhead -bg pink
   message .defs_win.header.message -width 400 -bg pink -text \
	"Defects to be added manually." 

   pack .defs_win.header.label .defs_win.header.message \
	 -side left -padx 15
   pack .defs_win.header -side top -pady 10 -padx 15

   frame .defs_win.row1
   frame .defs_win.row2
   radiobutton .defs_win.row1.phy -text "By Physical Sectors" \
	-variable my_defform -value "-D" -width $textwidth -command { set_msg $my_defform }
   radiobutton .defs_win.row1.byt -text "By Bytes from Index" \
	-variable my_defform -value "-B" -width $textwidth -command { set_msg $my_defform }
   radiobutton .defs_win.row2.def -text "By Logical Block Numbers" \
	-variable my_defform -value "-d" -width $textwidth -command { set_msg $my_defform }

   pack .defs_win.row1.phy .defs_win.row1.byt \
	 -side left -pady 5 -padx 15 -ipadx 2 -pady 2
   pack .defs_win.row2.def \
	 -side left -pady 5 -padx 15 -ipadx 2 -pady 2

   label .defs_win.mess1 -width $winwidth -text \
	"Select the format in which you want to enter the defects:"
   pack .defs_win.mess1 -side top -pady 5 -padx 15
   pack .defs_win.row1 -side top -pady 5 -padx 15
   pack .defs_win.row2 -side top -pady 5 -padx 15

   label .defs_win.mess2 -width $winwidth -text \
	"Enter an (optional) sequence of of defects:"
   pack .defs_win.mess2 -side top -pady 5 -padx 15

   frame .defs_win.frame
   scrollbar .defs_win.frame.yscroll -relief sunken \
        -command ".defs_win.frame.page yview"
   text .defs_win.frame.page -width $winwidth -background white -relief sunken \
	-borderwidth 2 -height 8 -wrap char -exportselection 1 \
	-yscrollcommand ".defs_win.frame.yscroll set"
   .defs_win.frame.page insert 1.0 $par_defects
   pack .defs_win.frame.yscroll -side right -fill y
   pack .defs_win.frame.page -side top -expand 1 -fill both

   bind .defs_win.frame.page <Key> {
	if { [ string first %A " 0123456789abcdefgABCDEF:-" ] >= 0 } then {
	    .defs_win.frame.page insert insert [string toupper %A]
	}
	if { [ string compare %A "
" ] == 0 } then {
	    .defs_win.frame.page insert insert "\x0a"
	}
	if { [ string first %A "xX" ] >= 0 } then {
	    .defs_win.frame.page insert insert "x"
	}
	.defs_win.frame.page yview -pickplace insert
   }
   bind .defs_win.frame.page <Button-2> {
	catch {
		set sel [string toupper [selection get]]
		regsub -all "\[^ 0123456789ABCDEFX:\x0a-\]" $sel "" sel2
		regsub -all "X" $sel2 "x" sel
		%W insert insert $sel
	}
   }
   bind_text .defs_win.frame.page
   pack .defs_win.frame -side top -pady 5 -padx 15

   message .defs_win.mess3 -justify center -text "X" -background green \
	-aspect 800

   set_msg $my_defform

   pack .defs_win.mess3 -side top -pady 5 -padx 15

   frame .defs_win.f_bot
   button .defs_win.f_bot.ok -text "Ok" \
        -activebackground green -command {
		set par_defects [ .defs_win.frame.page get 1.0 end ]
		set par_defform $my_defform
		destroy .defs_win
        } -width $butwidth2
   button .defs_win.f_bot.dismiss -text "Abort" \
        -activebackground red -activeforeground white \
	-command {destroy .defs_win} -width $butwidth2
   pack .defs_win.f_bot.ok .defs_win.f_bot.dismiss \
	 -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   pack .defs_win.f_bot -side top -pady 10 -padx 15

   tkwait window .defs_win
}

proc handle_trans {w ontop} {
   wm transient $w $ontop
   wm withdraw $w
   update idletasks
   set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
            - [winfo vrootx [winfo parent $w]]]
   set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
            - [winfo vrooty [winfo parent $w]]]
   wm geom $w +$x+$y
   wm deiconify $w

   set oldFocus [focus]
   grab $w
   focus $w

   tkwait window $w
   if { [string compare $ontop "."] != 0 } then {
	grab $ontop
   }
   focus $oldFocus
}

proc post_partsize {} {
   global butwidth2 par_partmin

   toplevel .partsize
   frame .partsize.f_bot
   wm title .partsize "Maximal partition size"
   wm group .
   frame .partsize.header
   label .partsize.header.label -bitmap questhead -bg pink
   message .partsize.header.message -width 400 -bg pink -text \
	"Maximal partition size." 

   pack .partsize.header.label .partsize.header.message \
	 -side left -padx 15
   pack .partsize.header -side top -pady 10 -padx 15

   message .partsize.expl -bg green -width 400 -text \
	"Enter the maximal partition size in Megabyte. If it is zero, \
	no partition is created and the partition table is left empty. \
	Otherwise a partition of this size is created as primary \
	partition 1. If the size does not fit the partition is made as \
	large as possible."

   pack .partsize.expl -side top -pady 10 -padx 15

   label .partsize.f_inter -text "Maximal partition size in MB:             "
   entry .partsize.f_inter.t -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1
   .partsize.f_inter.t insert 0 $par_partmin
   bind_entry .partsize.f_inter.t
   place .partsize.f_inter.t -in .partsize.f_inter -anchor e -relx 1.0 -rely 0.5

   pack .partsize.f_inter -side top -pady 20 -padx 15

   button .partsize.f_bot.ok -text "Ok" \
        -activebackground green -command {
	   set par_partmin [ .partsize.f_inter.t get ]
	   change_partmin
	   destroy .partsize
        } -width $butwidth2
   button .partsize.f_bot.dismiss -text "Abort" \
        -activebackground red -activeforeground white \
	-command {destroy .partsize} -width $butwidth2
   pack .partsize.f_bot.ok .partsize.f_bot.dismiss \
	 -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   pack .partsize.f_bot -side top -pady 10 -padx 15

   handle_trans .partsize .
}

proc change_geodet { geodet } {
    if { [ string compare $geodet "-G" ] == 0 } then {
	.geom.hese.heads configure -foreground black
	.geom.hese.heads.t configure -state normal
	.geom.hese.heads.t configure -background white
	.geom.hese.sectors configure -foreground black
	.geom.hese.sectors.t configure -state normal
	.geom.hese.sectors.t configure -background white
    } else {
	.geom.hese.heads configure -foreground gray70
	.geom.hese.heads.t configure -state disabled
	.geom.hese.heads.t configure -background bisque
	.geom.hese.sectors configure -foreground gray70
	.geom.hese.sectors.t configure -state disabled
	.geom.hese.sectors.t configure -background bisque
    }
}

proc post_geom {} {
   global winwidth butwidth2 par_geomdetect par_heads par_sectors textwidth
   global my_geomdetect

   set my_geomdetect $par_geomdetect

   toplevel .geom
   frame .geom.f_bot
   wm title .geom "Disk Drive Geometry"
   wm group .
   frame .geom.header
   label .geom.header.label -bitmap questhead -bg pink
   message .geom.header.message -width 400 -bg pink -text \
	"Disk Drive Geometry." 

   pack .geom.header.label .geom.header.message \
	 -side left -padx 15
   pack .geom.header -side top -pady 10 -padx 15

   message .geom.expl -bg green -width 400 -text \
	"Enter the geometry of the disk. Not the real one, but the one \
	DOS will see, s.t. the partition table can be build in a way that \
	DOS and other OS's will be able to handle it. Generally, linux \
	device drivers report the setting back which the corresponding adapters \
	use under DOS. If this fails, 64 heads and 32 are usually used. "

   pack .geom.expl -side top -pady 10 -padx 15

   checkbutton .geom.auto -variable my_geomdetect -onvalue "" -offvalue "-G" \
	-text " Query Geometry from Scsidriver " -command {change_geodet $my_geomdetect}
   
   pack .geom.auto -side top -pady 20 -padx 15

   frame .geom.hese

   label .geom.hese.heads -text   "Heads:             "
   entry .geom.hese.heads.t -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1
   .geom.hese.heads.t insert 0 $par_heads
   bind_entry .geom.hese.heads.t
   place .geom.hese.heads.t -in .geom.hese.heads -anchor e -relx 1.0 -rely 0.5

   label .geom.hese.sectors -text "Sectors:           "
   entry .geom.hese.sectors.t -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1
   .geom.hese.sectors.t insert 0 $par_sectors
   bind_entry .geom.hese.sectors.t
   place .geom.hese.sectors.t -in .geom.hese.sectors -anchor e -relx 1.0 -rely 0.5

   pack .geom.hese.heads  .geom.hese.sectors  -side left -pady 15 -padx 15
   pack .geom.hese -side top
   change_geodet $my_geomdetect

   button .geom.f_bot.ok -text "Ok" \
        -activebackground green -command {
	   set par_heads [ .geom.hese.heads.t get ]
	   set par_sectors [ .geom.hese.sectors.t get ]
	   set par_geomdetect $my_geomdetect
	   change_geom $par_geomdetect $par_heads $par_sectors
	   destroy .geom
        } -width $butwidth2
   button .geom.f_bot.dismiss -text "Abort" \
        -activebackground red -activeforeground white \
	-command {destroy .geom} -width $butwidth2
   pack .geom.f_bot.ok .geom.f_bot.dismiss \
	 -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   pack .geom.f_bot -side top -pady 10 -padx 15

   handle_trans .geom .
}

proc post_mkfs {} {
   global butwidth2 par_mkfs

   toplevel .mkfs
   frame .mkfs.f_bot
   wm title .mkfs "Make FileSystem Command"
   wm group .
   frame .mkfs.header
   label .mkfs.header.label -bitmap questhead -bg pink
   message .mkfs.header.message -width 400 -bg pink -text \
	"Make FileSystem Command."

   pack .mkfs.header.label .mkfs.header.message \
	 -side left -padx 15
   pack .mkfs.header -side top -pady 10 -padx 15

   message .mkfs.expl -bg green -width 400 -text \
	"Enter a command to execute to make a filesystem on the freshly created partition.\
         The string <DEVICE> in the string will be replaced by the name of disk device\
	 being formatted. Generally you'll have to use <DEVICE>1 to refer to the first\
	 partition."

   pack .mkfs.expl -side top -pady 10 -padx 15

   frame .mkfs.f_inter
   scrollbar .mkfs.f_inter.s -relief sunken -orient horiz -command \
            ".mkfs.f_inter.t xview"
   entry .mkfs.f_inter.t -background white -relief sunken -borderwidth 2 \
	-exportselection 1 -xscrollcommand ".mkfs.f_inter.s set"
   .mkfs.f_inter.t insert 0 $par_mkfs

   bind_eedit .mkfs.f_inter.t
   bind .mkfs.f_inter.t <Key-KP_Enter> { .mkfs.f_bot.ok invoke }
   bind .mkfs.f_inter.t <Key-Return> { .mkfs.f_bot.ok invoke }

   pack .mkfs.f_inter.t .mkfs.f_inter.s -side top -fill both -expand yes
   pack .mkfs.f_inter -side top -pady 20 -padx 15 -fill both -expand yes

   button .mkfs.f_bot.ok -text "Ok" \
        -activebackground green -command {
	   set par_mkfs [ .mkfs.f_inter.t get ]
	   change_mkfs
	   destroy .mkfs
        } -width $butwidth2
   button .mkfs.f_bot.dismiss -text "Abort" \
        -activebackground red -activeforeground white \
	-command {destroy .mkfs} -width $butwidth2
   pack .mkfs.f_bot.ok .mkfs.f_bot.dismiss \
	 -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   pack .mkfs.f_bot -side top -pady 10 -padx 15

   handle_trans .mkfs .
}

proc set_rands {} {
   set tworands [exec /usr/lib/scsi/tworands]
   .conf.equa.sol delete 0 end
   .conf.equa.a configure -state normal
   .conf.equa.b configure -state normal
   .conf.equa.a delete 0 end
   .conf.equa.b delete 0 end
   .conf.equa.a insert 0 [lindex $tworands 0]
   .conf.equa.b insert 0 [lindex $tworands 1]
   .conf.equa.a configure -state disabled
   .conf.equa.b configure -state disabled
}

proc query_format {} {
   global winwidth butwidth2 textwidth format_cmd sdevice par_fov par_inter par_query \
	  par_estim par_initpat par_initmode par_defform par_defects par_erase par_partstyle \
	  par_parttype par_partmin par_geomdetect par_heads par_sectors par_disprim par_nvram \
	  par_discert par_stop


   toplevel .conf
   frame .conf.f_bot
   wm title .conf "Format Confirmation Request"
   wm group .
   frame .conf.header
   label .conf.header.label -bitmap warning -bg pink
   message .conf.header.message -width 400 -bg pink -text \
	"Format Confirmation Request."

   pack .conf.header.label .conf.header.message \
	 -side left -padx 15
   pack .conf.header -side top -pady 10 -padx 15

   message .conf.expl -bg red -fg white -width 400 -justify center -text \
"Formatting will erase all data on $sdevice, regardless on which \
partition, and there will be NO way to recover your data.

Therefore, please check now if you really want to format this device. \
To ensure that your are really with me and know what you do, please \
answer the simple question below."

   pack .conf.expl -side top -pady 10 -padx 15

   frame .conf.equa

   entry .conf.equa.a -width 3 -relief sunken -borderwidth 2 -state disabled
   label .conf.equa.times -text "*"
   entry .conf.equa.b -width 3 -relief sunken -borderwidth 2 -state disabled
   label .conf.equa.equa -text "="
   entry .conf.equa.sol -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1
   bind_entry .conf.equa.sol
   set_rands

   pack .conf.equa.a .conf.equa.times .conf.equa.b .conf.equa.equa .conf.equa.sol \
	-side left -pady 10 -padx 3
   pack .conf.equa -side top

   message .conf.result -bg red -fg white -aspect 900 -text "Wrong! Please retry or bail out!"

   frame .conf.space
   pack .conf.space -side top -pady 8

   button .conf.f_bot.ok -text "Confirm" \
        -activebackground yellow -command {
	  if { [expr [.conf.equa.a get] * [.conf.equa.b get]] == [.conf.equa.sol get] } then {
	    destroy .conf
	    do_format $format_cmd
	  } else {
	    set_rands
	    pack .conf.result -after .conf.equa -side top -pady 2 -padx 15
          }
        } -width $butwidth2
   button .conf.f_bot.show -text "Show ScsiFormat Command" \
        -activebackground green -command {
	     show_format "$format_cmd $sdevice"
        } -width $butwidth2

   pack .conf.f_bot.ok .conf.f_bot.show -side left -pady 15 -padx 15 -ipadx 2 -pady 2

   button .conf.dismiss -text "Bail Out" \
        -activebackground red -activeforeground white \
	-command {destroy .conf} -width $butwidth2

   pack .conf.f_bot -side top -padx 15
   pack .conf.dismiss -side top -pady 10

   set format_cmd "/usr/sbin/scsiformat $par_erase -i$par_inter"

   regsub -all "\x0a" [string trim $par_defects] " " tmpstr
   regsub -all " +" $tmpstr "," tmpstr
   if { [string length $tmpstr] > 0 } then {
	append format_cmd " $par_defform$tmpstr"
   }
   if { [string compare $par_partstyle "none"] != 0 } then {
	append format_cmd " $par_partstyle $par_parttype -M$par_partmin"
   }
   if { [string compare $par_geomdetect "-G"] == 0 } then {
	append format_cmd " $par_geomdetect${par_heads}x$par_sectors"
   }
   if { [string compare $par_fov "-o"] == 0} then {
	append format_cmd " $par_fov"
	if { [string compare $par_initmode "none"] != 0 } then {
	    append format_cmd " $par_initmode"
	}
	regsub -all "\[ \x0a\]" [string trim $par_initpat] "" tmpstr
	if { [string length $tmpstr] > 0 } then {
	    append format_cmd " -I$tmpstr"
	}
	append format_cmd " $par_discert $par_disprim $par_stop $par_nvram"
   }
   if { [string compare $par_query "-b"] == 0 } then {
	append format_cmd " -b$par_estim"
   }
   #trim unneccessary spaces:
   regsub -all " +" [string trim $format_cmd] " " format_cmd
   handle_trans .conf .
}

proc show_format {cmd} {
   global winwidth butwidth2 textwidth

   toplevel .showcmd
   frame .showcmd.f_bot
   wm title .showcmd "Show ScsiFormat Command"
   wm group .
   frame .showcmd.header
   label .showcmd.header.label -bitmap info -bg pink
   message .showcmd.header.message -width 400 -bg pink -text \
	"Show ScsiFormat Command."

   pack .showcmd.header.label .showcmd.header.message \
	 -side left -padx 15
   pack .showcmd.header -side top -pady 10 -padx 15

   message .showcmd.expl -width 400 -text \
	"This is the command which will perform the scsi low level format you requested:"
   pack .showcmd.expl -side top -pady 10 -padx 15

   message .showcmd.cmd -width 400 -text $cmd -relief sunken
   pack .showcmd.cmd -side top -pady 10 -padx 15

   button .showcmd.dismiss -text "Dismiss" \
        -activebackground red -activeforeground white \
	-command {destroy .showcmd} -width $butwidth2

   pack .showcmd.dismiss -side top -pady 10

   handle_trans .showcmd .conf
}

proc do_format {fcmd} {
   global par_query par_estim sdevice
   global winwidth butwidth2 textwidth
   global check_cmd format_initiator

   set security "-F'Ene Mene Meck, und Du bist weg!'"
   append fcmd " $security -t0 -X $sdevice"
   
   if { [catch {exec sh -c "$fcmd" >& /var/run/scsiformat.[pid] } err] != 0 } then {
        set fd [open /var/run/scsiformat.[pid] r]
	set err "$err\x0a[read $fd]"
	close $fd
        exec rm /var/run/scsiformat.[pid]
	show_err scsiformat $err
	return;
   }
   exec rm /var/run/scsiformat.[pid]
   set format_initiator 1
   show_busy
}

proc show_err {cmd msg} {
   global winwidth butwidth2 textwidth

   if { [winfo exists .error] == 1 } {
	.error.msg configure -text $msg
	raise .error
        tkwait window .error
	return;
   }
   toplevel .error
   frame .error.f_bot
   wm title .error "ScsiFormat Error"
   wm group .
   frame .error.header
   label .error.header.label -bitmap error -bg pink
   message .error.header.message -width 400 -bg pink -text \
	"Show $cmd Error Message."

   pack .error.header.label .error.header.message \
	 -side left -padx 15
   pack .error.header -side top -pady 10 -padx 15

   message .error.expl -width 600 -text \
	"$cmd returned the following error message:"
   pack .error.expl -side top -pady 10 -padx 15

   message .error.msg -width 600 -text $msg -relief sunken
   pack .error.msg -side top -pady 10 -padx 15

   button .error.dismiss -text "Dismiss" \
        -activebackground red -activeforeground white \
	-command {destroy .error} -width $butwidth2

   pack .error.dismiss -side top -pady 10

   tkwait window .error
}

proc query_prog {} {
   global sdevice errorCode wasbusy format_initiator par_mkfs

   set check_cmd "/usr/sbin/scsiformat -T -t1 -X $sdevice"

   if { [winfo exists .showprog] != 1 } {
	return;
   }
   set errorCode [list CHILDSTATUS 0 0]
   catch {exec sh -c "$check_cmd"} err
   if { ([string compare [lindex $errorCode 0] CHILDSTATUS] != 0) 
				|| ([lindex $errorCode 2] > 1) } then {
	show_err scsiformat $err
   } elseif { [lindex $errorCode 2] == 1 } then {
	if {[catch {
	    .showprog.row2.start configure -text [lindex $err 0]
	    .showprog.row2.end configure -text [lindex $err 3]
	    set percent [lindex $err 1]
	    if { [string compare $percent "-"] != 0} then {
		.showprog.expl configure -text [format "%.10g%% in %s" [expr 100 * $percent] \
		    [lindex $err 2] ]
		if { $percent >= 1.0 } then { set percent 1.0 }
	    } else {
		.showprog.expl configure -text [lindex $err 2]
		set percent 0
	    }
	    place .showprog.slider.inner -in .showprog.slider -relwidth $percent -relheight 1.0 \
		-anchor nw -x 0 -y 0
	    set wasbusy 1
	    after 5000 query_prog}] != 0} then {
#Something weird went on. Like illegal device name, read-only device, etc..
		destroy .showprog
	}
   } else {
	destroy .showprog
	if { $format_initiator == 1} then {
	    set format_initiator 0
	    if { [string compare $par_mkfs "<DEVICE>1"] != 0} then {
		regsub "<DEVICE>" $par_mkfs "${sdevice}" cmd
#
#it seems that we have to wait even more...
#
#a mayor reason is that the format might have completed, but scsiformat is
#still creating the partion which will also include some sleep()'s
#
		exec sync
		exec sh -c "sleep 10"
		set errorCode [list NONE 0 0]
		catch {exec sh -c "$cmd"} err
		if { ([string compare [lindex $errorCode 0] CHILDSTATUS] == 0) } then {
		    show_err "Filesystem maker"\
		         "'$cmd' exited with errorcode - [lindex $errorCode 2]\x0a$err"
		}
	    }
	}
	if { $wasbusy == 1 } then {
	    puts -nonewline stderr "\x0a"
	    flush stderr
	}
   }
}

proc show_busy {} {
   global textwidth wasbusy

   toplevel .showprog
   frame .showprog.f_bot
   wm title .showprog "Show ScsiFormat Progress"
   wm group .
   frame .showprog.header
   label .showprog.header.label -bitmap hourglass -bg pink
   message .showprog.header.message -width 400 -bg pink -text \
	"Formatting in Progress."

   pack .showprog.header.label .showprog.header.message \
	 -side left -padx 15
   pack .showprog.header -side top -pady 10 -padx 15
   frame .showprog.space
   pack .showprog.space -side top -pady 5
   frame .showprog.row1
   frame .showprog.row2
   pack .showprog.row1 .showprog.row2 -side top -expand yes -fill both -padx 4

   label .showprog.row1.start -text "Started" -borderwidth -1
   pack .showprog.row1.start -side left
   frame .showprog.row1.space
   pack .showprog.row1.space -after .showprog.row1.start -side left -expand yes -fill both
   label .showprog.row1.end -text "Estimated End" -borderwidth -1
   pack .showprog.row1.end -side right

   label .showprog.row2.start -borderwidth -1
   pack .showprog.row2.start -side left
   frame .showprog.row2.space
   pack .showprog.row2.space -after .showprog.row2.start -side left -expand yes -fill both
   label .showprog.row2.end -borderwidth -1
   pack .showprog.row2.end -side right

   frame .showprog.slider -borderwidth 2 -height 20 -relief sunken
   pack .showprog.slider -side top -expand yes -fill both -pady 4 -padx 4
   frame .showprog.slider.inner -borderwidth 2 -relief raised -bg SlateGray1

   message .showprog.expl -width 400 -text "X" -borderwidth -1
   pack .showprog.expl -side top
   frame .showprog.space2
   pack .showprog.space2 -side top -pady 2

   set wasbusy 0
   query_prog
   if { [winfo exists .showprog] != 1 } {
	return;
   }
   handle_trans .showprog .
}

wm title . "TkScsiformat Version 1.0"

if { [string compare $whoami root] != 0} then {
    frame .warn
    frame .warn.h
    label .warn.h.l -bitmap info -background pink
    message .warn.h.m -aspect 200 -background pink -justify center -text \
	{You need to be root in order to format a SCSI device!}
    pack .warn.h.l .warn.h.m -side left -padx 10
    button .warn.quit -text "Quit" -command exit \
	-activeforeground white -activebackground red
    pack .warn.h .warn.quit -side top -pady 10
    pack .warn
    tkwait window .warn
}

if { [llength $argv] > 1 } then {
    puts stderr "Usage: tk_scsiformat \[device\]"
    exit
}

while { [string compare [lindex $sdevice 0] ""] == 0 } {
    frame .select
    frame .select.h
    label .select.h.l -bitmap questhead -background pink
    message .select.h.m -justify center -aspect 500 -background pink -text \
	{Select a SCSI device to low level format.}
    frame .select.f
    button .select.f.quit -text "    Quit    " -command exit \
	-activeforeground white -activebackground red
    button .select.f.continue -text " Continue " -activebackground green \
	-command {destroy .select}
    pack .select.f.continue .select.f.quit -side left -padx 10
    pack .select.h.l .select.h.m -side left -padx 10
    pack .select.h -pady 10
    pack .select
    set line [exec /sbin/scsiinfo -l]
    set n 0
    foreach x $line { 
        if {[string first "/dev/sd" "$x"] != 0} continue;
        radiobutton .select.$n -text "$x" -width 10 \
           -variable sdevice -value $x -anchor w
	pack .select.$n  -padx 3
        set n [expr $n+1]
    }
    if { $n == 0 } then {
	.select.f.continue configure -state disabled
    } else {
	.select.0 select
    }
    pack .select.f -pady 10
    tkwait window .select
}

set save_file "/usr/lib/scsi/scsiformat.defs.[file tail $sdevice]"
catch {source $save_file}

frame .header
label .header.label -bitmap question -bg pink
message .header.message -width 400 -bg pink -text \
	"Scsi Low Level Format - $sdevice." 

pack .header.label .header.message -side left -padx 15

frame .f_bot1
button .f_bot1.copyrights -activebackground green -text "Version Info"    \
	-command { copyrights } -width $butwidth
button .f_bot1.filesave -activebackground green -text "Save Defaults"    \
	-width $butwidth -command {
          global vars2save save_file
          set fd [open $save_file w]
	  foreach var $vars2save { save_var $fd $var }
	  close $fd
        }
button .f_bot1.simple -activebackground green -text "Simple Format Cmd"    \
	-command "simple" -width $butwidth
pack .f_bot1.copyrights .f_bot1.filesave .f_bot1.simple \
        -side left -padx 12 -ipadx 2 -ipady 2 -pady 5

frame .f_bot2
button .f_bot2.format -text "Format" -command { query_format } \
	-activebackground yellow -activeforeground black -width $butwidth2
button .f_bot2.quit -text "Quit" -command { exit } \
	-activebackground red -activeforeground white -width $butwidth2
pack .f_bot2.format .f_bot2.quit -side left -padx 12 -ipadx 2 -ipady 2 -pady 5

frame .f_mand -width $winwidth
checkbutton .f_mand.erase -offvalue "" -onvalue "-e" -variable par_erase -text \
	"Erase Grown Defect List" -width [expr $textwidth - 1]

label .f_mand.f_inter -text "Interleave (0 for default):            " -width $textwidth
entry .f_mand.f_inter.t -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1 -textvariable par_inter
bind_entry .f_mand.f_inter.t
place .f_mand.f_inter.t -in .f_mand.f_inter -anchor e -relx 1.0 -rely 0.5

pack .f_mand.erase .f_mand.f_inter -side left -padx 12 -ipadx 2 -ipady 2

frame .f_def
button .f_def.defects -text "Add Defects Manually" -activebackground yellow -command enter_defs \
	-width [expr $textwidth]
menubutton .f_def.part -text "Simple Partioning" \
	-width [expr $textwidth] -relief raised -menu .f_def.part.menu \
	-activebackground SlateGray1
menu .f_def.part.menu -background SlateGray1 -activebackground SlateGray2
.f_def.part.menu add radiobutton -label "Don't touch Partion Sector" \
	-variable par_partstyle -value "none"
.f_def.part.menu add radiobutton -label "DOS Style Partion" \
	-variable par_partstyle -value "-fdos"
.f_def.part.menu add radiobutton -label "Tight Style Partion (not on Cylinder Boundary)" \
	-variable par_partstyle -value "-ftight"
.f_def.part.menu add separator
.f_def.part.menu add cascade -menu .f_def.part.menu.types -label "Partition type"
.f_def.part.menu add cascade -menu .f_def.part.menu.mkfs -label "Filesystem type"
.f_def.part.menu add separator
.f_def.part.menu add command -command post_geom
.f_def.part.menu add command -command post_partsize

menu .f_def.part.menu.types -background SlateGray1 -activebackground SlateGray2
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "Linux/Minix" -value "-y81"
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "Linux swap" -value "-y82"
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "Linux native" -value "-y83"
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "DOS 12-bit FAT" -value "-y01"
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "DOS 16-bit FAT <32M" -value "-y52"
.f_def.part.menu.types add radiobutton -variable par_parttype \
	-label "DOS 16-bit FAT >=32M" -value "-y64"

menu .f_def.part.menu.mkfs -background SlateGray1 -activebackground SlateGray2
for {set i 0} {$i < [llength $par_mkfsnames]} {incr i} {
    .f_def.part.menu.mkfs add radiobutton -variable par_mkfs -command change_mkfs \
	-label "[lindex $par_mkfsnames $i]" -value "[lindex $par_mkfscmds $i]"
}
.f_def.part.menu.mkfs add separator
.f_def.part.menu.mkfs add command -command post_mkfs
change_mkfs

change_partmin
change_geom $par_geomdetect $par_heads $par_sectors

pack .f_def.defects .f_def.part -side left -padx 12 -ipadx 2 -ipady 2

frame .f_opt -width $winwidth -relief raised -borderwidth 2
checkbutton .f_opt.fov -offvalue "" -onvalue "-o" -variable par_fov -text \
	"    Use Custom Format Parameters" -command change_fov -activebackground yellow \
	-width [expr $winwidth - 2]
pack .f_opt.fov -side top -padx 12 -ipadx 2 -ipady 2 -pady 5
frame .f_opt.col1
frame .f_opt.col2

button .f_opt.col1.init -text "Enter initialization pattern" -activebackground yellow \
         -command enter_init -width [expr $textwidth + 2]
checkbutton .f_opt.col1.disprim -offvalue "" -onvalue "-p" -variable par_disprim -text \
	"Ignore Primary Defects" -width $textwidth
checkbutton .f_opt.col1.nvram -offvalue "" -onvalue "-S" -variable par_nvram -text \
	"Erase MODE SELECT Nvram" -width $textwidth
pack .f_opt.col1.init .f_opt.col1.disprim .f_opt.col1.nvram \
	-side top -padx 12 -ipadx 2 -ipady 2 -pady 5
checkbutton .f_opt.col2.discert -offvalue "" -onvalue "-c" -variable par_discert -text \
	"Disable Media Certification" -width $textwidth
checkbutton .f_opt.col2.stop -offvalue "" -onvalue "-s" -variable par_stop -text \
	"Stop On Missing Defectlist" -width $textwidth
label .f_opt.col2.dummy 
pack .f_opt.col2.discert .f_opt.col2.stop .f_opt.col2.dummy \
	-side top -padx 12 -ipadx 2 -ipady 2 -pady 5
pack .f_opt.col1 .f_opt.col2 -side left

frame .f_block
checkbutton .f_block.par_block -offvalue "-b" -onvalue "" -variable par_query -text \
	"Query progress from target" -width $textwidth -command { block_change $par_query }

label .f_block.f_estim -text "Estimated run time in sec:             " -width $textwidth
entry .f_block.f_estim.t -width 5 -background white -relief sunken -borderwidth 2 \
	-exportselection 1 -textvariable par_estim
bind_entry .f_block.f_estim.t

place .f_block.f_estim.t -in .f_block.f_estim -anchor e -relx 1.0 -rely 0.5
pack  .f_block.par_block .f_block.f_estim -side left -padx 12 -ipadx 2 -ipady 2
block_change $par_query

change_fov

pack .header -padx 10 -pady 10
pack .f_mand .f_def -pady 4
pack .f_opt -padx 10 -pady 10
pack .f_block -padx 10 -pady 4
pack .f_bot1 .f_bot2 -padx 10 -pady 4

show_busy