Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

583 lines
16 KiB

  1. #!perl -w
  2. #
  3. # .pl -- A tool to reorganize the layout.inx file based on usage
  4. #
  5. # Author: Milong Sabandith (milongs)
  6. #
  7. ##############################################################################
  8. # List of files that need to be on last floppy
  9. @lastlist = ("ntdll.dll", "usetup.exe", "spcmdcon.sys");
  10. # List of replacement destinations. Use "" for the same name as in @lastlist
  11. @lastrepl = ("system32\\ntdll.dll", "system32\\smss.exe", "");
  12. # List of files that need to be on first floppy
  13. # txtsetup.sif is special because it needs to be compressed.
  14. @firstlist = ("setupldr.bin", "txtsetup.sif", "biosinfo.inf", "ntdetect.com", "ntkrnlmp.exe");
  15. sub onlastdisk {
  16. local($filename) = @_;
  17. while (<@lastlist>) {
  18. if ($filename =~ /^$_$/ ) {
  19. return 1;
  20. }
  21. }
  22. return 0;
  23. }
  24. sub GetFromInf {
  25. local( $filename, $section, $name, $num) = @_;
  26. $retvalue = "";
  27. open( INFFILE, "<".$filename) or die "can't open $filename: $!";
  28. LINEG: while( <INFFILE>) {
  29. chomp $_;
  30. $line = lc $_;
  31. if ($line =~ /^\[/)
  32. {
  33. $InSection = 0;
  34. }
  35. if ($line =~ /^\[$section/)
  36. {
  37. $InSection = 1;
  38. next LINEG;
  39. }
  40. if (! $InSection)
  41. {
  42. next LINEG;
  43. }
  44. @linefields = split('=', $line);
  45. # empty line
  46. if ( $#linefields == -1) {
  47. next LINEG;
  48. }
  49. $nameg = $linefields[0];
  50. #print "nameg = " . $#linefields . $nameg . "\n";
  51. if( length( $nameg) < 1)
  52. {
  53. next LINEG;
  54. }
  55. $nameg =~ s/ *$//g;
  56. if ( not ($nameg =~ /$name/)) {
  57. next LINEG;
  58. }
  59. @linefields2 = split(',', $linefields[1]);
  60. $retvalue = $linefields2[$num];
  61. # Remove spaces
  62. $retvalue =~ s/ *$//g;
  63. $retvalue =~ s/^ *//g;
  64. if( length( $retvalue) > 0) {
  65. last LINEG;
  66. }
  67. } # while (there is still data in this inputfile)
  68. close( INFFILE);
  69. return $retvalue;
  70. }
  71. sub myprocess {
  72. local($shareloc) = @_;
  73. $output = "bootfiles";
  74. $layout = $shareloc . "\\layout.inf";
  75. $dosnet = $shareloc . "\\dosnet.inf";
  76. $txtsetup = $shareloc . "\\txtsetup.sif";
  77. $allfiles = $output.".all";
  78. $modified = $output.".mod";
  79. $enum = $output.".enum";
  80. $total = $output.".total";
  81. $final = $output.".final";
  82. $languageid = "00000409";
  83. print "Share location: " . $shareloc . "\n\n";
  84. print "Finding layout.inf at: " . $layout . "\n";
  85. open(OLD, "<" . $layout) or die "can't open $layout: $!";
  86. open(NEW, ">" . $allfiles) or die "can't open $allfiles: $!";
  87. # Read txtsetup.sif for required language id.
  88. $languageid = GetFromInf( $txtsetup, "nls", "defaultlayout", 0);
  89. if ( length($languageid) < 1) {
  90. print "Could not determine DefaultLayout from txtsetup.sif.\n";
  91. return 0;
  92. }
  93. print "Lanuage Id = " . $languageid ."\n";
  94. $keyboardfile = GetFromInf( $txtsetup, "files.keyboardlayout", $languageid, 0);
  95. if ( length($languageid) < 1) {
  96. print "Could not determine keyboard file from txtsetup.sif.\n";
  97. return 0;
  98. }
  99. print "Keyboard file = " . $keyboardfile ."\n";
  100. push( @lastlist, $keyboardfile);
  101. push( @lastrepl, $keyboardfile);
  102. # Compress txtsetup.sif locally
  103. (print "\nCopying $txtsetup for compression.\n");
  104. `dcomp $txtsetup .`;
  105. # Read dosnet.inf for .fon and .nls boot files
  106. print "Finding dosnet.inf at: " . $dosnet . "\n";
  107. open(DOSNET, "<" . $dosnet) or die "can't open $dosnet: $!";
  108. $InFloppySection = 0;
  109. $disknum = "-";
  110. print "\nAdding the following font and nls files to disk2.\n";
  111. LINE1: while( <DOSNET> ) {
  112. chomp $_;
  113. $line = lc $_;
  114. if ($line =~ /^\[/)
  115. {
  116. $InFloppySection = 0;
  117. }
  118. if ($line =~ /^\[floppyfiles\./)
  119. {
  120. $InFloppySection = 1;
  121. $line2 = $line;
  122. chop $line2;
  123. @linefields= split('\.', $line2);
  124. $disknum = $linefields[1];
  125. next LINE1;
  126. }
  127. if (! $InFloppySection)
  128. {
  129. next LINE1;
  130. }
  131. if ( $line =~ /^d1\,disk1\,disk/) {
  132. next LINE1;
  133. }
  134. if ($line =~ /^d1\,/)
  135. {
  136. @linefields = split(',', $line);
  137. $filename = $linefields[1];
  138. #Remove spaces from filesname
  139. $filename =~ s/ *$//g;
  140. #Skip .fon and .nls files since they are included in dosnet.txt
  141. if ($filename !~ /\.fon$/ and $filename !~ /\.nls$/)
  142. {
  143. next LINE1;
  144. }
  145. $filenamep = $shareloc. "\\".$filename;
  146. $filename2 = $filename;
  147. if (!(-e $filenamep) ) {
  148. chop $filenamep;
  149. $filenamep = $filenamep . "_";
  150. chop $filename2;
  151. $filename2 = $filename2 . "_";
  152. }
  153. if (-e $filenamep ) {
  154. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($filenamep);
  155. (printf "%20s %10s", " " . $filename, $size . "\n");
  156. (printf NEW "%2s %20s %10s %20s\n", 2, " " . $filename, $size, $filename2);
  157. }
  158. }
  159. } # while (there is still data in this inputfile)
  160. close(DOSNET);
  161. $InFileSection = 0;
  162. $maxdisknum = 1;
  163. # Now add files from layout.inf
  164. LINE2: while( <OLD> )
  165. {
  166. chomp $_;
  167. $line = lc $_;
  168. if ($line =~ /^\[/)
  169. {
  170. $InFileSection = 0;
  171. }
  172. if ($line eq "[sourcedisksfiles]" or $line eq "[sourcedisksfiles.x86]")
  173. {
  174. $InFileSection = 1;
  175. next LINE2;
  176. }
  177. if (! $InFileSection)
  178. {
  179. next LINE2;
  180. }
  181. if ($line =~ /=/)
  182. {
  183. ($filename = $line) =~ s/(.*:)?(\S*.?\S*)\s*=.*/$2/;
  184. #Remove spaces from filesname
  185. $filename =~ s/ *$//g;
  186. #Skip .fon and .nls files since they are included in dosnet.txt
  187. if ($filename =~ /\.fon$/ or $filename =~ /\.nls$/)
  188. {
  189. next LINE2;
  190. }
  191. ($fields = $line) =~ s/.*=\s*(.*)/$1/;
  192. @linefields = split(',', $fields);
  193. $disknum = $linefields[6];
  194. if ($disknum =~ /^_/)
  195. {
  196. $compressed = 0;
  197. }
  198. else
  199. {
  200. $compressed = 1;
  201. }
  202. $disknum =~ s/_//;
  203. if( length($disknum) > 0 && $disknum !~ /x/)
  204. {
  205. if( int($disknum) > $maxdisknum)
  206. {
  207. $maxdisknum = int($disknum);
  208. }
  209. $filename2 = $filename;
  210. if( $compressed)
  211. {
  212. chop $filename2;
  213. $filename2 = $filename2 . "_";
  214. }
  215. $filenamep = "$shareloc\\$filename2";
  216. if (-e $filenamep ) {
  217. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($filenamep);
  218. }
  219. else {
  220. $size = "0";
  221. }
  222. (printf NEW "%2s %20s %10s %20s\n", $disknum, " " . $filename, $size , $filename2);
  223. print ".";
  224. }
  225. }
  226. } # while (there is still data in this inputfile)
  227. close(OLD) or die "can't close $layout: $!";
  228. close(NEW) or die "can't close $allfiles: $!";
  229. #Remove from the list any files on the first or last flopy.
  230. open(OLD, "<" . $allfiles) or die "can't open $allfiles: $!";
  231. open(NEW, ">" . $modified) or die "can't open $modified: $!";
  232. $disknum = 0;
  233. $disksize = 0;
  234. NLINE:while (<OLD>) {
  235. $save = $_;
  236. @lnfields = split(' ', $_);
  237. $filename = $lnfields[1];
  238. while (<@firstlist>) {
  239. if ($filename =~ /^$_$/ ) {
  240. next NLINE;
  241. }
  242. }
  243. while (<@lastlist>) {
  244. if ($filename =~ /^$_$/ ) {
  245. next NLINE;
  246. }
  247. }
  248. (print NEW $save);
  249. print ".";
  250. }
  251. #Put the following files on the first floppy
  252. $count = 0;
  253. while (<@firstlist>) {
  254. $fname = $_;
  255. if ($fname =~ /^txtsetup.sif$/ ) {
  256. chop $fname;
  257. $fname = $fname . "_";
  258. if (-e $fname ) {
  259. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname);
  260. }
  261. else {
  262. $size = "0";
  263. }
  264. }
  265. else {
  266. $fname2 = "$shareloc\\$fname";
  267. if (-e $fname2 ) {
  268. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname2);
  269. }
  270. else {
  271. chop $fname2;
  272. $fname2 = $fname2 . "_";
  273. if (-e $fname2 ) {
  274. chop $fname;
  275. $fname = $fname . "_";
  276. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname2);
  277. }
  278. else {
  279. $size = "0";
  280. }
  281. }
  282. }
  283. (printf NEW " 1 %20s %10s %20s\n", " " . $_, $size ,$fname);
  284. $count = ($count +1);
  285. print ".";
  286. }
  287. #Put the following files on the last floppy
  288. $count = 0;
  289. while (<@lastlist>) {
  290. $fname = $_;
  291. $fname2 = "$shareloc\\$fname";
  292. if (-e $fname2 ) {
  293. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname2);
  294. }
  295. else {
  296. chop $fname2;
  297. $fname2 = $fname2 . "_";
  298. if (-e $fname2) {
  299. chop $fname;
  300. $fname = $fname . "_";
  301. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname2);
  302. }
  303. else {
  304. $size = "0";
  305. }
  306. }
  307. (printf NEW "%2d %20s %10s %20s\n", ($maxdisknum+1), " " . $_, $size, $fname);
  308. $count = ($count +1);
  309. print ".";
  310. }
  311. #On FE build, if bootfont.bin exist then add it to the last floppy
  312. $fname = "bootfont.bin";
  313. $fname2 = "$shareloc\\$fname";
  314. if (-e $fname2 ) {
  315. ($0,$0,$0,$0,$0,$0,$0,$size,$0,$0,$0,$0,$0) = stat($fname2);
  316. (printf NEW "%2d %20s %10s %20s\n", ($maxdisknum+1), " " . $fname, $size, $fname);
  317. }
  318. close(OLD) or die "can't close $old: $!";
  319. close(NEW) or die "can't close $new: $!";
  320. `sort $modified /o $modified`;
  321. # Reenumerate disk numbers in case all the files on the last in layout.inf
  322. # appears in our private list.
  323. open(OLD, "<" . $modified) or die "can't open $modified: $!";
  324. open(NEW, ">" . $enum) or die "can't open $enum: $!";
  325. $donefixup = 0;
  326. $disksize = 0;
  327. $maxdisknum = 1;
  328. while (<OLD>) {
  329. $save = $_;
  330. @lnfields = split(' ', $_);
  331. $cdisk = int($lnfields[0]);
  332. $fname = $lnfields[1];
  333. $fsize = $lnfields[2];
  334. $fact = $lnfields[3];
  335. if( !$donefixup and $cdisk > $maxdisknum)
  336. {
  337. $maxdisknum = $maxdisknum +1;
  338. if( $maxdisknum != $cdisk) {
  339. $donefixup = 1;
  340. }
  341. }
  342. (printf NEW "%2d %20s %10s %20s\n",$maxdisknum,$fname,$fsize,$fact);
  343. }
  344. close(OLD) or die "can't close $old: $!";
  345. close(NEW) or die "can't close $new: $!";
  346. # Create total file containing total disk sizes.
  347. open(OLD, "<" . $enum) or die "can't open $enum: $!";
  348. open(NEW, ">" . $total) or die "can't open $total: $!";
  349. $disknum = 0;
  350. $disksize = 0;
  351. while (<OLD>) {
  352. $save = $_;
  353. @lnfields = split(' ', $_);
  354. $cdisk = int($lnfields[0]);
  355. $sdisk = int($lnfields[2]);
  356. if( $cdisk == $disknum)
  357. {
  358. $disksize = $disksize + $sdisk;
  359. }
  360. else
  361. {
  362. if( $disknum != 0)
  363. {
  364. (printf NEW "%10s %24s", "Disk " . $disknum . ":", $disksize . "\n\n");
  365. }
  366. $disknum = $cdisk;
  367. $disksize = 0;
  368. }
  369. (print NEW $save);
  370. print ".";
  371. }
  372. if( $disknum != 0)
  373. {
  374. (printf NEW "%10s %24s", "Disk " . $disknum . ":", $disksize . "\n");
  375. }
  376. close(OLD) or die "can't close $old: $!";
  377. close(NEW) or die "can't close $new: $!";
  378. # Create boot floppies.
  379. # Create disk1 to be renamed accordingly for each floppy
  380. open(NEW, ">disk1") or die "Could not create disk1 file in current directory!";
  381. print NEW "\n";
  382. close NEW;
  383. # Now create list of files for each floppy
  384. open(OLD, "<" . $enum) or die "can't open $enum: $!";
  385. $disknum = 0;
  386. while (<OLD>) {
  387. @lnfields = split(' ', $_);
  388. $cdisk = int($lnfields[0]);
  389. $fname = $lnfields[1];
  390. $fact = $lnfields[3];
  391. if( $cdisk != $disknum)
  392. {
  393. if( $disknum > 0) {
  394. close( NEW);
  395. }
  396. open(NEW, ">" . $output . "\." . $cdisk) or die "can't open $: $!";
  397. # first floppy require the following information
  398. if( $cdisk == 1) {
  399. (printf NEW "\-bnt35setup\n");
  400. }
  401. (printf NEW "disk1=disk10%d\n", $cdisk);
  402. $disknum = $cdisk;
  403. }
  404. $icount = 0;
  405. $source = $shareloc."\\".$fact;
  406. $dest = $fact;
  407. #if the last disk, then final name of file maybe different
  408. if( $disknum == ($maxdisknum)) {
  409. $done = 0;
  410. while (<@lastlist>) {
  411. if ($done == 0) {
  412. $save = $_;
  413. if ($fname =~ /^$_$/ and length($lastrepl[$icount]) > 0) {
  414. $dest = $lastrepl[$icount];
  415. $done = 1;
  416. }
  417. $icount = ($icount + 1);
  418. }
  419. }
  420. }
  421. else {
  422. if ($fname =~ /^txtsetup.sif$/ ) {
  423. $dest = "txtsetup\.si_";
  424. $source = "txtsetup\.si_";
  425. }
  426. }
  427. (printf NEW "%s=%s\n", $source, $dest);
  428. print ".";
  429. }
  430. close(OLD) or die "can't close $old: $!";
  431. close(NEW) or die "can't close $new: $!";
  432. # Creating each floppy
  433. $disknum = 1;
  434. while ( $disknum <= $maxdisknum) {
  435. $fcmdline = "\nfcopy \-f \-3 \@$output" . "\." . $disknum . " cdboot" . $disknum . "\.img";
  436. print $fcmdline;
  437. print "\nCreating cdimage" . $disknum . "\.img";
  438. $message = `$fcmdline`;
  439. print $message;
  440. $disknum = $disknum +1;
  441. }
  442. # Create equivalent dosnet floppyfiles sections
  443. open(OLD, "<" . $enum) or die "can't open $enum: $!";
  444. open(NEW, ">" . $final) or die "can't open $final: $!";
  445. $disknum = 0;
  446. while (<OLD>) {
  447. @lnfields = split(' ', $_);
  448. $cdisk = int($lnfields[0]);
  449. $fname = $lnfields[1];
  450. if( $cdisk != $disknum)
  451. {
  452. (printf NEW "\n[FloppyFiles.%d]\n", $disknum);
  453. (printf NEW "d1,disk1,disk10%d\n", ($disknum+1));
  454. $disknum = $cdisk;
  455. }
  456. $icount = 0;
  457. if( $disknum == ($maxdisknum)) {
  458. $done = 0;
  459. while (<@lastlist>) {
  460. if ($done == 0) {
  461. $save = $_;
  462. if ($fname =~ /^$_$/ and length($lastrepl[$icount]) > 0 ) {
  463. $fname = $fname."\,".$lastrepl[$icount];
  464. $done = 1;
  465. }
  466. $icount = ($icount + 1);
  467. }
  468. }
  469. }
  470. (printf NEW "d1,%s\n", $fname);
  471. print ".";
  472. }
  473. close(OLD) or die "can't close $old: $!";
  474. close(NEW) or die "can't close $new: $!";
  475. print "\nTotal floppies is " . $maxdisknum . "\n";
  476. }
  477. foreach $share (@ARGV) {
  478. #print "arg is $file\n";
  479. #@filelist = <$file>;
  480. #@filelist = `dir /b /a-d $file`;
  481. foreach (@ARGV) {
  482. chomp $share;
  483. myprocess( $share);
  484. }
  485. }