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:26 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  * PUBLIC: int __os_exists __P((const char *, int *));
00026  */
00027 int
00028 __os_exists(path, isdirp)
00029         const char *path;
00030         int *isdirp;
00031 {
00032         struct stat sb;
00033         int ret;
00034 
00035         if (DB_GLOBAL(j_exists) != NULL)
00036                 return (DB_GLOBAL(j_exists)(path, isdirp));
00037 
00038 #ifdef HAVE_VXWORKS
00039         RETRY_CHK((stat((char *)path, &sb)), ret);
00040 #else
00041         RETRY_CHK((stat(path, &sb)), ret);
00042 #endif
00043         if (ret != 0)
00044                 return (ret);
00045 
00046 #if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
00047 #undef  S_ISDIR
00048 #ifdef _S_IFDIR
00049 #define S_ISDIR(m)      (_S_IFDIR & (m))
00050 #else
00051 #define S_ISDIR(m)      (((m) & 0170000) == 0040000)
00052 #endif
00053 #endif
00054         if (isdirp != NULL)
00055                 *isdirp = S_ISDIR(sb.st_mode);
00056 
00057         return (0);
00058 }
00059 
00060 /*
00061  * __os_ioinfo --
00062  *      Return file size and I/O size; abstracted to make it easier
00063  *      to replace.
00064  *
00065  * PUBLIC: int __os_ioinfo __P((DB_ENV *, const char *,
00066  * PUBLIC:    DB_FH *, u_int32_t *, u_int32_t *, u_int32_t *));
00067  */
00068 int
00069 __os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
00070         DB_ENV *dbenv;
00071         const char *path;
00072         DB_FH *fhp;
00073         u_int32_t *mbytesp, *bytesp, *iosizep;
00074 {
00075         struct stat sb;
00076         int ret;
00077 
00078         if (DB_GLOBAL(j_ioinfo) != NULL)
00079                 return (DB_GLOBAL(j_ioinfo)(path,
00080                     fhp->fd, mbytesp, bytesp, iosizep));
00081 
00082         /* Check for illegal usage. */
00083         DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
00084 
00085         RETRY_CHK((fstat(fhp->fd, &sb)), ret);
00086         if (ret != 0) {
00087                 __db_err(dbenv, "fstat: %s", strerror(ret));
00088                 return (ret);
00089         }
00090 
00091         /* Return the size of the file. */
00092         if (mbytesp != NULL)
00093                 *mbytesp = (u_int32_t)(sb.st_size / MEGABYTE);
00094         if (bytesp != NULL)
00095                 *bytesp = (u_int32_t)(sb.st_size % MEGABYTE);
00096 
00097         /*
00098          * Return the underlying filesystem blocksize, if available.
00099          *
00100          * XXX
00101          * Check for a 0 size -- the HP MPE/iX architecture has st_blksize,
00102          * but it's always 0.
00103          */
00104 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
00105         if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
00106                 *iosizep = DB_DEF_IOSIZE;
00107 #else
00108         if (iosizep != NULL)
00109                 *iosizep = DB_DEF_IOSIZE;
00110 #endif
00111         return (0);
00112 }

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