]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - logprint/logprint.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / logprint / logprint.c
CommitLineData
2bd0ea18 1/*
0d3e0b37 2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
dfc130f3 3 *
2bd0ea18
NS
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.
dfc130f3 7 *
2bd0ea18
NS
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.
dfc130f3 11 *
2bd0ea18
NS
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.
dfc130f3 18 *
2bd0ea18
NS
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.
dfc130f3 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
dfc130f3
RC
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include "logprint.h"
5000d01d
SL
34#include <sys/types.h>
35#include <sys/stat.h>
2bd0ea18
NS
36
37int print_data;
38int print_only_data;
39int print_inode;
40int print_quota;
41int print_buffer;
42int print_transactions;
43int print_overwrite;
44int print_no_data;
45int print_no_print;
46int print_exit = 1; /* -e is now default. specify -c to override */
47
2bd0ea18
NS
48xfs_mount_t mp;
49
50void
51usage(void)
52{
53 fprintf(stderr, "Usage: %s [options...] <device>\n\n\
54Options:\n\
55 -c try to continue if error found in log\n\
49d4ff13 56 -f specified device is actually a file\n\
2bd0ea18
NS
57 -l <device> filename of external log\n\
58 -n don't try and interpret log data\n\
59 -o print buffer data in hex\n\
60 -s <start blk> block # to start printing\n\
61 -v print \"overwrite\" data\n\
62 -t print out transactional view\n\
dfc130f3
RC
63 -b in transactional view, extract buffer info\n\
64 -i in transactional view, extract inode info\n\
65 -q in transactional view, extract quota info\n\
2bd0ea18 66 -D print only data; no decoding\n\
dfc130f3
RC
67 -V print version information\n",
68 progname);
2bd0ea18
NS
69 exit(1);
70}
71
72int
73logstat(libxfs_init_t *x)
74{
75 int fd;
76 char buf[BBSIZE];
77 xfs_sb_t *sb;
78
79 /* On Linux we always read the superblock of the
80 * filesystem. We need this to get the length of the
81 * log. Otherwise we end up seeking forever. -- mkp
82 */
83 if ((fd = open(x->dname, O_RDONLY)) == -1) {
84 fprintf(stderr, " Can't open device %s: %s\n",
85 x->dname, strerror(errno));
86 exit(1);
87 }
88 lseek64(fd, 0, SEEK_SET);
89 if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
90 fprintf(stderr, " read of XFS superblock failed\n");
91 exit(1);
dfc130f3
RC
92 }
93 close (fd);
2bd0ea18 94
5000d01d 95 if (!x->disfile) {
dfc130f3
RC
96 /*
97 * Conjure up a mount structure
5000d01d
SL
98 */
99 libxfs_xlate_sb(buf, &(mp.m_sb), 1, ARCH_CONVERT, XFS_SB_ALL_BITS);
100 sb = &(mp.m_sb);
101 mp.m_blkbb_log = sb->sb_blocklog - BBSHIFT;
102
103 x->logBBsize = XFS_FSB_TO_BB(&mp, sb->sb_logblocks);
104 x->logBBstart = XFS_FSB_TO_DADDR(&mp, sb->sb_logstart);
105 if (!x->logname && sb->sb_logstart == 0) {
106 fprintf(stderr, " external log device not specified\n\n");
107 usage();
108 /*NOTREACHED*/
dfc130f3 109 }
5000d01d
SL
110 } else {
111 struct stat s;
2bd0ea18 112
5000d01d
SL
113 stat(x->dname, &s);
114 x->logBBsize = s.st_size >> 9;
115 x->logBBstart = 0;
116 }
2bd0ea18 117
2bd0ea18
NS
118
119 if (x->logname && *x->logname) { /* External log */
120 if ((fd = open(x->logname, O_RDONLY)) == -1) {
121 fprintf(stderr, "Can't open file %s: %s\n",
122 x->logname, strerror(errno));
123 exit(1);
124 }
dfc130f3 125 close(fd);
2bd0ea18
NS
126 } else { /* Internal log */
127 x->logdev = x->ddev;
128 }
129
130 return 0;
131}
132
133int
134main(int argc, char **argv)
135{
136 int print_start = -1;
137 int c;
dfc130f3
RC
138 int logfd;
139 xlog_t log = {0};
2bd0ea18
NS
140
141 progname = basename(argv[0]);
49d4ff13 142 while ((c = getopt(argc, argv, "befl:iqnors:tDVvc")) != EOF) {
2bd0ea18
NS
143 switch (c) {
144 case 'D': {
145 print_only_data++;
146 print_data++;
147 break;
148 }
149 case 'b': {
150 print_buffer++;
151 break;
152 }
49d4ff13
NS
153 case 'f': {
154 x.disfile = 1;
155 break;
156 }
2bd0ea18
NS
157 case 'l': {
158 x.logname = optarg;
159 x.lisfile = 1;
160 break;
161 }
dfc130f3
RC
162 case 'c': {
163 /* default is to stop on error.
164 * -c turns this off.
165 */
2bd0ea18
NS
166 print_exit=0;
167 break;
168 }
dfc130f3
RC
169 case 'e': {
170 /* -e is now default
171 */
2bd0ea18
NS
172 print_exit++;
173 break;
174 }
175 case 'i': {
176 print_inode++;
177 break;
178 }
179 case 'q': {
180 print_quota++;
181 break;
182 }
183 case 'n': {
184 print_no_data++;
185 break;
186 }
187 case 'o': {
188 print_data++;
189 break;
190 }
191 case 's': {
192 print_start = atoi(optarg);
193 break;
194 }
195 case 't': {
196 print_transactions++;
197 break;
198 }
199 case 'V': {
200 printf("%s version %s\n", progname, VERSION);
3d98fe63 201 exit(0);
dfc130f3
RC
202 }
203 case 'v': {
204 print_overwrite++;
205 break;
2bd0ea18
NS
206 }
207 case '?': {
208 usage();
209 }
dfc130f3 210 }
2bd0ea18
NS
211 }
212
213 if (argc - optind != 1)
214 usage();
215
216 x.dname = argv[optind];
217
218 if (x.dname == NULL)
219 usage();
220
221 x.notvolok = 1;
222 x.isreadonly = LIBXFS_ISINACTIVE;
223 x.notvolmsg = "You should never see this message.\n";
224
dfc130f3 225 printf("xfs_logprint:\n");
2bd0ea18
NS
226 if (!libxfs_init(&x))
227 exit(1);
228
229 logstat(&x);
230
5b64e00a 231 logfd=(x.logfd<0)?(x.dfd):(x.logfd);
dfc130f3 232
5b64e00a
NS
233 printf(" data device: 0x%llx\n", (unsigned long long)x.ddev);
234
235 if (x.logname) {
236 printf(" log file: \"%s\" ", x.logname);
237 } else {
238 printf(" log device: 0x%llx ", (unsigned long long)x.logdev);
239 }
240
241 printf("daddr: %lld length: %lld\n\n",
242 (long long)x.logBBstart, (long long)x.logBBsize);
243
244 ASSERT(x.logBBstart <= INT_MAX);
2bd0ea18 245
5b64e00a 246 /* init log structure */
2bd0ea18
NS
247 log.l_dev = x.logdev;
248 log.l_logsize = BBTOB(x.logBBsize);
249 log.l_logBBstart = x.logBBstart;
250 log.l_logBBsize = x.logBBsize;
dfc130f3
RC
251 log.l_mp = &mp;
252
2bd0ea18
NS
253 if (print_transactions)
254 xfs_log_print_trans(&log, print_start);
255 else
256 xfs_log_print(&log, logfd, print_start);
dfc130f3 257
2bd0ea18
NS
258 exit(0);
259}