]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/logprint.c
bump minor version number.
[thirdparty/xfsprogs-dev.git] / logprint / logprint.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include "logprint.h"
34 #include <errno.h>
35 #include <fcntl.h>
36
37 int print_data;
38 int print_only_data;
39 int print_inode;
40 int print_quota;
41 int print_buffer;
42 int print_transactions;
43 int print_overwrite;
44 int print_no_data;
45 int print_no_print;
46 int print_exit = 1; /* -e is now default. specify -c to override */
47
48 libxfs_init_t x;
49 xfs_mount_t mp;
50
51 void
52 usage(void)
53 {
54 fprintf(stderr, "Usage: %s [options...] <device>\n\n\
55 Options:\n\
56 -c try to continue if error found in log\n\
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\
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\
66 -D print only data; no decoding\n\
67 -V print version information\n",
68 progname);
69 exit(1);
70 }
71
72 int
73 logstat(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);
92 }
93 close (fd);
94
95 /*
96 * Conjure up a mount structure
97 */
98 libxfs_xlate_sb(buf, &(mp.m_sb), 1, ARCH_CONVERT, XFS_SB_ALL_BITS);
99 sb = &(mp.m_sb);
100 mp.m_blkbb_log = sb->sb_blocklog - BBSHIFT;
101
102 x->logBBsize = XFS_FSB_TO_BB(&mp, sb->sb_logblocks);
103 x->logBBstart = XFS_FSB_TO_DADDR(&mp, sb->sb_logstart);
104
105 if (!x->logname && sb->sb_logstart == 0) {
106 fprintf(stderr, " external log device not specified\n\n");
107 usage();
108 /*NOTREACHED*/
109 }
110
111 if (x->logname && *x->logname) { /* External log */
112 if ((fd = open(x->logname, O_RDONLY)) == -1) {
113 fprintf(stderr, "Can't open file %s: %s\n",
114 x->logname, strerror(errno));
115 exit(1);
116 }
117 close(fd);
118 } else { /* Internal log */
119 x->logdev = x->ddev;
120 }
121
122 return 0;
123 }
124
125 int
126 main(int argc, char **argv)
127 {
128 int print_start = -1;
129 int c;
130 int logfd;
131 xlog_t log = {0};
132
133 progname = basename(argv[0]);
134 while ((c = getopt(argc, argv, "bel:iqnors:tDVvc")) != EOF) {
135 switch (c) {
136 case 'D': {
137 print_only_data++;
138 print_data++;
139 break;
140 }
141 case 'b': {
142 print_buffer++;
143 break;
144 }
145 case 'l': {
146 x.logname = optarg;
147 x.lisfile = 1;
148 break;
149 }
150 case 'c': {
151 /* default is to stop on error.
152 * -c turns this off.
153 */
154 print_exit=0;
155 break;
156 }
157 case 'e': {
158 /* -e is now default
159 */
160 print_exit++;
161 break;
162 }
163 case 'i': {
164 print_inode++;
165 break;
166 }
167 case 'q': {
168 print_quota++;
169 break;
170 }
171 case 'n': {
172 print_no_data++;
173 break;
174 }
175 case 'o': {
176 print_data++;
177 break;
178 }
179 case 's': {
180 print_start = atoi(optarg);
181 break;
182 }
183 case 't': {
184 print_transactions++;
185 break;
186 }
187 case 'V': {
188 printf("%s version %s\n", progname, VERSION);
189 break;
190 }
191 case 'v': {
192 print_overwrite++;
193 break;
194 }
195 case '?': {
196 usage();
197 }
198 }
199 }
200
201 if (argc - optind != 1)
202 usage();
203
204 x.dname = argv[optind];
205
206 if (x.dname == NULL)
207 usage();
208
209 x.notvolok = 1;
210 x.isreadonly = LIBXFS_ISINACTIVE;
211 x.notvolmsg = "You should never see this message.\n";
212
213 printf("xfs_logprint:\n");
214 if (!libxfs_init(&x))
215 exit(1);
216
217 logstat(&x);
218
219 logfd=(x.logfd<0)?(x.dfd):(x.logfd);
220
221 printf(" data device: 0x%llx\n", (unsigned long long)x.ddev);
222
223 if (x.logname) {
224 printf(" log file: \"%s\" ", x.logname);
225 } else {
226 printf(" log device: 0x%llx ", (unsigned long long)x.logdev);
227 }
228
229 printf("daddr: %lld length: %lld\n\n",
230 (long long)x.logBBstart, (long long)x.logBBsize);
231
232 ASSERT(x.logBBstart <= INT_MAX);
233
234 /* init log structure */
235 log.l_dev = x.logdev;
236 log.l_logsize = BBTOB(x.logBBsize);
237 log.l_logBBstart = x.logBBstart;
238 log.l_logBBsize = x.logBBsize;
239 log.l_mp = &mp;
240
241 if (print_transactions)
242 xfs_log_print_trans(&log, print_start);
243 else
244 xfs_log_print(&log, logfd, print_start);
245
246 exit(0);
247 }