1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is
13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement
14f08c3bdfSopenharmony_ci * or the like.  Any license provided herein, whether implied or
15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file.  Patent licenses, if
16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with
17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever.
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24f08c3bdfSopenharmony_ci * Mountain View, CA  94043, or:
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * http://www.sgi.com
27f08c3bdfSopenharmony_ci *
28f08c3bdfSopenharmony_ci * For further information regarding this notice, see:
29f08c3bdfSopenharmony_ci *
30f08c3bdfSopenharmony_ci * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31f08c3bdfSopenharmony_ci */
32f08c3bdfSopenharmony_ci#ifndef _WRITE_LOG_H_
33f08c3bdfSopenharmony_ci#define _WRITE_LOG_H_
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci/*
36f08c3bdfSopenharmony_ci * Constants defining the max size of various wlog_rec fields.  ANY SIZE
37f08c3bdfSopenharmony_ci * CHANGES HERE MUST BE REFLECTED IN THE WLOG_REC_DISK STRUCTURE DEFINED
38f08c3bdfSopenharmony_ci * BELOW.
39f08c3bdfSopenharmony_ci */
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_ci#define WLOG_MAX_PATH		128
42f08c3bdfSopenharmony_ci#define WLOG_MAX_PATTERN	64
43f08c3bdfSopenharmony_ci#define WLOG_MAX_HOST           8
44f08c3bdfSopenharmony_ci#define WLOG_REC_MAX_SIZE	(sizeof(struct wlog_rec)+WLOG_MAX_PATH+WLOG_MAX_PATTERN+WLOG_MAX_HOST+2)
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_ci/*
47f08c3bdfSopenharmony_ci * User view of a write log record.  Note that this is not necessiliary
48f08c3bdfSopenharmony_ci * how the data is formatted on disk (signifigant compression occurrs), so
49f08c3bdfSopenharmony_ci * don't expect to od the write log file and see things formatted this way.
50f08c3bdfSopenharmony_ci */
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_cistruct wlog_rec {
53f08c3bdfSopenharmony_ci    int	    w_pid;	    /* pid doing the write  	    */
54f08c3bdfSopenharmony_ci    int	    w_offset;       /* file offset  	    	    */
55f08c3bdfSopenharmony_ci    int	    w_nbytes;	    /* # bytes written	    	    */
56f08c3bdfSopenharmony_ci    int	    w_oflags;       /* low-order open() flags	    */
57f08c3bdfSopenharmony_ci    int	    w_done;	    /* 1 if io confirmed done	    */
58f08c3bdfSopenharmony_ci    int	    w_async;	    /* 1 if async write	(writea)    */
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci    char    w_host[WLOG_MAX_HOST+1];		/* host doing write -	*/
61f08c3bdfSopenharmony_ci						/* null terminated */
62f08c3bdfSopenharmony_ci    int	    w_hostlen;				/* host name length	*/
63f08c3bdfSopenharmony_ci    char    w_path[WLOG_MAX_PATH+1];		/* file written to -	*/
64f08c3bdfSopenharmony_ci						/* null terminated */
65f08c3bdfSopenharmony_ci    int	    w_pathlen;				/* file name length	*/
66f08c3bdfSopenharmony_ci    char    w_pattern[WLOG_MAX_PATTERN+1];	/* pattern written -	*/
67f08c3bdfSopenharmony_ci						/* null terminated */
68f08c3bdfSopenharmony_ci    int	    w_patternlen;			/* pattern length	*/
69f08c3bdfSopenharmony_ci};
70f08c3bdfSopenharmony_ci
71f08c3bdfSopenharmony_ci#ifndef uint
72f08c3bdfSopenharmony_ci#define uint	unsigned int
73f08c3bdfSopenharmony_ci#endif
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci/*
76f08c3bdfSopenharmony_ci * On-disk structure of a wlog_rec.  Actually, the record consists of
77f08c3bdfSopenharmony_ci * 3 parts:  [wlog_rec_disk structure][variable length data][length]
78f08c3bdfSopenharmony_ci * where length is a 2 byte field containing the total record length
79f08c3bdfSopenharmony_ci * (including the 2 bytes).  It is used for scanning the logfile in reverse
80f08c3bdfSopenharmony_ci * order.
81f08c3bdfSopenharmony_ci *
82f08c3bdfSopenharmony_ci * The variable length data includes the path, host, and pattern (in that
83f08c3bdfSopenharmony_ci * order).  The lengths of these pieces of data are held in the
84f08c3bdfSopenharmony_ci * wlog_rec_disk structure.  Thus, the actual on-disk record looks like
85f08c3bdfSopenharmony_ci * this (top is lower byte offset):
86f08c3bdfSopenharmony_ci *
87f08c3bdfSopenharmony_ci *		struct wlog_rec_disk
88f08c3bdfSopenharmony_ci *		path    (w_pathlen bytes - not null terminated)
89f08c3bdfSopenharmony_ci *		host    (w_hostlen bytes - not null terminated)
90f08c3bdfSopenharmony_ci *		pattern (w_patternlen bytes - not null terminated)
91f08c3bdfSopenharmony_ci *		2-byte record length
92f08c3bdfSopenharmony_ci *
93f08c3bdfSopenharmony_ci * Another way of looking at it is:
94f08c3bdfSopenharmony_ci *
95f08c3bdfSopenharmony_ci * <struct wlog_rec_disk><path (wpathlen bytes)>-->
96f08c3bdfSopenharmony_ci * --><host (w_hostlen bytes)><pattern (w_patternlen bytes)><length (2 bytes)>
97f08c3bdfSopenharmony_ci *
98f08c3bdfSopenharmony_ci * The maximum length of this record is defined by the WLOG_REC_MAX_SIZE
99f08c3bdfSopenharmony_ci * record.  Note that the 2-byte record length forces this to be
100f08c3bdfSopenharmony_ci * <= 64k bytes.
101f08c3bdfSopenharmony_ci *
102f08c3bdfSopenharmony_ci * Note that there is lots of bit-masking done here.  The w_pathlen,
103f08c3bdfSopenharmony_ci * w_hostlen, and w_patternlen fields MUST have enough bits to hold
104f08c3bdfSopenharmony_ci * WLOG_MAX_PATH, WLOG_MAX_HOST, and WLOG_MAX_PATTERN bytes respectivly.
105f08c3bdfSopenharmony_ci */
106f08c3bdfSopenharmony_ci
107f08c3bdfSopenharmony_cistruct wlog_rec_disk {
108f08c3bdfSopenharmony_ci#ifdef CRAY
109f08c3bdfSopenharmony_ci    uint    w_offset    : 44;	    /* file offset  	    	    */
110f08c3bdfSopenharmony_ci    uint    w_extra0    : 20;       /* EXTRA BITS IN WORD 0         */
111f08c3bdfSopenharmony_ci#else
112f08c3bdfSopenharmony_ci    /* NB: sgi is pissy about fields > 32 bit, even cc -mips3 */
113f08c3bdfSopenharmony_ci    uint    w_offset    : 32;	    /* file offset  	    	    */
114f08c3bdfSopenharmony_ci    uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
115f08c3bdfSopenharmony_ci#endif
116f08c3bdfSopenharmony_ci
117f08c3bdfSopenharmony_ci    uint    w_nbytes    : 32;	    /* # bytes written	    	    */
118f08c3bdfSopenharmony_ci    uint    w_oflags	: 32;	    /* low-order open() flags	    */
119f08c3bdfSopenharmony_ci
120f08c3bdfSopenharmony_ci    uint    w_pid       : 17;	    /* pid doing the write  	    */
121f08c3bdfSopenharmony_ci    uint    w_pathlen	:  7;	    /* length of file path  	    */
122f08c3bdfSopenharmony_ci    uint    w_patternlen:  6;	    /* length of pattern            */
123f08c3bdfSopenharmony_ci    uint    w_hostlen   :  4;       /* length of host               */
124f08c3bdfSopenharmony_ci    uint    w_done      :  1;	    /* 1 if io confirmed done	    */
125f08c3bdfSopenharmony_ci    uint    w_async     :  1;	    /* 1 if async write	(writea)    */
126f08c3bdfSopenharmony_ci    uint    w_extra2 	: 28;	    /* EXTRA BITS IN WORD 2 	    */
127f08c3bdfSopenharmony_ci};
128f08c3bdfSopenharmony_ci
129f08c3bdfSopenharmony_ci/*
130f08c3bdfSopenharmony_ci * write log file datatype.  wlog_open() initializes this structure
131f08c3bdfSopenharmony_ci * which is then passed around to the various wlog_xxx routines.
132f08c3bdfSopenharmony_ci */
133f08c3bdfSopenharmony_ci
134f08c3bdfSopenharmony_cistruct wlog_file {
135f08c3bdfSopenharmony_ci    int		w_afd;			/* append fd			*/
136f08c3bdfSopenharmony_ci    int		w_rfd;			/* random-access fd		*/
137f08c3bdfSopenharmony_ci    char	w_file[1024];		/* name of the write_log	*/
138f08c3bdfSopenharmony_ci};
139f08c3bdfSopenharmony_ci
140f08c3bdfSopenharmony_ci/*
141f08c3bdfSopenharmony_ci * return value defines for the user-supplied function to
142f08c3bdfSopenharmony_ci * wlog_scan_backward().
143f08c3bdfSopenharmony_ci */
144f08c3bdfSopenharmony_ci
145f08c3bdfSopenharmony_ci#define WLOG_STOP_SCAN		0
146f08c3bdfSopenharmony_ci#define WLOG_CONTINUE_SCAN	1
147f08c3bdfSopenharmony_ci
148f08c3bdfSopenharmony_ci/*
149f08c3bdfSopenharmony_ci * wlog prototypes
150f08c3bdfSopenharmony_ci */
151f08c3bdfSopenharmony_ci
152f08c3bdfSopenharmony_ci#if __STDC__
153f08c3bdfSopenharmony_ciextern int	wlog_open(struct wlog_file *wfile, int trunc, int mode);
154f08c3bdfSopenharmony_ciextern int	wlog_close(struct wlog_file *wfile);
155f08c3bdfSopenharmony_ciextern int	wlog_record_write(struct wlog_file *wfile,
156f08c3bdfSopenharmony_ci				  struct wlog_rec *wrec, long offset);
157f08c3bdfSopenharmony_ciextern int	wlog_scan_backward(struct wlog_file *wfile, int nrecs,
158f08c3bdfSopenharmony_ci				   int (*func)(struct wlog_rec *rec),
159f08c3bdfSopenharmony_ci				   long data);
160f08c3bdfSopenharmony_ci#else
161f08c3bdfSopenharmony_ciint	wlog_open();
162f08c3bdfSopenharmony_ciint	wlog_close();
163f08c3bdfSopenharmony_ciint	wlog_record_write();
164f08c3bdfSopenharmony_ciint	wlog_scan_backward();
165f08c3bdfSopenharmony_ci#endif
166f08c3bdfSopenharmony_ci
167f08c3bdfSopenharmony_ciextern char	Wlog_Error_String[];
168f08c3bdfSopenharmony_ci
169f08c3bdfSopenharmony_ci#endif /* _WRITE_LOG_H_ */
170f08c3bdfSopenharmony_ci
171