xfstests: rework "dmapi" subtree build mechanism
[xfstests-dev.git] / include / write_log.h
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18 #ifndef _WRITE_LOG_H_
19 #define _WRITE_LOG_H_
20
21 /*
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
24  * BELOW.
25  */
26
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)
31
32 /*
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.
36  */
37
38 struct wlog_rec {
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)    */
45
46     char    w_host[WLOG_MAX_HOST+1];            /* host doing write -   */
47                                                 /* null terminated */
48     int     w_hostlen;                          /* host name length     */
49     char    w_path[WLOG_MAX_PATH+1];            /* file written to -    */
50                                                 /* null terminated */
51     int     w_pathlen;                          /* file name length     */
52     char    w_pattern[WLOG_MAX_PATTERN+1];      /* pattern written -    */
53                                                 /* null terminated */
54     int     w_patternlen;                       /* pattern length       */
55 };
56
57 #ifndef uint
58 #define uint    unsigned int
59 #endif
60
61 /*
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
66  * order.
67  *
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):
72  *
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
78  *
79  * Another way of looking at it is:
80  *
81  * <struct wlog_rec_disk><path (wpathlen bytes)>-->
82  * --><host (w_hostlen bytes)><pattern (w_patternlen bytes)><length (2 bytes)>
83  *
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
86  * <= 64k bytes.
87  *
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.
91  */
92
93 struct wlog_rec_disk {
94 #ifdef sgi      /* sgi is pissy about fields > 32 bit, even cc -mips3 */
95     uint    w_offset    : 32;       /* file offset                  */
96     uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
97 #endif
98 #ifdef linux
99     uint    w_offset    : 32;       /* file offset                  */
100     uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
101 #endif
102 #ifdef CRAY
103     uint    w_offset    : 44;       /* file offset                  */
104     uint    w_extra0    : 20;       /* EXTRA BITS IN WORD 0         */
105 #endif
106
107     uint    w_nbytes    : 32;       /* # bytes written              */
108     uint    w_oflags    : 32;       /* low-order open() flags       */
109
110     uint    w_pid       : 17;       /* pid doing the write          */
111     uint    w_pathlen   :  7;       /* length of file path          */
112     uint    w_patternlen:  6;       /* length of pattern            */
113     uint    w_hostlen   :  4;       /* length of host               */
114     uint    w_done      :  1;       /* 1 if io confirmed done       */
115     uint    w_async     :  1;       /* 1 if async write (writea)    */
116     uint    w_extra2    : 28;       /* EXTRA BITS IN WORD 2         */
117 };
118
119 /*
120  * write log file datatype.  wlog_open() initializes this structure
121  * which is then passed around to the various wlog_xxx routines.
122  */
123
124 struct wlog_file {
125     int         w_afd;                  /* append fd                    */
126     int         w_rfd;                  /* random-access fd             */
127     char        w_file[1024];           /* name of the write_log        */
128 };
129
130 /*
131  * return value defines for the user-supplied function to
132  * wlog_scan_backward().
133  */
134
135 #define WLOG_STOP_SCAN          0
136 #define WLOG_CONTINUE_SCAN      1
137
138 /*
139  * wlog prototypes
140  */
141
142 #if __STDC__
143 extern int      wlog_open(struct wlog_file *wfile, int trunc, int mode);
144 extern int      wlog_close(struct wlog_file *wfile);
145 extern int      wlog_record_write(struct wlog_file *wfile,
146                                   struct wlog_rec *wrec, long offset);
147 extern int      wlog_scan_backward(struct wlog_file *wfile, int nrecs,
148                                    int (*func)(struct wlog_rec *rec),
149                                    long data);
150 #else
151 int     wlog_open();
152 int     wlog_close();
153 int     wlog_record_write();
154 int     wlog_scan_backward();
155 #endif
156
157 extern char     Wlog_Error_String[];
158
159 #endif /* _WRITE_LOG_H_ */
160