#include "db_config.h"
#include "db_int.h"
int
__os_exists(env, path, isdirp)
ENV *env;
const char *path;
int *isdirp;
{
DB_ENV *dbenv;
DWORD attrs;
_TCHAR *tpath;
int ret;
dbenv = env == NULL ? NULL : env->dbenv;
TO_TSTRING(env, path, tpath, ret);
if (ret != 0)
return (ret);
if (dbenv != NULL &&
FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS | DB_VERB_FILEOPS_ALL))
__db_msg(env, "fileops: stat %s", path);
RETRY_CHK(
((attrs = GetFileAttributes(tpath)) == (DWORD)-1 ? 1 : 0), ret);
if (ret == 0) {
if (isdirp != NULL)
*isdirp = (attrs & FILE_ATTRIBUTE_DIRECTORY);
} else
ret = __os_posix_err(ret);
FREE_STRING(env, tpath);
return (ret);
}
int
__os_ioinfo(env, path, fhp, mbytesp, bytesp, iosizep)
ENV *env;
const char *path;
DB_FH *fhp;
u_int32_t *mbytesp, *bytesp, *iosizep;
{
int ret;
BY_HANDLE_FILE_INFORMATION bhfi;
unsigned __int64 filesize;
RETRY_CHK((!GetFileInformationByHandle(fhp->handle, &bhfi)), ret);
if (ret != 0) {
__db_syserr(env, ret, "GetFileInformationByHandle");
return (__os_posix_err(ret));
}
filesize = ((unsigned __int64)bhfi.nFileSizeHigh << 32) +
bhfi.nFileSizeLow;
if (mbytesp != NULL)
*mbytesp = (u_int32_t)(filesize / MEGABYTE);
if (bytesp != NULL)
*bytesp = (u_int32_t)(filesize % MEGABYTE);
if (iosizep != NULL)
*iosizep = DB_DEF_IOSIZE;
return (0);
}