2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Constants defining the max size of various wlog_rec fields. ANY SIZE
23 * CHANGES HERE MUST BE REFLECTED IN THE WLOG_REC_DISK STRUCTURE DEFINED
27 #define WLOG_MAX_PATH 128
28 #define WLOG_MAX_PATTERN 64
29 #define WLOG_MAX_HOST 8
30 #define WLOG_REC_MAX_SIZE (sizeof(struct wlog_rec)+WLOG_MAX_PATH+WLOG_MAX_PATTERN+WLOG_MAX_HOST+2)
33 * User view of a write log record. Note that this is not necessiliary
34 * how the data is formatted on disk (signifigant compression occurrs), so
35 * don't expect to od the write log file and see things formatted this way.
39 int w_pid; /* pid doing the write */
40 int w_offset; /* file offset */
41 int w_nbytes; /* # bytes written */
42 int w_oflags; /* low-order open() flags */
43 int w_done; /* 1 if io confirmed done */
44 int w_async; /* 1 if async write (writea) */
46 char w_host[WLOG_MAX_HOST+1]; /* host doing write - */
48 int w_hostlen; /* host name length */
49 char w_path[WLOG_MAX_PATH+1]; /* file written to - */
51 int w_pathlen; /* file name length */
52 char w_pattern[WLOG_MAX_PATTERN+1]; /* pattern written - */
54 int w_patternlen; /* pattern length */
58 #define uint unsigned int
62 * On-disk structure of a wlog_rec. Actually, the record consists of
63 * 3 parts: [wlog_rec_disk structure][variable length data][length]
64 * where length is a 2 byte field containing the total record length
65 * (including the 2 bytes). It is used for scanning the logfile in reverse
68 * The variable length data includes the path, host, and pattern (in that
69 * order). The lengths of these pieces of data are held in the
70 * wlog_rec_disk structure. Thus, the actual on-disk record looks like
71 * this (top is lower byte offset):
73 * struct wlog_rec_disk
74 * path (w_pathlen bytes - not null terminated)
75 * host (w_hostlen bytes - not null terminated)
76 * pattern (w_patternlen bytes - not null terminated)
77 * 2-byte record length
79 * Another way of looking at it is:
81 * <struct wlog_rec_disk><path (wpathlen bytes)>-->
82 * --><host (w_hostlen bytes)><pattern (w_patternlen bytes)><length (2 bytes)>
84 * The maximum length of this record is defined by the WLOG_REC_MAX_SIZE
85 * record. Note that the 2-byte record length forces this to be
88 * Note that there is lots of bit-masking done here. The w_pathlen,
89 * w_hostlen, and w_patternlen fields MUST have enough bits to hold
90 * WLOG_MAX_PATH, WLOG_MAX_HOST, and WLOG_MAX_PATTERN bytes respectivly.
93 struct wlog_rec_disk {
95 uint w_offset : 32; /* file offset */
96 uint w_extra0 : 32; /* EXTRA BITS IN WORD 0 */
99 uint w_nbytes : 32; /* # bytes written */
100 uint w_oflags : 32; /* low-order open() flags */
102 uint w_pid : 17; /* pid doing the write */
103 uint w_pathlen : 7; /* length of file path */
104 uint w_patternlen: 6; /* length of pattern */
105 uint w_hostlen : 4; /* length of host */
106 uint w_done : 1; /* 1 if io confirmed done */
107 uint w_async : 1; /* 1 if async write (writea) */
108 uint w_extra2 : 28; /* EXTRA BITS IN WORD 2 */
112 * write log file datatype. wlog_open() initializes this structure
113 * which is then passed around to the various wlog_xxx routines.
117 int w_afd; /* append fd */
118 int w_rfd; /* random-access fd */
119 char w_file[1024]; /* name of the write_log */
123 * return value defines for the user-supplied function to
124 * wlog_scan_backward().
127 #define WLOG_STOP_SCAN 0
128 #define WLOG_CONTINUE_SCAN 1
135 extern int wlog_open(struct wlog_file *wfile, int trunc, int mode);
136 extern int wlog_close(struct wlog_file *wfile);
137 extern int wlog_record_write(struct wlog_file *wfile,
138 struct wlog_rec *wrec, long offset);
139 extern int wlog_scan_backward(struct wlog_file *wfile, int nrecs,
140 int (*func)(struct wlog_rec *rec),
145 int wlog_record_write();
146 int wlog_scan_backward();
149 extern char Wlog_Error_String[];
151 #endif /* _WRITE_LOG_H_ */