	.title	JTModAce
; modify ACE by deleting old one and adding new one
; Copyright 9c) 1994 Glenn C. Everhart
; All Rights Reserved
	$atrdef
	$acldef
	$acedef
	$fibdef
	$iodef
	.psect	pdata,rd,wrt,quad
; FIB for filacc to use
fafib:	.long	0
fafid:	.long	0,0,0,0,0,0,0,0,0,0,0,0,0
fafds:	.long	0	;fib$l_status
fafd:	.long	.-fafib
	.address	fafib
faios:	.long	0,0
; set up data areas we need here
myfib:	.long	<fib$m_nolock+fib$m_norecord>	;don't alter dates
fibfid:	.blkw	3	;file id
fibdid:	.blkw	3	; dir id
fibctx:	.long	0
	.blkl	7	;other junk
fibacx:	.long	0	; acl context
fibast:	.long	0
fibsts:	.long	0,0
myfibl=.-myfib
mytgt:	.ascii	/GCEV/	;my flag indicator in ACE
; set up a fib
inbuf:	.long	0	;header
	.long	0	;flags go here
mynam:	.long	0	; should equal mytgt for my ACE
	.blkl	125	; rest of ACE
bufsiz=255
myfid:	.long	0,0	; file id
iosb:	.long	0,0	; iosb for synchronization
; generate a descriptor for my fib
mfdsc:	.long	myfibl
	.address myfib;
;
; itemlist to get file chars (so existence test has something to do)
chril3:	.word	4
	.word	atr$c_uchar
	.address	ufchr
	.long	0,0
ufchr:	.long	0		;file characs
; Itemlist to read our ACL
myitl3:	.word	255	;buff size
	.word	atr$c_readace	;read an ACE
	.address	inbuf	;to here
	.long	0,0	; terminate list
;
dskchn:	.long	0	;channel to disk
; delete acl entry item list
mydla:	.word	255	;size
	.word atr$c_delaclent	;delete entry
	.address	inbuf	; delete the one we find
	.long	0,0		; terminate the list
myadd:	.word	255
	.word	atr$c_addaclent	; add an entry
	.address	myace
	.long	0,0
myace:
	.word	0
myacf:	.word	0	;flags
	.blkl	128		; our ACL entry scratch storage
	.long	0	;safety
p1=4
p2=8
p3=12
; alpha wants code and data .psects separate
; call replent(ifid,ichan,newace)
; where ifid is FID we start with, chan is channel to disk we want,
; and newace is ACE to put in. If newace 1st byte = 0 just delete old
; ace.
	.psect pcode,rd,exe,quad
	.entry	replent,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
	movq	@p1(ap),myfid		; get file id
	movzwl	@p2(ap),dskchn		; get disk channel
	pushr	#^m<r0,r1,r2,r3,r4,r5>
	clrl	myace		; if p3 not there read ace as empty
	movab	myace,r2
	movl	p3(ap),r1
	beql	1$
	movc3	#256,(r1),(r2)		; get a copy of our ACE arg
1$:	movc5   #0,myfib,#0,#myfibl,myfib	;clear our FIB out
	popr	#^m<r0,r1,r2,r3,r4,r5>
	movl	myfid,fibfid
	movw	myfid+4,fibfid+4	; copy the FID into our FIB
3$:	movab	myitl3,r8		; get find-ace itemlist
	$qiow_s efn=#1,chan=dskchn,iosb=iosb,func=#io$_access,p1=mfdsc,p5=r8
; check status
	blbc	r0,900$
	blbc	iosb,953$
	blbc	fibast,953$
	brb	901$
900$:	brw	930$
901$:
	cmpl	mynam,mytgt		; got a target ACE entry?
	bneq	3$			; if not keep looking
;
; LOOKS like we got our ACE so delete it and add the other if that
; is appropriate.
	movab	mydla,r8		; get my delete access
	$qiow_s efn=#1,chan=dskchn,iosb=iosb,func=#io$_modify,p1=mfdsc,p5=r8
953$:	movl	mytgt,myace+8	;ensure we insert our marking
	movab	myadd,r8		; add the new item
	movl	#1,iosb
	tstb	myace		; is the new ACE empty?
	beql	4$		; if so scram
	$qiow_s efn=#1,chan=dskchn,iosb=iosb,func=#io$_modify,p1=mfdsc,p5=r8
4$:	movzwl	iosb,r0
	ret
930$:	movl	#2,r0
	ret
	.entry filacc,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
; call filacc(lchnl,ifid,iexist) to see if file
; exists
	movl	@4(ap),r2	;channel to r2
	movl	8(ap),r3	;addr of FID
	clrq	fafib
	clrq	fafib+8
	clrq	fafib+16
	clrq	fafib+24
	clrq	fafib+32
	clrq	fafib+40
	clrq	fafib+48
	movl	(r3),fafid
	movzwl	4(r3),fafid+4	;fill FID into FIB
	movl	#1,@12(ap)
	movab	fafd,r4
; no open, so no need really to deaccess the file. This should just say
; if it's there.
	movab	chril3,r5
	$qiow_s	efn=#1,chan=r2,func=#io$_access,iosb=faios,p1=(r4),p5=r5
	tstl	r0
	blbc	r0,1$		;don't declare file absent if qio screwed up
	blbs	faios,1$
;	blbs	fafds,1$	;status of i/o
	clrl	@12(ap)		;if access fails zero "iexist" param
1$:
	ret
	.end

