generic: mmap and copy file data with page overlapping
[xfstests-dev.git] / include / write_log.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef _WRITE_LOG_H_
7 #define _WRITE_LOG_H_
8
9 /*
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
12  * BELOW.
13  */
14
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)
19
20 /*
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.
24  */
25
26 struct wlog_rec {
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)    */
33
34     char    w_host[WLOG_MAX_HOST+1];            /* host doing write -   */
35                                                 /* null terminated */
36     int     w_hostlen;                          /* host name length     */
37     char    w_path[WLOG_MAX_PATH+1];            /* file written to -    */
38                                                 /* null terminated */
39     int     w_pathlen;                          /* file name length     */
40     char    w_pattern[WLOG_MAX_PATTERN+1];      /* pattern written -    */
41                                                 /* null terminated */
42     int     w_patternlen;                       /* pattern length       */
43 };
44
45 #ifndef uint
46 #define uint    unsigned int
47 #endif
48
49 /*
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
54  * order.
55  *
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):
60  *
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
66  *
67  * Another way of looking at it is:
68  *
69  * <struct wlog_rec_disk><path (wpathlen bytes)>-->
70  * --><host (w_hostlen bytes)><pattern (w_patternlen bytes)><length (2 bytes)>
71  *
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
74  * <= 64k bytes.
75  *
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.
79  */
80
81 struct wlog_rec_disk {
82 #ifdef linux
83     uint    w_offset    : 32;       /* file offset                  */
84     uint    w_extra0    : 32;       /* EXTRA BITS IN WORD 0         */
85 #endif
86
87     uint    w_nbytes    : 32;       /* # bytes written              */
88     uint    w_oflags    : 32;       /* low-order open() flags       */
89
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         */
97 };
98
99 /*
100  * write log file datatype.  wlog_open() initializes this structure
101  * which is then passed around to the various wlog_xxx routines.
102  */
103
104 struct wlog_file {
105     int         w_afd;                  /* append fd                    */
106     int         w_rfd;                  /* random-access fd             */
107     char        w_file[1024];           /* name of the write_log        */
108 };
109
110 /*
111  * return value defines for the user-supplied function to
112  * wlog_scan_backward().
113  */
114
115 #define WLOG_STOP_SCAN          0
116 #define WLOG_CONTINUE_SCAN      1
117
118 /*
119  * wlog prototypes
120  */
121
122 #if __STDC__
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),
129                                    long data);
130 #else
131 int     wlog_open();
132 int     wlog_close();
133 int     wlog_record_write();
134 int     wlog_scan_backward();
135 #endif
136
137 extern char     Wlog_Error_String[];
138
139 #endif /* _WRITE_LOG_H_ */
140