Exemple #1
0
int nb_Mkdir(char *Directory)
{
    DWORD   rc;
    char    FileName[128];
    char    command[256];
    char    NewDirectory[256];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if (strlen(Directory) == 0)
    {
        return(LeaveThread(1, "mkdir failed on no path specified\n", CMD_MKDIR));
    }
    strcpy(NewDirectory, Directory);
    memset(command, '\0', sizeof(command));
    strcpy(command,"mkdir ");
    strcat(command, NewDirectory);

    StartFirstTimer();
    rc = system(command);

    if (rc > 1)
    {
        EndFirstTimer(CMD_MKDIR, 0);
        sprintf(temp,  "mkdir failed on %s\n", command);
        LeaveThread(rc, temp, CMD_MKDIR);
        sprintf(temp, "ERROR: Thread %d - mkdir failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_MKDIR, 1);
    return(0);
}
Exemple #2
0
int nb_Move(char *Source, char *Destination)
{
    DWORD   rc;
    char    command[256];
    char    FileName[128];
    char    temp[512];
    char    NewSource[256];
    char    NewDestination[256];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if ((strlen(Source) == 0) || (strlen(Destination) == 0))
    {
        return(LeaveThread(1, "nb_Move failed to move: either source or destination is missing\n", CMD_MOVE));
    }
    strcpy(NewSource, Source);
    strcpy(NewDestination, Destination);
    memset(command, '\0', sizeof(command));
    sprintf(command, "move /Y %s %s > .\\test\\%s%d", NewSource, NewDestination, HostName, ProcessNumber);
    StartFirstTimer();
    rc = system(command);

    if (rc)
    {
        EndFirstTimer(CMD_MOVE, 0);
        sprintf(temp, "move failed on \"%s\"\n", command);
        LeaveThread(rc, temp, CMD_MOVE);
        sprintf(temp, "FAILURE: Thread %d - move failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_MOVE, 1);
    return(0);
}
Exemple #3
0
int nb_DeleteFile(char *path)
{
    DWORD   rc;
    char    FileName[128];
    char    command[256];
    char    NewPath[256];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if (strlen(path) == 0)
    {
        return(LeaveThread(1, "nb_DeleteFile failed to delete files: no path specified\n", CMD_DELETEFILES));
    }
    strcpy(NewPath, path);

    memset(command, '\0', sizeof(command));
    sprintf(command, "del /Q %s", NewPath);

    StartFirstTimer();
    rc = system(command);

    if (rc)
    {
        EndFirstTimer(CMD_DELETEFILES, 0);
        sprintf(temp, "del failed on \"%s\"\n", NewPath);
        LeaveThread(rc, temp, CMD_DELETEFILES);
        sprintf(temp, "ERROR: Thread %d - del failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_DELETEFILES, 1);
    return(0);
}
Exemple #4
0
int nb_CreateFile(char *path, DWORD size)
{
    char    NewPath[256];
    char    Buffer[512];
    char    temp[512];
    char    FileName[128];
    HANDLE  fHandle;
    DWORD   Moved;
    DWORD   BytesWritten;
    DWORD   BytesToWrite;
    BOOL    rc;
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if (strlen(path) == 0)
    {
        return(LeaveThread(1, "nb_CreateFile failed no path specified\n", CMD_CREATEFILE));
    }

    strcpy(NewPath, path);

    StartFirstTimer();
    fHandle = CreateFile(NewPath, 
                         GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_ALL,
                         FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                         NULL,
                         CREATE_ALWAYS,
                         FILE_ATTRIBUTE_NORMAL,
                         NULL);
    gle = GetLastError();
    if (fHandle == INVALID_HANDLE_VALUE)
    {
        EndFirstTimer(CMD_CREATEFILE, 0);
        sprintf(temp, "Create file failed on \"%s\" GLE(0x%x)\n", NewPath, gle);
        LeaveThread(0, temp, CMD_CREATEFILE);
        sprintf(temp, "ERROR: Thread %d - Create file failed on \"%s\" GLE(0x%x)\n", ProcessNumber, NewPath, gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_CREATEFILE, 1);
    Moved = SetFilePointer(fHandle,
                           size - sizeof(Buffer) <= 0 ? 0 : size - sizeof(Buffer),
                           NULL,
                           FILE_BEGIN);
    memset(Buffer, 'A', sizeof(Buffer));
    BytesToWrite = sizeof(Buffer);
    rc = WriteFile(fHandle, Buffer, BytesToWrite, &BytesWritten, NULL);

    FlushFileBuffers(fHandle);
    CloseHandle(fHandle);

    return(0);
}
Exemple #5
0
int nb_close(int handle)
{
    int     i;
    int     ret;
    char    FileName[128];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    if ((i = FindHandle(handle)) == -1)
        return(0);

    StartFirstTimer();
    ret = nb_close1(ftable[i].fd); 
    EndFirstTimer(CMD_CLOSE, ret);
    if (!ret) 
    {
        LeaveThread(0, "", CMD_CLOSE);
        sprintf(temp, "(%d) close failed on handle %d\n", LineCount, handle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }

    ftable[i].handle = 0;
    ftable[i].fd = 0;
    if (ftable[i].name) 
        free(ftable[i].name);
    ftable[i].name = NULL;
    return(0);   
}
Exemple #6
0
int nb_rmdir(char *fname)
{
    int     rc;
    pstring path;
    char    FileName[128];
    char    temp[512];
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(path, AfsLocker);
    strcat(path, fname);

    StartFirstTimer();
    rc = RemoveDirectory(path);
    gle = GetLastError();
    EndFirstTimer(CMD_RMDIR, rc);

    if (!rc)
    {
        LeaveThread(0, "", CMD_RMDIR);
        sprintf(temp, "Directory: RemoveDirectory %s failed GLE(0x%x)\n", fname, gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    return(0);
}
Exemple #7
0
int nb_unlink(char *fname)
{
    int     rc;
    char    temp[512];
    char    FileName[128];
    pstring path;
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(path, AfsLocker);
    strcat(path, fname);

    StartFirstTimer();
    rc = DeleteFile(path);
    gle = GetLastError();
    EndFirstTimer(CMD_UNLINK, 1);
    if (!rc)
    {
        LeaveThread(0, "", CMD_UNLINK);
        sprintf(temp, "FILE: DeleteFile %s failed GLE(0x%x)\n", path, gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }

    return(0);
}
Exemple #8
0
int nb_qfileinfo(int handle)
{
    int     i;
    int     rc;
    char    FileName[128];
    char    temp[512];
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    if ((i = FindHandle(handle)) == -1)
        return(-1);

    StartFirstTimer();
    rc = GetFileInfo(ftable[i].name, ftable[i].fd, NULL, NULL, NULL, NULL, NULL, NULL);
    gle = GetLastError();
    if (!rc)
    {
        EndFirstTimer(CMD_QUERY_FILE_INFO, 0);
        LeaveThread(0, "", CMD_QUERY_FILE_INFO);
        sprintf(temp, "File: qfileinfo failed for %s GLE(0x%x)\n", ftable[i].name, gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_QUERY_FILE_INFO, 1);

    return(0);
}
Exemple #9
0
int nb_findfirst(char *mask)
{
    int     rc;
    char    FileName[128];
    char    NewMask[512];
    char    temp[512];

    if (strstr(mask, "<.JNK"))
        return(0);

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(NewMask, AfsLocker);
    strcat(NewMask, mask);

    StartFirstTimer();
    rc = GetFileList(NewMask, (void *)find_fn, NULL);

    if (!rc)
    {
        EndFirstTimer(CMD_FIND_FIRST, 0);
        sprintf(temp, "File: findfirst cannot find for %s\n", mask);
        if (verbose)
            printf("%s", temp);
        LeaveThread(1, temp, CMD_FIND_FIRST);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_FIND_FIRST, 1);
    return(0);
}
Exemple #10
0
int nb_readx(int handle, int offset, int size, int ret_size)
{
    int     i;
    ssize_t ret;
    char    FileName[128];
    char    temp[512];
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    if ((i = FindHandle(handle)) == -1)
        return(-1);

    StartFirstTimer();
    ret = nb_read(ftable[i].fd, IoBuffer, offset, size);
    gle = GetLastError();
    if ((ret != size) && (ret != ret_size))
    {
        EndFirstTimer(CMD_READX, 0);
        LeaveThread(0, "", CMD_READX);
        if (ret == 0)
            sprintf(temp, "File: read failed on index=%d, offset=%d ReadSize=%d ActualRead=%d handle=%p GLE(0x%x)\n",
                    handle, offset, size, ret, ftable[i].fd, gle);
        if (ret == -1)
            sprintf(temp, "File: %s. On read, cannot set file pointer GLE(0x%x)\n", ftable[i].name, gle);
        if (verbose)
            printf("%s", temp);
        nb_close(handle);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_READX, 1);
    ftable[i].reads++;
    return(0);
}
Exemple #11
0
void delete_fn(file_info *finfo, const char *name, void *state)
{
    int     rc;
    char    temp[512];
    char    s[1024];
    char    FileName[128];
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    if (finfo->mode & aDIR) 
    {
        char s2[1024];
        sprintf(s2, "%s\\*", name);
        GetFileList(s2, delete_fn, NULL);
        sprintf(s, "%s", &name[strlen(AfsLocker)]);
        nb_rmdir(s);
    }
    else
    {
        rc = DeleteFile(name);
        gle = GetLastError();
        if (!rc)
        {
            LeaveThread(0, "", CMD_UNLINK);
            sprintf(temp, "FILE: DeleteFile %s failed GLE(0x%x)\n", name, gle);
            if (verbose)
                printf("%s", temp);
            LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
            return;
        }
    }
    return;
}
Exemple #12
0
LastFMServices::~LastFMServices(void)
{
	m_bExitThread = TRUE;
	if (m_pThread != NULL)
	{
		LeaveThread(m_pThread->m_hThread, 500);
	}
}
Exemple #13
0
int nb_Detach(char *Name, char *type)
{
    DWORD   rc;
    char    FileName[128];
    char    command[512];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    memset(command, '\0', sizeof(command));
    strcpy(command,"detach -q ");
    rc = 0;
    if (!stricmp(type, "drive"))
    {
        sprintf(temp, "-D %s ", Name);
        strcat(command, temp);
    }
    else if (!stricmp(type, "locker"))
    {
        strcat(command, Name);
    }
    else
    {
        return(LeaveThread(1, "nb_Detach failed unknown type: %s\n", CMD_DETACH));
    }

    StartFirstTimer();
    rc = system(command);

    if (rc)
    {
        EndFirstTimer(CMD_DETACH, 0);
        sprintf(temp, "detach failed on %s\n", command);
        LeaveThread(rc, temp, CMD_DETACH);
        sprintf(temp, "ERROR: Thread %d - detach failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_DETACH, 1);
    return(0);
}
Exemple #14
0
int FindHandle(int handle)
{
    int i;
    for (i=0;i<MAX_FILES;i++)
    {
        if (ftable[i].handle == handle)
            return(i);
    }
    if (verbose)
        printf("(%d) ERROR: handle %d was not found\n", LineCount, handle);
    return(LeaveThread(1, "", -1));
}
Exemple #15
0
int nb_Xrmdir(char *Directory, char *type)
{
    DWORD   rc;
    char    FileName[128];
    char    command[256];
    char    NewDirectory[256];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if (strlen(Directory) == 0)
    {
        return(LeaveThread(1, "rmdir failed no path specified\n", CMD_XRMDIR));
    }
    strcpy(NewDirectory, Directory);
    memset(command, '\0', sizeof(command));
    strcpy(command,"rmdir /Q ");
    if (!stricmp(type, "all"))
    {
        strcat(command, "/S ");
    }
    strcat(command, NewDirectory);

    StartFirstTimer();
    rc = system(command);

    if ((rc) && (rc != 2) && (rc != 3))
    {
        EndFirstTimer(CMD_XRMDIR, 0);
        sprintf(temp, "rmdir failed on %s\n", command);
        LeaveThread(rc, temp, CMD_XRMDIR);
        sprintf(temp, "FAILURE: Thread %d - Xrmdir failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_XRMDIR, 1);
    return(0);
}
Exemple #16
0
int nb_CopyFile(char *Source, char *Destination)
{
    DWORD   rc;
    char    FileName[128];
    char    temp[512];
    char    command[256];
    char    NewSource[256];
    char    NewDestination[256];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if ((strlen(Source) == 0) || (strlen(Destination) == 0))
    {
        return(LeaveThread(1, "nb_CopyFile failed to copy files: either source or destination path not specified\n", CMD_COPYFILES));
    }
    strcpy(NewSource, Source);
    strcpy(NewDestination, Destination);

    memset(command, '\0', sizeof(command));
    sprintf(command, "copy /V /Y /B %s %s > .\\test\\%s%d", NewSource, NewDestination, HostName, ProcessNumber);

    StartFirstTimer();
    rc = system(command);

    if (rc)
    {
        EndFirstTimer(CMD_COPYFILES, 0);
        sprintf(temp, "copy failed on \"%s\"\n", command);
        LeaveThread(rc, temp, CMD_COPYFILES);
        sprintf(temp, "FAILURE: Thread %d - copy failed on \"%s\"\n", ProcessNumber, command);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        if (verbose)
            printf("%s", temp);
        return(-1);
    }
    EndFirstTimer(CMD_COPYFILES, 1);
    return(0);
}
Exemple #17
0
int nb_xcopy(char *Source, char *Destination)
{
    intptr_t   rc;
    char    FileName[128];
    char    temp[512];
    char    command[256];
    char    NewSource[256];
    char    NewDestination[256];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if ((strlen(Source) == 0) || (strlen(Destination) == 0))
    {
        return(LeaveThread(1, "nb_xcopy failed to xcopy: either source or destination is missing\n", CMD_XCOPY));
    }
    strcpy(NewSource, Source);
    strcpy(NewDestination, Destination);
    memset(command, '\0', sizeof(command));
    sprintf(command, "xcopy /E /I /V /Y /Q %s %s > .\\test\\%s%d", NewSource, NewDestination, HostName, ProcessNumber);

    StartFirstTimer();
    rc = SystemCall(command);

    if (rc)
    {
        EndFirstTimer(CMD_XCOPY, 0);
        sprintf(temp, "xcopy failed on %s\n", command);
        LeaveThread((int)rc, temp, CMD_XCOPY);
        sprintf(temp, "FAIURE: Thread %d - xcopy failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_XCOPY, 1);
    return(0);
}
Exemple #18
0
int nb_writex(int handle, int offset, int size, int ret_size)
{
    int     i;
    ssize_t status;
    char    FileName[128];
    char    temp[512];
    unsigned char magic = (unsigned char)getpid();

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    if (IoBuffer[0] != magic ||
        IoBuffer[1] != magic ||
        IoBuffer[2] != magic ||
        IoBuffer[3] != magic)
        memset(IoBuffer, magic, BufferSize);

    if ((i = FindHandle(handle)) == -1)
        return(-1);
    StartFirstTimer();
    status = nb_write(ftable[i].fd, IoBuffer, offset, size);
    if (status != ret_size) 
    {
        EndFirstTimer(CMD_WRITEX, 0);
		LeaveThread(0, "", CMD_WRITEX);
        if (status == 0)
            sprintf(temp, "File: %s. wrote %d bytes, got %d bytes\n", ftable[i].name, size, status);
        if (status == -1)
            sprintf(temp, "File: %s. On write, cannot set file pointer\n", ftable[i].name);
        if (verbose)
            printf("%s", temp);
        nb_close(handle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
	}
    EndFirstTimer(CMD_WRITEX, 1);

    ftable[i].writes++;
    return(0);
}
Exemple #19
0
int nb_deltree(char *dname)
{
    int     rc;
    char    mask[1024];
    pstring path;
    DWORD   gle;

    strcpy(path, AfsLocker);
    strcat(path, dname);
    sprintf(mask, "%s\\*", path);

    total_deleted = 0;

    StartFirstTimer();
    GetFileList(mask, delete_fn, NULL);

//    pstrcpy(path, AfsLocker);
//    pstrcat(path, dname);
    rc = RemoveDirectory(path);
    gle = GetLastError();
    EndFirstTimer(CMD_DELTREE, rc);
    if (!rc)
    {
        char FileName[256];
        char temp[512];

        if ((gle != ERROR_FILE_NOT_FOUND) && (gle != ERROR_PATH_NOT_FOUND))
        {
            LeaveThread(0, "", CMD_DELTREE);
            sprintf(FileName, "Thread_%05d.log", ProcessNumber);
            sprintf(temp, "ERROR: Thread %d - Unable to remove %s.\n", ProcessNumber, path);
            LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
            SetLastError(gle);
            if (verbose)
                printf(temp);
            return(-1);
        }
    }
    return(0);
}
Exemple #20
0
int nb_Attach(char *Locker, char *Drive)
{
    DWORD   rc;
    char    FileName[128];
    char    command[512];
    char    temp[512];

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    if (strlen(Locker) == 0)
    {
        return(LeaveThread(1, "attach failed no locker specified\n", CMD_ATTACH));
    }
    memset(command, '\0', sizeof(command));
    strcpy(command,"attach -q ");
    rc = 0;
    if (strlen(Drive) != 0)
    {
        sprintf(temp, "-D %s ", Drive);
        strcat(command, temp);
    }
    strcat(command, Locker);

    StartFirstTimer();
    rc = system(command);

    if (rc)
    {
        EndFirstTimer(CMD_ATTACH, 0);
        sprintf(pExitStatus->Reason, "attach failed on %s\n", command);
        pExitStatus->ExitStatus = rc;
        sprintf(temp, "ERROR: Thread %d - attach failed on \"%s\"\n", ProcessNumber, command);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
    }
    EndFirstTimer(CMD_ATTACH, 1);
    return(0);
}
Exemple #21
0
int nb_qfsinfo(int level)
{

//	int     bsize;
//    int     total;
//    int     avail;
    int     rc;
    char    FileName[128];
    char    temp[512];
    char    Path[512];
    ULARGE_INTEGER FreeBytesAvailable;
    ULARGE_INTEGER TotalNumberOfBytes;
    ULARGE_INTEGER TotalNumberOfFreeBytes;
    DWORD   gle;
 
    sprintf(FileName, "Thread_%05d.log", ProcessNumber);
    sprintf(Path, "%s\\%s%05d", AfsLocker, HostName, LogID);

    StartFirstTimer();
    rc = GetDiskFreeSpaceEx(Path, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
//    rc = cli_dskattr(c, &bsize, &total, &avail);
    gle = GetLastError();

    if (!rc)
    {
        EndFirstTimer(CMD_QUERY_FS_INFO, 0);
        LeaveThread(0, "", CMD_QUERY_FS_INFO);
        sprintf(temp, "File: Disk free space failed GLE(0x%x)\n", gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    EndFirstTimer(CMD_QUERY_FS_INFO, 1);

    return(0);
}
Exemple #22
0
/* 
 * Type is used to determine whether the file is expected 
 * to exist or not.  It is overloaded (temporarily) to control
 * Flag which indicates whether an error is treated as an error
 * or not.  The StreamFiles.txt script does not have the Type
 * parameter set correctly for all 120,000+ lines.  As a result
 * it is not possible to enforce the presence test throughout
 * the entire script.
 */
int nb_qpathinfo(char *fname, int Type)
{
    pstring path;
    int     rc;
    char    FileName[128];
    char    temp[512];
    DWORD   gle = 0;

    if (Type == 1111) {
        EnforcePathInfoErrors = 1;
        Type = 1;
    } else if (Type == 1001) {
        EnforcePathInfoErrors = 0;
        Type = 1;
    } else if (Type == 1000) {
        EnforcePathInfoErrors = 0;
        Type = 0;
    } else if (Type == 1110) {
        EnforcePathInfoErrors = 1;
        Type = 0;
    }

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(path, AfsLocker);
    strcat(path, fname);

    StartFirstTimer();
    rc = GetPathInfo(path, NULL, NULL, NULL, NULL, NULL);
    if (rc == 0)
        gle = GetLastError();
    if (strstr(fname, "~TS"))
    {
        if (rc == 0)
            rc = 1;
        else
            rc = 0;
    }

    if (!EnforcePathInfoErrors)
    {
        if (Type)
        {
            if (rc)
                rc = 0;
            else
                rc = 1;
        }
        if (!rc)
        {
            EndFirstTimer(CMD_QUERY_PATH_INFO, 0);
            LeaveThread(0, "", CMD_QUERY_PATH_INFO);
            sprintf(temp, "File: qpathinfo failed for %s type %d GLE(0x%x)\n", path, Type, gle);
            if (verbose)
                printf("%s", temp);
            LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
            return(-1);
        }
    }
    EndFirstTimer(CMD_QUERY_PATH_INFO, 1);
    return(0);
}
Exemple #23
0
int nb_createx(char *fname, unsigned create_options, unsigned create_disposition, int handle)
{
    HANDLE  fd;
    int     i;
    uint32  desired_access;
    char    FileName[128];
    char    temp[512];
    pstring path;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(path, AfsLocker);
    strcat(path, fname);
    if (create_options & FILE_DIRECTORY_FILE)
    {
        desired_access = FILE_READ_DATA;
    }
    else
    {
        desired_access = FILE_READ_DATA | FILE_WRITE_DATA;
    }

    StartFirstTimer();
    fd = CreateObject(path, 
                       desired_access,
                       0x0,
                       FILE_SHARE_READ|FILE_SHARE_WRITE, 
                       create_disposition, 
                       create_options);

    if (fd == INVALID_HANDLE_VALUE && handle != -1)
    {
        if (create_options & FILE_DIRECTORY_FILE)
        {
            EndFirstTimer(CMD_NTCREATEX, 0);
            LeaveThread(0, "", CMD_NTCREATEX);
            sprintf(temp, "Directory: unable to create directory %s\n", path);
            if (verbose)
                printf("%s", temp);
            LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
            return(-1);
        }
        else
        {
            EndFirstTimer(CMD_NTCREATEX, 0);
            LeaveThread(0, "", CMD_NTCREATEX);
            sprintf(temp, "File: unable to create file %s\n", path);
            if (verbose)
                printf("%s", temp);
            LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
            return(-1);
        }
    }

    EndFirstTimer(CMD_NTCREATEX, 1);

    if (fd != INVALID_HANDLE_VALUE && handle == -1)
    {
        CloseHandle(fd);
        nb_unlink(fname);
        return(0);
    }

    if (fd == INVALID_HANDLE_VALUE && handle == -1)
        return(0);

    for (i = 0; i < MAX_FILES; i++) 
    {
        if (ftable[i].handle == 0) 
            break;
    }
    if (i == MAX_FILES) 
    {
        printf("(%d) file table full for %s\n", LineCount, path);
        return(LeaveThread(1, "file table is full\n", CMD_NTCREATEX));
    }
    ftable[i].handle = handle;
    ftable[i].fd = fd;
    if (ftable[i].name) 
        free(ftable[i].name);
    ftable[i].name = strdup(path);
    ftable[i].reads = ftable[i].writes = 0;
    return(0);
}
Exemple #24
-1
int nb_rename(char *old, char *New)
{
    int     rc;
    pstring opath;
    pstring npath;
    char    FileName[128];
    char    temp[512];
    DWORD   gle;

    sprintf(FileName, "Thread_%05d.log", ProcessNumber);

    strcpy(opath, AfsLocker);
    strcat(opath, old);
    strcpy(npath, AfsLocker);
    strcat(npath, New); 

    StartFirstTimer();
    rc = MoveFileEx(opath, npath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
    gle = GetLastError();
    EndFirstTimer(CMD_RENAME, rc);

    if (!rc)
    {
        LeaveThread(0, "", CMD_RENAME);
        sprintf(temp, "File: rename %s %s failed GLE(0x%x)\n", old, New, gle);
        if (verbose)
            printf("%s", temp);
        LogMessage(ProcessNumber, HostName, FileName, temp, LogID);
        return(-1);
    }
    return(0);
}