Sync some headers with ltp project, missed on initial checkin
[xfstests-dev.git] / include / write_log.h
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., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, 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
52 struct 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
107 struct wlog_rec_disk {
108 #ifdef sgi      /* sgi is pissy about fields > 32 bit, even cc -mips3 */
109     uint    w_offset    : 32;       /* file offset                  */
110     uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
111 #endif
112 #ifdef linux
113     uint    w_offset    : 32;       /* file offset                  */
114     uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
115 #endif
116 #ifdef CRAY
117     uint    w_offset    : 44;       /* file offset                  */
118     uint    w_extra0    : 20;       /* EXTRA BITS IN WORD 0         */
119 #endif
120
121     uint    w_nbytes    : 32;       /* # bytes written              */
122     uint    w_oflags    : 32;       /* low-order open() flags       */
123
124     uint    w_pid       : 17;       /* pid doing the write          */
125     uint    w_pathlen   :  7;       /* length of file path          */
126     uint    w_patternlen:  6;       /* length of pattern            */
127     uint    w_hostlen   :  4;       /* length of host               */
128     uint    w_done      :  1;       /* 1 if io confirmed done       */
129     uint    w_async     :  1;       /* 1 if async write (writea)    */
130     uint    w_extra2    : 28;       /* EXTRA BITS IN WORD 2         */
131 };
132
133 /*
134  * write log file datatype.  wlog_open() initializes this structure
135  * which is then passed around to the various wlog_xxx routines.
136  */
137
138 struct wlog_file {
139     int         w_afd;                  /* append fd                    */
140     int         w_rfd;                  /* random-access fd             */
141     char        w_file[1024];           /* name of the write_log        */
142 };
143
144 /*
145  * return value defines for the user-supplied function to
146  * wlog_scan_backward().
147  */
148
149 #define WLOG_STOP_SCAN          0
150 #define WLOG_CONTINUE_SCAN      1
151
152 /*
153  * wlog prototypes
154  */
155
156 #if __STDC__
157 extern int      wlog_open(struct wlog_file *wfile, int trunc, int mode);
158 extern int      wlog_close(struct wlog_file *wfile);
159 extern int      wlog_record_write(struct wlog_file *wfile,
160                                   struct wlog_rec *wrec, long offset);
161 extern int      wlog_scan_backward(struct wlog_file *wfile, int nrecs,
162                                    int (*func)(struct wlog_rec *rec),
163                                    long data);
164 #else
165 int     wlog_open();
166 int     wlog_close();
167 int     wlog_record_write();
168 int     wlog_scan_backward();
169 #endif
170
171 extern char     Wlog_Error_String[];
172
173 #endif /* _WRITE_LOG_H_ */
174