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