1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/tools/bigfilewriter.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,166 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +//
1.21 +// T_BIGFILE_WRITER.CPP
1.22 +//
1.23 +
1.24 +
1.25 +
1.26 +#include <windows.h>
1.27 +
1.28 +#pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
1.29 +#include <winioctl.h>
1.30 +
1.31 +#include <stdio.h>
1.32 +
1.33 +#define __WRITE_FILE_CONTENTS__
1.34 +
1.35 +
1.36 +const DWORD K1Kb = 1 << 10;
1.37 +const DWORD K1Mb = 1 << 20;
1.38 +const DWORD K1Gb = 1 << 30;
1.39 +const DWORD K2Gb = 0x80000000;
1.40 +const DWORD K3Gb = 0xC0000000;
1.41 +const DWORD K4GbMinusOne = 0xFFFFFFFF;
1.42 +const DWORD KBufSize = 256 * K1Kb;
1.43 +
1.44 +BYTE gBuffer[KBufSize];
1.45 +
1.46 +template <class T>
1.47 +T Min(T aLeft,T aRight)
1.48 + {return(aLeft<aRight ? aLeft : aRight);}
1.49 +
1.50 +
1.51 +BOOL WriteFile(char* aFileName, DWORD aSize)
1.52 + {
1.53 + BOOL success = TRUE;
1.54 +
1.55 + HANDLE deviceHandle = CreateFileA(
1.56 + aFileName,
1.57 + GENERIC_WRITE, FILE_SHARE_WRITE,
1.58 + NULL, CREATE_ALWAYS, 0, NULL);
1.59 +
1.60 + if (deviceHandle == INVALID_HANDLE_VALUE)
1.61 + {
1.62 + printf("Open file error %d", GetLastError());
1.63 + return FALSE;
1.64 + }
1.65 +
1.66 +#ifdef __WRITE_FILE_CONTENTS__
1.67 +//printf("size of DWORD is %d", sizeof(DWORD));
1.68 + DWORD nNumberOfBytesToWrite;
1.69 + for (DWORD pos = 0; pos < aSize; pos+=nNumberOfBytesToWrite)
1.70 + {
1.71 + for (DWORD n=0; n<KBufSize; n+=4)
1.72 + {
1.73 + *((DWORD*) &gBuffer[n]) = pos + n;
1.74 + }
1.75 +
1.76 + nNumberOfBytesToWrite = Min(KBufSize, aSize - pos);
1.77 + DWORD nNumberOfBytesWritten;
1.78 +
1.79 + success = WriteFile (deviceHandle, gBuffer, nNumberOfBytesToWrite, &nNumberOfBytesWritten, NULL);
1.80 + if (!success)
1.81 + {
1.82 + printf("Write file error %d", GetLastError());
1.83 + break;
1.84 + }
1.85 + printf("\rWriting %s %lu%% done...", aFileName, (LONG64(pos) + LONG64(nNumberOfBytesToWrite)) * LONG64(100) / LONG64(aSize));
1.86 + }
1.87 +
1.88 + printf("\n");
1.89 +#else
1.90 + printf("Setting file size for %s to %u\n", aFileName, aSize);
1.91 + LONG dwSeekLo = (LONG) aSize;
1.92 + LONG dwSeekHi = 0;
1.93 + DWORD dwPos = SetFilePointer(deviceHandle, dwSeekLo, &dwSeekHi, FILE_BEGIN);
1.94 + if (dwPos != aSize)
1.95 + {
1.96 + printf("SetFilePointer() error %d", GetLastError());
1.97 + success = FALSE;
1.98 + }
1.99 + else
1.100 + {
1.101 + success = SetEndOfFile(deviceHandle);
1.102 + if (!success)
1.103 + {
1.104 + printf("SetFilePointer() error %d", GetLastError());
1.105 + }
1.106 + }
1.107 +
1.108 +#endif
1.109 +
1.110 + CloseHandle(deviceHandle);
1.111 + return success;
1.112 + }
1.113 +
1.114 +
1.115 +
1.116 +int main(int argc,char *argv[])
1.117 + {
1.118 + printf("BigFileWriter...\n");
1.119 +
1.120 + if (argc != 2)
1.121 + {
1.122 + printf("Creates big (between 2 & 4GB) files on a Windows drive for use by T_BIGFILE.EXE\n");
1.123 + printf("Syntax : BigFileWriter <drive letter>\n");
1.124 + exit(0);
1.125 + }
1.126 +
1.127 + char filePath[] = "\\\\.\\?:\\F32-TST";
1.128 +
1.129 + char driveLetter = argv[1][0];
1.130 + filePath[4] = driveLetter;
1.131 + printf("Creating big files on %s\n", filePath);
1.132 +
1.133 + BOOL success;
1.134 +
1.135 +
1.136 + success = CreateDirectory(filePath, NULL);
1.137 + if (!success && GetLastError() != ERROR_ALREADY_EXISTS)
1.138 + {
1.139 + printf("Unable to create directory %d", GetLastError());
1.140 + exit(4);
1.141 + }
1.142 +
1.143 + success = SetCurrentDirectory(filePath);
1.144 + if (!success)
1.145 + {
1.146 + printf("Unable to change to directory %d", GetLastError());
1.147 + exit(4);
1.148 + }
1.149 +
1.150 + success = WriteFile("File2GBMinusOne.txt", K2Gb-1);
1.151 + if (!success) exit(4);
1.152 +
1.153 + success = WriteFile("File2GB.txt", K2Gb);
1.154 + if (!success) exit(4);
1.155 +
1.156 + success = WriteFile("File3GB.txt", K3Gb);
1.157 + if (!success) exit(4);
1.158 +
1.159 + // NB This won't fit on an 8GB drive
1.160 + success = WriteFile("File4GBMinusOne.txt", K4GbMinusOne);
1.161 + if (!success)
1.162 + {
1.163 + DeleteFile("File4GBMinusOne.txt");
1.164 + exit(4);
1.165 + }
1.166 +
1.167 +
1.168 + return 0;
1.169 + }
1.170 \ No newline at end of file