mariadb/storage/bdb/os/os_stat.c

113 lines
2.3 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2005-12-05 10:27:46 -08:00
* Copyright (c) 1997-2005
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
2005-07-20 15:48:22 -07:00
*
2005-12-05 10:27:46 -08:00
* $Id: os_stat.c,v 12.1 2005/06/16 20:23:26 bostic Exp $
2001-03-04 19:42:05 -05:00
*/
#include "db_config.h"
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <sys/stat.h>
2002-10-30 15:57:05 +04:00
2001-03-04 19:42:05 -05:00
#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;
{
struct stat sb;
2005-07-20 15:48:22 -07:00
int ret;
2001-03-04 19:42:05 -05:00
2002-10-30 15:57:05 +04:00
if (DB_GLOBAL(j_exists) != NULL)
return (DB_GLOBAL(j_exists)(path, isdirp));
2001-03-04 19:42:05 -05:00
#ifdef HAVE_VXWORKS
2005-07-20 15:48:22 -07:00
RETRY_CHK((stat((char *)path, &sb)), ret);
2001-03-04 19:42:05 -05:00
#else
2005-07-20 15:48:22 -07:00
RETRY_CHK((stat(path, &sb)), ret);
2001-03-04 19:42:05 -05:00
#endif
2002-10-30 15:57:05 +04:00
if (ret != 0)
return (ret);
2001-03-04 19:42:05 -05:00
#if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
2002-10-30 15:57:05 +04:00
#undef S_ISDIR
#ifdef _S_IFDIR
2001-03-04 19:42:05 -05:00
#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;
{
struct stat sb;
2005-07-20 15:48:22 -07:00
int ret;
2001-03-04 19:42:05 -05:00
2002-10-30 15:57:05 +04:00
if (DB_GLOBAL(j_ioinfo) != NULL)
return (DB_GLOBAL(j_ioinfo)(path,
2001-03-04 19:42:05 -05:00
fhp->fd, mbytesp, bytesp, iosizep));
2005-07-20 15:48:22 -07:00
/* Check for illegal usage. */
DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
RETRY_CHK((fstat(fhp->fd, &sb)), ret);
if (ret != 0) {
2001-03-04 19:42:05 -05:00
__db_err(dbenv, "fstat: %s", strerror(ret));
return (ret);
}
/* Return the size of the file. */
if (mbytesp != NULL)
2002-10-30 15:57:05 +04:00
*mbytesp = (u_int32_t)(sb.st_size / MEGABYTE);
2001-03-04 19:42:05 -05:00
if (bytesp != NULL)
2002-10-30 15:57:05 +04:00
*bytesp = (u_int32_t)(sb.st_size % MEGABYTE);
2001-03-04 19:42:05 -05:00
/*
* 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.
*/
2002-10-30 15:57:05 +04:00
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
2001-03-04 19:42:05 -05:00
if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
*iosizep = DB_DEF_IOSIZE;
#else
if (iosizep != NULL)
*iosizep = DB_DEF_IOSIZE;
#endif
return (0);
}