/* * Copyright (c) 2001-2005 Greg Becker. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: dits.h,v 1.2 2004/04/05 02:53:27 greg Exp $ */ #ifndef DITS_MAIN_H #define DITS_MAIN_H typedef uint32_t crc32_t; extern void crc32_init(void); extern crc32_t crc32(u_char *buf, int len, crc32_t crc); /* Preload shift register, per CRC-32 spec. */ #define CRC32_PRELOAD (0xffffffff) #define DITS_MAGIC (0x12345678) #define DITS_MIN(a, b) ((a) < (b) ? (a) : (b)) /* A record defines the data stored in each sector. Each record has * a unique ID which is used to detect missing or multiple instances * that might occur due to system faults. */ typedef struct { int64_t ctime; /* Time test bed was created */ int64_t mtime; /* Time of last modification */ int64_t nsectors; /* # of sectors in the test bed */ int64_t pid; /* Proc that last updated the sector */ int64_t id; /* Record unique ID */ int64_t src; /* Swap source sector */ int64_t dst; /* Swap destination sector */ int32_t len; /* Swap length (in sectors) */ int32_t nswaps; /* # of swaps */ int32_t spare1; int32_t spare2; } record_t; /* Flags for sector_t.flags; */ #define DITS_FRTCK (0x0001) /* Initialized with run time ck file */ /* Each sector_t must occupy exactly one disk sector. rec[0] is * the active record, while rec[1] is the rollback record, which is * to say it contains the contents of rec[0] prior to the last swap. * rec[1] is used to implement an inexpensive transaction log so that * in the event of a failure (e.g., system crash or abnormal child * termination) the transaction (i.e., the swap) can be rolled back. */ typedef struct { uint32_t magic; /* DITS_MAGIC */ uint32_t revision; /* From svnrev2num() */ uint64_t flags; record_t rec[2]; /* The current and saved records */ char session[32]; /* Session name */ uint64_t randupd; /* Random update # */ uint64_t kscratch; /* Kernel scratch area */ char payload[300]; /* Pad sector_t out to 512-bytes */ crc32_t crc; /* CRC of the entire record */ } sector_t; extern off_t oseek; extern void eprintf(char *fmt, ...); #endif /* DITS_MAIN_H */