home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / USAGE.ZIP / USAGE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-02-16  |  8.5 KB  |  262 lines

  1. {$R-}    {Range checking off}
  2. program usage;
  3.  
  4. {
  5.   Utility program for Novell networks.
  6.  
  7.   Show disk utilization statistics for all users of all volumes.
  8.  
  9.   This program makes Novell function calls through interrupt 21h. These
  10.   calls are not compatible with any other network, as far as I know.
  11.   There are probably equivalent calls in 3com 3+, but I don't know them.
  12.  
  13.   This program will only list volumes on the current server.
  14.  
  15.   Written by:
  16.     Mark Sersen
  17.     Austin Consulting
  18.     9801 W. Higgins Rd.
  19.     Rosemont, IL  60018
  20.  
  21.   CompuServe 71121,3177
  22.  
  23.   Released to the Public Domain, February 1988.
  24.  
  25.   Use this program any way you wish. The author retains the right to forget
  26.   that he ever wrote this. (No warranty whatsoever.)
  27.  
  28. }
  29.  
  30.  
  31. uses
  32.   dos;
  33.  
  34. const
  35.   maxvols = 10;             { increase if you have more than 10 hard disks
  36.                               on your server (!?!?!?) }
  37.  
  38. type
  39.   idtype = longint;
  40.   string20 = string[20];
  41.   obname = array[1..48] of char;
  42.   obptr = ^objectlist;
  43.   objectlist = record                { record for holder user definitions }
  44.                  id : idtype;
  45.                  name : obname;
  46.                  next : obptr;
  47.                end;
  48.  
  49. var
  50.   reg : registers;
  51.   volname : array[0..maxvols] of string20;
  52.   volsize, voldirs : array[0..maxvols] of integer;
  53.   volquan, totdirs, totfiles, totblocks : integer;
  54.   obfirst, obnext, oblast : obptr;
  55.   cur_vol, charnum, vol : integer;
  56.  
  57.  
  58. function lohi(original:integer):integer;
  59.   { convert lo-byte/hi-byte format to Pascal integer }
  60.   begin
  61.     lohi:=(lo(original) * 256) + hi(original);
  62.   end;
  63.  
  64.  
  65. procedure get_vol_stats;
  66.   var
  67.     count : integer;
  68.     done : boolean;
  69.  
  70.   procedure get_name(count:integer);
  71.     var
  72.       request : record
  73.                   len : integer;     { length of request packet }
  74.                   funct : byte;      { Novell function number }
  75.                   volnum : byte;     { volume # to check }
  76.                 end;
  77.  
  78.       reply : record
  79.                 len : integer;        { length of reply packet }
  80.                 vol_name : string20;  { name of volume }
  81.               end;
  82.  
  83.       stats : record
  84.                 sectors : integer;          { sectors / block }
  85.                 blocks : integer;           { total # of blocks }
  86.                 emptyblocks : integer;      { # of empty blocks }
  87.                 dirs : integer;             { # of dir entries used }
  88.                 emptydirs : integer;        { # of dir entries left }
  89.                 volname : array[1..16] of byte;   { vol name again }
  90.                 remove : integer;           { removable media flag }
  91.               end;
  92.  
  93.     begin
  94.       request.len:=2;                      { see of there is a volume 'count' }
  95.       request.funct:=6;
  96.       request.volnum:=count;
  97.       reply.len:=21;
  98.       reply.vol_name:='xx';                { someting to take up space }
  99.       reg.ax:=$E200;
  100.       reg.ds:=seg(request);                { setup for Novell call }
  101.       reg.si:=ofs(request);
  102.       reg.es:=seg(reply);
  103.       reg.di:=ofs(reply);
  104.       msdos(dos.registers(reg));
  105.       if length(reply.vol_name) <> 0 then   { is there a volume? }
  106.         begin
  107.           { get statistics for found volume }
  108.           volname[count]:=reply.vol_name;
  109.           reg.ax:=$DA00;
  110.           reg.dx:=lo(count);
  111.           reg.es:=seg(stats);
  112.           reg.di:=ofs(stats);
  113.           msdos(Dos.Registers(reg));
  114.           volsize[count]:=lohi(stats.blocks);      { size in 128 byte blocks }
  115.           voldirs[count]:=lohi(stats.emptydirs);   { # of remaining dir slots }
  116.         end
  117.       else
  118.         done:=true;     { no volume 'count'; stop looking }
  119.     end;
  120.  
  121.   begin
  122.     done:=false;
  123.     count:=0;
  124.     repeat                                 { find all volumes (10 max) }
  125.       get_name(count);
  126.       if not done then
  127.         count:=count+1;
  128.     until done;
  129.     volquan:=count;                        { number of volumes found }
  130.   end;
  131.  
  132. procedure object_list;
  133.   var
  134.     request : record                       { Novell request packet for }
  135.                 len : integer;             { scan bindery objects (users) }
  136.                 funct : byte;
  137.                 lastob : idtype;           { last object found }
  138.                 pat_type:integer;          { type of object we're looking for }
  139.                 pat_len : byte;            { length of match pattern }
  140.                 pattern : char;
  141.               end;
  142.     reply : record
  143.               len : integer;               { length of reply packet }
  144.               id : idtype;                 { id found }
  145.               ptype : integer;             { type of object }
  146.               name : obname;               { object's name }
  147.               flag,sec,prop : byte;        { particulars about object }
  148.             end;
  149.  
  150.     done : boolean;
  151.     last : idtype;
  152.     count : integer;
  153.  
  154.   begin
  155.     obfirst:=nil;
  156.     obnext:=nil;
  157.     done:=false;
  158.     last:=$FFFFFFFF;              { $FFFFFFFF = find first }
  159.     repeat
  160.       request.len:=9;
  161.       request.funct:=55;
  162.       request.lastob:=last;
  163.       request.pat_type:=$0100;    { type 1 = net_user }
  164.       request.pat_len:=1;
  165.       request.pattern:='*';       { any name }
  166.       reply.len:=57;
  167.       reg.ax:=$E300;
  168.       reg.ds:=seg(request);
  169.       reg.si:=ofs(request);
  170.       reg.es:=seg(reply);
  171.       reg.di:=ofs(reply);
  172.       msdos(Dos.Registers(reg));
  173.       if lo(reg.ax) <> 0 then              { ax <> 0 means no find }
  174.         done:=true
  175.       else
  176.         begin
  177.           new(obnext);
  178.           obnext^.id:=reply.id;            { put id and name into linked list }
  179.           obnext^.name:=reply.name;
  180.           obnext^.next:=nil;
  181.           if obfirst = nil then            { increment list pointers }
  182.             obfirst:=obnext
  183.           else
  184.             oblast^.next:=obnext;
  185.           oblast:=obnext;
  186.           last:=reply.id;                  { start next search with new id }
  187.         end;
  188.     until done;
  189.   end;
  190.  
  191. procedure get_util(s_id:idtype);
  192.   { get stats for user 's_id'.
  193.     add user stats to grand total stats.
  194.     print user stats. }
  195.   var
  196.     request : record                    { request packet for Novell call: }
  197.                 len : integer;          { Get Objects Disk Utilization Stats } 
  198.                 funct : byte;
  199.                 volume : byte;          { which Novell drive }
  200.                 id : idtype;            { which user id }
  201.               end;
  202.  
  203.     reply : record
  204.               len : integer;
  205.               volume : byte;            { which Novell drive }
  206.               id : idtype;              { which user id }
  207.               numdirs, numfiles, numblocks : integer;   { returned stats }
  208.             end;
  209.  
  210.   begin
  211.     request.len:=6;
  212.     request.funct:=14;
  213.     request.volume:=cur_vol;        { set in main loop }
  214.     request.id:=s_id;               { passed by main loop }
  215.     reply.len:=11;
  216.     reg.ax:=$E300;
  217.     reg.ds:=seg(request);
  218.     reg.si:=ofs(request);
  219.     reg.es:=seg(reply);
  220.     reg.di:=ofs(reply);
  221.     msdos(Dos.Registers(reg));
  222.     totdirs:=totdirs + lohi(reply.numdirs);        { increment volume totals }
  223.     totfiles:=totfiles + lohi(reply.numfiles);
  224.     totblocks:=totblocks + lohi(reply.numblocks);
  225.     write(lohi(reply.numdirs):4,' Directories  ');   { print user stats }
  226.     write(lohi(reply.numfiles):6,' Files  ');
  227.     write(lohi(reply.numblocks):4,' Blocks Used  ');
  228.     write(100*(lohi(reply.numblocks) / volsize[cur_vol]):5:2,'% of Disk');
  229.   end;
  230.  
  231.  
  232. begin
  233.   writeln('Disk Utilization Statistics v2.2');
  234.   get_vol_stats;                   { get # of volumes & stats for each }
  235.   object_list;                     { put all users in system into list }
  236.   for vol:=1 to volquan do
  237.     begin
  238.       cur_vol:=vol - 1;            { actual volume # is 1 less than total }
  239.       writeln;
  240.       writeln('Volume ',volname[cur_vol]);
  241.       totdirs:=0;                  { initialize totals for this volume }
  242.       totfiles:=0;
  243.       totblocks:=0;
  244.       obnext:=obfirst;             { set pointer to first user }
  245.       while obnext <> nil do
  246.         with obnext^ do
  247.           begin
  248.             for charnum:=1 to 12 do   { name passed as array- }
  249.               write(name[charnum]);   { must print string!    }
  250.             get_util(id);          { print stats for each user }
  251.             writeln;
  252.             obnext:=next;
  253.           end;
  254.       { print totals for volume }
  255.       write('Totals      ',totdirs:4,' Directories  ',totfiles:6,' Files  ',totblocks:4,' Blocks Used  ');
  256.       writeln((totblocks / volsize[cur_vol]) * 100:5:2,'% of Disk');
  257.     end;
  258. end.
  259.  
  260.  
  261.  
  262.