os_stat.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

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