add missing {} after if()
[dragonfly.git] / sbin / jscan / jscan.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2004,2005 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $DragonFly: src/sbin/jscan/jscan.h,v 1.6 2005/09/06 06:42:44 dillon Exp $
35 */
36
37#include <sys/types.h>
38#include <sys/time.h>
39#include <sys/journal.h>
40#include <sys/stat.h>
41#include <stdio.h>
42#include <stdarg.h>
43#include <stdlib.h>
44#include <stddef.h>
45#include <unistd.h>
46#include <string.h>
47#include <limits.h>
48#include <time.h>
49#include <fcntl.h>
50#include <errno.h>
51#include <ctype.h>
52#include <assert.h>
53#include "jattr.h"
54
55struct jdata;
56
57enum jdirection { JD_FORWARDS, JD_BACKWARDS };
58
59struct jfile {
60 off_t jf_pos; /* current seek position */
61 int jf_fd;
62 int jf_error;
63 enum jdirection jf_direction;
64 int jf_open_flags;
65 struct jdata *jf_data;
66 char *jf_prefix; /* prefix: name */
67 unsigned int jf_seq_beg; /* prefix: sequence space */
68 unsigned int jf_seq_end; /* prefix: sequence space */
69 unsigned int jf_seq; /* prefix: current sequence number */
70};
71
72#define JF_FULL_DUPLEX 0x0001
73
74struct jdata {
75 struct jdata *jd_next;
76 int64_t jd_transid; /* transaction id from header */
77 int jd_alloc; /* allocated bytes */
78 int jd_size; /* data bytes */
79 int jd_refs; /* ref count */
80 char jd_data[4]; /* must be last field */
81};
82
83struct jstream {
84 struct jstream *js_next; /* linked list / same transaction */
85 char *js_alloc_buf;
86 int js_alloc_size;
87
88 /*
89 * Normalized fields strip all rawrecbeg, rawrecend, and deadspace except
90 * for the initial rawrecbeg header.
91 */
92 char *js_normalized_base;
93 int js_normalized_size;
94 off_t js_normalized_off;
95 off_t js_normalized_total;
96
97 /*
98 * This is used by the first js record only to cache other records in the
99 * chain.
100 */
101 struct jstream *js_cache;
102 struct jfile *js_jfile;
103 struct jdata *js_jdata;
104 struct journal_rawrecbeg *js_head;
105};
106
107struct jhash {
108 struct jhash *jh_hash;
109 struct jstream *jh_first;
110 struct jstream *jh_last;
111 int16_t jh_transid;
112};
113
114#define JHASH_SIZE 1024
115#define JHASH_MASK (JHASH_SIZE - 1)
116
117#define JMODEF_DEBUG 0x00000001
118#define JMODEF_MIRROR 0x00000002
119#define JMODEF_UNUSED0004 0x00000004
120#define JMODEF_RECORD 0x00000008
121#define JMODEF_RECORD_TMP 0x00000010
122#define JMODEF_INPUT_FULL 0x00000020
123#define JMODEF_INPUT_PIPE 0x00000040
124#define JMODEF_INPUT_PREFIX 0x00000080
125#define JMODEF_OUTPUT 0x00000100
126#define JMODEF_OUTPUT_FULL 0x00000200
127#define JMODEF_MEMORY_TRACKING 0x00000400
128
129#define JMODEF_OUTPUT_TRANSID_GOOD 0x00010000
130#define JMODEF_RECORD_TRANSID_GOOD 0x00020000
131#define JMODEF_MIRROR_TRANSID_GOOD 0x00040000
132#define JMODEF_TRANSID_GOOD_MASK (JMODEF_OUTPUT_TRANSID_GOOD|\
133 JMODEF_RECORD_TRANSID_GOOD|\
134 JMODEF_MIRROR_TRANSID_GOOD)
135#define JMODEF_COMMAND_MASK (JMODEF_RECORD|JMODEF_MIRROR|JMODEF_DEBUG|\
136 JMODEF_OUTPUT)
137
138extern int jmodes;
139extern int fsync_opt;
140extern off_t record_size;
141extern off_t trans_count;
142
143const char *type_to_name(int16_t rectype);
144void stringout(FILE *fp, char c, int exact);
145void jattr_reset(struct jattr *jattr);
146int64_t buf_to_int64(const void *buf, int bytes);
147void *dupdata(const void *buf, int bytes);
148char *dupdatastr(const void *buf, int bytes);
149char *dupdatapath(const void *buf, int bytes);
150void get_transid_from_file(const char *path, int64_t *transid, int flags);
151
152struct jfile *jopen_fd(int fd, enum jdirection direction);
153struct jfile *jopen_prefix(const char *prefix, enum jdirection direction, int rw);
154void jclose(struct jfile *jf);
155int jread(struct jfile *jf, struct jdata **jdp, enum jdirection direction);
156int jwrite(struct jfile *jf, struct jdata *jd);
157void jseek(struct jfile *jf, int64_t transid, enum jdirection direction);
158struct jdata *jref(struct jdata *jd);
159void jfree(struct jfile *jf, struct jdata *jd);
160void jf_warn(struct jfile *jf, const char *ctl, ...);
161
162struct jstream *jaddrecord(struct jfile *jf, struct jdata *jd);
163void jscan_dispose(struct jstream *js);
164
165void dump_debug(struct jfile *jf, struct jdata *jd, int64_t transid);
166void dump_mirror(struct jfile *jf, struct jdata *jd, int64_t transid);
167void dump_record(struct jfile *jf, struct jdata *jd, int64_t transid);
168void dump_output(struct jfile *jf, struct jdata *jd, int64_t transid);
169
170int jrecord_init(const char *record_prefix);
171
172int jsreadany(struct jstream *js, off_t off, const void **bufp);
173int jsreadp(struct jstream *js, off_t off, const void **bufp, int bytes);
174int jsread(struct jstream *js, off_t off, void *buf, int bytes);
175int jsreadcallback(struct jstream *js, ssize_t (*func)(int, const void *, size_t), int fd, off_t off, int bytes);
176