]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxlog/util.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
12 int print_record_header
;
16 * Return 1 for dirty, 0 for clean, -1 for errors
26 xfs_daddr_t head_blk
, tail_blk
;
28 memset(log
, 0, sizeof(*log
));
30 /* We (re-)init members of libxfs_init_t here? really? */
31 x
->logBBsize
= XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
32 x
->logBBstart
= XFS_FSB_TO_DADDR(mp
, mp
->m_sb
.sb_logstart
);
34 if (xfs_sb_version_hassector(&mp
->m_sb
))
35 x
->lbsize
<<= (mp
->m_sb
.sb_logsectlog
- BBSHIFT
);
37 log
->l_dev
= mp
->m_logdev_targp
;
38 log
->l_logBBsize
= x
->logBBsize
;
39 log
->l_logBBstart
= x
->logBBstart
;
40 log
->l_sectBBsize
= BTOBB(x
->lbsize
);
42 if (xfs_sb_version_hassector(&mp
->m_sb
)) {
43 log
->l_sectbb_log
= mp
->m_sb
.sb_logsectlog
- BBSHIFT
;
44 ASSERT(log
->l_sectbb_log
<= mp
->m_sectbb_log
);
45 /* for larger sector sizes, must have v2 or external log */
46 ASSERT(log
->l_sectbb_log
== 0 ||
47 log
->l_logBBstart
== 0 ||
48 xfs_sb_version_haslogv2(&mp
->m_sb
));
49 ASSERT(mp
->m_sb
.sb_logsectlog
>= BBSHIFT
);
51 log
->l_sectbb_mask
= (1 << log
->l_sectbb_log
) - 1;
53 error
= xlog_find_tail(log
, &head_blk
, &tail_blk
);
55 xlog_warn(_("%s: cannot find log head/tail "
56 "(xlog_find_tail=%d)\n"),
63 _("%s: head block %" PRId64
" tail block %" PRId64
"\n"),
64 __func__
, head_blk
, tail_blk
);
66 if (head_blk
!= tail_blk
)
73 header_check_uuid(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
75 char uu_log
[64], uu_sb
[64];
79 if (!platform_uuid_compare(&mp
->m_sb
.sb_uuid
, &head
->h_fs_uuid
))
82 platform_uuid_unparse(&mp
->m_sb
.sb_uuid
, uu_sb
);
83 platform_uuid_unparse(&head
->h_fs_uuid
, uu_log
);
85 printf(_("* ERROR: mismatched uuid in log\n"
86 "* SB : %s\n* log: %s\n"),
89 memcpy(&mp
->m_sb
.sb_uuid
, &head
->h_fs_uuid
, sizeof(uuid_t
));
95 xlog_header_check_recover(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
97 if (print_record_header
)
98 printf(_("\nLOG REC AT LSN cycle %d block %d (0x%x, 0x%x)\n"),
99 CYCLE_LSN(be64_to_cpu(head
->h_lsn
)),
100 BLOCK_LSN(be64_to_cpu(head
->h_lsn
)),
101 CYCLE_LSN(be64_to_cpu(head
->h_lsn
)),
102 BLOCK_LSN(be64_to_cpu(head
->h_lsn
)));
104 if (be32_to_cpu(head
->h_magicno
) != XLOG_HEADER_MAGIC_NUM
) {
106 printf(_("* ERROR: bad magic number in log header: 0x%x\n"),
107 be32_to_cpu(head
->h_magicno
));
109 } else if (header_check_uuid(mp
, head
)) {
111 /* failed - fall through */
113 } else if (be32_to_cpu(head
->h_fmt
) != XLOG_FMT
) {
115 printf(_("* ERROR: log format incompatible (log=%d, ours=%d)\n"),
116 be32_to_cpu(head
->h_fmt
), XLOG_FMT
);
119 /* everything is ok */
123 /* bail out now or just carry on regardless */
125 xlog_exit(_("Bad log"));
131 xlog_header_check_mount(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
133 if (platform_uuid_is_null(&head
->h_fs_uuid
)) return 0;
134 if (header_check_uuid(mp
, head
)) {
135 /* bail out now or just carry on regardless */
137 xlog_exit(_("Bad log"));
143 * Userspace versions of common diagnostic routines (varargs fun).
146 xlog_warn(char *fmt
, ...)
151 vfprintf(stderr
, fmt
, ap
);
157 xlog_exit(char *fmt
, ...)
162 vfprintf(stderr
, fmt
, ap
);
169 xlog_panic(char *fmt
, ...)
174 vfprintf(stderr
, fmt
, ap
);