Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

OpenVMS API to check free space in a disk

 
SOLVED
Go to solution
madhav_poddar
Occasional Advisor

OpenVMS API to check free space in a disk

Hi there,

 

Is there an API to check the remaining free space in disk / mounted device (preferrably in bytes)?

 

Thanks in advance.

7 REPLIES 7
Steven Schweda
Honored Contributor

Re: OpenVMS API to check free space in a disk

> Is there an API to check the remaining free space in disk / mounted
> device (preferrably in bytes)?

   For information about a device or volume, (assuming C) I'd look at
sys$getdvi().  In <dvidef.h>, I see:

#define DVI$_FREEBLOCKS 42 /* Number of free blocks on the volume (disk) - VALUE - 4 bytes */

   So far as I know, VMS tracks disk space only in 512-byte blocks.

Highlighted
Steven Schweda
Honored Contributor
Solution

Re: OpenVMS API to check free space in a disk

   Look what I found lying around (df.c):

 

#include <unistd.h>
#include <stdio.h>

#include <descrip.h>
#include <dvidef.h>
#include <starlet.h>


/* GETDVI item descriptor structure. */
typedef struct
{
    short buf_len;
    short itm_cod;
    void *buf;
    int *ret_len;
} dvi_item_t;


int main( int argc, char **argv)
{
    int sts;

    $DESCRIPTOR( sys_disk_descr, "SYS$DISK");

    /* DVI item buffers. */
    static unsigned freeblocks;
    static unsigned maxblocks;

    /* GETDVI item lengths. */
    static int freeblocks_len;          /* Should come back 4. */
    static int maxblocks_len;           /* Should come back 4. */

    /* GETJPI item descriptor set. */
    struct
    {
        dvi_item_t freeblocks_itm;
        dvi_item_t maxblocks_itm;
        int term;
    } dvi_itm_lst =
     { { 4, DVI$_FREEBLOCKS, &freeblocks, &freeblocks_len },
       { 4, DVI$_MAXBLOCK, &maxblocks, &maxblocks_len },
       0
     };

    sts = sys$getdviw( 0, 0, &sys_disk_descr, &dvi_itm_lst, 0, 0, 0);

    printf( " dvi sts = %%%08x .\n", sts);

    printf( " freeblocks = %d (len = %d).\n", freeblocks, freeblocks_len);
    printf( "  maxblocks = %d (len = %d).\n", maxblocks, maxblocks_len);

    return sts;
}

 

abrsvc
Respected Contributor

Re: OpenVMS API to check free space in a disk

Note that the space will be allocated and reported in an integer multiple of the cluster size which will likely be larger than 512 bytes.  Most, if not all, disks still in use today will have cluster sizes greater than 1, usually at least 3.

 

Also, the space reported here will reflect only the available clusters/blocks.  The actual amount of space used by a file may be less than calculated here since this level of data only looks at allocated blocks/clusters.  There is no direct way to view an entire disk and know the number of available "bytes" without looking at each file.

Steven Schweda
Honored Contributor

Re: OpenVMS API to check free space in a disk

> Note that the space will be allocated and reported in an integer
> multiple of the cluster size which will likely be larger than 512 bytes.
> [...]

   Yes, but $GETDVI returns (512-byte) block counts, not disk cluster
counts.

> Also, the space reported here will reflect only the available
> clusters/blocks. [...]

   Huh?  Are FREEBLOCKS not FREEBLOCKS?

> [...] The actual amount of space used by a file [...]

   As I read the original question, it involved "free space", not "space
used by a file" (or any number of files).

> There is no direct way to view an entire disk and know the number of
> available "bytes" without looking at each file.

   Is this some new meaning for "available"?  "Not occupied by useful
data" and "available" are spelled differently for a reason.  I'd say
that a disk cluster ceases to be "available" when it's allocated to a
file, regardless of how much of that disk cluster is occupied by useful
data.  Who else could use that unoccupied space?  To whom is it
"available"?

   For "used space", you might have an argument, but that was not
requested.

abrsvc
Respected Contributor

Re: OpenVMS API to check free space in a disk

Yes, but $GETDVI returns (512-byte) block counts, not disk cluster
>counts.

Agreed, but this will be a multiple of the cluster size (the point I was trying to make as noted below.)

>> Also, the space reported here will reflect only the available
>> clusters/blocks. [...]

 >  Huh?  Are FREEBLOCKS not FREEBLOCKS?

Yes they are.  However, since the OP was looking for bytes, that suggests familiarity with the dreaded Windows systems which do not suffer from the block/cluster restrictions (at least not in the same way).  Also, I have run across folks that use the FREE stats to determine the amount of USED space.  Yes, an allocated block is technically "used", but again Windows based systems report the number of used bytes for a file rather than the allocated space for the file by default.  Perhaps, I was anticipating that since the OP requested a byte count, he/she was looking to compare to a Windows box.

Sorry if I struck a nerve.

Steven Schweda
Honored Contributor

Re: OpenVMS API to check free space in a disk

> [...] suggests familiarity with the dreaded Windows systems [...]

   Not mentioned.

> [...] Perhaps, I was anticipating [...]

   And I was trying to answer the question which was asked, not some
other question which I made up myself.

> Sorry if I struck a nerve.

   Free advice: If you want to answer your own questions instead of the
original question, then say so, and say what your questions are.
Otherwise risk causing unnecessary confusion.

Arch_Muthiah
Honored Contributor

Re: OpenVMS API to check free space in a disk

Dear Steve,

<<< +++++
And I was trying to answer the question which was asked, not some other question which I made up myself.

Free advice: If you want to answer your own questions instead of the
original question, then say so, and say what your questions are.
Otherwise risk causing unnecessary confusion.
+++++ >>>>

It is always interesting and happy reading your responses since I joined in ITRC in 2004 I guess or may be before that.
I had a big struggle, almost few years recovering my old ITRC ID and joining with you all again and I am extremely happy coming back and seeing my friends Steven, abvsrc, etc. here.  

Thanks

Regards
Archie