1 | /*- |
---|
2 | * See the file LICENSE for redistribution information. |
---|
3 | * |
---|
4 | * Copyright (c) 1997-2002 |
---|
5 | * Sleepycat Software. All rights reserved. |
---|
6 | */ |
---|
7 | |
---|
8 | #include "db_config.h" |
---|
9 | |
---|
10 | #ifndef lint |
---|
11 | static const char revid[] = "Id: os_stat.c,v 11.22 2002/07/12 18:56:56 bostic Exp "; |
---|
12 | #endif /* not lint */ |
---|
13 | |
---|
14 | #ifndef NO_SYSTEM_INCLUDES |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/stat.h> |
---|
17 | |
---|
18 | #include <string.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | #include "db_int.h" |
---|
22 | |
---|
23 | /* |
---|
24 | * __os_exists -- |
---|
25 | * Return if the file exists. |
---|
26 | * |
---|
27 | * PUBLIC: int __os_exists __P((const char *, int *)); |
---|
28 | */ |
---|
29 | int |
---|
30 | __os_exists(path, isdirp) |
---|
31 | const char *path; |
---|
32 | int *isdirp; |
---|
33 | { |
---|
34 | int ret; |
---|
35 | DWORD attrs; |
---|
36 | |
---|
37 | if (DB_GLOBAL(j_exists) != NULL) |
---|
38 | return (DB_GLOBAL(j_exists)(path, isdirp)); |
---|
39 | |
---|
40 | ret = 0; |
---|
41 | do { |
---|
42 | attrs = GetFileAttributes(path); |
---|
43 | if (attrs == (DWORD)-1) |
---|
44 | ret = __os_win32_errno(); |
---|
45 | } while (ret == EINTR); |
---|
46 | |
---|
47 | if (ret != 0) |
---|
48 | return (ret); |
---|
49 | |
---|
50 | if (isdirp != NULL) |
---|
51 | *isdirp = (attrs & FILE_ATTRIBUTE_DIRECTORY); |
---|
52 | |
---|
53 | return (0); |
---|
54 | } |
---|
55 | |
---|
56 | /* |
---|
57 | * __os_ioinfo -- |
---|
58 | * Return file size and I/O size; abstracted to make it easier |
---|
59 | * to replace. |
---|
60 | * |
---|
61 | * PUBLIC: int __os_ioinfo __P((DB_ENV *, const char *, |
---|
62 | * PUBLIC: DB_FH *, u_int32_t *, u_int32_t *, u_int32_t *)); |
---|
63 | */ |
---|
64 | int |
---|
65 | __os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep) |
---|
66 | DB_ENV *dbenv; |
---|
67 | const char *path; |
---|
68 | DB_FH *fhp; |
---|
69 | u_int32_t *mbytesp, *bytesp, *iosizep; |
---|
70 | { |
---|
71 | int ret; |
---|
72 | BY_HANDLE_FILE_INFORMATION bhfi; |
---|
73 | unsigned __int64 filesize; |
---|
74 | |
---|
75 | if (DB_GLOBAL(j_ioinfo) != NULL) |
---|
76 | return (DB_GLOBAL(j_ioinfo)(path, |
---|
77 | fhp->fd, mbytesp, bytesp, iosizep)); |
---|
78 | |
---|
79 | retry: if (!GetFileInformationByHandle(fhp->handle, &bhfi)) { |
---|
80 | if ((ret = __os_win32_errno()) == EINTR) |
---|
81 | goto retry; |
---|
82 | __db_err(dbenv, |
---|
83 | "GetFileInformationByHandle: %s", strerror(ret)); |
---|
84 | return (ret); |
---|
85 | } |
---|
86 | |
---|
87 | filesize = ((unsigned __int64)bhfi.nFileSizeHigh << 32) + |
---|
88 | bhfi.nFileSizeLow; |
---|
89 | |
---|
90 | /* Return the size of the file. */ |
---|
91 | if (mbytesp != NULL) |
---|
92 | *mbytesp = (u_int32_t)(filesize / MEGABYTE); |
---|
93 | if (bytesp != NULL) |
---|
94 | *bytesp = (u_int32_t)(filesize % MEGABYTE); |
---|
95 | |
---|
96 | /* The filesystem blocksize is not easily available. */ |
---|
97 | if (iosizep != NULL) |
---|
98 | *iosizep = DB_DEF_IOSIZE; |
---|
99 | return (0); |
---|
100 | } |
---|