	.title	getquota - callable SHOW QUOTA
	.ident	/V1.02/
	.sbttl	Documentation
;
;	This routine returns information about a user's quota.
;
;	Calling format:
;
;	status = GETQUOTA(diskname, group, member, used, perm, overdraft)
;
;	Inputs:
;		diskname	- ascii descriptor of the disk name
;		group		- address of longword containing group number
;		member		- address of longword containing member number
;
;	Outputs:
;		status		- return status code
;		used	 	- address of longword to receive amount used
;		perm		- address of longword to receive perm quota
;		overdraft	- address of longword to receive the overdraft
;
;	All input parameters must be specified.
;	No null parameters are allowed.
;
;	Eric F. Richards
;	10-Aug-85
;	Gould OSD VAX-11/780, VAX/VMS V4.1
;
	.sbttl	Definitions
	.enable	suppression		; clean up listing file
	.disable traceback, debug	; hands off w/ the debugger
	.library /sys$library:lib/	; use alternate macro library
	$ssdef				; system service offsets
	$iodef				; I/O function codes
	$dqfdef				; disk quota file offsets
	$fibdef				; file info block offsets
	minargs = 3			; minimum allowable arguments
	devnam  = 4			; device name descriptor here
	group	= 8			; uic group is here
	member	= 12			; uic member is here
	usage	= 16			; return current usage
	permq	= 20			; return permquota
	overdr	= 24			; return overdraft

	.macro	clrsp space, fill=#0	; macro for clearing space
	subl	space, sp		; on stack for a data area.
	movc5	#0, (sp), fill, -	; data area is init'd to
		  space, (sp)		; nulls by this macro
	.endm	clrsp			; that's it!

	.macro	soblss, loc, lbl	; macro to be similar to SOBGTR
	decw	loc			; decrement location
	blss	lbl			; branch on loc < 0
	.endm	soblss			; that's it!

	.sbttl	Main Code
	.psect	$code, pic, shr, long, exe, nowrt

	.entry	getquota^m<r2, r3, r4, r5, r6, r7, r8>

	subw3	#minargs, (ap), r7	; get number of args
	bgeq	20$			; yes - continue
	movzwl	#ss$_insfarg, r0	; no - not enough args
10$:	ret				; return w/out doing anything

20$:	clrl	-(sp)			; Make room for channel on stack
	movl	sp, r8			; (l.w. aligned) save ptr to it

	$assign_s devnam=@devnam(ap), -	; assign a channel to
		  chan=(r8)		; the current disk
	blbc	r0, 10$			; error check

	clrsp	#fib$k_length		; make room for FIB	
	movw	#fib$c_exa_quota, -	; set control field in FIB
		fib$w_cntrlfunc(sp)	; Examine quota entry
	pushl	sp			; create FIB descriptor
	pushl	#fib$k_length		; consists of address and length
	movl	sp, r6			; save address of FIB desc

	clrsp	#dqf$k_length		; make room on stack for DQF
	movl	sp, r5			; get address of quota FTB
	addl3	#dqf$l_uic, r5, r0	; get offset into QFTB
	movw	@member(ap), (r0)+	; store member
	movw	@group(ap), (r0)+	; store group
	pushl	sp			; create FTB descriptor
	pushl	#dqf$k_length		; ...as above
	movl	sp, r4			; save address of descriptor

	clrq	-(sp)			; make room for IOSB on stack
	movl	sp, r3			; save IOSB address

	$qiow_s	chan=(r8), -		; ask the acp (xqp) for
		func=#io$_acpcontrol, -	; information
		iosb=(r3), -		; return I/O status block
		p1=(r6), -		; need to give it: File info block,
		p2=r4, -		; give it Quota FTB
		p4=r4			; receive same
	blbc	r0, 30$			; error check
	movzwl	(r3), r0		; check IOSB for error
	blbc	r0, 30$			; return status in r0 

	soblss	r7, 30$			; stop if not enough args
	movl	dqf$l_usage(r5), -	; get usage for this user
			@usage(ap)	; return current use
	soblss	r7, 30$			; enough args?
	movl	dqf$l_permquota(r5), -	; get quota limit for this user
			@permq(ap)	; return current quo
	soblss	r7, 30$			; any more?
	movl	dqf$l_overdraft(r5), -	; get overdraft for this user
			@overdr(ap)	; return current overdraft

30$:	pushl	r0			; save error status
	$dassgn_s chan=(r8)		; close the channel
	popl	r0			; restore status
	ret				; go home

	.end				; all done!
