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