home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / spcsave.zip / SPCSAVE.CMD
OS/2 REXX Batch file  |  1995-05-08  |  15KB  |  367 lines

  1. /* ADDUPEAS.CMD This REXX program looks at specified drive */
  2. /* and lists all files to determine the total amount of    */
  3. /* EA space that should be used on the drive in file       */
  4. /* EA DATA. SF given that each EA takes one cluster of     */
  5. /* a FAT formatted disk. This will not match exactly the   */
  6. /* size of the EA file since ... well I don't know why but */
  7. /* it consistently reports one less cluster on my system   */
  8. /* than the size of EA DATA. SF really is.                 */
  9. /* Author Trevor Hemsley - 95/04/30                        */   
  10.  
  11. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  12. Call SysLoadFuncs
  13.  
  14. inputfile = "C:\temp\filelist.txt" /* this is the file to DIR to */
  15. outputfile = "C:\temp\ealist.txt"  /* file to contain the list   */ 
  16. file_with_ea = 0                   /* initialise counter         */  
  17. ea_amounts = 0                     /* initialise counters        */  
  18. dir_count = 0
  19. tot_file_size = 0
  20. tot_clusters = 0
  21. tot_clustersHPFS = 0
  22. tot_clusters64 = 0
  23. tot_clusters128 = 0
  24. tot_clusters256 = 0
  25. tot_clusters512 = 0
  26. tot_clusters1024 = 0
  27. ea_totals = 0
  28. ea_amountsHPFS = 0
  29. ea_amounts64 = 0
  30. ea_amounts128 = 0
  31. ea_amounts256 = 0
  32. ea_amounts512 = 0
  33. ea_amounts1024 = 0
  34. cluster_sizeHPFS = 512
  35. cluster_size64 = 2048
  36. cluster_size128 = 4096
  37. cluster_size256 = 8192
  38. cluster_size512 = 16382
  39. cluster_size1024 = 32768
  40.  
  41. rx = SysFileTree("C:\TEMP",rx.,"D") /* test existence of temp dir*/
  42. if rx.0 = 0 then                          
  43.    do
  44.    say "Directory C:\TEMP does not exist. Create it Y/N?"
  45.    parse upper pull answer
  46.    if answer ¬= "Y" then exit
  47.      else 
  48.      do
  49.      "@MD C:\TEMP"
  50.      end
  51.    end
  52.  
  53. rx = stream(inputfile,"c","query exists") /* test existence of file   */
  54. if rx ¬= "" then                          /* to stop from overwriting */
  55.    do
  56.    say "Warning - existing file "inputfile" will be overwritten. Continue Y/N?"
  57.    answer = SysGetKey("NOECHO")
  58.    parse upper var answer answer
  59.    if answer ¬= "Y" then exit
  60.      else
  61.       "@del "inputfile
  62.    end
  63.  
  64. rx = stream(outputfile,"c","query exists") /* test existence of file */
  65. if rx ¬= "" then 
  66.    do
  67.    say "Warning - existing file "outputfile" will be overwritten. Continue Y/N?"
  68.    answer = SysGetKey("NOECHO")
  69.    parse upper var answer answer
  70.    if answer ¬= "Y" then exit
  71.     else
  72.      "@del "outputfile
  73.    end
  74.  
  75. say "Please maximise this window and reply any character to continue"
  76. answer = SysGetKey("NOECHO")
  77.  
  78. "@MODE co80,29"  /* accidently make the OS/2 session large enough to display all lines */
  79.  
  80. do while drive_letter = "DRIVE_LETTER"       /* Ask which drive to process */
  81.   say "Which disk drive letter do you wish to examine (eg C) ?"
  82.   drive_letter = SysGetKey("NOECHO")
  83.   if DATATYPE(drive_letter,"M") = 1 then 
  84.     do 
  85.     drive_letter=drive_letter||":"
  86.     end
  87.    else drive_letter = "DRIVE_LETTER"
  88. end
  89.  
  90. disk_info = sysdriveinfo(drive_letter)
  91. disk_size = word(disk_info,3)
  92. disk_used_space = word(disk_info,3) - word(disk_info,2)
  93.  
  94. real_size = stream(drive_letter"\EA DATA. SF","c","Query size")
  95. if real_size = "" then 
  96.    do
  97.    say "Could not find file EA DATA. SF - this must be run against a FAT disk"
  98.    exit
  99.    end  
  100.  
  101. if disk_size > 64*1024*1024 then cluster_size=2048
  102. if disk_size > 128*1024*1024 then cluster_size=4096
  103. if disk_size > 256*1024*1024 then cluster_size=8192
  104. if disk_size > 512*1024*1024 then cluster_size=16384
  105. if disk_size > 1024*1024*1024 then cluster_size=32768
  106.  
  107. say "Listing file information from "word(disk_info,1)". Please wait..."
  108.  
  109. "@dir "drive_letter"\ /a /s /n >"inputfile
  110. if rc¬=0 then 
  111.   do
  112.   say "Non-zero return code ("rc") from DIR. Ending Rexx exec."
  113.   exit
  114.   end  
  115.  
  116. say "Now checking for EA's. This may take some time..."
  117. rc = TIME("R")
  118. do while lines(inputfile) ¬= 0       /* repeat for each line in input file */
  119.   rx = linein(inputfile)             /* read next record from input file   */ 
  120.   if words(rx) = 0 then iterate      /* ignore blank lines                 */
  121.   if word(rx,1) = "The" then iterate /* ignore all lines that meet the...  */
  122.   if word(rx,1) = "Directory" then   /* ...criteria listed here      */
  123.      do
  124.      dir_count = dir_count + 1
  125.      iterate 
  126.      end
  127.   if word(rx,2) = "file(s)" then iterate
  128.   if word(rx,2) = "files" then iterate
  129.   if word(rx,2) = "bytes" then iterate
  130.   if word(rx,5) ¬= "EA" && word(rx,6) ¬= "DATA." && word(rx,7) ¬= "SF" then
  131.   do
  132.    if word(rx,3) ¬= "<DIR>" then 
  133.      do
  134.       file_size = word(rx,3)
  135.  
  136.       if file_size//cluster_size = 0 then
  137.         file_clusters = (file_size%cluster_size)
  138.        else
  139.         file_clusters = (file_size%cluster_size)+1
  140.  
  141.       if file_size//cluster_sizeHPFS = 0 then
  142.         file_clustersHPFS = (file_size%cluster_sizeHPFS)
  143.        else
  144.         file_clustersHPFS = (file_size%cluster_sizeHPFS)+1
  145.  
  146.       if file_size//cluster_size64 = 0 then
  147.         file_clusters64 = (file_size%cluster_size64)
  148.        else
  149.         file_clusters64 = (file_size%cluster_size64)+1
  150.  
  151.       if file_size//cluster_size128 = 0 then
  152.         file_clusters128 = (file_size%cluster_size128)
  153.        else
  154.         file_clusters128 = (file_size%cluster_size128)+1
  155.  
  156.       if file_size//cluster_size256 = 0 then
  157.         file_clusters256 = (file_size%cluster_size256)
  158.        else
  159.         file_clusters256 = (file_size%cluster_size256)+1
  160.  
  161.       if file_size//cluster_size512 = 0 then
  162.         file_clusters512 = (file_size%cluster_size512)
  163.        else
  164.         file_clusters512 = (file_size%cluster_size512)+1
  165.  
  166.       if file_size//cluster_size1024 = 0 then
  167.         file_clusters1024 = (file_size%cluster_size1024)
  168.        else
  169.         file_clusters1024 = (file_size%cluster_size1024)+1
  170.  
  171.       tot_file_size = tot_file_size+file_size
  172.       tot_clusters = tot_clusters+file_clusters
  173.       tot_clustersHPFS = tot_clustersHPFS+file_clustersHPFS
  174.       tot_clusters64 = tot_clusters64+file_clusters64
  175.       tot_clusters128 = tot_clusters128+file_clusters128
  176.       tot_clusters256 = tot_clusters256+file_clusters256
  177.       tot_clusters512 = tot_clusters512+file_clusters512
  178.       tot_clusters1024 = tot_clusters1024+file_clusters1024
  179.  
  180.      end                                 /* Do if word(rx,3) ne <dir>         */
  181.     end                                  /* Do if word(rx,5) ne EA DATA. SF   */
  182.     if word(rx,4) = 0 then iterate
  183.       else 
  184.        do                               /* this line is for a file with EA's */
  185.        file_with_ea = file_with_ea + 1  /* add 1 to count of files found     */
  186.        ry = LINEOUT(outputfile,rx)      /* write this line to output file    */
  187.        ea_amount=word(rx,4)             /* extract size of EA's for this file*/  
  188.  
  189.        ea_totals=ea_totals+ea_amount    /* keep running total of amount used */
  190.  
  191.         if ea_amount//cluster_size = 0 then /* determine how many...         */
  192.          this_file_ea=(ea_amount%cluster_size) /* clusters the EA's take up  */
  193.         else
  194.          this_file_ea=(ea_amount%cluster_size)+1 /* round up cluster numbers */
  195.         ea_amounts=ea_amounts+this_file_ea       /* keep running total       */
  196.  
  197.       if ea_amount//cluster_size64 = 0 then /* determine how many...         */
  198.          this_file_ea64=(ea_amount%cluster_size64)/* clusters the EA's take  */
  199.         else
  200.          this_file_ea64=(ea_amount%cluster_size64)+1 /* round cluster numbers*/
  201.         ea_amounts64=ea_amounts64+this_file_ea64 /* keep running total       */
  202.  
  203.        if ea_amount//cluster_size128 = 0 then /* determine how many...       */
  204.          this_file_ea128=(ea_amount%cluster_size128)/* clusters the EA's take*/
  205.         else
  206.          this_file_ea128=(ea_amount%cluster_size128)+1 /* round clust numbers*/
  207.         ea_amounts128=ea_amounts128+this_file_ea128 /* keep running total    */
  208.  
  209.        if ea_amount//cluster_size256 = 0 then /* determine how many...       */
  210.          this_file_ea256=(ea_amount%cluster_size256)/* clusters the EA's take*/
  211.         else
  212.          this_file_ea256=(ea_amount%cluster_size256)+1 /* round clust numbers*/
  213.         ea_amounts256=ea_amounts256+this_file_ea256    /* keep running total */
  214.  
  215.        if ea_amount//cluster_size512 = 0 then /* determine how many...       */
  216.          this_file_ea512=(ea_amount%cluster_size512)/* clusters the EA's take*/
  217.         else
  218.          this_file_ea512=(ea_amount%cluster_size512)+1 /* round clust numbers*/
  219.         ea_amounts512=ea_amounts512+this_file_ea512 /* keep running total    */
  220.  
  221.        if ea_amount//cluster_size1024 = 0 then /* determine how many...      */
  222.          this_file_ea1024=(ea_amount%cluster_size1024)/* clusters the EA's*/
  223.         else
  224.          this_file_ea1024=(ea_amount%cluster_size1024)+1 /* round clust nums */
  225.         ea_amounts1024=ea_amounts1024+this_file_ea1024  /* keep running total*/
  226.  
  227.          end                              /* end of DO word(rx,4) = 0          */
  228. end                                       /* End of DO WHILE LINES(INPUTFILE)  */
  229. rc = TIME("E")
  230. Say "Gathering information took "rc" seconds"
  231. say "Size of drive "word(disk_info,1)" is "disk_size" with a cluster size of "cluster_size
  232. ea_file_size = ea_amounts*cluster_size
  233. Say "Number of files with EA's is "file_with_ea" making EA DATA. SF approx. "ea_file_size
  234. size_difference = real_size-(ea_amounts*cluster_size)
  235. Say " "
  236. Say "Difference between calculated size and actual size is "size_difference
  237. If size_difference/cluster_size <= 3 then 
  238.    say "This is probably nothing to worry about ! (I mean it's normal)" 
  239.  else
  240.    say "You may want to run CHKDSK "drive_letter" /F against this drive to double check."
  241. z = stream(inputfile,"c",close)        /* close input file                 */
  242. z = stream(outputfile,"c",close)       /* close output file                */
  243.  
  244. Say "List of files with EA's is in "outputfile ". Do you wish to keep this?"
  245. answer = SysGetKey("NOECHO")
  246.  
  247. parse upper var answer answer  /* pull answer */
  248. if answer = "Y" | answer ="YES" then
  249.    do
  250.    "@del "inputfile                     /* clean up after us                */
  251.    Say "Sorting file into EA size order ..."
  252.    "@sort /+32 /R <"outputfile" >"inputfile 
  253.    "@del "outputfile 
  254.    "@copy "inputfile" "outputfile" >nul" 
  255.    "@del "inputfile 
  256.    end
  257.   else
  258.    do  
  259.    "@del "outputfile 
  260.    "@del "inputfile     
  261.    end
  262.  
  263. dir_space = cluster_size*(dir_count+1)
  264. ea_waste = 0+(ea_amounts * cluster_size) - ea_totals
  265. file_waste = disk_used_space - tot_file_size
  266.  
  267. disk_used_space = format(disk_used_space,10)
  268. tot_file_size = format(tot_file_size,12)
  269. ea_totals = format(ea_totals,12)
  270. dir_space = format(dir_space,11)
  271. ea_waste = format(ea_waste,10)
  272. file_waste = format(file_waste,10)
  273.  
  274. say " "
  275. say "                                                    Space wasted by"
  276. say "    Total       Space      Extended    Directory   incomplete clusters"
  277. say " Space Used   for files   Attributes     Space      by EA's   by Files"
  278. say disk_used_space" "tot_file_size" "ea_totals" "dir_space" "ea_waste" "file_waste
  279. say " "
  280.  
  281. /* 
  282.  Space for Files is the number of bytes the actual file takes up.
  283.  Extended Attributes is the nuber of bytes the actual EA's take up
  284.  Directory space is a guess assuming each directory uses a cluster
  285.  Wasted by EA's is the number of clusters used by EA's minus the actual size
  286.  Wasted by files is the number of clusters the files consume minus the actual file size
  287.  
  288.  Wasted means unused in this context
  289.  */
  290.  
  291. say "By my calculations, the space that would be consumed by your files if you"
  292. say "repartitioned your disk as smaller FAT partitions or an HPFS partition would be:"
  293.  
  294. spc_usedHPFS = tot_clustersHPFS*cluster_sizeHPFS+dir_space
  295. spc_used64 = tot_clusters64*cluster_size64+dir_space
  296. spc_used128 = tot_clusters128*cluster_size128+dir_space
  297. spc_used256 = tot_clusters256*cluster_size256+dir_space
  298. spc_used512 = tot_clusters512*cluster_size512+dir_space
  299. spc_used1024 = tot_clusters1024*cluster_size1024+dir_space
  300.  
  301. spc_usedHPFS = format(spc_usedHPFS,10)
  302. spc_used64 = format(spc_used64,10)
  303. spc_used128 = format(spc_used128,10)
  304. spc_used256 = format(spc_used256,10)
  305. spc_used512 = format(spc_used512,10)
  306. spc_used1024 = format(spc_used1024,10)
  307.  
  308. spc_ea64 = ea_amounts64*cluster_size64
  309. spc_ea128 = ea_amounts128*cluster_size128
  310. spc_ea256 = ea_amounts256*cluster_size256
  311. spc_ea512 = ea_amounts512*cluster_size512
  312. spc_ea1024 = ea_amounts1024*cluster_size1024
  313.  
  314. spc_eaHPFS = format(ea_totals,8)
  315. spc_ea64 = format(spc_ea64,8)
  316. spc_ea128 = format(spc_ea128,8)
  317. spc_ea256 = format(spc_ea256,8)
  318. spc_ea512 = format(spc_ea512,8)
  319. spc_ea1024 = format(spc_ea1024,8)
  320. /* trace "i" */
  321. spc_savHPFS = cluster_size*tot_clusters+ea_file_size-(spc_usedHPFS+ea_totals)+dir_space
  322. spc_sav64 = cluster_size*tot_clusters + ea_file_size - (spc_used64+spc_ea64)+dir_space
  323. spc_sav128 = cluster_size*tot_clusters + ea_file_size - (spc_used128+spc_ea128)+dir_space
  324. spc_sav256 = cluster_size*tot_clusters + ea_file_size - (spc_used256+spc_ea256)+dir_space
  325. spc_sav512 = cluster_size*tot_clusters + ea_file_size - (spc_used512+spc_ea512)+dir_space
  326. spc_sav1024 = cluster_size*tot_clusters + ea_file_size - (spc_used1024+spc_ea1024)+dir_space
  327.  
  328. if SIGN(spc_savHPFS) < 0 then 
  329.    spc_savHsign = "loss"
  330.  else spc_savHsign = " "
  331. spc_savHPFS = format(ABS(spc_savHPFS),10)
  332.  
  333. if SIGN(spc_sav64) < 0 then
  334.    spc_sav64sign = "loss"
  335.  else spc_sav64sign = " "
  336. spc_sav64 = format(ABS(spc_sav64),10)
  337.  
  338. if SIGN(spc_sav128) < 0 then
  339.    spc_sav128sign = "loss"
  340.   else spc_sav128sign = " "
  341. spc_sav128 = format(ABS(spc_sav128),10)
  342.  
  343. if SIGN(spc_sav256) < 0 then 
  344.    spc_sav256sign = "loss"
  345.  else spc_sav256sign = " "
  346. spc_sav256 = format(ABS(spc_sav256),10)
  347.  
  348. if SIGN(spc_sav512) < 0 then 
  349.    spc_sav512sign = "loss"
  350.  else spc_sav512sign = " "
  351. spc_sav512 = format(ABS(spc_sav512),10)
  352.  
  353. if SIGN(spc_sav1024) < 0 then
  354.    spc_sav1024sign = "loss"
  355.  else spc_sav1024sign = " "
  356. spc_sav1024 = format(ABS(spc_sav1024),10)
  357.  
  358. say "Partition     Space     Size of        Space"
  359. say "  size        used     EA DATA. SF     saving"
  360. say "==========   ========= ===========   =========="
  361. say "HPFS drive  "spc_usedHPFS"  "spc_eaHPFS"     "spc_savHPFS" "spc_savHsign
  362. say "64-127Mb    "spc_used64"  "spc_ea64"     "spc_sav64" "spc_sav64sign
  363. say "128-255Mb   "spc_used128"  "spc_ea128"     "spc_sav128" "spc_sav128sign
  364. say "256-511Mb   "spc_used256"  "spc_ea256"     "spc_sav256" "spc_sav256sign
  365. say "512-1023Mb  "spc_used512"  "spc_ea512"     "spc_sav512" "spc_sav512sign
  366. say "1024-2047Mb "spc_used1024"  "spc_ea1024"     "spc_sav1024" "spc_sav1024sign
  367.