From: SHOECRAFT@MC.MARICOPA.EDU (Steve Shoecraft)
Newsgroups: comp.os.vms
Subject: Re: ACP-QIO to read QUOTA.SYS
Date: 3 Jan 93 05:22:44 GMT
Distribution: world
Organization: The Internet


  o Is the CHAN arg to $QIO a channel to the device or to QUOTA.SYS?

A channel to the device, returned by the $ASSIGN system service.
 
  o Can/should the P1 parameter be Fortran structure type /JIBDEF1/,
     /JIBDEF/, or those UNIONed togather? (i.e. can it be a short JIB,
     and if so how short?)

I've used FIBDEF1 in the example below.  If you'll notice, FIBDEF1 has the 
declarations for cntrlfunc and cntrlval in it. Those are all you will need to 
access the quota information.
 
  o Do you need the P2 arg if the JIB$L_CNTRLVAL is set to match all
     group & member UIC's, and if so, what do you put in the the
     DQF$L_UIC field of the quota data block?

You need the P2 arg regardless if you are getting one or all of the quota 
records.  Think of the P2 arg as the input block and the P4 arg as the output 
block. In the example below, I've used the same block for input and output, 
since I'm only getting information for 1 user.  If you want to return quota 
records for multiple users, you have to specify the starting UIC in the 
DQF$L_UIC field of the input block.  If you want an example on returning 
multiple records, e-mail me directly, and I'll send you one.
 
  o What value do you put in the 2nd word of the descriptor to the
     JIB & quota block? (e.q. what are "x" and "y" in DSC$K_DTYPE_x
     DCS$K_CLASS_y.  I'm currently trying to use zero for both...)

I just declared a structure containing two longwords; 1 for the length, 1 for 
the address of the structure I'm passing.  The DSC$K_DTYPE is the data type, 
the DSC$K_CLASS is the class of the 

	++ Dave

Do you have an address dave??

- Steve
SHOECRAFT@MC.MARICOPA.EDU
---------------------------------------------------------------------------
#include <fibdef.h>
#include <iodef.h>
#include <jpidef.h>
#include <psldef.h>

#define NEAR_PCT	0.10		/* 10% left or 90% used */

main()
{
	struct item_desc {
		long len;
		long addr;
	};
	struct item {
		short len;
		short code;
		long buffer;
		long retlen;
	};
	struct io_status_block {
		short status;
		short count;
		long devdep;
		long more;
	};
	struct quota_transfer_block {
		long dqf$l_flags;
		long dqf$l_uic;
		long dqf$l_usage;
		long dqf$l_permquota;
		long dqf$l_overdraft;
		long reserved[3];
	};
	char *devname = "SYS$DISK", *ptr;
	struct item_desc curdev, fibdesc, qtbdesc;
	struct io_status_block iosb;
	struct fibdef1 fib;
	struct quota_transfer_block qftb;
	unsigned long status, uic, current, max;
	unsigned short io_channel, qftb_len;
	struct {
		struct item uic;
		struct item nullitem;
	} jpi_itmlst = {
		{ sizeof(uic),JPI$_UIC,&uic,0 },
		{ 0, 0, 0, 0 }
	};
	register int x;

	/* Set up the default device descriptor */
	curdev.len = strlen(devname);
	curdev.addr = devname;

	/* Assign an IO channel to the default device */
	status = sys$assign(&curdev,&io_channel,PSL$C_USER,0);
	if ( (status & 1) == 0)
		exit(status);

	/* Call $GETJPI to get the current user's UIC */
	status = sys$getjpi(0,0,0,&jpi_itmlst,&iosb,0,0);
	if ( (status & 1) == 0 || iosb.status != 1)
		goto abort;

	/* Set up the FIB, QTB, and descriptors */
	ptr = &fib;
	for(x=0; x < sizeof(fib); x++) ptr[x] = 0;
	fib.fib$w_cntrlfunc = FIB$C_EXA_QUOTA;
	fibdesc.len = FIB$K_LENGTH;
	fibdesc.addr = &fib;
	qftb.dqf$l_uic = uic;
	qtbdesc.len = sizeof(qftb);
	qtbdesc.addr = &qftb;
	qftb_len = 0;

	/* Call $QIO to get the quota info */
	status = sys$qiow(0,io_channel,IO$_ACPCONTROL,&iosb,0,0,
		&fibdesc,&qtbdesc,&qftb_len,&qtbdesc,0,0);
	if ( (status & 1) == 0 || iosb.status != 1)
		goto abort;

	current = qftb.dqf$l_usage;
	max = qftb.dqf$l_permquota;
	if (current > max-(max*NEAR_PCT) && current < max)
		near_message();
	else if (current >= max)
		full_message();
abort:
	sys$dassgn(io_channel);
	exit(status);
}

near_message()
{
	printf("%c\t%s",7,"WARNING: Your are near to using all of your");
	printf(" disk quota.\n");
}

full_message()
{
	printf("%c\t%s",7,"WARNING: You have exhausted your disk quota.");
	printf("  You will need to\n\t  purge or delete files before you");
	printf(" will be able to add new ones.\n\t  Call your System");
	printf(" Manager for information on how to do this.\n");
}