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