It wouldn't have occurred to me that seeking was a problem, because if I were doing any
serious file system, I would not be using anything with a 32-bit limitation. Haven't
really worried about this problem since about 1997, when I did my first database that was
expected to hit terabytes. We just ignored the primitive and outdated C library, since it
did nothing useful for us. I notice you are still using the obsolete SetFilePointer,
instead of the more modern SetFilePointerEx, which has been around for a decade.
Also, returning the .QuadPart component should fail in any environment in which TINT is
declared as a DWORD, since the compiler should complain about truncation of a value (you
should always build at /W4). You should use the same cast as for the file size, (TINT).
On Thu, 14 Jan 2010 21:51:24 -0500, Hector Santos <sant9442@nospam.gmail.com> wrote:
Joseph M. Newcomer wrote:
Yes, but the file size was given as 50MB.
joe
Its amazing how "big" is relative these days. My first computer had a
$1,500 Micropolis 10 meg drive! :)
BTW, it (the code posted) should not be an issue when just streaming
in a file of any size.
The problem begins when seeking a file.
When seeking is required, we know by using the 64 bit WIN32 file I/O
functions that it works for large +2gig files.
In one part of our server product file handing, a ISAM database with
four key index files have DWORD position indices. Issues occur as the
database grows and a index goes beyond a 32 bit value. A documented
limitation but a limitations that is not outdated.
A simple solution in the works was to use the 64 bit extended file I/O
functions which offer QUAD (double DWORD) positions. Its about to be
implemented in new major revision of our server.
For backward single source compatibility, I produced a header and
wrapper functions. Here is the *.h and *.cpp files:
//------------------------------------------------------------
// File Name : ss64lib.h
//------------------------------------------------------------
#ifndef __SS64LIB_H
#define __SS64LIB_H
#ifndef _WINDOWS_
#include <windows.h>
#endif
#define SUPPORT_FILEIO_64BIT
#ifdef SUPPORT_FILEIO_64BIT
# define TINT INT64
# define TWORD QWORD
# define TFILESIZE INT64
# define MAXQWORD _UI64_MAX
# define MAXINT64 _I64_MAX
#else
# define TINT DWORD
# define TWORD DWORD
# define TFILESIZE DWORD
#endif
TINT ssFileSeek(HANDLE hf, TINT distance,
WORD MoveMethod = FILE_BEGIN);
TINT ssFileEnd(HANDLE hf);
TINT ssFilePos(HANDLE hf);
BOOL ssFileRewind(HANDLE hf);
BOOL ssFileLock(HANDLE hf, TINT Offset, TINT nBytes);
BOOL ssFileUnlock(HANDLE hf, TINT Offset, TINT nBytes);
TFILESIZE ssFileSize(HANDLE hf);
#endif // __SS64LIB_H
//------------------------------------------------------------
// File Name : ss64lib.cpp
//------------------------------------------------------------
#include "ss64lib.h"
TINT ssFileSeek(HANDLE hf, TINT dist, WORD method)
{
LARGE_INTEGER li;
li.QuadPart = dist;
li.LowPart = SetFilePointer (hf, li.LowPart, &li.HighPart, method);
if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
li.QuadPart = -1;
}
return li.QuadPart;
}
BOOL ssFileRewind(HANDLE hf)
{
return ssFileSeek(hf,0,FILE_BEGIN) == 0;
}
TINT ssFilePos(HANDLE hf)
{
return ssFileSeek(hf,0,FILE_CURRENT);
}
TINT ssFileEnd(HANDLE hf)
{
return ssFileSeek(hf,0,FILE_END);
}
BOOL ssFileLock(HANDLE hf, TINT Offset, TINT nBytes)
{
LARGE_INTEGER fp, nb;
fp.QuadPart = Offset;
nb.QuadPart = nBytes;
return LockFile (hf,fp.LowPart,fp.HighPart,nb.LowPart,nb.HighPart);
}
BOOL ssFileUnlock(HANDLE hf, TINT Offset, TINT nBytes)
{
LARGE_INTEGER fp, nb;
fp.QuadPart = Offset;
nb.QuadPart = nBytes;
return UnlockFile(hf,fp.LowPart,fp.HighPart,nb.LowPart,nb.HighPart);
}
TFILESIZE ssFileSize(HANDLE hf)
{
LARGE_INTEGER li;
li.LowPart = GetFileSize(hf,(DWORD *)&li.HighPart);
return (TINT)li.QuadPart;
}
Joseph M. Newcomer [MVP]