2 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
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.
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.
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
21 * loggen: Generate log entries. Very much incomplete. The empty log
22 * record is a bit of a misnomer since we need to jump through
23 * hoops to get a log record that parses ok yet does nothing.
28 #include <xfs/libxfs.h>
29 #include <xfs/xfs_log.h>
30 #include <xfs/xfs_log_priv.h>
32 #ifndef ASSIGN_ANY_LSN_DISK
33 #define ASSIGN_ANY_LSN_DISK(lsn,cycle,block) \
35 INT_SET(((uint *)&(lsn))[0], ARCH_CONVERT, (cycle)); \
36 INT_SET(((uint *)&(lsn))[1], ARCH_CONVERT, (block)); \
43 fprintf(stderr,"Usage: loggen\n"
44 " set up parameters before writing record(s):\n"
45 " -f f - set format\n"
49 " -C c - set tail cycle\n"
50 " -B b - set tail block\n"
51 " write log record(s):\n"
52 " -z n - write n zero block(s) (1BB)\n"
53 " -e n - write n empty record(s) (2BB)\n"
54 " -m n - write n unmount record(s) (2BB)\n"
56 " redirect stdout to external log partition, or pipe to\n"
57 " dd with appropriate parameters to stuff into internal log.\n"
66 int param_tail_cycle = 1;
67 int param_tail_block = 0;
68 int param_fmt = XLOG_FMT;
69 uuid_t param_uuid = {0};
72 loggen_alloc(int blocks)
74 if (!(buf=realloc(buf, blocks*BBSIZE))) {
75 fprintf(stderr,"failed to allocate %d block(s)\n", blocks);
78 memset(buf, 0, blocks*BBSIZE);
86 fprintf(stderr,"no buffer allocated\n");
90 if (fwrite(buf, BBSIZE, bufblocks, stdout) != bufblocks) {
98 loggen_zero(int count)
102 fprintf(stderr," *** zero block (1BB) x %d\n", count);
109 loggen_unmount(int count)
111 xlog_rec_header_t *head;
112 xlog_op_header_t *op;
113 /* the data section must be 32 bit size aligned */
117 __uint32_t pad2; /* may as well make it 64 bits */
118 } magic = { XLOG_UNMOUNT_TYPE, 0, 0 };
122 fprintf(stderr," *** unmount record (2BB) x %d\n", count);
125 head = (xlog_rec_header_t *)buf;
126 op = (xlog_op_header_t *)(((char*)buf)+BBSIZE);
128 /* note that oh_tid actually contains the cycle number
129 * and the tid is stored in h_cycle_data[0] - that's the
130 * way things end up on disk.
133 head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
134 head->h_cycle = cpu_to_be32(param_cycle);
135 head->h_version = cpu_to_be32(1);
136 head->h_len = cpu_to_be32(20);
137 head->h_prev_block = cpu_to_be32(-1);
138 head->h_num_logops = cpu_to_be32(1);
139 head->h_cycle_data[0] = cpu_to_be32(0xb0c0d0d0);
140 head->h_fmt = cpu_to_be32(param_fmt);
142 head->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(param_tail_cycle,
145 memcpy(head->h_fs_uuid, param_uuid, sizeof(uuid_t));
147 /* now a log unmount op */
148 op->oh_tid = cpu_to_be32(param_cycle);
149 op->oh_len = cpu_to_be32(sizeof(magic));
150 op->oh_clientid = XFS_LOG;
151 op->oh_flags = XLOG_UNMOUNT_TRANS;
152 op->oh_res2 = cpu_to_be16(0);
154 /* and the data for this op */
156 memcpy(op+1, &magic, sizeof(magic));
159 head->h_lsn = cpu_to_be64(xlog_assign_lsn(param_cycle, param_block++));
166 loggen_empty(int count)
168 xlog_rec_header_t *head;
169 xlog_op_header_t *op1, *op2, *op3, *op4, *op5;
170 xfs_trans_header_t *trans;
171 xfs_buf_log_format_t blfs;
172 xfs_buf_log_format_t *blf;
178 fprintf(stderr," *** empty record (2BB) x %d\n", count);
182 head = (xlog_rec_header_t *)p; p+=BBSIZE;
183 op1 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
184 op2 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
185 trans = (xfs_trans_header_t *)p; p+=sizeof(xfs_trans_header_t);
186 op3 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
187 blf = (xfs_buf_log_format_t*)p; p+=sizeof(xfs_buf_log_format_t);
188 op4 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
189 data = (int *)p; p+=sizeof(int);
190 op5 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
192 /* note that oh_tid actually contains the cycle number
193 * and the tid is stored in h_cycle_data[0] - that's the
194 * way things end up on disk.
197 head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
198 head->h_cycle = cpu_to_be32(param_cycle);
199 head->h_version = cpu_to_be32(1);
200 head->h_len = cpu_to_be32(5*sizeof(xlog_op_header_t) +
201 sizeof(xfs_trans_header_t)+
202 sizeof(xfs_buf_log_format_t)+
204 head->h_prev_block = cpu_to_be32(-1);
205 head->h_num_logops = cpu_to_be32(5);
206 head->h_cycle_data[0] = cpu_to_be32(0xb0c0d0d0);
207 head->h_fmt = cpu_to_be32(param_fmt);
209 head->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(param_tail_cycle,
212 memcpy(head->h_fs_uuid, param_uuid, sizeof(uuid_t));
215 op1->oh_tid = cpu_to_be32(1);
216 op1->oh_len = cpu_to_be32(0);
217 op1->oh_clientid = XFS_TRANSACTION;
218 op1->oh_flags = XLOG_START_TRANS;
219 op1->oh_res2 = cpu_to_be16(0);
221 op2->oh_tid = cpu_to_be32(0xb0c0d0d0);
222 op2->oh_len = cpu_to_be32(sizeof(xfs_trans_header_t));
223 op2->oh_clientid = XFS_TRANSACTION;
225 op2->oh_res2 = cpu_to_be16(0);
226 /* dummy transaction - this stuff doesn't get endian converted */
227 trans->th_magic = XFS_TRANS_MAGIC;
228 trans->th_type = XFS_TRANS_DUMMY1;
230 trans->th_num_items = 1;
232 op3->oh_tid = cpu_to_be32(0xb0c0d0d0);
233 op3->oh_len = cpu_to_be32(sizeof(xfs_buf_log_format_t));
234 op3->oh_clientid = XFS_TRANSACTION;
236 op3->oh_res2 = cpu_to_be16(0);
237 /* an empty buffer too */
238 blfs.blf_type = XFS_LI_BUF;
240 #ifdef XFS_BLF_CANCEL
241 blfs.blf_flags = XFS_BLF_CANCEL;
243 blfs.blf_flags = XFS_BLI_CANCEL;
247 blfs.blf_map_size = 1;
248 blfs.blf_data_map[0]= 0;
249 memcpy(blf, &blfs, sizeof(blfs));
251 op4->oh_tid = cpu_to_be32(0xb0c0d0d0);
252 op4->oh_len = cpu_to_be32(sizeof(int));
253 op4->oh_clientid = XFS_TRANSACTION;
255 op4->oh_res2 = cpu_to_be16(0);
257 *data=*(int*)(char*)"FISH"; /* this won't get written (I hope) */
259 op5->oh_tid = cpu_to_be32(0xb0c0d0d0);
260 op5->oh_len = cpu_to_be32(0);
261 op5->oh_clientid = XFS_TRANSACTION;
262 op5->oh_flags = XLOG_COMMIT_TRANS;
263 op5->oh_res2 = cpu_to_be16(0);
266 head->h_lsn = cpu_to_be64(xlog_assign_lsn(param_cycle, param_block++));
273 main(int argc, char *argv[])
277 fprintf(stderr,"*** loggen\n");
281 while ((c = getopt(argc, argv, "f:u:c:b:C:B:z:e:m:")) != -1) {
284 param_fmt=atoi(optarg);
287 memset(param_uuid, atoi(optarg), sizeof(param_uuid));
290 param_cycle=atoi(optarg);
293 param_block=atoi(optarg);
296 param_tail_cycle=atoi(optarg);
299 param_tail_block=atoi(optarg);
303 loggen_zero(atoi(optarg));
306 loggen_empty(atoi(optarg));
309 loggen_unmount(atoi(optarg));
313 fprintf(stderr, "unknown option\n");