]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/logprint.c
c6e5051e8f8c4ece45e541e517b2903cc6fc84ed
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2004 Silicon Graphics, Inc.
15 #define OP_PRINT_TRANS 1
27 static int print_operation
= OP_PRINT
;
28 static struct libxfs_init x
;
33 fprintf(stderr
, _("Usage: %s [options...] <device>\n\n\
35 -c try to continue if error found in log\n\
36 -C <filename> copy the log from the filesystem to filename\n\
37 -d dump the log in log-record format\n\
38 -e exit when an error is found in the log\n\
39 -f specified device is actually a file\n\
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\
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\
49 -D print only data; no decoding\n\
50 -V print version information\n"),
63 /* On Linux we always read the superblock of the
64 * filesystem. We need this to get the length of the
65 * log. Otherwise we end up seeking forever. -- mkp
67 if ((fd
= open(x
.dname
, O_RDONLY
)) == -1) {
68 fprintf(stderr
, _(" Can't open device %s: %s\n"),
69 x
.dname
, strerror(errno
));
72 lseek(fd
, 0, SEEK_SET
);
73 if (read(fd
, buf
, sizeof(buf
)) != sizeof(buf
)) {
74 fprintf(stderr
, _(" read of XFS superblock failed\n"));
80 struct xfs_sb
*sb
= &mp
->m_sb
;
83 * Conjure up a mount structure
85 libxfs_sb_from_disk(sb
, (struct xfs_dsb
*)buf
);
86 mp
->m_features
|= libxfs_sb_version_to_features(&mp
->m_sb
);
87 mp
->m_blkbb_log
= sb
->sb_blocklog
- BBSHIFT
;
91 if (!x
.logname
&& sb
->sb_logstart
== 0) {
92 fprintf(stderr
, _(" external log device not specified\n\n"));
101 log
->l_logBBsize
= s
.st_size
>> 9;
102 log
->l_logBBstart
= 0;
103 log
->l_sectBBsize
= BTOBB(BBSIZE
);
104 log
->l_dev
= mp
->m_logdev_targp
;
108 if (x
.logname
&& *x
.logname
) { /* External log */
109 if ((fd
= open(x
.logname
, O_RDONLY
)) == -1) {
110 fprintf(stderr
, _("Can't open file %s: %s\n"),
111 x
.logname
, strerror(errno
));
115 } else { /* Internal log */
123 main(int argc
, char **argv
)
125 int print_start
= -1;
128 char *copy_file
= NULL
;
129 struct xlog log
= {0};
132 setlocale(LC_ALL
, "");
133 bindtextdomain(PACKAGE
, LOCALEDIR
);
135 memset(&mount
, 0, sizeof(mount
));
136 print_exit
= 1; /* -e is now default. specify -c to override */
138 progname
= basename(argv
[0]);
139 while ((c
= getopt(argc
, argv
, "bC:cdefl:iqnors:tDVv")) != EOF
) {
149 /* default is to stop on error.
160 print_operation
= OP_COPY
;
164 print_operation
= OP_DUMP
;
187 print_start
= atoi(optarg
);
190 print_operation
= OP_PRINT_TRANS
;
196 printf(_("%s version %s\n"), progname
, VERSION
);
203 if (argc
- optind
!= 1)
206 x
.dname
= argv
[optind
];
211 x
.isreadonly
= LIBXFS_ISINACTIVE
;
212 printf(_("xfs_logprint:\n"));
213 if (!libxfs_init(&x
))
216 libxfs_buftarg_init(&mount
, x
.ddev
, x
.logdev
, x
.rtdev
);
217 logstat(&mount
, &log
);
219 logfd
= (x
.logfd
< 0) ? x
.dfd
: x
.logfd
;
221 printf(_(" data device: 0x%llx\n"), (unsigned long long)x
.ddev
);
224 printf(_(" log file: \"%s\" "), x
.logname
);
226 printf(_(" log device: 0x%llx "), (unsigned long long)x
.logdev
);
229 printf(_("daddr: %lld length: %lld\n\n"),
230 (long long)log
.l_logBBstart
, (long long)log
.l_logBBsize
);
232 ASSERT(log
.l_logBBsize
<= INT_MAX
);
234 switch (print_operation
) {
236 xfs_log_print(&log
, logfd
, print_start
);
239 xfs_log_print_trans(&log
, print_start
);
242 xfs_log_dump(&log
, logfd
, print_start
);
245 xfs_log_copy(&log
, logfd
, copy_file
);