]>
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
;
19 unsigned int log_sect_size
= BBSIZE
;
21 memset(log
, 0, sizeof(*log
));
23 log
->l_dev
= mp
->m_logdev_targp
;
24 log
->l_logBBsize
= XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
25 log
->l_logBBstart
= XFS_FSB_TO_DADDR(mp
, mp
->m_sb
.sb_logstart
);
26 if (xfs_has_sector(mp
))
27 log_sect_size
<<= (mp
->m_sb
.sb_logsectlog
- BBSHIFT
);
28 log
->l_sectBBsize
= BTOBB(log_sect_size
);
30 if (xfs_has_sector(mp
)) {
31 log
->l_sectbb_log
= mp
->m_sb
.sb_logsectlog
- BBSHIFT
;
32 ASSERT(log
->l_sectbb_log
<= mp
->m_sectbb_log
);
33 /* for larger sector sizes, must have v2 or external log */
34 ASSERT(log
->l_sectbb_log
== 0 ||
35 log
->l_logBBstart
== 0 ||
37 ASSERT(mp
->m_sb
.sb_logsectlog
>= BBSHIFT
);
39 log
->l_sectbb_mask
= (1 << log
->l_sectbb_log
) - 1;
43 * Return 1 for dirty, 0 for clean, -1 for errors
51 xfs_daddr_t head_blk
, tail_blk
;
55 error
= xlog_find_tail(log
, &head_blk
, &tail_blk
);
57 xlog_warn(_("%s: cannot find log head/tail "
58 "(xlog_find_tail=%d)\n"),
63 if (head_blk
!= tail_blk
)
70 header_check_uuid(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
72 char uu_log
[64], uu_sb
[64];
76 if (!platform_uuid_compare(&mp
->m_sb
.sb_uuid
, &head
->h_fs_uuid
))
79 platform_uuid_unparse(&mp
->m_sb
.sb_uuid
, uu_sb
);
80 platform_uuid_unparse(&head
->h_fs_uuid
, uu_log
);
82 printf(_("* ERROR: mismatched uuid in log\n"
83 "* SB : %s\n* log: %s\n"),
86 memcpy(&mp
->m_sb
.sb_uuid
, &head
->h_fs_uuid
, sizeof(uuid_t
));
92 xlog_header_check_recover(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
94 if (print_record_header
)
95 printf(_("\nLOG REC AT LSN cycle %d block %d (0x%x, 0x%x)\n"),
96 CYCLE_LSN(be64_to_cpu(head
->h_lsn
)),
97 BLOCK_LSN(be64_to_cpu(head
->h_lsn
)),
98 CYCLE_LSN(be64_to_cpu(head
->h_lsn
)),
99 BLOCK_LSN(be64_to_cpu(head
->h_lsn
)));
101 if (be32_to_cpu(head
->h_magicno
) != XLOG_HEADER_MAGIC_NUM
) {
103 printf(_("* ERROR: bad magic number in log header: 0x%x\n"),
104 be32_to_cpu(head
->h_magicno
));
106 } else if (header_check_uuid(mp
, head
)) {
108 /* failed - fall through */
110 } else if (be32_to_cpu(head
->h_fmt
) != XLOG_FMT
) {
112 printf(_("* ERROR: log format incompatible (log=%d, ours=%d)\n"),
113 be32_to_cpu(head
->h_fmt
), XLOG_FMT
);
116 /* everything is ok */
120 /* bail out now or just carry on regardless */
122 xlog_exit(_("Bad log"));
128 xlog_header_check_mount(xfs_mount_t
*mp
, xlog_rec_header_t
*head
)
130 if (platform_uuid_is_null(&head
->h_fs_uuid
)) return 0;
131 if (header_check_uuid(mp
, head
)) {
132 /* bail out now or just carry on regardless */
134 xlog_exit(_("Bad log"));
140 * Userspace versions of common diagnostic routines (varargs fun).
143 xlog_warn(char *fmt
, ...)
148 vfprintf(stderr
, fmt
, ap
);
154 xlog_exit(char *fmt
, ...)
159 vfprintf(stderr
, fmt
, ap
);
166 xlog_panic(char *fmt
, ...)
171 vfprintf(stderr
, fmt
, ap
);