]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/logprint.c
2 * Copyright (c) 2000-2004 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
18 #include <sys/types.h>
27 #define OP_PRINT_TRANS 1
39 int print_exit
= 1; /* -e is now default. specify -c to override */
40 int print_operation
= OP_PRINT
;
45 fprintf(stderr
, _("Usage: %s [options...] <device>\n\n\
47 -c try to continue if error found in log\n\
48 -C <filename> copy the log from the filesystem to filename\n\
49 -d dump the log in log-record format\n\
50 -e exit when an error is found in the log\n\
51 -f specified device is actually a file\n\
52 -l <device> filename of external log\n\
53 -n don't try and interpret log data\n\
54 -o print buffer data in hex\n\
55 -s <start blk> block # to start printing\n\
56 -v print \"overwrite\" data\n\
57 -t print out transactional view\n\
58 -b in transactional view, extract buffer info\n\
59 -i in transactional view, extract inode info\n\
60 -q in transactional view, extract quota info\n\
61 -D print only data; no decoding\n\
62 -V print version information\n"),
68 logstat(xfs_mount_t
*mp
)
74 /* On Linux we always read the superblock of the
75 * filesystem. We need this to get the length of the
76 * log. Otherwise we end up seeking forever. -- mkp
78 if ((fd
= open(x
.dname
, O_RDONLY
)) == -1) {
79 fprintf(stderr
, _(" Can't open device %s: %s\n"),
80 x
.dname
, strerror(errno
));
83 lseek64(fd
, 0, SEEK_SET
);
84 if (read(fd
, buf
, sizeof(buf
)) != sizeof(buf
)) {
85 fprintf(stderr
, _(" read of XFS superblock failed\n"));
92 * Conjure up a mount structure
95 libxfs_sb_from_disk(sb
, (xfs_dsb_t
*)buf
);
96 mp
->m_blkbb_log
= sb
->sb_blocklog
- BBSHIFT
;
98 x
.logBBsize
= XFS_FSB_TO_BB(mp
, sb
->sb_logblocks
);
99 x
.logBBstart
= XFS_FSB_TO_DADDR(mp
, sb
->sb_logstart
);
101 if (xfs_sb_version_hassector(sb
))
102 x
.lbsize
<<= (sb
->sb_logsectlog
- BBSHIFT
);
104 if (!x
.logname
&& sb
->sb_logstart
== 0) {
105 fprintf(stderr
, _(" external log device not specified\n\n"));
113 x
.logBBsize
= s
.st_size
>> 9;
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
));
126 } else { /* Internal log */
134 main(int argc
, char **argv
)
136 int print_start
= -1;
139 char *copy_file
= NULL
;
140 struct xlog log
= {0};
143 setlocale(LC_ALL
, "");
144 bindtextdomain(PACKAGE
, LOCALEDIR
);
146 memset(&mount
, 0, sizeof(mount
));
148 progname
= basename(argv
[0]);
149 while ((c
= getopt(argc
, argv
, "bC:cdefl:iqnors:tDVv")) != EOF
) {
159 /* default is to stop on error.
170 print_operation
= OP_COPY
;
174 print_operation
= OP_DUMP
;
197 print_start
= atoi(optarg
);
200 print_operation
= OP_PRINT_TRANS
;
206 printf(_("%s version %s\n"), progname
, VERSION
);
213 if (argc
- optind
!= 1)
216 x
.dname
= argv
[optind
];
221 x
.isreadonly
= LIBXFS_ISINACTIVE
;
222 printf(_("xfs_logprint:\n"));
223 if (!libxfs_init(&x
))
227 libxfs_buftarg_init(&mount
, x
.ddev
, x
.logdev
, x
.rtdev
);
229 logfd
= (x
.logfd
< 0) ? x
.dfd
: x
.logfd
;
231 printf(_(" data device: 0x%llx\n"), (unsigned long long)x
.ddev
);
234 printf(_(" log file: \"%s\" "), x
.logname
);
236 printf(_(" log device: 0x%llx "), (unsigned long long)x
.logdev
);
239 printf(_("daddr: %lld length: %lld\n\n"),
240 (long long)x
.logBBstart
, (long long)x
.logBBsize
);
242 ASSERT(x
.logBBsize
<= INT_MAX
);
244 log
.l_dev
= mount
.m_logdev_targp
;
245 log
.l_logBBstart
= x
.logBBstart
;
246 log
.l_logBBsize
= x
.logBBsize
;
247 log
.l_sectBBsize
= BTOBB(x
.lbsize
);
250 switch (print_operation
) {
252 xfs_log_print(&log
, logfd
, print_start
);
255 xfs_log_print_trans(&log
, print_start
);
258 xfs_log_dump(&log
, logfd
, print_start
);
261 xfs_log_copy(&log
, logfd
, copy_file
);