tstFile.cpp revision 5eabf773597082761832bc0a32b3660e8771f9f1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* $Id$ */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/** @file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * IPRT Testcase - File I/O.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (C) 2006-2007 Sun Microsystems, Inc.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This file is part of VirtualBox Open Source Edition (OSE), as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * available from http://www.virtualbox.org. This file is free software;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * you can redistribute it and/or modify it under the terms of the GNU
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * General Public License (GPL) as published by the Free Software
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Foundation, in version 2 as it comes in the "COPYING" file of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file may alternatively be used under the terms
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the Common Development and Distribution License Version 1.0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VirtualBox OSE distribution, in which case the provisions of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL are applicable instead of those of the GPL.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may elect to license modified versions of this file under the
12b65585e720714b31036daaa2b30eb76014048eGordon Ross * terms and conditions of either the GPL or the CDDL or both.
12b65585e720714b31036daaa2b30eb76014048eGordon Ross *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Clara, CA 95054 USA or visit http://www.sun.com if you need
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * additional information or have any questions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/*******************************************************************************
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw* Header Files *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw*******************************************************************************/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <iprt/file.h>
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas#include <iprt/err.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <iprt/string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <iprt/stream.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <iprt/initterm.h>
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint main()
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States int cErrors = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: TESTING\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTR3Init();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTFILE File;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc = RTFileOpen(&File, "tstFile#1.tst", RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: FATAL ERROR - Failed to open file #1. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTFOFF cbMax = -2;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileGetMaxSizeEx(File, &cbMax);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: RTFileGetMaxSizeEx failed: %Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (cbMax <= 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: RTFileGetMaxSizeEx failed: cbMax=%RTfoff\n", cbMax);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (RTFileGetMaxSize(File) != cbMax)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: RTFileGetMaxSize failed; returns %RTfoff instead of %RTfoff\n", RTFileGetMaxSize(File), cbMax);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Maximum file size is %RTfoff bytes.\n", cbMax);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /* grow file beyond 2G */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileSetSize(File, _2G + _1M);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to grow file #1 to 2.001GB. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego uint64_t cb;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileGetSize(File, &cb);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (RT_FAILURE(rc))
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to get file size of #1. rc=%Rrc\n", rc);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (cb != _2G + _1M)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego RTPrintf("RTFileGetSize return %RX64 bytes, expected %RX64.\n", cb, _2G + _1M);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: cb=%RX64\n", cb);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Try some writes at the beginning of the file.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t offFile = RTFileTell(File);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (offFile != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego RTPrintf("RTFileTell -> %#RX64, expected 0 (#1)\n", offFile);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego static const char szTestBuf[] = "Sausages and bacon for breakfast again!";
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States size_t cbWritten = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (cbWritten < sizeof(szTestBuf))
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t cbWrittenPart;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileWrite(File, &szTestBuf[cbWritten], sizeof(szTestBuf) - cbWritten, &cbWrittenPart);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego break;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cbWritten += cbWrittenPart;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to write to file #1 at offset 0. rc=%Rrc\n", rc);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* check that it was written correctly. */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego rc = RTFileSeek(File, 0, RTFILE_SEEK_BEGIN, NULL);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to seek offset 0 in file #1. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char szReadBuf[sizeof(szTestBuf)];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t cbRead = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (cbRead < sizeof(szTestBuf))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t cbReadPart;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileRead(File, &szReadBuf[cbRead], sizeof(szTestBuf) - cbRead, &cbReadPart);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cbRead += cbReadPart;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to read from file #1 at offset 0. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!memcmp(szReadBuf, szTestBuf, sizeof(szTestBuf)))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: head write ok\n");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Data read from file #1 at offset 0 differs from what we wrote there.\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Try some writes at the end of the file.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = RTFileSeek(File, _2G + _1M, RTFILE_SEEK_BEGIN, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego RTPrintf("Failed to seek to _2G + _1M in file #1. rc=%Rrc\n", rc);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States offFile = RTFileTell(File);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (offFile != _2G + _1M)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("RTFileTell -> %#llx, expected %#llx (#2)\n", offFile, _2G + _1M);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States size_t cbWritten = 0;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while (cbWritten < sizeof(szTestBuf))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States size_t cbWrittenPart;
12b65585e720714b31036daaa2b30eb76014048eGordon Ross rc = RTFileWrite(File, &szTestBuf[cbWritten], sizeof(szTestBuf) - cbWritten, &cbWrittenPart);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross if (RT_FAILURE(rc))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States break;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cbWritten += cbWrittenPart;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to write to file #1 at offset 2G + 1M. rc=%Rrc\n", rc);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = RTFileSeek(File, offFile, RTFILE_SEEK_BEGIN, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to seek offset %RX64 in file #1. rc=%Rrc\n", offFile, rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char szReadBuf[sizeof(szTestBuf)];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t cbRead = 0;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas while (cbRead < sizeof(szTestBuf))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas size_t cbReadPart;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileRead(File, &szReadBuf[cbRead], sizeof(szTestBuf) - cbRead, &cbReadPart);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cbRead += cbReadPart;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to read from file #1 at offset 2G + 1M. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego else
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!memcmp(szReadBuf, szTestBuf, sizeof(szTestBuf)))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("tstFile: tail write ok\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Data read from file #1 at offset 2G + 1M differs from what we wrote there.\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Some general seeking around.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileSeek(File, _2G + 1, RTFILE_SEEK_BEGIN, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States RTPrintf("Failed to seek to _2G + 1 in file #1. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offFile = RTFileTell(File);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (offFile != _2G + 1)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States RTPrintf("RTFileTell -> %#llx, expected %#llx (#3)\n", offFile, _2G + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* seek end */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = RTFileSeek(File, 0, RTFILE_SEEK_END, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("Failed to seek to end of file #1. rc=%Rrc\n", rc);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States offFile = RTFileTell(File);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (offFile != _2G + _1M + sizeof(szTestBuf)) /* assuming tail write was ok. */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw RTPrintf("RTFileTell -> %#RX64, expected %#RX64 (#4)\n", offFile, _2G + _1M + sizeof(szTestBuf));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* seek start */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = RTFileSeek(File, 0, RTFILE_SEEK_BEGIN, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (RT_FAILURE(rc))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
12b65585e720714b31036daaa2b30eb76014048eGordon Ross RTPrintf("Failed to seek to end of file #1. rc=%Rrc\n", rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cErrors++;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offFile = RTFileTell(File);
if (offFile != 0)
{
RTPrintf("RTFileTell -> %#llx, expected 0 (#5)\n", offFile);
cErrors++;
}
}
}
/*
* Cleanup.
*/
rc = RTFileClose(File);
if (RT_FAILURE(rc))
{
RTPrintf("Failed to close file #1. rc=%Rrc\n", rc);
cErrors++;
}
rc = RTFileDelete("tstFile#1.tst");
if (RT_FAILURE(rc))
{
RTPrintf("Failed to delete file #1. rc=%Rrc\n", rc);
cErrors++;
}
/*
* Summary
*/
if (cErrors == 0)
RTPrintf("tstFile: SUCCESS\n");
else
RTPrintf("tstFile: FAILURE - %d errors\n", cErrors);
return !!cErrors;
}