1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13/*
14 * __os_exists --
15 *	Return if the file exists.
16 */
17int
18__os_exists(env, path, isdirp)
19	ENV *env;
20	const char *path;
21	int *isdirp;
22{
23	FileInfo fInfo;
24	IFileMgr *pIFileMgr;
25	int ret;
26
27	FILE_MANAGER_CREATE(env, pIFileMgr, ret);
28	if (ret != 0)
29		return (ret);
30
31	ret = 0;
32	if (IFILEMGR_Test(pIFileMgr, path) == EFAILED) {
33		FILE_MANAGER_ERR(
34		    env, pIFileMgr, path, "IFILEMGR_Test", ret);
35		goto err;
36	}
37
38	if (isdirp != NULL) {
39		if (IFILEMGR_GetInfo(pIFileMgr, path, &fInfo) == EFAILED) {
40			FILE_MANAGER_ERR(
41			    env, pIFileMgr, path, "IFILEMGR_GetInfo", ret);
42			goto err;
43		}
44		*isdirp = fInfo.attrib == _FA_DIR ? 1 : 0;
45	}
46
47err:	IFILEMGR_Release(pIFileMgr);
48
49	return (ret);
50}
51
52/*
53 * __os_ioinfo --
54 *	Return file size and I/O size; abstracted to make it easier
55 *	to replace.
56 */
57int
58__os_ioinfo(env, path, fhp, mbytesp, bytesp, iosizep)
59	ENV *env;
60	const char *path;
61	DB_FH *fhp;
62	u_int32_t *mbytesp, *bytesp, *iosizep;
63{
64	FileInfo fInfo;
65	IFileMgr *pIFileMgr;
66	int ret;
67
68	FILE_MANAGER_CREATE(env, pIFileMgr, ret);
69	if (ret != 0)
70		return (ret);
71
72	if (IFILE_GetInfo(fhp->ifp, &fInfo) != SUCCESS) {
73		FILE_MANAGER_ERR(env, pIFileMgr, path, "IFILE_GetInfo", ret);
74		goto err;
75	}
76
77	/* Return the size of the file. */
78	if (mbytesp != NULL)
79		*mbytesp = (u_int32_t)(fInfo.dwSize / MEGABYTE);
80	if (bytesp != NULL)
81		*bytesp = (u_int32_t)(fInfo.dwSize % MEGABYTE);
82
83	/* Default the filesystem I/O size. */
84	if (iosizep != NULL)
85		*iosizep = DB_DEF_IOSIZE;
86
87err:	IFILEMGR_Release(pIFileMgr);
88	return (ret);
89}
90