program usage ! ! USAGE.BAS - List disk space by user ! ! Author: Don Stokes (don@gp.govt.nz) ! ! This program parses an ANALYZE/DISK/USAGE disk accounting file and ! displays the amount of disk space used for each UIC found on the disk. ! ! Two questions are asked: ! ANALYZE/DISK/USAGE output file [USAGE.DAT] : ! Disk accounting file to use. ! ! Output file [SYS$OUTPUT] : ! Output file to write the listing to. ! !-- option type = explicit external long function SYS$FAO, & SYS$IDTOASC, & SOR$BEGIN_SORT, & SOR$RELEASE_REC, & SOR$SORT_MERGE, & SOR$RETURN_REC, & SOR$END_SORT external sub LIB$STOP( long by value ) %include "$SSDEF" %from %library %include "$DSCDEF" %from %library %include "$USGDEF" %from %library map (USAGEFIL) USGDEF usg.i map (USAGEFIL) USGDEF1 usg.f map (USAGEFIL) string usg.str = USG$S_USGDEF1 map (KEYBUF) word kbf.keys, & kbf.type, & kbf.direction, & kbf.offset, & kbf.size declare long constant TRUE = -1, & FALSE = 0 declare long sts, & uic, & allocated, & used, & files, & first, & n,z declare string out_uic, & usage_file, & output_file, & header ! ! Ask for and open usage file ! set no prompt linput "ANALYZE/DISK/USAGE output file [USAGE.DAT] : "; usage_file open usage_file for input as file #1, map USAGEFIL, & defaultname "USAGE.DAT" ! ! Ask for and open listing file (default = terminal) ! linput "Output file [SYS$OUTPUT] : "; output_file output_file = "SYS$OUTPUT" if output_file = "" open output_file for output as file #2, recordsize 132, & defaultname "USAGE.LIS" ! ! Get header record ! get #1 header = usg.str first = TRUE ! ! Set up for SORT ! kbf.keys = 1% kbf.type = DSC$K_DTYPE_L kbf.direction = 0% kbf.offset = loc(usg.f::USG$L_FILEOWNER) - loc(usg.str) kbf.size = 4% sts = SOR$BEGIN_SORT( kbf.keys, USG$S_USGDEF1) call LIB$STOP(sts) unless sts and SS$_NORMAL ! ! Read rest of file and feed into SORT ! while -1% when error in get #1 use continue end_of_file end when sts = SOR$RELEASE_REC( usg.str) call LIB$STOP(sts) unless sts and SS$_NORMAL next end_of_file: ! ! Do the SORT ! sts = SOR$SORT_MERGE call LIB$STOP(sts) unless sts and SS$_NORMAL ! ! Print the header info and headings ! usg.str = header print #2, "Volume " + usg.i::USG$T_VOLNAME & + " Owner " + usg.i::USG$T_OWNERNAME & + " Format " + usg.i::USG$T_FORMAT print #2 print #2, "Owner____________________________________________" & + "__Allocated______Used_____Files" ! ! Read back SORTed records and prcocess... ! until SOR$RETURN_REC( usg.str ) = SS$_ENDOFFILE call LIB$STOP(sts) unless sts and SS$_NORMAL ! ! Break if first time through or on change of UIC ! Print totals for old uic if not first time ! Clear totals and set up for new uic ! if usg.f::USG$L_FILEOWNER <> uic or first then gosub output_record unless first allocated, used, files = 0% uic = usg.f::USG$L_FILEOWNER first = FALSE end if ! ! Tally up usage for this uic ! allocated = allocated + usg.f::USG$L_ALLOCATED - 1% used = used + usg.f::USG$L_USED files = files + 1% next ! ! Finish up - end SORT, print last record, close files. ! sts = SOR$END_SORT call LIB$STOP(sts) unless sts and SS$_NORMAL gosub output_record unless first close #1 close #2 exit program ! ! Subroutine to display totals for a uic ! output_record: out_uic = " " sts = SYS$IDTOASC( uic by value, z, out_uic,,,) sts = SYS$FAO( "!%U", z, out_uic, uic by value) if sts = SS$_NOSUCHID call LIB$STOP( sts ) unless sts and SS$_NORMAL out_uic = left(out_uic, z) print #2, out_uic; tab(50); format$( allocated, "##########") & + format$( used, "##########") & + format$( files, "##########") return end program