1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000 Silicon Graphics, Inc.
10 * Constants defining the max size of various wlog_rec fields. ANY SIZE
11 * CHANGES HERE MUST BE REFLECTED IN THE WLOG_REC_DISK STRUCTURE DEFINED
15 #define WLOG_MAX_PATH 128
16 #define WLOG_MAX_PATTERN 64
17 #define WLOG_MAX_HOST 8
18 #define WLOG_REC_MAX_SIZE (sizeof(struct wlog_rec)+WLOG_MAX_PATH+WLOG_MAX_PATTERN+WLOG_MAX_HOST+2)
21 * User view of a write log record. Note that this is not necessiliary
22 * how the data is formatted on disk (signifigant compression occurrs), so
23 * don't expect to od the write log file and see things formatted this way.
27 int w_pid; /* pid doing the write */
28 int w_offset; /* file offset */
29 int w_nbytes; /* # bytes written */
30 int w_oflags; /* low-order open() flags */
31 int w_done; /* 1 if io confirmed done */
32 int w_async; /* 1 if async write (writea) */
34 char w_host[WLOG_MAX_HOST+1]; /* host doing write - */
36 int w_hostlen; /* host name length */
37 char w_path[WLOG_MAX_PATH+1]; /* file written to - */
39 int w_pathlen; /* file name length */
40 char w_pattern[WLOG_MAX_PATTERN+1]; /* pattern written - */
42 int w_patternlen; /* pattern length */
46 #define uint unsigned int
50 * On-disk structure of a wlog_rec. Actually, the record consists of
51 * 3 parts: [wlog_rec_disk structure][variable length data][length]
52 * where length is a 2 byte field containing the total record length
53 * (including the 2 bytes). It is used for scanning the logfile in reverse
56 * The variable length data includes the path, host, and pattern (in that
57 * order). The lengths of these pieces of data are held in the
58 * wlog_rec_disk structure. Thus, the actual on-disk record looks like
59 * this (top is lower byte offset):
61 * struct wlog_rec_disk
62 * path (w_pathlen bytes - not null terminated)
63 * host (w_hostlen bytes - not null terminated)
64 * pattern (w_patternlen bytes - not null terminated)
65 * 2-byte record length
67 * Another way of looking at it is:
69 * <struct wlog_rec_disk><path (wpathlen bytes)>-->
70 * --><host (w_hostlen bytes)><pattern (w_patternlen bytes)><length (2 bytes)>
72 * The maximum length of this record is defined by the WLOG_REC_MAX_SIZE
73 * record. Note that the 2-byte record length forces this to be
76 * Note that there is lots of bit-masking done here. The w_pathlen,
77 * w_hostlen, and w_patternlen fields MUST have enough bits to hold
78 * WLOG_MAX_PATH, WLOG_MAX_HOST, and WLOG_MAX_PATTERN bytes respectivly.
81 struct wlog_rec_disk {
83 uint w_offset : 32; /* file offset */
84 uint w_extra0 : 32; /* EXTRA BITS IN WORD 0 */
87 uint w_nbytes : 32; /* # bytes written */
88 uint w_oflags : 32; /* low-order open() flags */
90 uint w_pid : 17; /* pid doing the write */
91 uint w_pathlen : 7; /* length of file path */
92 uint w_patternlen: 6; /* length of pattern */
93 uint w_hostlen : 4; /* length of host */
94 uint w_done : 1; /* 1 if io confirmed done */
95 uint w_async : 1; /* 1 if async write (writea) */
96 uint w_extra2 : 28; /* EXTRA BITS IN WORD 2 */
100 * write log file datatype. wlog_open() initializes this structure
101 * which is then passed around to the various wlog_xxx routines.
105 int w_afd; /* append fd */
106 int w_rfd; /* random-access fd */
107 char w_file[1024]; /* name of the write_log */
111 * return value defines for the user-supplied function to
112 * wlog_scan_backward().
115 #define WLOG_STOP_SCAN 0
116 #define WLOG_CONTINUE_SCAN 1
123 extern int wlog_open(struct wlog_file *wfile, int trunc, int mode);
124 extern int wlog_close(struct wlog_file *wfile);
125 extern int wlog_record_write(struct wlog_file *wfile,
126 struct wlog_rec *wrec, long offset);
127 extern int wlog_scan_backward(struct wlog_file *wfile, int nrecs,
128 int (*func)(struct wlog_rec *rec),
133 int wlog_record_write();
134 int wlog_scan_backward();
137 extern char Wlog_Error_String[];
139 #endif /* _WRITE_LOG_H_ */