From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,606c0005f6ae9b72 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1993-07-20 21:33:10 PST Newsgroups: comp.sys.dec Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!agate!ames!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!peavax.mlo.dec.com!helix.enet.dec.com!miano From: miano@helix.enet.dec.com (Michael Miano) Subject: Re: VAXeln Question Message-ID: <1993Jul21.041833.22730@peavax.mlo.dec.com> Sender: usenet@peavax.mlo.dec.com (USENET News System) Organization: Digital Equipment Corporation References: <1993Jul19.182014.4115@linus.mitre.org> Date: Wed, 21 Jul 1993 05:15:29 GMT In article <1993Jul19.182014.4115@linus.mitre.org>, art@cyclone.mitre.org (Arthur T. McClinton) writes... >I have an RTVAX 300 with a scusi drive. The problem we continually have is >the drive runs out of free space. Is their any way that a program running >under VAXeln can figure out the amount of free space on the disk? I forwarded your question to the VAXELN Customer Support people in Atlanta and got the following response. I've been informed that the program below is accessible via DSNlink/DSIN to those VAXELN customers with a support contract. The database includes numerous other useful articles like this. Good luck. -------------------------------------------------------------------------------- Determining Free And Contiguous Space On An ODS-2 DISK COPYRIGHT (c) 1988, 1993 by Digital Equipment Corporation. ALL RIGHTS RESERVED. No distribution except as provided under contract. PRODUCT: VAXELN V4.3, V4.4 SOURCE: Digital Customer Support Center PROGRAM EXAMPLE: /* * * COPYRIGHT (c) 1992 by Digital Equipment Corporation. * ALL RIGHTS RESERVED. No distribution except as provided under contract. * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the inclusion * of the above copyright notice. This software or any other copies thereof * may not be provided or otherwise made available to any other person. No * title to and ownership of the software is hereby transferred. * * The information in this software is subject to change without notice and * should not be construed as a commitment by Digital Equipment Corporation. * * Digital assumes no responsibility for the use or reliability of its * software on equipment which is not supported by Digital. * * This program is for demonstration purposes only and may not be the * solution to similiar situations. */ /* freespace.c - Displays free space on ODS-2 disk - main program * For VAX/ELN or VAX/VMS, depending if you use the include the $vaxelnc * definitions or not. * * This is an example of a program which invokes freesub() to obtain * a count of free blocks on a disk from the storage bitmap. * The program prompts for the disk device name. * * SYSTEM: VAXELN V3.2-V4.4 * * VAXELN Compile and Link: * $set ver * $CC/debug/noopt/define=(VAXELN='p2') 'p1' + eln$:vaxelnc/lib * $link/debug/map/full 'p1' + eln$:crtlshare/lib + eln$:rtlshare/lib + - * eln$:rtl/lib * $set nover * * Sample EBUILD: * characteristic /remote_cli /shared_status /net_device=EZA /noserver - * /objects=2048 /io_region=2048 /volumes=("DUA1") /target=37 * program ELN$:EDISPLAY /norun * program FREESPACE /norun * device EZA /vector=%X130 /net_def * device DUA /vector=%X550 /priority=6 /file=ELN$:KRDRIVER.EXE - * /device_dependent=%X7FF * terminal CONSOLE /scope /cli * * To run: * ECL>EXECUTE/WAIT FREESPACE */ #include $vaxelnc #include main() { long int freespace,totalspace; int n; char namestring[40]; while (TRUE) { printf("\nEnter device name, or ^Z to exit: "); if (scanf("%s",&namestring) == -1) exit(); /* ^Z, go home */ n = strlen(namestring); /* Ensure the device spec ends in a colon */ if (n>0) /* Just in case... */ if (namestring[n-1] != ':') { namestring[n]= ':'; /* append ':' */ namestring[n+1]= '\0'; /* terminate string */ } /* Look for free space. The subroutine will return a failure flag on a * bogus device spec or I/O error. Priv violations are especially easy * to get on VMS. */ n = freesub(&namestring,&freespace,&totalspace); if (n >= 0) printf("Volume %s %d blocks free, of %d blocks total\n",namestring,freespace,totalspace); else printf("Failed to find free space on volume %s\n",namestring); } } /* freesub() - Obtain free space on ODS-2 disk by reading BITMAP.SYS * For VAX/ELN or VAX/VMS. * A subroutine for an application to find free space on a given * mounted disk volume. While it is unsupported, it should work on any * version of VAX/ELN or VAX/VMS, present or past. * * The result will be reasonably accurate. Since the file system may * have work in progress, you cannot be absolutely certain. On top of that, * note that VMS extent caching optimizes performance by preallocating * disk space, so that this routine will likely report something less than * the actual free space on VMS. * */ /* Storage control block offsets, in *WORDS* */ #define CLEVOFF 0 /* Offset to structure level */ #define CLSFOFF 1 /* Offset to cluster factor */ #define CVSZOFF 2 /* Offset to volume size longword */ int freesub(devptr,freptr,totptr) /* Output: 0 == success, <0 == error */ char *devptr; /* Input: device name, including colon */ long int *freptr; /* Output: free block count */ long int *totptr; { /* Output: total block count */ long int frecnt; /* 32 bit integers */ short int clsfac; /* 16 bit signed integers */ unsigned short int n; /* 16 bit unsigned, for logical shift */ int i, j, ifil; /* Assorted integers */ short int buf[256]; /* bitmap data buffer */ char filspec[100]; /* temp buffer for creating filespec */ strcpy (filspec,devptr); /* Copy device spec into name buffer */ strcat (filspec,"[000000]BITMAP.SYS;1"); /* Append dir, filename */ if ((ifil=open(filspec,0)) < 0) /* Open bitmap file */ return(ifil); /* Open failed, return error */ /* The first block of the bitmap file is a control block containing general * information about the volume. The remaining blocks are the actual bitmap, * one bit set for each cluster of blocks allocated. */ i= read(ifil,buf,512); /* Read the storage control block */ if (i < 1) return(i); /* Read failed, return error */ /* The storage bitmap level word should have a 2 in the high byte, and * a 1 in the low byte. That is the only structure level we understand, * so return an error if something else is there. */ if (buf[CLEVOFF] != 0x201) /* Verify ODS-2, bitmap format 1 */ return(-1); /* Allocation of blocks on an ODS-2 volume is done in bunches called * clusters. The cluster factor (number of 512 byte blocks in a cluster) * is needed to calculate the number of free blocks. */ clsfac = buf[CLSFOFF]; /* Stash the cluster factor */ /* "Buf" is an array of 16-bit integers. The volume's total block size * is a longword, present in words CVSZOFF and CVSZOFF+1. Take the longword * starting at buf[CVSZOFF] and move it to the address in totptr. */ *totptr = *((long int *) &buf[CVSZOFF]); /* Invoke compiler magic */ /* Read the remaining bitmap blocks, counting bits by shifting each bit off. */ frecnt = 0; /* Nothing counted yet */ i= read(ifil,buf,512); /* Read first bitmap block */ while (i > 0) { /* While not EOF... */ for (j=0;j<256;j++) { /* Examine each word in the block */ n = buf[j]; /* Get unsigned data word */ while (n != 0) { /* Count free bits until zero */ if (n & 01) /* If low bit is set... */ frecnt++; /* ...count a cluster free. */ n >>= 1; /* Shift off low bit of n */ } } i= read(ifil,buf,512); /* Read next block */ } /* The read failed: was it an error (i<0) or end-of-file (i==0)? */ if (i < 0) return(i); /* Read failed, return error */ /* Multiply the count of bits set in the bitmap by the cluster factor, * yielding the count of free blocks on the volume. */ *freptr = frecnt * clsfac; /* Consider custer factor */ return(close(ifil)); /* All done */ } WARNING: * The result will be reasonably accurate. Since the file system may * have work in progress, you cannot be absolutely certain. On top of that, * note that VMS extent caching optimizes performance by preallocating * disk space, so that this routine will likely report something less than * the actual free space on VMS.