home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
mapdr.exe
/
MAPDRIVE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-29
|
5KB
|
203 lines
/*
This program is provided as is and carries no warranty
whatsoever. Novell disclaims and excludes any and all implied
warranties of merchantability, title and fitness for a particular
purpose. Novell does not warrant that the software will satisfy
your requirements or that the software is without defect or error
or that operation of the software will be uninterrupted. You are
using the software at your risk. The software is not a product
of Novell, Inc. or any of subsidiaries.
*/
/* Programmer : Belinda Adams */
/* Program to map and reset a drive. */
#define NWDOS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <nwcalls.h>
static void display_all_mappings(void);
static void display_mapping(int);
static void change_mappings(void);
static void reset_mapping( char, NWCONN_HANDLE, char *);
/*************************************************************************/
void main(void)
{
int rtn_code;
char drive;
char ans = 'n';
if ( rtn_code = NWCallsInit( NULL, NULL ) )
{
printf( "\nNWCallsInit: failed %04x", rtn_code );
exit(1);
}
system( "cls" );
display_all_mappings();
puts("\n\nChange current mappings (y/n)? ");
ans = getche();
puts("\n");
if ( ans == 'y' || ans == 'Y' )
change_mappings();
}
/*************************************************************************/
void display_all_mappings(void)
{
int drive_num;
puts( "Current drive mapping:\n" );
for (drive_num = 1; drive_num <= 26; drive_num++)
display_mapping(drive_num);
}
/*************************************************************************/
void display_mapping
(
int drive_num
)
{
int rtn_code;
char rootPath[304], relativePath[304];
int status;
rtn_code = NWGetDriveStatus( drive_num, NW_FORMAT_SERVER_VOLUME, &status,
NULL, rootPath, relativePath, NULL );
if ( rtn_code == NW_INVALID_DRIVE )
printf( "\nNWGetDriveStatus: Invalid Drive Number %d", drive_num );
else
{
if ( rtn_code )
{
printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
exit(1);
}
if ( status & NW_NETWARE_DRIVE )
{
printf("Drive %c: = %s", drive_num + '@', rootPath);
puts( relativePath );
}
}
}
/*************************************************************************/
void change_mappings(void)
{
char drive_ltr, drive_num;
int rtn_code, status;
NWCONN_HANDLE conn;
char ans, ans_str[100];
char *upr_ans;
char server[50], rootPath[304], relativePath[304], *volumePath;
puts( "Enter drive letter to change " );
drive_ltr = getche();
if (drive_ltr >= 'a' && drive_ltr <= 'z')
drive_ltr = _toupper(drive_ltr);
puts("\n");
if (drive_ltr >= 'A' && drive_ltr <= 'Z')
drive_num = drive_ltr - '@';
else
{
printf("Drive letter %c is an invalid drive letter", drive_ltr);
exit(1);
}
/* Read current info */
rtn_code = NWGetDriveStatus( drive_num, NW_FORMAT_SERVER_VOLUME, &status,
&conn, rootPath, relativePath, NULL);
if ( rtn_code )
{
printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
exit(1);
}
/* delete the drive's current mapping */
if ( status != NW_UNMAPPED_DRIVE )
if ( rtn_code = NWDeleteDriveBase( drive_num, 0 ) )
{
printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
exit(1);
}
puts("Enter new mapping (server\\volume:path): ");
gets(ans_str);
upr_ans = strupr(ans_str);
rtn_code = NWParsePath( upr_ans, server, &conn, NULL, NULL );
if (rtn_code == NO_CONNECTION_TO_SERVER )
{
if ( rtn_code = NWAttachToFileServer( server, 0, &conn ) )
{
printf( "\nNWAttachToFileServer: failed %04x", rtn_code );
exit(1);
}
}
else if (rtn_code)
{
printf( "\nNWParsePath: failed %04x", rtn_code );
exit(1);
}
volumePath = NWStripServerOffPath( upr_ans, NULL );
if ( rtn_code = NWSetDriveBase( drive_num, conn, 0, volumePath, 0) )
{
printf( "\nNWSetDriveBase: failed %04x", rtn_code );
exit(1);
}
system( "cls" );
puts("Drive mappings updated.\n");
display_mapping(drive_num);
puts("\n\nReset to original mappings (y/n)? ");
ans = getche();
puts("\n");
if ( ans == 'y' || ans == 'Y' )
{
strcat(rootPath, relativePath);
reset_mapping(drive_num, conn, rootPath);
system( "cls" );
puts("Drive mappings reset.");
}
display_all_mappings();
}
/*************************************************************************/
void reset_mapping
(
char drive_num,
NWCONN_HANDLE conn,
char *rootPath
)
{
int rtn_code;
char *volumePath;
if ( rtn_code = NWDeleteDriveBase( drive_num, 0 ) )
{
printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
exit(1);
}
volumePath = NWStripServerOffPath( rootPath, NULL );
if ( rtn_code = NWSetDriveBase( drive_num, conn, 0, volumePath, 0) )
{
printf( "\nNWSetDriveBase: failed %04x", rtn_code );
exit(1);
}
}