1204076Spjd/*-
2204076Spjd * Copyright (c) 2009-2010 The FreeBSD Foundation
3204076Spjd * All rights reserved.
4204076Spjd *
5204076Spjd * This software was developed by Pawel Jakub Dawidek under sponsorship from
6204076Spjd * the FreeBSD Foundation.
7204076Spjd *
8204076Spjd * Redistribution and use in source and binary forms, with or without
9204076Spjd * modification, are permitted provided that the following conditions
10204076Spjd * are met:
11204076Spjd * 1. Redistributions of source code must retain the above copyright
12204076Spjd *    notice, this list of conditions and the following disclaimer.
13204076Spjd * 2. Redistributions in binary form must reproduce the above copyright
14204076Spjd *    notice, this list of conditions and the following disclaimer in the
15204076Spjd *    documentation and/or other materials provided with the distribution.
16204076Spjd *
17204076Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20204076Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24204076Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27204076Spjd * SUCH DAMAGE.
28204076Spjd *
29204076Spjd * $FreeBSD$
30204076Spjd */
31204076Spjd
32204076Spjd#ifndef	_ACTIVEMAP_H_
33204076Spjd#define	_ACTIVEMAP_H_
34204076Spjd
35204076Spjd#include <stdbool.h>
36204076Spjd#include <stdint.h>
37204076Spjd
38204076Spjdstruct activemap;
39204076Spjd
40204076Spjdint activemap_init(struct activemap **ampp, uint64_t mediasize,
41204076Spjd    uint32_t extentsize, uint32_t sectorsize, uint32_t keepdirty);
42204076Spjdvoid activemap_free(struct activemap *amp);
43204076Spjd
44204076Spjdbool activemap_write_start(struct activemap *amp, off_t offset, off_t length);
45204076Spjdbool activemap_write_complete(struct activemap *amp, off_t offset,
46204076Spjd    off_t length);
47204076Spjdbool activemap_extent_complete(struct activemap *amp, int extent);
48204076Spjduint64_t activemap_ndirty(const struct activemap *amp);
49204076Spjd
50204076Spjdbool activemap_differ(const struct activemap *amp);
51204076Spjdsize_t activemap_size(const struct activemap *amp);
52204076Spjdsize_t activemap_ondisk_size(const struct activemap *amp);
53204076Spjdvoid activemap_copyin(struct activemap *amp, const unsigned char *buf,
54204076Spjd    size_t size);
55204076Spjdvoid activemap_merge(struct activemap *amp, const unsigned char *buf,
56204076Spjd    size_t size);
57204076Spjdconst unsigned char *activemap_bitmap(struct activemap *amp, size_t *sizep);
58204076Spjd
59204076Spjdsize_t activemap_calc_ondisk_size(uint64_t mediasize, uint32_t extentsize,
60204076Spjd    uint32_t sectorsize);
61204076Spjd
62204076Spjdvoid activemap_sync_rewind(struct activemap *amp);
63204076Spjdoff_t activemap_sync_offset(struct activemap *amp, off_t *lengthp,
64204076Spjd    int *syncextp);
65204076Spjdbool activemap_need_sync(struct activemap *amp, off_t offset, off_t length);
66204076Spjd
67204076Spjdvoid activemap_dump(const struct activemap *amp);
68204076Spjd
69204076Spjd#endif	/* !_ACTIVEMAP_H_ */
70