os_finit.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
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 /* not lint */
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  * CDB___os_finit --
00025  *      Initialize a regular file, optionally zero-filling it as well.
00026  *
00027  * PUBLIC: int CDB___os_finit __P((DB_ENV *, DB_FH *, size_t, int));
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         /* Write nuls to the new bytes. */
00044         memset(buf, 0, sizeof(buf));
00045 
00046         /*
00047          * Extend the region by writing the last page.  If the region is >4Gb,
00048          * increment may be larger than the maximum possible seek "relative"
00049          * argument, as it's an unsigned 32-bit value.  Break the offset into
00050          * pages of 1MB each so that we don't overflow (2^20 + 2^32 is bigger
00051          * than any memory I expect to see for awhile).
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          * We may want to guarantee that there is enough disk space for the
00067          * file, so we also write a byte to each page.  We write the byte
00068          * because reading it is insufficient on systems smart enough not to
00069          * instantiate disk pages to satisfy a read (e.g., Solaris).
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                 /* Write a byte to each page. */
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  * CDB___os_fpinit --
00094  *      Initialize a page in a regular file.
00095  *
00096  * PUBLIC: int CDB___os_fpinit __P((DB_ENV *, DB_FH *, db_pgno_t, int, int));
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 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5