home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xvol1.exe
/
XVOL1.C
next >
Wrap
Text File
|
1994-12-15
|
6KB
|
203 lines
/****************************************************************************
** File: XVOL1.C
**
** Description:
**
** Sample code that shows how to determine the number of bytes free on a
** NetWare volume.
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Developer support for this software
** may be provided at the discretion of Novell.
**
** QMK386 options used:
**
** None
**
** Programmers:
**
** Ini Name Firm
** -----------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 12-06-94 ABJ First code.
*/
/****************************************************************************
** Compiler setup.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <STDLIB.H>
#include <STDIO.H>
#include <ERRNO.H>
/*------------------------------------------------------------------------
** NetWare
*/
#include <NWDIR.H>
#include <NITERROR.H>
/****************************************************************************
** Program start.
*/
void main(int argC, char *argV[])
{
VOLUME_INFO volInfo;
int rVal;
LONG freeBlocks;
LONG bytesPerSector;
LONG bytesPerBlock;
LONG freeBytes;
int volumeNumber;
char *volumeName = "SYS";
char pathName[255+1];
LONG availableSpace;
/*------------------------------------------------------------------------
** Parse command line.
*/
if(argC > 2)
{
printf("Usage: LOAD %s <volumeName>\n", argV[0]);
printf("\n");
printf(" <volumeName> Optional volume name. (default = SYS)\n");
goto END_ERR;
}
if(argC > 1)
volumeName=argV[1];
/*------------------------------------------------------------------------
** Convert volume name to volume number.
*/
rVal=GetVolumeNumber(
/* I- volumeName */ volumeName,
/* -O volumeNumber */ &volumeNumber
);
switch(rVal)
{
case ESUCCESS:
break;
case ERR_INVALID_VOLUME:
printf("ERROR: GetVolumeNumber() reports: Volume does not exist.\n");
goto END_ERR;
default:
printf("ERROR: GetVolumeNumber() reports error code: %d\n", rVal);
goto END_ERR;
}
/*------------------------------------------------------------------------
** Get volume stats.
*/
rVal=GetVolumeStatistics(
/* I- fileServerID */ 0,
/* I- volumeNumber */ volumeNumber,
/* I- structSize */ sizeof(volInfo),
/* -O returnedVolumeStatistics */ &volInfo
);
switch(rVal)
{
case ESUCCESS:
break;
case ERR_INVALID_VOLUME:
printf("ERROR: GetVolumeStatistics() reports: Invalid volume number.\n");
goto END_ERR;
default:
printf("ERROR: GetVolumeStatistics() reports error code: %d\n", rVal);
goto END_ERR;
}
/*------------------------------------------------------------------------
** Calculate values.
**
** Note: An unsigned long can store a number between 0 and 4294967295.
** Therefore, if the volume is greater than 4gb, some of the values
** below may -wrap- and become invalid when multiplied to resolve
** to a number of bytes. In otherwords; the formula is correct, but
** may be limited to a total volume size of 4gb or less.
*/
freeBlocks = volInfo.availableBlocks + volInfo.purgableBlocks;
bytesPerSector = 512; /* According to Rob Carlson - Novell CLIB team. */
bytesPerBlock = bytesPerSector * volInfo.sectorsPerBlock;
freeBytes = freeBlocks * bytesPerBlock;
/*------------------------------------------------------------------------
** Print report.
*/
printf("Volume...........: %s\n", volumeName);
printf("\n");
printf("Available Blocks.: %10u\n", volInfo.availableBlocks);
printf("Purgable Blocks..: %10u\n", volInfo.purgableBlocks);
printf(" ----------\n");
printf("Free Blocks......: %10u\n", freeBlocks);
printf("\n");
printf("\n");
printf("Bytes Per Sector.: %10u (Constant)\n", bytesPerSector);
printf("Sectors Per block: %10hu\n", volInfo.sectorsPerBlock);
printf(" ----------\n");
printf("Bytes Per Block..: %10u\n", bytesPerBlock);
printf("\n");
printf("\n");
printf("Free Blocks......: %10u\n", freeBlocks);
printf("Bytes Per Block..: %10u\n", bytesPerBlock);
printf(" ----------\n");
printf("Free Bytes.......: %10u\n", freeBytes);
printf("\n");
printf("\n");
/*------------------------------------------------------------------------
** Get this user's available disk space (I know, it's connection 0, which
** has no user restrictions. It's the formula that counts.)
**
** GetAvailableUserDiskSpace() returns the same value as 'freeBlocks'
** (detailed above) if there are no current user space restrictions.
*/
sprintf(pathName, "%s:", volumeName);
rVal=GetAvailableUserDiskSpace(
/* I- pathName */ pathName,
/* -O availableSpace */ &availableSpace
);
switch(rVal)
{
case ESUCCESS:
break;
default:
printf("ERROR: GetAvailableUserDiskSpace() reports error code: %d\n", rVal);
goto END_ERR;
}
printf("GetAvailableUserDiskSpace: %10u\n", availableSpace);
END_ERR:
exit(0);
}