Add a PAM config for kde.
[dragonfly.git] / sbin / jscan / jscan.h
CommitLineData
ce5e5ac4
MD
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 *
36456e49 34 * $DragonFly: src/sbin/jscan/jscan.h,v 1.10 2005/09/07 19:10:09 dillon Exp $
ce5e5ac4
MD
35 */
36
37#include <sys/types.h>
38#include <sys/time.h>
39#include <sys/journal.h>
712e03b0 40#include <sys/stat.h>
ce5e5ac4
MD
41#include <stdio.h>
42#include <stdarg.h>
43#include <stdlib.h>
44#include <stddef.h>
45#include <unistd.h>
46#include <string.h>
c2b2044a 47#include <limits.h>
ce5e5ac4
MD
48#include <time.h>
49#include <fcntl.h>
50#include <errno.h>
712e03b0
MD
51#include <ctype.h>
52#include <assert.h>
53#include "jattr.h"
ce5e5ac4 54
c2b2044a
MD
55struct jdata;
56
a9cb3889 57enum jdirection { JD_FORWARDS, JD_BACKWARDS, JD_SEQFIRST, JD_SEQLAST };
ce5e5ac4
MD
58
59struct jfile {
60 off_t jf_pos; /* current seek position */
bb406b71
MD
61 int jf_fd; /* reading/scanning */
62 int jf_write_fd; /* appending */
63 off_t jf_write_pos; /* append position */
ce5e5ac4 64 int jf_error;
c2b2044a 65 int jf_open_flags;
c2b2044a
MD
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 */
bb406b71
MD
70 int64_t jf_last_transid;/* prefix: last recorded transid */
71};
72
73/*
74 * Output session (debug, record, output, etc)
75 */
76struct jsession {
77 struct jfile *ss_jfin;
78 struct jfile *ss_jfout;
a9cb3889 79 enum jdirection ss_direction;
bb406b71
MD
80 const char *ss_mirror_directory;
81 const char *ss_transid_file;
82 int ss_transid_fd;
83 int64_t ss_transid;
ce5e5ac4
MD
84};
85
5adba82e
MD
86#define JF_FULL_DUPLEX 0x0001
87
ce5e5ac4 88struct jdata {
c2b2044a
MD
89 int64_t jd_transid; /* transaction id from header */
90 int jd_alloc; /* allocated bytes */
91 int jd_size; /* data bytes */
92 int jd_refs; /* ref count */
a9cb3889
MD
93 unsigned int jd_seq; /* location data */
94 off_t jd_pos; /* location data */
ce5e5ac4
MD
95 char jd_data[4]; /* must be last field */
96};
97
98struct jstream {
99 struct jstream *js_next; /* linked list / same transaction */
bb406b71 100 struct jsession *js_session;
ce5e5ac4
MD
101 char *js_alloc_buf;
102 int js_alloc_size;
712e03b0
MD
103
104 /*
105 * Normalized fields strip all rawrecbeg, rawrecend, and deadspace except
106 * for the initial rawrecbeg header.
107 */
108 char *js_normalized_base;
109 int js_normalized_size;
110 off_t js_normalized_off;
111 off_t js_normalized_total;
112
113 /*
114 * This is used by the first js record only to cache other records in the
115 * chain.
116 */
ce5e5ac4 117 struct jstream *js_cache;
c2b2044a
MD
118 struct jdata *js_jdata;
119 struct journal_rawrecbeg *js_head;
ce5e5ac4
MD
120};
121
122struct jhash {
123 struct jhash *jh_hash;
124 struct jstream *jh_first;
125 struct jstream *jh_last;
bb406b71 126 struct jsession *jh_session;
ce5e5ac4
MD
127 int16_t jh_transid;
128};
129
130#define JHASH_SIZE 1024
131#define JHASH_MASK (JHASH_SIZE - 1)
132
c2b2044a
MD
133#define JMODEF_DEBUG 0x00000001
134#define JMODEF_MIRROR 0x00000002
135#define JMODEF_UNUSED0004 0x00000004
136#define JMODEF_RECORD 0x00000008
137#define JMODEF_RECORD_TMP 0x00000010
138#define JMODEF_INPUT_FULL 0x00000020
139#define JMODEF_INPUT_PIPE 0x00000040
140#define JMODEF_INPUT_PREFIX 0x00000080
141#define JMODEF_OUTPUT 0x00000100
142#define JMODEF_OUTPUT_FULL 0x00000200
143#define JMODEF_MEMORY_TRACKING 0x00000400
cbeb73b9 144#define JMODEF_LOOP_FOREVER 0x00000800
c2b2044a
MD
145
146#define JMODEF_OUTPUT_TRANSID_GOOD 0x00010000
147#define JMODEF_RECORD_TRANSID_GOOD 0x00020000
148#define JMODEF_MIRROR_TRANSID_GOOD 0x00040000
149#define JMODEF_TRANSID_GOOD_MASK (JMODEF_OUTPUT_TRANSID_GOOD|\
150 JMODEF_RECORD_TRANSID_GOOD|\
151 JMODEF_MIRROR_TRANSID_GOOD)
152#define JMODEF_COMMAND_MASK (JMODEF_RECORD|JMODEF_MIRROR|JMODEF_DEBUG|\
153 JMODEF_OUTPUT)
154
155extern int jmodes;
156extern int fsync_opt;
bb406b71
MD
157extern int verbose_opt;
158extern off_t prefix_file_size;
c2b2044a 159extern off_t trans_count;
712e03b0 160
ce5e5ac4 161const char *type_to_name(int16_t rectype);
9c118cb2 162void stringout(FILE *fp, char c, int exact);
712e03b0
MD
163void jattr_reset(struct jattr *jattr);
164int64_t buf_to_int64(const void *buf, int bytes);
165void *dupdata(const void *buf, int bytes);
166char *dupdatastr(const void *buf, int bytes);
167char *dupdatapath(const void *buf, int bytes);
c2b2044a
MD
168void get_transid_from_file(const char *path, int64_t *transid, int flags);
169
bb406b71 170void jsession_init(struct jsession *ss, struct jfile *jfin,
a9cb3889 171 enum jdirection direction,
bb406b71
MD
172 const char *transid_file, int64_t transid);
173void jsession_update_transid(struct jsession *ss, int64_t transid);
36456e49 174int jsession_check(struct jsession *ss, struct jdata *jd);
bb406b71
MD
175void jsession_term(struct jsession *ss);
176
a9cb3889
MD
177struct jfile *jopen_fd(int fd);
178struct jfile *jopen_prefix(const char *prefix, int rw);
c2b2044a 179void jclose(struct jfile *jf);
a9cb3889
MD
180struct jdata *jread(struct jfile *jf, struct jdata *jd,
181 enum jdirection direction);
182struct jdata *jseek(struct jfile *jf, int64_t transid,
183 enum jdirection direction);
bb406b71 184void jwrite(struct jfile *jf, struct jdata *jd);
c2b2044a
MD
185struct jdata *jref(struct jdata *jd);
186void jfree(struct jfile *jf, struct jdata *jd);
187void jf_warn(struct jfile *jf, const char *ctl, ...);
712e03b0 188
bb406b71 189struct jstream *jaddrecord(struct jsession *ss, struct jdata *jd);
ce5e5ac4 190void jscan_dispose(struct jstream *js);
ce5e5ac4 191
bb406b71
MD
192void dump_debug(struct jsession *ss, struct jdata *jd);
193void dump_mirror(struct jsession *ss, struct jdata *jd);
194void dump_record(struct jsession *ss, struct jdata *jd);
195void dump_output(struct jsession *ss, struct jdata *jd);
c2b2044a
MD
196
197int jrecord_init(const char *record_prefix);
ce5e5ac4
MD
198
199int jsreadany(struct jstream *js, off_t off, const void **bufp);
200int jsreadp(struct jstream *js, off_t off, const void **bufp, int bytes);
201int jsread(struct jstream *js, off_t off, void *buf, int bytes);
36d6bdee
MD
202int jsreadcallback(struct jstream *js, ssize_t (*func)(int, const void *, size_t), int fd, off_t off, int bytes);
203