1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: os_stat.c,v 1.1.1.1 2003/11/20 22:13:37 toshok Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#endif
#include "db_int.h"
/*
* __os_exists --
* Return if the file exists.
*
* PUBLIC: int __os_exists __P((const char *, int *));
*/
int
__os_exists(path, isdirp)
const char *path;
int *isdirp;
{
int ret;
struct stat sb;
if (DB_GLOBAL(j_exists) != NULL)
return (DB_GLOBAL(j_exists)(path, isdirp));
do {
ret =
#ifdef HAVE_VXWORKS
stat((char *)path, &sb);
#else
stat(path, &sb);
#endif
if (ret != 0)
ret = __os_get_errno();
} while (ret == EINTR);
if (ret != 0)
return (ret);
#if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
#undef S_ISDIR
#ifdef _S_IFDIR
#define S_ISDIR(m) (_S_IFDIR & (m))
#else
#define S_ISDIR(m) (((m) & 0170000) == 0040000)
#endif
#endif
if (isdirp != NULL)
*isdirp = S_ISDIR(sb.st_mode);
return (0);
}
/*
* __os_ioinfo --
* Return file size and I/O size; abstracted to make it easier
* to replace.
*
* PUBLIC: int __os_ioinfo __P((DB_ENV *, const char *,
* PUBLIC: DB_FH *, u_int32_t *, u_int32_t *, u_int32_t *));
*/
int
__os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
DB_ENV *dbenv;
const char *path;
DB_FH *fhp;
u_int32_t *mbytesp, *bytesp, *iosizep;
{
int ret;
struct stat sb;
if (DB_GLOBAL(j_ioinfo) != NULL)
return (DB_GLOBAL(j_ioinfo)(path,
fhp->fd, mbytesp, bytesp, iosizep));
retry:
if (fstat(fhp->fd, &sb) == -1) {
if ((ret = __os_get_errno()) == EINTR)
goto retry;
__db_err(dbenv, "fstat: %s", strerror(ret));
return (ret);
}
/* Return the size of the file. */
if (mbytesp != NULL)
*mbytesp = (u_int32_t)(sb.st_size / MEGABYTE);
if (bytesp != NULL)
*bytesp = (u_int32_t)(sb.st_size % MEGABYTE);
/*
* Return the underlying filesystem blocksize, if available.
*
* XXX
* Check for a 0 size -- the HP MPE/iX architecture has st_blksize,
* but it's always 0.
*/
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
*iosizep = DB_DEF_IOSIZE;
#else
if (iosizep != NULL)
*iosizep = DB_DEF_IOSIZE;
#endif
return (0);
}
|