Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_stat.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_stat.c,v 12.1 2005/06/16 20:23:31 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #include <sys/stat.h>
00015 
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 
00021 /*
00022  * __os_exists --
00023  *      Return if the file exists.
00024  */
00025 int
00026 __os_exists(path, isdirp)
00027         const char *path;
00028         int *isdirp;
00029 {
00030         int ret;
00031         DWORD attrs;
00032         _TCHAR *tpath;
00033 
00034         if (DB_GLOBAL(j_exists) != NULL)
00035                 return (DB_GLOBAL(j_exists)(path, isdirp));
00036 
00037         TO_TSTRING(NULL, path, tpath, ret);
00038         if (ret != 0)
00039                 return (ret);
00040 
00041         RETRY_CHK(
00042             ((attrs = GetFileAttributes(tpath)) == (DWORD)-1 ? 1 : 0), ret);
00043 
00044         if (ret == 0 && isdirp != NULL)
00045                 *isdirp = (attrs & FILE_ATTRIBUTE_DIRECTORY);
00046 
00047         FREE_STRING(NULL, tpath);
00048         return (ret);
00049 }
00050 
00051 /*
00052  * __os_ioinfo --
00053  *      Return file size and I/O size; abstracted to make it easier
00054  *      to replace.
00055  */
00056 int
00057 __os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
00058         DB_ENV *dbenv;
00059         const char *path;
00060         DB_FH *fhp;
00061         u_int32_t *mbytesp, *bytesp, *iosizep;
00062 {
00063         int ret;
00064         BY_HANDLE_FILE_INFORMATION bhfi;
00065         unsigned __int64 filesize;
00066 
00067         if (DB_GLOBAL(j_ioinfo) != NULL)
00068                 return (DB_GLOBAL(j_ioinfo)(path,
00069                     fhp->fd, mbytesp, bytesp, iosizep));
00070 
00071         RETRY_CHK((!GetFileInformationByHandle(fhp->handle, &bhfi)), ret);
00072         if (ret != 0) {
00073                 __db_err(dbenv,
00074                     "GetFileInformationByHandle: %s", strerror(ret));
00075                 return (ret);
00076         }
00077 
00078         filesize = ((unsigned __int64)bhfi.nFileSizeHigh << 32) +
00079             bhfi.nFileSizeLow;
00080 
00081         /* Return the size of the file. */
00082         if (mbytesp != NULL)
00083                 *mbytesp = (u_int32_t)(filesize / MEGABYTE);
00084         if (bytesp != NULL)
00085                 *bytesp = (u_int32_t)(filesize % MEGABYTE);
00086 
00087         /*
00088          * The filesystem blocksize is not easily available.  In particular,
00089          * the values returned by GetDiskFreeSpace() are not very helpful
00090          * (NTFS volumes often report 512B clusters, which are too small to
00091          * be a useful default).
00092          */
00093         if (iosizep != NULL)
00094                 *iosizep = DB_DEF_IOSIZE;
00095         return (0);
00096 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2