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