Hi,
Does anyone have a clue why this is going wrong on the second
directories (it creates the first dirs like data:nlm, data:c, but on
getting a NXCreatePathContext it returns an error which is shown in a
trace as Disk Map Error)
#define TRUE 1
#define FALSE 0
#define NDS 12
#define MIRRORDIR 14
#define DEBUG 0
#include <setjmp.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <screen.h>
#include <stdio.h>
#include <nks/dirio.h>
#include <nks/errno.h>
#include <client.h>
#include <errno.h>
#include "lib.h"
/*************************************************************************
** main
*/
static NXPathCtx_t PathCtxt_UserConnection1 = 0;
static NXPathCtx_t PathCtxt_UserConnection2 = 0;
static int ServerIdentity1 = 0;
static int ServerIdentity2 = 0;
int LoginToNDS (char Nds_Treename[MAX_TREENAME_LEN], char
Nds_UserName[MAX_DN_CHARS], char Nds_Password[MAX_DN_CHARS]);
int LogoutFromNDS (void);
int decodends(char *, char *);
int CheckRemoteDir(char *, char *);
int LoginToNDS(char Nds_Treename[MAX_TREENAME_LEN], char
Nds_UserName[MAX_DN_CHARS], char Nds_Password[MAX_DN_CHARS])
{
int err = 0;
printf(" logging in with: '%s',
'%s'\n",Nds_UserName,Nds_Password);
err = create_identity (Nds_Treename, Nds_UserName,
Nds_Password, NULL, XPORT_WILD|USERNAME_ASCII, &ServerIdentity1);
if (err)
{
printf(" * Details: create_identity failed with rc=%d,
errno: %d\n",err,errno);
return FALSE;
}
err = create_identity (Nds_Treename, Nds_UserName,
Nds_Password, NULL, XPORT_WILD|USERNAME_ASCII, &ServerIdentity2);
if (err)
{
printf(" * Details: create_identity failed with rc=%d,
errno: %d\n",err,errno);
return FALSE;
}
return TRUE;
}
int LogoutFromNDS(void)
{
int err = 0;
if (PathCtxt_UserConnection1)
{
err = NXFreePathContext(PathCtxt_UserConnection1);
if (err)
printf(" * Details: NXFreePathContext2 failed
with rc=%d, errno: %d\n",err,errno);
PathCtxt_UserConnection1 = 0;
}
if (PathCtxt_UserConnection2)
{
err = NXFreePathContext(PathCtxt_UserConnection2);
if (err)
printf(" * Details: NXFreePathContext2 failed
with rc=%d, errno: %d\n",err,errno);
PathCtxt_UserConnection2 = 0;
}
delete_identity(ServerIdentity1);
delete_identity(ServerIdentity2);
return TRUE;
}
int MirrorDir(char *startPath, char *destPath)
{
char *start, reentpath[PATH_MAX+1] = "\0", *checkpath;
NXDirAttrWithName_t *pFileNameAttr;
int i;
char buffer[1024];
NXHandle_t desHand;
size_t entriesReturned;
NXDirMark_t next;
NXPathCtx_t pCtx;
int rc;
NXBool_t sequenceGuarantee;
PathCtxt_UserConnection1 = 0;
rc = NXCreatePathContext(0, startPath, NX_PNF_DEFAULT, (void
*) ServerIdentity1, &PathCtxt_UserConnection1);
if (rc)
{
consoleprintf("\n * Details: NXCreatePathContext1
failed with rc=%d, errno: %d\n",rc,errno);
return FALSE;
}
rc = NXDirEnumStart(PathCtxt_UserConnection1, ".",
NX_DELEVEL_NAME_ONLY, &desHand);
if (rc)
return FALSE;
rc = NXDirMarkInit(desHand, &next);
if (rc)
return FALSE;
rc=0;
do
{
rc = NXDirEnumGetEntries(desHand, &next, &buffer,
sizeof(buffer), &entriesReturned, &next, &sequenceGuarantee);
start = buffer;
for (i = 0; i < entriesReturned; i++)
{
NXThreadYield();
pFileNameAttr = (NXDirAttrWithName_t *)start;
switch(pFileNameAttr->deHeader.objectType)
{
case NX_OBJ_FILE:
{
printf("%s\n",
pFileNameAttr->deName);
break;
}
case NX_OBJ_DIR:
{
printf("%s/%s [DIR]\n",
startPath, pFileNameAttr->deName);
rc = strcmp(".",
pFileNameAttr->deName);
if(rc != 0)
{
rc = strcmp("..",
pFileNameAttr->deName);
if(rc != 0)
{
sprintf(reentpath, "%s/%s", startPath, pFileNameAttr->deName);
checkpath =
strdup(reentpath);
CheckRemoteDir(checkpath, destPath);
free(checkpath);
MirrorDir(reentpath, destPath);
}
}
break;
}
default:
{
printf("%s [%0x08X]\n",
pFileNameAttr->deName, pFileNameAttr->deHeader.objectType );
break;
}
}
start += pFileNameAttr->deHeader.length;
}
}while (rc != NX_EEXHAUSTED);
rc = NXDirEnumEnd(desHand);
return TRUE;
}
int CheckRemoteDir(char *remotePath, char *destinationServerVolume)
{
char *start, reentpath[PATH_MAX+1] = "\0",
pathcontextexist[PATH_MAX+1], dircreated[PATH_MAX+1];
NXDirAttrWithName_t *pFileNameAttr;
int i, j, k;
NXPathCtx_t PathCtxt_UserConnection3 = 0;
char buffer[1024], *ptr;
NXHandle_t desHand;
size_t entriesReturned;
NXDirMark_t next;
NXPathCtx_t pCtx;
int rc;
NXBool_t sequenceGuarantee;
PathCtxt_UserConnection3 = 0;
ptr = strchr(remotePath, ':');
i = ptr-remotePath;
i++;
k = strlen(remotePath);
strcpy(pathcontextexist, destinationServerVolume);
j=strlen(pathcontextexist);
for(j,i; i<k; i++, j++)
pathcontextexist[j] = remotePath[i];
pathcontextexist[j] = '\0';
printf("remotePath become: %s\n", pathcontextexist);
// pressanykey();
strcpy(remotePath, pathcontextexist);
rc = NXCreatePathContext(0, remotePath, 0, (void *)
ServerIdentity2, &PathCtxt_UserConnection3);
if (!rc)
{
printf("\nRemote path exist: %s\n", remotePath);
pressanykey();
return TRUE;
}
else
{
strcpy(reentpath, remotePath);
i = strlen(reentpath);
k = i;
for(i;i>0;i--)
{
if((reentpath[i] == '\\') || (reentpath[i] ==
'/'))
break;
}
for(j=0; j < i; j++)
pathcontextexist[j] = reentpath[j];
pathcontextexist[j] = '\0';
for(i, j=0; i <=k; i++, j++)
dircreated[j] = reentpath[i];
dircreated[j] = '\0';
printf("\nCreate remote path:%s->%s\n",
pathcontextexist, dircreated);
rc = NXCreatePathContext(0, pathcontextexist, 0, (void
*) ServerIdentity2, &PathCtxt_UserConnection3);
if (rc)
{
printf("\nError in getting path context %s,
rc=%d, errno=0x%04x\n", pathcontextexist, rc, errno);
pressanykey();
return FALSE;
}
else
{
rc = NXDirCreate(PathCtxt_UserConnection3,
dircreated, 0, &PathCtxt_UserConnection3);
if(rc)
{
printf("\nError creating: %s rc: %d,
errno: %d\n", reentpath, rc, errno);
pressanykey();
if (PathCtxt_UserConnection3)
{
rc =
NXFreePathContext(PathCtxt_UserConnection3);
if (rc)
printf(" * Details:
NXFreePathContext3-1 failed with rc=%d, errno: %d\n",rc,errno);
PathCtxt_UserConnection3 = 0;
}
return FALSE;
}
if (PathCtxt_UserConnection3)
{
rc =
NXFreePathContext(PathCtxt_UserConnection3);
if (rc)
printf(" * Details:
NXFreePathContext3-2 failed with rc=%d, errno: %d\n",rc,errno);
PathCtxt_UserConnection3 = 0;
}
}
return TRUE;
}
}
int main(int argc, char *argv[])
{
FILE *inifile;
char options[280] = "\0", opt1[280] = "\0";
int optval, i, rc;
char Nds_Treename[MAX_TREENAME_LEN] = "\0";
char Nds_UserName[MAX_DN_CHARS] = "\0";
char Nds_Password[MAX_DN_CHARS] = "\0";
char SourcePath[PATH_MAX+1];
char DestinationPath[PATH_MAX+1];
char *PathPtr;
if(argc == 1 || argc > 2)
{
consoleprintf("\n\nUsage:\n\t%s <inifile>\n",
argv[0]);
return FALSE;
}
if ((inifile = fopen(argv[1], "rt")) == NULL)
{
printf("\n\bCannot open ini file: %s\n", argv[1]);
return FALSE;
}
memset(Nds_Treename, ' ', MAX_TREENAME_LEN);
memset(Nds_UserName, ' ', MAX_DN_CHARS);
memset(Nds_Password, ' ', MAX_DN_CHARS);
optval = 0;
while(!feof(inifile))
{
fgets(options, 256, inifile);
rc = strnicmp("[nds]", options, 5);
if(!rc)
{
fgets(opt1, 280, inifile);
rc = strnicmp("treename=", opt1, 9);
if(!rc)
{
for(i=9;;i++)
{
if(opt1[i] == '\n')
break;
else
Nds_Treename[i-9] =
opt1[i];
}
Nds_Treename[i-9] = '\0';
}
fgets(opt1, 280, inifile);
rc = strnicmp("username=", opt1, 9);
if(!rc)
{
for(i=9;;i++)
{
if(opt1[i] == '\n')
break;
else
Nds_UserName[i-9] =
opt1[i];
}
Nds_UserName[i-9] = '\0';
}
fgets(opt1, 280, inifile);
rc = strnicmp("password=", opt1, 9);
if(!rc)
{
for(i=9;;i++)
{
if(opt1[i] == '\n')
break;
else
Nds_Password[i-9] =
opt1[i];
}
Nds_Password[i-9] = '\0';
}
break;
}
}
fclose(inifile);
#ifdef DEBUG
printf("\nDone reading ini file.\n");
printf("\nTreename: %s, Username: %s, password: %s\n",
Nds_Treename, Nds_UserName, Nds_Password);
#endif
if(strlen(Nds_Treename) && strlen(Nds_UserName) &&
strlen(Nds_Password))
{
if (!LoginToNDS(Nds_Treename, Nds_UserName,
Nds_Password))
printf(" -!> ERROR logging in to server!\n");
}
else
{
consoleprintf("\nNo login credetials provided, don't
know how to continue.\n");
return FALSE;
}
if ((inifile = fopen(argv[1], "rt")) == NULL)
{
printf("\n\bCannot open ini file: %s\n", argv[1]);
return FALSE;
}
memset(SourcePath, ' ', PATH_MAX+1);
memset(DestinationPath, ' ', PATH_MAX+1);
optval = 0;
while(!feof(inifile))
{
fgets(options, 256, inifile);
rc = strnicmp("[mirrorpaths]", options, 11);
if(!rc)
{
fgets(options, 2048, inifile);
PathPtr = strchr(options, '=');
if(PathPtr)
{
for(i=0; i< (PathPtr-options); i++)
SourcePath[i] = options[i];
SourcePath[i++] = '\0';
for(i,rc=0; i<strlen(options)-1; i++,
rc++)
DestinationPath[rc]=options[i];
DestinationPath[rc] = '\0';
}
printf("\nMirror: %s -> %s", SourcePath,
DestinationPath);
MirrorDir(SourcePath, DestinationPath);
}
}
fclose(inifile);
LogoutFromNDS();
printf("\nDone.\n");
pressanykey();
}
|