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