2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 * loggen: Generate log entries. Very much incomplete. The empty log
36 * record is a bit of a misnomer since we need to jump through
37 * hoops to get a log record that parses ok yet does nothing.
45 #include <xfs_log_priv.h>
50 fprintf(stderr,"Usage: loggen\n"
51 " set up parameters before writing record(s):\n"
52 " -f f - set format\n"
56 " -C c - set tail cycle\n"
57 " -B b - set tail block\n"
58 " write log record(s):\n"
59 " -z n - write n zero block(s) (1BB)\n"
60 " -e n - write n empty record(s) (2BB)\n"
61 " -m n - write n unmount record(s) (2BB)\n"
63 " redirect stdout to external log partition, or pipe to\n"
64 " dd with appropriate parameters to stuff into internal log.\n"
73 int param_tail_cycle = 1;
74 int param_tail_block = 0;
75 int param_fmt = XLOG_FMT;
76 uuid_t param_uuid = {0};
79 loggen_alloc(int blocks)
81 if (!(buf=realloc(buf, blocks*BBSIZE))) {
82 fprintf(stderr,"failed to allocate %d block(s)\n", blocks);
85 memset(buf, 0, blocks*BBSIZE);
93 fprintf(stderr,"no buffer allocated\n");
97 if (fwrite(buf, BBSIZE, bufblocks, stdout) != bufblocks) {
105 loggen_zero(int count)
109 fprintf(stderr," *** zero block (1BB) x %d\n", count);
116 loggen_unmount(int count)
118 xlog_rec_header_t *head;
119 xlog_op_header_t *op;
120 /* the data section must be 32 bit size aligned */
124 __uint32_t pad2; /* may as well make it 64 bits */
125 } magic = { XLOG_UNMOUNT_TYPE, 0, 0 };
129 fprintf(stderr," *** unmount record (2BB) x %d\n", count);
132 head = (xlog_rec_header_t *)buf;
133 op = (xlog_op_header_t *)(((char*)buf)+BBSIZE);
135 /* note that oh_tid actually contains the cycle number
136 * and the tid is stored in h_cycle_data[0] - that's the
137 * way things end up on disk.
140 INT_SET(head->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
141 INT_SET(head->h_cycle, ARCH_CONVERT, param_cycle);
142 INT_SET(head->h_version, ARCH_CONVERT, 1);
143 INT_SET(head->h_len, ARCH_CONVERT, 20);
144 INT_SET(head->h_chksum, ARCH_CONVERT, 0);
145 INT_SET(head->h_prev_block, ARCH_CONVERT, -1);
146 INT_SET(head->h_num_logops, ARCH_CONVERT, 1);
147 INT_SET(head->h_cycle_data[0], ARCH_CONVERT, 0xb0c0d0d0);
148 INT_SET(head->h_fmt, ARCH_CONVERT, param_fmt);
150 ASSIGN_ANY_LSN(head->h_tail_lsn,
151 param_tail_cycle, param_tail_block, ARCH_CONVERT);
153 memcpy(head->h_fs_uuid, param_uuid, sizeof(uuid_t));
155 /* now a log unmount op */
156 INT_SET(op->oh_tid, ARCH_CONVERT, param_cycle);
157 INT_SET(op->oh_len, ARCH_CONVERT, sizeof(magic));
158 INT_SET(op->oh_clientid, ARCH_CONVERT, XFS_LOG);
159 INT_SET(op->oh_flags, ARCH_CONVERT, XLOG_UNMOUNT_TRANS);
160 INT_SET(op->oh_res2, ARCH_CONVERT, 0);
162 /* and the data for this op */
164 memcpy(op+1, &magic, sizeof(magic));
167 ASSIGN_ANY_LSN(head->h_lsn,
168 param_cycle, param_block++, ARCH_CONVERT);
175 loggen_empty(int count)
177 xlog_rec_header_t *head;
178 xlog_op_header_t *op1, *op2, *op3, *op4, *op5;
179 xfs_trans_header_t *trans;
180 xfs_buf_log_format_t *blf;
186 fprintf(stderr," *** empty record (2BB) x %d\n", count);
190 head = (xlog_rec_header_t *)p; p+=BBSIZE;
191 op1 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
192 op2 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
193 trans = (xfs_trans_header_t *)p; p+=sizeof(xfs_trans_header_t);
194 op3 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
195 blf = (xfs_buf_log_format_t*)p; p+=sizeof(xfs_buf_log_format_t);
196 op4 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
197 data = (int *)p; p+=sizeof(int);
198 op5 = (xlog_op_header_t *)p; p+=sizeof(xlog_op_header_t);
200 /* note that oh_tid actually contains the cycle number
201 * and the tid is stored in h_cycle_data[0] - that's the
202 * way things end up on disk.
205 INT_SET(head->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
206 INT_SET(head->h_cycle, ARCH_CONVERT, param_cycle);
207 INT_SET(head->h_version, ARCH_CONVERT, 1);
208 INT_SET(head->h_len, ARCH_CONVERT, 5*sizeof(xlog_op_header_t) +
209 sizeof(xfs_trans_header_t)+
210 sizeof(xfs_buf_log_format_t)+
212 INT_SET(head->h_chksum, ARCH_CONVERT, 0);
213 INT_SET(head->h_prev_block, ARCH_CONVERT, -1);
214 INT_SET(head->h_num_logops, ARCH_CONVERT, 5);
215 INT_SET(head->h_cycle_data[0], ARCH_CONVERT, 0xb0c0d0d0);
216 INT_SET(head->h_fmt, ARCH_CONVERT, param_fmt);
218 ASSIGN_ANY_LSN(head->h_tail_lsn,
219 param_tail_cycle, param_tail_block, ARCH_CONVERT);
221 memcpy(head->h_fs_uuid, param_uuid, sizeof(uuid_t));
224 INT_SET(op1->oh_tid, ARCH_CONVERT, 1);
225 INT_SET(op1->oh_len, ARCH_CONVERT, 0);
226 INT_SET(op1->oh_clientid, ARCH_CONVERT, XFS_TRANSACTION);
227 INT_SET(op1->oh_flags, ARCH_CONVERT, XLOG_START_TRANS);
228 INT_SET(op1->oh_res2, ARCH_CONVERT, 0);
230 INT_SET(op2->oh_tid, ARCH_CONVERT, 0xb0c0d0d0);
231 INT_SET(op2->oh_len, ARCH_CONVERT, sizeof(xfs_trans_header_t));
232 INT_SET(op2->oh_clientid, ARCH_CONVERT, XFS_TRANSACTION);
233 INT_SET(op2->oh_flags, ARCH_CONVERT, 0);
234 INT_SET(op2->oh_res2, ARCH_CONVERT, 0);
235 /* dummy transaction - this stuff doesn't get endian converted */
236 trans->th_magic = XFS_TRANS_MAGIC;
237 trans->th_type = XFS_TRANS_DUMMY1;
239 trans->th_num_items = 1;
241 INT_SET(op3->oh_tid, ARCH_CONVERT, 0xb0c0d0d0);
242 INT_SET(op3->oh_len, ARCH_CONVERT, sizeof(xfs_buf_log_format_t));
243 INT_SET(op3->oh_clientid, ARCH_CONVERT, XFS_TRANSACTION);
244 INT_SET(op3->oh_flags, ARCH_CONVERT, 0);
245 INT_SET(op3->oh_res2, ARCH_CONVERT, 0);
246 /* an empty buffer too */
247 blf->blf_type = XFS_LI_BUF;
249 blf->blf_flags = XFS_BLI_CANCEL;
251 blf->blf_map_size = 1;
252 blf->blf_data_map[0]= 0;
254 INT_SET(op4->oh_tid, ARCH_CONVERT, 0xb0c0d0d0);
255 INT_SET(op4->oh_len, ARCH_CONVERT, sizeof(int));
256 INT_SET(op4->oh_clientid, ARCH_CONVERT, XFS_TRANSACTION);
257 INT_SET(op4->oh_flags, ARCH_CONVERT, 0);
258 INT_SET(op4->oh_res2, ARCH_CONVERT, 0);
260 *data=*(int*)(char*)"FISH"; /* this won't get written (I hope) */
262 INT_SET(op5->oh_tid, ARCH_CONVERT, 0xb0c0d0d0);
263 INT_SET(op5->oh_len, ARCH_CONVERT, 0);
264 INT_SET(op5->oh_clientid, ARCH_CONVERT, XFS_TRANSACTION);
265 INT_SET(op5->oh_flags, ARCH_CONVERT, XLOG_COMMIT_TRANS);
266 INT_SET(op5->oh_res2, ARCH_CONVERT, 0);
269 ASSIGN_ANY_LSN(head->h_lsn,
270 param_cycle, param_block++, ARCH_CONVERT);
277 main(int argc, char *argv[])
281 fprintf(stderr,"*** loggen\n");
285 while ((c = getopt(argc, argv, "f:u:c:b:C:B:z:e:m:")) != -1) {
288 param_fmt=atoi(optarg);
291 memset(param_uuid, atoi(optarg), sizeof(param_uuid));
294 param_cycle=atoi(optarg);
297 param_block=atoi(optarg);
300 param_tail_cycle=atoi(optarg);
303 param_tail_block=atoi(optarg);
307 loggen_zero(atoi(optarg));
310 loggen_empty(atoi(optarg));
313 loggen_unmount(atoi(optarg));
317 fprintf(stderr, "unknown option\n");