PROGRAM MODLUN CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C MODLUN -- MODify LUN (Logical UNit) assignments for a task image C C AUTHOR - Scott Snadow C C General Dynamics C C P.O. Box 2507 Mail Zone #4-68 C C Pomona, California 91769 C C (714)-620-7511 Extension 8262 C C DATE - 27-SEP-82 C C C C DESCRIPTION C C This program is used to modify the "static" lun assignments C C of a task image file (equivalent to TKB's /ASG option). C C Should it be desired to change the static lun assignments C C after a task has already been built, it is usually much C C faster to use MODLUN than to re-build the task. C C C C MODLUN is simple to use; after starting MODLUN, it will C C issue the prompt C C Filename: C C Enter the name of the task image to modify (.TSK is the C C default filetype). MODLUN will open the file, read in all C C lun information, and display current lun assignments. C C At this point, the user may modify the luns; only one lun C C is modified at a time, in a two-step process. First, enter C C the number of the lun which you wish to modify; MODLUN will C C display that lun's current assignment, and prompt you for C C the new assignment. Enter the new assignment in "standard" C C device-name form, i.e., C C DDnnn: C C where DD is the 2-letter device name, and nnn is the octal C C unit number (leading zeros are not needed; if nnn is omitted, C C unit 0 will be assumed). Don't forget the colon (":") at the C C end of the device name. C C When you are done, entering -1 when the program prompts for C C a lun number will cause MODLUN to write the new assignments C C back to the file; entering 0 will cancel all changes. C C C C CONVENTIONS C C 1. Lower-case input is acceptable. C C 2. Entering a control-Z at any prompt will cancel the program, C C with no changes made to any currently-open task image. C C 3. Any lun that is "allocated" but not "assigned" will be dis- C C played with a device name of "**0:"; if you wish to C C "de-assign" any lun, enter **0: as the new assignment. C C 4. New assignments are not checked for validity; a device name C C of #@1: will be accepted (although the task-loader will C C issue a warning if you run the program with such an C C illegal lun assignment). Lower-case letters, however, are C C converted to upper-case. C C 5. The task-image file is opened as "readonly"; it is closed C C and re-opened for updating ONLY when a -1 is entered for a C C lun number (so the file's revision date will not change if C C you use MODLUN only to examine existing lun assignments). C C C C SUBROUTINE CALLED C C OCTDIG(NUMBER) - INTEGER*2 FUNCTION that accepts an INTEGER*2 C C argument, and returns the number of significant C C octal digits in the number (assumed unsigned). C C Used for printing left-justified octal numbers. C C C C REFERENCE - See the RSX-11M/M-PLUS Task Builder Manual, C C Appendix "Detailed Task Image File Structure" C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC PARAMETER (NMLNLC = '362'O) ! Location in label block; number of luns LOGICAL*1 BLOCK2(0:511) ! First lun block (if at least 1 lun) LOGICAL*1 BLOCK3(0:511) ! Second lun block (if more than 128 luns) INTEGER*2 BIGBUF(512) ! Equivalenced to BLOCK2 and BLOCK3 INTEGER*2 DEVICE ! Holds device name, in ASCII INTEGER*2 DOT ! Index of "." in filename INTEGER*2 NUMLNS ! Number of luns in task image INTEGER*2 OCTDIG ! Function -- see header comments INTEGER*2 SEMI ! Index of ";" in filename INTEGER*2 UNITNM ! Holds octal unit number, in binary CHARACTER*40 FILNAM ! Filename of task image CHARACTER*40 TMPCHR ! Temporary, used for several purposes EQUIVALENCE (BLOCK2(0),BIGBUF(1)) EQUIVALENCE (BLOCK3(0),BIGBUF(257)) 10 WRITE (UNIT=5,FMT=20) 20 FORMAT ('$Filename: ') READ (UNIT=5,FMT=30,ERR=300,END=999) LRECL,FILNAM 30 FORMAT (Q,A) IF (LRECL .NE. 0) THEN ! If a filename was entered, then. . . C C Default filetype is (naturally) ".TSK"; following code implements this default C SEMI = INDEX(FILNAM, ';') DOT = INDEX(FILNAM, '.') IF (SEMI .NE. 0) THEN ! If a version number was entered. . . IF (DOT .EQ. 0) THEN ! If no filetype was entered. . . TMPCHR = FILNAM(SEMI:) FILNAM(SEMI:) = '.TSK' FILNAM(SEMI+4:) = TMPCHR END IF ELSE ! If no version number was entered. . . IF (DOT .EQ. 0) FILNAM(LEN(FILNAM)-3:) = '.TSK' END IF C C Filename is now ready. Try to open (Readonly, until ready to modify) C OPEN (UNIT=1,FILE=FILNAM,STATUS='OLD',ACCESS='DIRECT', $ FORM='UNFORMATTED',READONLY,ERR=400) READ (UNIT=1,REC=1,ERR=500) BLOCK2 ! Read in "label" block NUMLNS=BLOCK2(NMLNLC) .AND. "177777 ! Convert Unsigned byte to integer WRITE (UNIT=5,FMT=40) NUMLNS 40 FORMAT (' Number of logical units: ',I3) IF (NUMLNS .EQ. 0) THEN ! If program has NO luns, then. . . CLOSE (UNIT=1) GOTO 10 ! Start over (get a new filename) END IF C C Program has lun(s). Read in the lun block. C If there are more than 128 luns, read in the second lun block. C READ (UNIT=1,REC=2,ERR=500) BLOCK2 IF (NUMLNS .GT. 128) READ (UNIT=1,REC=3,ERR=500) BLOCK3 C C Display current lun assignments C WRITE (UNIT=5,FMT=50) 50 FORMAT (' Current LUN assignments:'/) DO 80 I = 1, NUMLNS DEVICE=BIGBUF(2*I-1) UNITNM=BIGBUF(2*I) C C Substitute "**" for un-assigned luns C IF (DEVICE .EQ. 0) DEVICE='**' WRITE (UNIT=5,FMT=60) DEVICE,UNITNM,I 60 FORMAT (X,A2,O,':',T8,I4,'.') 80 CONTINUE C C Now, get modifications C 90 WRITE (UNIT=5,FMT=100) 100 FORMAT ('-Changes ... 0=Cancel, -1=Record changes.') 110 WRITE (UNIT=5,FMT=120) 120 FORMAT ('$LUN: ') READ (UNIT=5,FMT=130,ERR=300,END=999) I 130 FORMAT (I3) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C I=0: Cancel. C C I=-1: Record changes back to disk. C C I>NUMLNS: Error. C C I<-1: Error. C C Else: OK. Make change in memory. C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC IF (I .EQ. 0) THEN ! Cancel WRITE (UNIT=5,FMT=140) 140 FORMAT ('-Changes cancelled.') CLOSE (UNIT=1) GOTO 10 ! Start over (get a new filename) ELSE IF (I .EQ. -1) THEN ! Record changes back to disk WRITE (UNIT=5,FMT=150) 150 FORMAT ('-Changes being recorded.') CLOSE (UNIT=1) ! Close and re-open, this time NOT readonly OPEN (UNIT=1,FILE=FILNAM,STATUS='OLD',ACCESS='DIRECT', $ FORM='UNFORMATTED',ERR=400) WRITE (UNIT=1,REC=2,ERR=600) BLOCK2 IF (NUMLNS .GT. 128) WRITE (UNIT=1,REC=3,ERR=600) BLOCK3 CLOSE (UNIT=1) ! Success GOTO 10 ! Start over (get a new filename) ELSE IF (I .GT. NUMLNS) THEN ! Error WRITE (UNIT=5,FMT=170) NUMLNS 170 FORMAT (' Task only has',I4,' LUN''s. Try again.') GOTO 90 ! Get next lun, and explain 0 and -1 answers ELSE IF (I .LT. -1) THEN ! Error WRITE (UNIT=5,FMT=190) 190 FORMAT ('-Invalid response. Try again.') GOTO 90 ! Get next lun, and explain 0 and -1 answers ELSE ! OK. Make change in memory 200 DEVICE=BIGBUF(2*I-1) UNITNM=BIGBUF(2*I) C C Display current assignment. If a lun is "unassigned", use ** as device name C IF (DEVICE .EQ. 0) DEVICE = '**' WRITE (UNIT=5,FMT=210) DEVICE,UNITNM 210 FORMAT ('$Current assignment: ',A2,O, $ ': New assignment: ') C C Read new assignment into TMPCHR, then "process" TMPCHR into DEVICE and UNITNM C (This is necessary if no unit number is entered, defaulting to 0) C READ (UNIT=5,FMT=220,ERR=300,END=999) J,TMPCHR 220 FORMAT (Q,A) IF (J .GT. 0) J = INDEX (TMPCHR(1:J),':') ! Find end of name IF (J .EQ. 3) THEN ! If name is at least 3 chars long. . . READ (UNIT=TMPCHR(1:J),FMT=230) DEVICE ! Get device 230 FORMAT (A2) UNITNM=0 ! Unit number defaults to zero ELSE IF (J .GT. 3) THEN ! Else, if unit number present. . . C C Note -- Error can occur in next READ statement if unit number is not octal. C If error, a message will be printed, and control will be passed C back to 110 (where user will be prompted for next lun). C READ (UNIT=TMPCHR(1:J),FMT=240,ERR=700) DEVICE,UNITNM 240 FORMAT (A2,O) ELSE ! Otherwise, answer has invalid syntax WRITE (UNIT=5,FMT=250) 250 FORMAT (' Error - Answer too short, or', $ ' no terminating colon ('':'').') GOTO 110 ! Get next lun from user END IF IF (DEVICE .EQ. '**') DEVICE = 0 ! "De-assign" lun DEVICE = DEVICE .AND. "157737 ! Convert to upper case BIGBUF(2*I-1) = DEVICE BIGBUF(2*I) = UNITNM GOTO 110 ! Get next lun from user END IF ELSE GOTO 10 ! Start over (get a new filename) END IF STOP 'PROGRAM CAN''T GET HERE' 300 WRITE (UNIT=5,FMT=310) 310 FORMAT (' Error reading from terminal, exiting') GOTO 999 ! Exit 400 WRITE (UNIT=5,FMT=410) 410 FORMAT (' Error opening file') GOTO 10 ! Start over (get a new filename) 500 WRITE (UNIT=5,FMT=510) 510 FORMAT (' Error reading file') GOTO 10 ! Start over (get a new filename) 600 WRITE (UNIT=5,FMT=610) 610 FORMAT (' *** ERROR WRITING BACK TO FILE, EXITING ***') GOTO 999 ! Exit 700 WRITE (UNIT=5,FMT=710) 710 FORMAT (' Error - invalid octal unit number') GOTO 110 ! Get next lun from user 999 CLOSE (UNIT=1) END INTEGER*2 FUNCTION OCTDIG(NUMBER) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C This function returns the number of octal digits in the UNSIGNED argument. C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC INTEGER*2 NUMBER IF (NUMBER .LT. 0) THEN ! Negative implies > 32767 (unsigned) OCTDIG = 6 ELSE IF (NUMBER .LT. 8) THEN OCTDIG = 1 ELSE IF (NUMBER .LT. 64) THEN OCTDIG = 2 ELSE IF (NUMBER .LT. 512) THEN OCTDIG = 3 ELSE IF (NUMBER .LT. 4096) THEN OCTDIG = 4 ELSE OCTDIG = 5 END IF RETURN END