home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xdfs1.exe
/
XDFS1.C
next >
Wrap
C/C++ Source or Header
|
1995-04-07
|
9KB
|
304 lines
/**************************************************************************
** File: xdfs1.c
**
** Desc: Example program for making Direct File System calls.
**
** This program demonstrates a simple implementation of
** Direct File System calls.
**
**
** 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. Technical support for this software
** may be provided at the discretion of Novell.
**
** QMK386 options used:
**
** None
**
** Programmers:
**
** Ini Who Firm
** ---------------------------------------------------------------------
** DWH Dirk W. Howard Novell Developer Support
**
**
** History:
**
** When Who What
** ---------------------------------------------------------------------
** 2-21-1995 DWH First code.
** 4-7-1995 DWH Made changes for portability to Power PC.
**
*/
/**************************************************************************
** Prototypes and macro definitions
*/
#ifndef PPC
/*------------------------------------------------
** NetWare Intel include files
*/
#include <dfs.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <nwdir.h>
#include <process.h>
#include <conio.h>
#include <stdio.h>
#include <errno.h>
#include <niterror.h>
#else
/*------------------------------------------------
** NetWare Power PC include files
*/
#include <nwtypes.h>
#include <nwdfs.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <nwdir.h>
#include <nwthread.h>
#include <nwconio.h>
#include <stdio.h>
#include <errno.h>
#include <nwerrno.h>
#endif
/*------------------------------------------------
** Macro substitutions
*/
#define bytesPerSector 512
#define SIZEOFBUF 4096
/*------------------------------------------------
** Function Prototypes
*/
void WeWereUnloaded(int sigtype);
void genericThread(void *arg);
/**************************************************************************
** Global variables
*/
LONG lNLMThreadCount;
LONG lNLMShutdown;
LONG lBytesPerBlock;
LONG lBlockingFactor;
LONG lSectorsInBuf;
/**************************************************************************
** main procedure
*/
void main()
{
VOLUME_INFO volInfo;
int iCompCode;
int iCount;
/*------------------------------------------------
** Register for SIGTERM
*/
signal(SIGTERM, WeWereUnloaded);
/*------------------------------------------------------------------------
** Get volume stats.
*/
iCompCode=GetVolumeStatistics(
/* I- fileServerID */ 0,
/* I- volumeNumber */ 0, /* SYS: */
/* I- structSize */ sizeof(volInfo),
/* -O returnedVolumeStatistics */ &volInfo
);
switch(iCompCode)
{
case ESUCCESS:
break;
case ERR_INVALID_VOLUME:
printf( "XDFS1: Error GetVolumeStatistics() reports: Invalid "
"volume number.\n\r");
exit( 0 );
default:
printf( "XDFS1: Error GetVolumeStatistics() reports error "
"code: %d\n\r", iCompCode);
exit( 0 );
}
lBytesPerBlock = bytesPerSector * volInfo.sectorsPerBlock;
lSectorsInBuf = SIZEOFBUF / bytesPerSector;
lBlockingFactor = lBytesPerBlock / SIZEOFBUF;
/*------------------------------------------------
** Spin off ten threads working on DFS calls.
*/
for ( iCount=0; iCount<10; iCount++ )
{
iCompCode = BeginThread( genericThread, NULL, 0, (void *)iCount );
if( iCompCode == EFAILURE )
switch( errno )
{
case ENOMEM:
printf( "XDFS1: Error BeginThread() indicated \"Not enough "
"memory\"\n\r");
return;
case EINVAL:
printf( "XDFS1: Error BeginThread() indicated \"Invalid "
"arg was passed in.\"\n\r");
return;
default:
printf( "XDFS1: Error BeginThread() returned unknown "
"error: %d.\n\r", iCompCode);
return;
}
}
/*------------------------------------------------
** Do a thread switch to allow the spawned thread to startup
*/
ThreadSwitchWithDelay();
/*------------------------------------------------
** Wait for threads to complete
*/
while ( lNLMThreadCount != 0 )
ThreadSwitchWithDelay();
SetAutoScreenDestructionMode( TRUE );
exit( 0 );
}
/**************************************************************************
** WeWereUnloaded Procedure
*/
void WeWereUnloaded(int sigtype)
{
sigtype = sigtype;
lNLMShutdown = TRUE;
while(lNLMThreadCount > 0)
ThreadSwitchWithDelay();
}
/**************************************************************************
** Generic Thread
*/
void genericThread(void *arg)
{
LONG lCount;
LONG lThreadNo = (LONG)arg;
LONG lFH;
LONG lCompCode;
char caFilename[80];
char caBuf[ SIZEOFBUF ];
lNLMThreadCount++;
sprintf( caFilename, "DFS%ld.DWH", lThreadNo );
lFH = DFScreat(
/* I- filename */ (BYTE *)caFilename,
/* I- access */ O_RDWR | O_CREAT | O_TRUNC,
/* I- flagBits */ 0x0001
);
if ( lFH == -1 )
{
printf( "XDFS1: Error in DFScreat in thread %ld\n\r", lThreadNo );
perror( "DFScreat" );
lNLMThreadCount--;
return;
}
printf( "Opened file %s in thread %ld.\n\r", caFilename, lThreadNo );
/*------------------------------------------------
** Write caBuf to the file 64 times
*/
for ( lCount=0; lCount<64; lCount++ )
{
memset( caBuf, '!'+lCount, SIZEOFBUF );
/*------------------------------------------------
** Check to see if we are exiting
*/
if ( lNLMShutdown == TRUE )
{
DFSSetEndOfFile( lFH, (LONG)( sizeof(caBuf) * lCount ), 1 );
DFSclose( lFH );
lNLMThreadCount--;
return;
}
/*------------------------------------------------
** Allocated disk storage
*/
if ( (lCount % lBlockingFactor) == 0 )
{
lCompCode = DFSExpandFile(
/* I- fileHandle */ lFH,
/* I- fileBlockNumber */ lCount/lBlockingFactor,
/* I- numberOfBlocks */ 1,
/* I- volumeBlockNumber */ -1,
/* I- segmentNumber */ -1
);
if ( lCompCode != 0 )
{
printf( "XDFS1: Error in DFSExpandFile in thread %ld\n\r"
"Error Code %X\n\r\n\r", lThreadNo, lCompCode );
DFSSetEndOfFile( lFH, (LONG)( sizeof(caBuf) * lCount ), 1 );
DFSclose( lFH );
lNLMThreadCount--;
return;
}
printf( "Expanded file %s in thread %ld.\n\r",
caFilename, lThreadNo );
}
/*------------------------------------------------
** Write buffer to file
*/
lCompCode = DFSWrite(
/* I- fileHandle */ lFH,
/* I- startingSector */ lCount * lSectorsInBuf,
/* I- sectorCount */ lSectorsInBuf,
/* I- buffer */ (BYTE *)caBuf
);
if ( lCompCode != 0 )
{
printf( "XDFS1: Error %ld during DFSWrite in thread %ld\n\r\n\r",
lCompCode, lThreadNo );
DFSSetEndOfFile( lFH, (LONG)( sizeof(caBuf) * lCount ), 1 );
DFSclose( lFH );
lNLMThreadCount--;
return;
}
printf( "Wrote data to %s beginning at sector %ld in thread %ld.\n\r",
caFilename, lCount * lSectorsInBuf, lThreadNo );
}
DFSSetEndOfFile( lFH, (LONG)( sizeof(caBuf) * lCount ), 1 );
DFSclose( lFH );
lNLMThreadCount--;
return;
}