Home | History | Annotate | Line # | Download | only in vndcompress
      1 /*	$NetBSD: offtab.h,v 1.3 2017/04/16 23:50:40 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Taylor R. Campbell.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef	VNDCOMPRESS_OFFTAB_H
     33 #define	VNDCOMPRESS_OFFTAB_H
     34 
     35 #include <sys/cdefs.h>
     36 
     37 #include <stdbool.h>
     38 #include <stdint.h>
     39 
     40 #include "common.h"
     41 
     42 struct offtab {
     43 	uint32_t	ot_n_offsets;
     44 	uint32_t	ot_window_size;
     45 	uint32_t	ot_window_start;
     46 	uint64_t	*ot_window;
     47 	uint32_t	ot_blkno;
     48 	int		ot_fd;
     49 	off_t		ot_fdpos;
     50 	void		(*ot_report)(const char *, ...) __printflike(1,2);
     51 	void		(*ot_reportx)(const char *, ...) __printflike(1,2);
     52 	enum offtab_mode {
     53 		OFFTAB_MODE_NONE,
     54 		OFFTAB_MODE_READ,
     55 		OFFTAB_MODE_WRITE,
     56 	}		ot_mode;
     57 };
     58 
     59 #define	OFFTAB_MAX_FDPOS						      \
     60 	((off_t)(MIN(OFF_MAX, UINT64_MAX) -				      \
     61 	    (off_t)MAX_N_OFFSETS*sizeof(uint64_t)))
     62 
     63 void		offtab_init(struct offtab *, uint32_t, uint32_t, int, off_t);
     64 void		offtab_destroy(struct offtab *);
     65 
     66 bool		offtab_transmogrify_read_to_write(struct offtab *, uint32_t);
     67 
     68 bool		offtab_reset_read(struct offtab *,
     69 		    void (*)(const char *, ...) __printflike(1,2),
     70 		    void (*)(const char *, ...) __printflike(1,2));
     71 bool		offtab_prepare_get(struct offtab *, uint32_t);
     72 uint64_t	offtab_get(struct offtab *, uint32_t);
     73 
     74 void		offtab_reset_write(struct offtab *);
     75 void		offtab_checkpoint(struct offtab *, uint32_t, int);
     76 #define	OFFTAB_CHECKPOINT_SYNC	1
     77 void		offtab_prepare_put(struct offtab *, uint32_t);
     78 void		offtab_put(struct offtab *, uint32_t, uint64_t);
     79 
     80 #endif	/* VNDCOMPRESS_OFFTAB_H */
     81