18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/fs/befs/debug.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2001 Will Dyson (will_dyson at pobox.com)
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * With help from the ntfs-tng driver by Anton Altparmakov
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 1999  Makoto Kato (m_kato@ga2.so-net.ne.jp)
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * debug functions
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
158c2ecf20Sopenharmony_ci#ifdef __KERNEL__
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <stdarg.h>
188c2ecf20Sopenharmony_ci#include <linux/string.h>
198c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
208c2ecf20Sopenharmony_ci#include <linux/kernel.h>
218c2ecf20Sopenharmony_ci#include <linux/fs.h>
228c2ecf20Sopenharmony_ci#include <linux/slab.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#endif				/* __KERNEL__ */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "befs.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_civoid
298c2ecf20Sopenharmony_cibefs_error(const struct super_block *sb, const char *fmt, ...)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	struct va_format vaf;
328c2ecf20Sopenharmony_ci	va_list args;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	va_start(args, fmt);
358c2ecf20Sopenharmony_ci	vaf.fmt = fmt;
368c2ecf20Sopenharmony_ci	vaf.va = &args;
378c2ecf20Sopenharmony_ci	pr_err("(%s): %pV\n", sb->s_id, &vaf);
388c2ecf20Sopenharmony_ci	va_end(args);
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_civoid
428c2ecf20Sopenharmony_cibefs_warning(const struct super_block *sb, const char *fmt, ...)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	struct va_format vaf;
458c2ecf20Sopenharmony_ci	va_list args;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	va_start(args, fmt);
488c2ecf20Sopenharmony_ci	vaf.fmt = fmt;
498c2ecf20Sopenharmony_ci	vaf.va = &args;
508c2ecf20Sopenharmony_ci	pr_warn("(%s): %pV\n", sb->s_id, &vaf);
518c2ecf20Sopenharmony_ci	va_end(args);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_civoid
558c2ecf20Sopenharmony_cibefs_debug(const struct super_block *sb, const char *fmt, ...)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	struct va_format vaf;
608c2ecf20Sopenharmony_ci	va_list args;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	va_start(args, fmt);
638c2ecf20Sopenharmony_ci	vaf.fmt = fmt;
648c2ecf20Sopenharmony_ci	vaf.va = &args;
658c2ecf20Sopenharmony_ci	pr_debug("(%s): %pV\n", sb->s_id, &vaf);
668c2ecf20Sopenharmony_ci	va_end(args);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_civoid
728c2ecf20Sopenharmony_cibefs_dump_inode(const struct super_block *sb, befs_inode *inode)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	befs_block_run tmp_run;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	befs_debug(sb, "befs_inode information");
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	befs_debug(sb, "  magic1 %08x", fs32_to_cpu(sb, inode->magic1));
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, inode->inode_num);
838c2ecf20Sopenharmony_ci	befs_debug(sb, "  inode_num %u, %hu, %hu",
848c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	befs_debug(sb, "  uid %u", fs32_to_cpu(sb, inode->uid));
878c2ecf20Sopenharmony_ci	befs_debug(sb, "  gid %u", fs32_to_cpu(sb, inode->gid));
888c2ecf20Sopenharmony_ci	befs_debug(sb, "  mode %08x", fs32_to_cpu(sb, inode->mode));
898c2ecf20Sopenharmony_ci	befs_debug(sb, "  flags %08x", fs32_to_cpu(sb, inode->flags));
908c2ecf20Sopenharmony_ci	befs_debug(sb, "  create_time %llu",
918c2ecf20Sopenharmony_ci		   fs64_to_cpu(sb, inode->create_time));
928c2ecf20Sopenharmony_ci	befs_debug(sb, "  last_modified_time %llu",
938c2ecf20Sopenharmony_ci		   fs64_to_cpu(sb, inode->last_modified_time));
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, inode->parent);
968c2ecf20Sopenharmony_ci	befs_debug(sb, "  parent [%u, %hu, %hu]",
978c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, inode->attributes);
1008c2ecf20Sopenharmony_ci	befs_debug(sb, "  attributes [%u, %hu, %hu]",
1018c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	befs_debug(sb, "  type %08x", fs32_to_cpu(sb, inode->type));
1048c2ecf20Sopenharmony_ci	befs_debug(sb, "  inode_size %u", fs32_to_cpu(sb, inode->inode_size));
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	if (S_ISLNK(fs32_to_cpu(sb, inode->mode))) {
1078c2ecf20Sopenharmony_ci		befs_debug(sb, "  Symbolic link [%s]", inode->data.symlink);
1088c2ecf20Sopenharmony_ci	} else {
1098c2ecf20Sopenharmony_ci		int i;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci		for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; i++) {
1128c2ecf20Sopenharmony_ci			tmp_run =
1138c2ecf20Sopenharmony_ci			    fsrun_to_cpu(sb, inode->data.datastream.direct[i]);
1148c2ecf20Sopenharmony_ci			befs_debug(sb, "  direct %d [%u, %hu, %hu]", i,
1158c2ecf20Sopenharmony_ci				   tmp_run.allocation_group, tmp_run.start,
1168c2ecf20Sopenharmony_ci				   tmp_run.len);
1178c2ecf20Sopenharmony_ci		}
1188c2ecf20Sopenharmony_ci		befs_debug(sb, "  max_direct_range %llu",
1198c2ecf20Sopenharmony_ci			   fs64_to_cpu(sb,
1208c2ecf20Sopenharmony_ci				       inode->data.datastream.
1218c2ecf20Sopenharmony_ci				       max_direct_range));
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci		tmp_run = fsrun_to_cpu(sb, inode->data.datastream.indirect);
1248c2ecf20Sopenharmony_ci		befs_debug(sb, "  indirect [%u, %hu, %hu]",
1258c2ecf20Sopenharmony_ci			   tmp_run.allocation_group,
1268c2ecf20Sopenharmony_ci			   tmp_run.start, tmp_run.len);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci		befs_debug(sb, "  max_indirect_range %llu",
1298c2ecf20Sopenharmony_ci			   fs64_to_cpu(sb,
1308c2ecf20Sopenharmony_ci				       inode->data.datastream.
1318c2ecf20Sopenharmony_ci				       max_indirect_range));
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci		tmp_run =
1348c2ecf20Sopenharmony_ci		    fsrun_to_cpu(sb, inode->data.datastream.double_indirect);
1358c2ecf20Sopenharmony_ci		befs_debug(sb, "  double indirect [%u, %hu, %hu]",
1368c2ecf20Sopenharmony_ci			   tmp_run.allocation_group, tmp_run.start,
1378c2ecf20Sopenharmony_ci			   tmp_run.len);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci		befs_debug(sb, "  max_double_indirect_range %llu",
1408c2ecf20Sopenharmony_ci			   fs64_to_cpu(sb,
1418c2ecf20Sopenharmony_ci				       inode->data.datastream.
1428c2ecf20Sopenharmony_ci				       max_double_indirect_range));
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci		befs_debug(sb, "  size %llu",
1458c2ecf20Sopenharmony_ci			   fs64_to_cpu(sb, inode->data.datastream.size));
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/*
1528c2ecf20Sopenharmony_ci * Display super block structure for debug.
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_civoid
1568c2ecf20Sopenharmony_cibefs_dump_super_block(const struct super_block *sb, befs_super_block *sup)
1578c2ecf20Sopenharmony_ci{
1588c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	befs_block_run tmp_run;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	befs_debug(sb, "befs_super_block information");
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	befs_debug(sb, "  name %s", sup->name);
1658c2ecf20Sopenharmony_ci	befs_debug(sb, "  magic1 %08x", fs32_to_cpu(sb, sup->magic1));
1668c2ecf20Sopenharmony_ci	befs_debug(sb, "  fs_byte_order %08x",
1678c2ecf20Sopenharmony_ci		   fs32_to_cpu(sb, sup->fs_byte_order));
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	befs_debug(sb, "  block_size %u", fs32_to_cpu(sb, sup->block_size));
1708c2ecf20Sopenharmony_ci	befs_debug(sb, "  block_shift %u", fs32_to_cpu(sb, sup->block_shift));
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	befs_debug(sb, "  num_blocks %llu", fs64_to_cpu(sb, sup->num_blocks));
1738c2ecf20Sopenharmony_ci	befs_debug(sb, "  used_blocks %llu", fs64_to_cpu(sb, sup->used_blocks));
1748c2ecf20Sopenharmony_ci	befs_debug(sb, "  inode_size %u", fs32_to_cpu(sb, sup->inode_size));
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	befs_debug(sb, "  magic2 %08x", fs32_to_cpu(sb, sup->magic2));
1778c2ecf20Sopenharmony_ci	befs_debug(sb, "  blocks_per_ag %u",
1788c2ecf20Sopenharmony_ci		   fs32_to_cpu(sb, sup->blocks_per_ag));
1798c2ecf20Sopenharmony_ci	befs_debug(sb, "  ag_shift %u", fs32_to_cpu(sb, sup->ag_shift));
1808c2ecf20Sopenharmony_ci	befs_debug(sb, "  num_ags %u", fs32_to_cpu(sb, sup->num_ags));
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	befs_debug(sb, "  flags %08x", fs32_to_cpu(sb, sup->flags));
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, sup->log_blocks);
1858c2ecf20Sopenharmony_ci	befs_debug(sb, "  log_blocks %u, %hu, %hu",
1868c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	befs_debug(sb, "  log_start %lld", fs64_to_cpu(sb, sup->log_start));
1898c2ecf20Sopenharmony_ci	befs_debug(sb, "  log_end %lld", fs64_to_cpu(sb, sup->log_end));
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	befs_debug(sb, "  magic3 %08x", fs32_to_cpu(sb, sup->magic3));
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, sup->root_dir);
1948c2ecf20Sopenharmony_ci	befs_debug(sb, "  root_dir %u, %hu, %hu",
1958c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	tmp_run = fsrun_to_cpu(sb, sup->indices);
1988c2ecf20Sopenharmony_ci	befs_debug(sb, "  indices %u, %hu, %hu",
1998c2ecf20Sopenharmony_ci		   tmp_run.allocation_group, tmp_run.start, tmp_run.len);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci#if 0
2058c2ecf20Sopenharmony_ci/* unused */
2068c2ecf20Sopenharmony_civoid
2078c2ecf20Sopenharmony_cibefs_dump_small_data(const struct super_block *sb, befs_small_data *sd)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* unused */
2128c2ecf20Sopenharmony_civoid
2138c2ecf20Sopenharmony_cibefs_dump_run(const struct super_block *sb, befs_disk_block_run run)
2148c2ecf20Sopenharmony_ci{
2158c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	befs_block_run n = fsrun_to_cpu(sb, run);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
2228c2ecf20Sopenharmony_ci}
2238c2ecf20Sopenharmony_ci#endif  /*  0  */
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_civoid
2268c2ecf20Sopenharmony_cibefs_dump_index_entry(const struct super_block *sb,
2278c2ecf20Sopenharmony_ci		      befs_disk_btree_super *super)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	befs_debug(sb, "Btree super structure");
2328c2ecf20Sopenharmony_ci	befs_debug(sb, "  magic %08x", fs32_to_cpu(sb, super->magic));
2338c2ecf20Sopenharmony_ci	befs_debug(sb, "  node_size %u", fs32_to_cpu(sb, super->node_size));
2348c2ecf20Sopenharmony_ci	befs_debug(sb, "  max_depth %08x", fs32_to_cpu(sb, super->max_depth));
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	befs_debug(sb, "  data_type %08x", fs32_to_cpu(sb, super->data_type));
2378c2ecf20Sopenharmony_ci	befs_debug(sb, "  root_node_pointer %016LX",
2388c2ecf20Sopenharmony_ci		   fs64_to_cpu(sb, super->root_node_ptr));
2398c2ecf20Sopenharmony_ci	befs_debug(sb, "  free_node_pointer %016LX",
2408c2ecf20Sopenharmony_ci		   fs64_to_cpu(sb, super->free_node_ptr));
2418c2ecf20Sopenharmony_ci	befs_debug(sb, "  maximum size %016LX",
2428c2ecf20Sopenharmony_ci		   fs64_to_cpu(sb, super->max_size));
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
2458c2ecf20Sopenharmony_ci}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_civoid
2488c2ecf20Sopenharmony_cibefs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *node)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci#ifdef CONFIG_BEFS_DEBUG
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	befs_debug(sb, "Btree node structure");
2538c2ecf20Sopenharmony_ci	befs_debug(sb, "  left %016LX", fs64_to_cpu(sb, node->left));
2548c2ecf20Sopenharmony_ci	befs_debug(sb, "  right %016LX", fs64_to_cpu(sb, node->right));
2558c2ecf20Sopenharmony_ci	befs_debug(sb, "  overflow %016LX", fs64_to_cpu(sb, node->overflow));
2568c2ecf20Sopenharmony_ci	befs_debug(sb, "  all_key_count %hu",
2578c2ecf20Sopenharmony_ci		   fs16_to_cpu(sb, node->all_key_count));
2588c2ecf20Sopenharmony_ci	befs_debug(sb, "  all_key_length %hu",
2598c2ecf20Sopenharmony_ci		   fs16_to_cpu(sb, node->all_key_length));
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci#endif				//CONFIG_BEFS_DEBUG
2628c2ecf20Sopenharmony_ci}
263