00001
00002
00003
00004
00005
00006
00007
00008 #include "config.h"
00009
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__finit_8c-source.html,v 1.1 2008/06/08 10:21:14 sebdiaz Exp $";
00012 #endif
00013
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016
00017 #include <errno.h>
00018 #include <string.h>
00019 #endif
00020
00021 #include "db_int.h"
00022
00023
00024
00025
00026
00027
00028
00029 int
00030 CDB___os_finit(dbenv, fhp, size, zerofill)
00031 DB_ENV *dbenv;
00032 DB_FH *fhp;
00033 size_t size;
00034 int zerofill;
00035 {
00036 db_pgno_t pages;
00037 size_t i;
00038 size_t nw;
00039 u_int32_t relative;
00040 int ret;
00041 char buf[OS_VMPAGESIZE];
00042
00043
00044 memset(buf, 0, sizeof(buf));
00045
00046
00047
00048
00049
00050
00051
00052
00053 if ((ret = CDB___os_seek(dbenv, fhp, 0, 0, 0, 0, DB_OS_SEEK_END)) != 0)
00054 return (ret);
00055 pages = (size - OS_VMPAGESIZE) / MEGABYTE;
00056 relative = (size - OS_VMPAGESIZE) % MEGABYTE;
00057 if ((ret = CDB___os_seek(dbenv,
00058 fhp, MEGABYTE, pages, relative, 0, DB_OS_SEEK_CUR)) != 0)
00059 return (ret);
00060 if ((ret = CDB___os_write(dbenv, fhp, buf, sizeof(buf), &nw)) != 0)
00061 return (ret);
00062 if (nw != sizeof(buf))
00063 return (EIO);
00064
00065
00066
00067
00068
00069
00070
00071 if (zerofill) {
00072 pages = size / MEGABYTE;
00073 relative = size % MEGABYTE;
00074 if ((ret = CDB___os_seek(dbenv, fhp,
00075 MEGABYTE, pages, relative, 1, DB_OS_SEEK_END)) != 0)
00076 return (ret);
00077
00078
00079 for (i = 0; i < size; i += OS_VMPAGESIZE) {
00080 if ((ret = CDB___os_write(dbenv, fhp, buf, 1, &nw)) != 0)
00081 return (ret);
00082 if (nw != 1)
00083 return (EIO);
00084 if ((ret = CDB___os_seek(dbenv, fhp,
00085 0, 0, OS_VMPAGESIZE - 1, 0, DB_OS_SEEK_CUR)) != 0)
00086 return (ret);
00087 }
00088 }
00089 return (0);
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 int
00099 CDB___os_fpinit(dbenv, fhp, pgno, pagecount, pagesize)
00100 DB_ENV *dbenv;
00101 DB_FH *fhp;
00102 db_pgno_t pgno;
00103 int pagecount, pagesize;
00104 {
00105 COMPQUIET(dbenv, NULL);
00106 COMPQUIET(fhp, NULL);
00107 COMPQUIET(pgno, 0);
00108 COMPQUIET(pagecount, 0);
00109 COMPQUIET(pagesize, 0);
00110
00111 return (0);
00112 }