replay-log: add support for replaying ops in target device sector range
[xfstests-dev.git] / lib / datapid.c
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 /************
19
20 64 bits in a Cray word
21
22                                 12345678901234567890123456789012
23 1234567890123456789012345678901234567890123456789012345678901234
24 ________________________________________________________________
25 <    pid       >< word-offset in file (same #) ><    pid       >
26
27 1234567890123456789012345678901234567890123456789012345678901234
28 ________________________________________________________________
29 <    pid       >< offset in file of this word  ><    pid       >
30
31
32 8 bits to a bytes == character
33  NBPW            8 
34 ************/
35
36 #include <stdio.h>
37 #include <sys/param.h>
38 #ifdef UNIT_TEST
39 #include <unistd.h>
40 #include <stdlib.h>
41 #endif
42
43 static char Errmsg[80];
44
45 #define LOWER16BITS(X)  (X & 0177777)
46 #define LOWER32BITS(X)  (X & 0xffffffff)
47
48 /***
49 #define HIGHBITS(WRD, bits) ( (-1 << (64-bits)) & WRD)
50 #define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD)
51 ****/
52
53 #define NBPBYTE         8               /* number bits per byte */
54
55 #ifndef DEBUG
56 #define DEBUG   0
57 #endif
58
59 /***********************************************************************
60  *
61  * 
62  * 1   2   3   4   5   6   7   8   9   10  11  12  13  14  14  15       bytes
63  * 1234567890123456789012345678901234567890123456789012345678901234     bits
64  * ________________________________________________________________     1 word
65  * <    pid       >< offset in file of this word  ><    pid       >
66  * 
67  * the words are put together where offset zero is the start.
68  * thus, offset 16 is the start of  the second full word
69  * Thus, offset 8 is in middle of word 1
70  ***********************************************************************/
71 int
72 datapidgen(pid, buffer, bsize, offset)
73 int pid;
74 char *buffer;
75 int bsize;
76 int offset;
77 {
78         return -1;      /* not support on non-64 bits word machines  */
79
80
81
82
83 /***********************************************************************
84  *
85  *
86  ***********************************************************************/
87 int
88 datapidchk(pid, buffer, bsize, offset, errmsg)
89 int pid;
90 char *buffer;
91 int bsize;
92 int offset;
93 char **errmsg;
94 {
95     if ( errmsg != NULL ) {
96         *errmsg = Errmsg;
97     }
98     sprintf(Errmsg, "Not supported on this OS.");
99     return 0;
100
101 }       /* end of datapidchk */
102
103 #if UNIT_TEST
104
105 /***********************************************************************
106  * main for doing unit testing
107  ***********************************************************************/
108 int
109 main(ac, ag)
110 int ac;
111 char **ag;
112 {
113
114 int size=1234;
115 char *buffer;
116 int ret;
117 char *errmsg;
118
119     if ((buffer=(char *)malloc(size)) == NULL ) {
120         perror("malloc");
121         exit(2);
122     }
123
124
125     datapidgen(-1, buffer, size, 3);
126
127 /***
128 fwrite(buffer, size, 1, stdout);
129 fwrite("\n", 1, 1, stdout);
130 ****/
131
132     printf("datapidgen(-1, buffer, size, 3)\n");
133
134     ret=datapidchk(-1, buffer, size, 3, &errmsg);
135     printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
136         size, ret, errmsg);
137     ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
138     printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
139         size-1, ret, errmsg);
140
141     buffer[25]= 0x0;
142     buffer[26]= 0x0;
143     buffer[27]= 0x0;
144     buffer[28]= 0x0;
145     printf("changing char 25-28\n");
146
147     ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
148     printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
149         size-1, ret, errmsg);
150
151 printf("------------------------------------------\n");
152
153     datapidgen(getpid(), buffer, size, 5);
154
155 /*******
156 fwrite(buffer, size, 1, stdout);
157 fwrite("\n", 1, 1, stdout);
158 ******/
159
160     printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
161
162     ret=datapidchk(getpid(), buffer, size, 5, &errmsg);
163     printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
164         size, ret, errmsg);
165
166     ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
167     printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
168         size-1, ret, errmsg);
169
170     buffer[25]= 0x0;
171     printf("changing char 25\n");
172
173     ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
174     printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
175         size-1, ret, errmsg);
176
177     exit(0);
178 }
179
180 #endif
181