.TITLE SETFNB Fill in File Name Block .IDENT "V2.2" ;(P/OS Support added) .ENABL LC .PSECT C$CODE ;+ ; Index SETFNB Fill in File Name Block ; ; ; Usage ; ; #include ; #include /* Filename Block def. */ ; struct fnb xfnb; /* Filename block */ ; char *fsp; /* File spec string */ ; int lun; /* LUN to use for lookups */ ; char *dext; /* Default extension */ ; int status; /* Status returned */ ; ; status = setfnb(&xfnb, fsp, lun, dext); ; ; ; Description ; ; This function is not strictly a mapping of an RSX-11M ; executive directive into a C call. It is provided with the ; CX library to allow block-oriented file I/O and control ; operations with the Files-11 ACP, rather than using the ; FCS or RMS I/O library functions. ; ; This version supports the P/OS "Get Default Directory" ; request, allowing programs to be ported to P/OS and do ; file I/O bypassing RMS. In the case of P/OS, generalized ; RAD50 directory strings of up to 9 characters are accepted ; as explicit directory specifications. If the string within ; the square brackets does not contain a comma, a P/OS style ; directory string is assumed. ; ; setfnb() performs the messy part of getting a file open ; on a specified LUN by performing all filespec parsing and ; directory lookup operations required to fill in a Filename ; Block (FNB). All that is needed as inputs are a filespec ; string and a free LUN. ; ; Default directory and device processing are performed ; transparently, i.e., the filespec need not be "fully ; qualified", this includes P/OS support as outlined above. ; ; If the file already exists, all that remains to be done to ; get the file open is to issue one of the Files-11 ACP "file ; access" QIO's. You may then read and write blox with the ; IO.RVB and IO.WVB functions. ; ; If the file does not exist, setfnb() will return with IE.NSF ; (No such file). In this case, you must manually issue the ; Files-11 "create file" (IO.CRE) function, followed by a ; directory enter (IO.ENA) function, thus creating the file. ; All of the fields in the FNB except N.FID are valid upon ; return from setfnb() if the error is IE.NSF. ; ; ; Notes ; ; Returns Directive or I/O status. If hi byte < 0, status is ; directive status, else is I/O status. ; ; Errors from filespec parsing or directory operations return ; IE.BAD (for lack of anything better). ; ; If setfnb() returns with a status of IE.NSF (no such file) ; all fields except N.FID are silll usable, and the FNB is ; all set for use in creating a new file. ; [end] ;- ; Edits: ; V1.0 26-Aug-82 RBD Initial edit ; V1.1 20-Oct-82 RBD Remove CSD copyright notice; release to public ; domain. Ready for new DECUS C distribution. ; V2.0 21-Jan-83 TTC Add P/OS support ; V2.1 06-Jan-84 TTC Clear N.NEXT field of FNB after FNAQIO so first ; .find call will not skip the first matching file. ; It turns out that the wildcard matching is actually ; performed by the ACP. ; V2.2 19-Jan-87 JMC Change .psect for I/D space. ; .mcall ALUN$S GLUN$S QIOW$ DIR$ C$PMTR = 4 ; Offset to parameters after csv$ EF.FCS == 16. ; Use EFN 16 for QIO's .psect c$data,d ;2.3 lundat: .blkw 6 ; LUN information block isb: .blkw 2 ; I/O Status fnaqio: QIOW$ IO.FNA,,EF.FCS,,isb .psect C$CODE .enabl lsb SETFNB:: ; **ENTRY** jsr r5,csv$ ; Save our environment mov C$PMTR+0(r5),r0 ; r0 --> FNB mov C$PMTR+4(r5),r3 ; r3 = LUN to use ; ; Convert the default extension and fill in to working FNB ; mov r0,(sp) ; (sp) --> FNB add #n.ftyp,(sp) ; (sp) --> extension word mov C$PMTR+6(r5),r1 ; r1 --> def ext ASCII string addr. beq 10$ ; (null, no default) mov r1,-(sp) ; Push ASCII address mov #3,-(sp) ; Convert 3 ASCII characters call ascr50 cmp (sp)+,(sp)+ ; Clean off stack mov C$PMTR+0(r5),r0 ; Restore r0 --> FNB ; ; Parse the filespec as far as possible ; 10$: mov C$PMTR+2(r5),r1 ; r1 --> filespec string mov #IE.BAD&377,r4 ; Preset "no such file" call parse ; Parse filespec bcs err ; ; Assign LN.F11 to the given device and check it out thoroughly ; ALUN$S r3,n.dvnm(r0),n.unit(r0) mov $dsw,r4 ; Return DSW if dir error bic #177400,r4 ; Clear hi byte bis #100000,r4 ; Indicate directive error bcs err ; (dir. error) mov #lundat,r1 ; R1 --> LUN info block GLUN$S r3,r1 ; Get LUN info mov #IE.IDU!100000,r4 ; Preset "Invalid device or unit" tstb g.lufb(r1) ; Is driver loaded? bpl err ; (no, dir. error) bit #40000,g.lucw(r1) ; Is it files-11? beq err ; (no, dir. error) ; ; OK, device looks good. Replace the device and unit in the FNB with ; the redirect device/unit to cut down on redirect chain overhead later. ; R0 --> FNB ; mov g.luna(r1),n.dvnm(r0) movb g.lunu(r1),n.unit(r0) ; ; Determine issuing task's "default UIC", invoke directory processing ; to fill in the Directory ID of the FNB. ; mov r3,r1 ; r1 = LUN mov #IE.BAD&377,r4 ; Directory error = bad params?? (sick) call dirset ; Try to look up dir, fill in DID bcs err ; ; Now look up the file, fill in the file ID in the FNB. ; mov r3,fnaqio+q.iolu ; Set the LUN mov r0,fnaqio+q.iopl+10. ; P6 --> FNB DIR$ #fnaqio mov $dsw,r4 ; Return DSW if dir error bic #177400,r4 ; Clear hi byte bis #100000,r4 ; Indicate directive error bcs err ; (dir. error) clr n.next(r0) ; clear n.next for wildcarding ;2.1 mov isb,r4 ; r4 = I/O status ; ; Done! ; err: mov r4,r0 ; Return code jmp cret$ .end