⛏️ index : haiku.git

author Axel Dörfler <axeld@pinc-software.de> 2025-12-17 6:45:00.0 +01:00:00
committer Axel Dörfler <axeld@pinc-software.de> 2025-12-25 17:26:09.0 +00:00:00
commit
b15cb7f6d0908b5b82dbdbcea0bf11dff3cc9d77 [patch]
tree
ff198a0bee6ca75e066c1ae8f8f962d452d5a7ef
parent
27512d20c7d6cbf205257f1e5c5ab71e71d40ae2
download
b15cb7f6d0908b5b82dbdbcea0bf11dff3cc9d77.tar.gz

bfswhich/bfsinfo/recover can now run on Linux

* You can build them using the <build> prefix; their Jamfiles are below
  src/tools/ as with other host builds.

Change-Id: I9986b85ba0f758d8420f625873b5e37c3274e678
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10126
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>

Diff

 src/tools/Jamfile                            |  1 +
 src/bin/bfs_tools/bfswhich.cpp               | 22 ++++++++++++----------
 src/bin/bfs_tools/recover.cpp                |  2 ++
 src/build/libshared/Jamfile                  |  1 +
 src/build/libshared/StringForSize.cpp        | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/tools/bfs_tools/Jamfile                  | 42 ++++++++++++++++++++++++++++++++++++++++++
 headers/build/private/shared/StringForSize.h |  1 +
 src/bin/bfs_tools/lib/Disk.cpp               | 19 ++++++++++++++++++-
 src/bin/bfs_tools/lib/Inode.cpp              |  4 ++++
 src/bin/bfs_tools/lib/bfs.h                  |  6 +-----
 src/bin/bfs_tools/lib/dump.cpp               |  3 ++-
 src/build/libbe/storage/Statable.cpp         | 15 +++++++++++++++
 12 files changed, 169 insertions(+), 19 deletions(-)

diff --git a/src/tools/Jamfile b/src/tools/Jamfile
index 6a27516..61f1b6d 100644
--- a/src/tools/Jamfile
+++ b/src/tools/Jamfile
@@ -91,6 +91,7 @@
SubInclude HAIKU_TOP src tools addattr ;
SubInclude HAIKU_TOP src tools anyboot ;
SubInclude HAIKU_TOP src tools bfs_shell ;
SubInclude HAIKU_TOP src tools bfs_tools ;
SubInclude HAIKU_TOP src tools fat_shell ;
SubInclude HAIKU_TOP src tools cppunit ;
SubInclude HAIKU_TOP src tools create_repository_config ;
diff --git a/src/bin/bfs_tools/bfswhich.cpp b/src/bin/bfs_tools/bfswhich.cpp
index 2829154..3a27ef0 100644
--- a/src/bin/bfs_tools/bfswhich.cpp
+++ b/src/bin/bfs_tools/bfswhich.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright (c) 2002-2009 pinc Software. All Rights Reserved.
 * Copyright (c) 2002-2025 pinc Software. All Rights Reserved.
 * Released under the terms of the MIT license.
 */

@@ -118,7 +118,7 @@
	const block_run& checkForRun)
{
	if (checkNode(disk, inode, checkForRun)) {
		printf("Inode at (%ld, %u, %u) \"%s\" intersects\n",
		printf("Inode at (%" B_PRIu32 ", %u, %u) \"%s\" intersects\n",
			inode->BlockRun().allocation_group, inode->BlockRun().start,
			inode->BlockRun().length, name);
	}
@@ -154,7 +154,7 @@
			continue;

		if (++gCount % 50 == 0)
			printf("  %7Ld%s1A\n", gCount, gEscape);
			printf("  %7" B_PRIdOFF "%s1A\n", gCount, gEscape);

		Inode *inode = Inode::Factory(&disk, run);
		if (inode != NULL) {
@@ -167,10 +167,10 @@

			delete inode;
		} else {
			printf("  Directory \"%s\" (%ld, %d) points to corrupt inode \"%s\" "
				"(%ld, %d)\n", directory->Name(),
				directory->BlockRun().allocation_group,directory
					->BlockRun().start,
			printf("  Directory \"%s\" (%" B_PRIu32 ", %d) points to corrupt inode \"%s\" "
				"(%" B_PRIu32 ", %d)\n", directory->Name(),
				directory->BlockRun().allocation_group,
				directory->BlockRun().start,
				name, run.allocation_group, run.start);
		}
	}
@@ -203,7 +203,7 @@
		delete indices;
	}

	printf("  %7Ld nodes found.\n", gCount);
	printf("  %7" B_PRIdOFF " nodes found.\n", gCount);
}


@@ -217,7 +217,7 @@
		return;
	}

	printf("Block bitmap sees block %lld as %s.\n", disk.ToBlock(run),
	printf("Block bitmap sees block %" B_PRIdOFF " as %s.\n", disk.ToBlock(run),
		bitmap.UsedAt(disk.ToBlock(run)) ? "used" : "free");
}

@@ -304,13 +304,13 @@
	testBitmap(disk, run);

	if (checkForBlockRunIntersection(disk.Log(), run)) {
		printf("Log area (%lu.%u.%u) intersects\n",
		printf("Log area (%" B_PRIu32 ".%u.%u) intersects\n",
			disk.Log().allocation_group, disk.Log().start,
			disk.Log().length);
	} else if (block < 1) {
		printf("Superblock intersects\n");
	} else if (block < 1 + disk.BitmapSize()) {
		printf("Block bitmap intersects (start %d, end %lu)\n", 1,
		printf("Block bitmap intersects (start %d, end %" B_PRIu32 ")\n", 1,
			disk.BitmapSize());
	} else
		scanNodes(disk, run, scanAll);
diff --git a/src/bin/bfs_tools/recover.cpp b/src/bin/bfs_tools/recover.cpp
index 8f5e630..e12c14c 100644
--- a/src/bin/bfs_tools/recover.cpp
+++ b/src/bin/bfs_tools/recover.cpp
@@ -804,6 +804,7 @@
		return -1;
	}

#ifdef __HAIKU__
	if (argv[1] != NULL) {
		dev_t device = dev_for_path(argv[1]);
		fs_info info;
@@ -824,6 +825,7 @@
			}
		}
	}
#endif

	bool recreatedSuperBlock = false;

diff --git a/src/build/libshared/Jamfile b/src/build/libshared/Jamfile
index f641868..f85bb9a 100644
--- a/src/build/libshared/Jamfile
+++ b/src/build/libshared/Jamfile
@@ -12,6 +12,7 @@
	Keymap.cpp
	NaturalCompare.cpp
	RegExp.cpp
	StringForSize.cpp

	:

diff --git a/src/build/libshared/StringForSize.cpp b/src/build/libshared/StringForSize.cpp
new file mode 100644
index 0000000..8d5c3e2 100644
--- /dev/null
+++ b/src/build/libshared/StringForSize.cpp
@@ -1,0 +1,72 @@
/*
 * Copyright 2010-2024 Haiku Inc. All rights reserved.
 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
 * Distributed under the terms of the MIT License.
 */

#include "StringForSize.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>


namespace BPrivate {


const char*
string_for_size(double size, char* string, size_t stringSize)
{
	const char* kFormats[] = {
		"%.0g B", "%.2g KiB", "%.2g MiB", "%.2g GiB", "%.2g TiB"
	};

	size_t index = 0;
	while (index < B_COUNT_OF(kFormats) - 1 && size >= 1024.0) {
		size /= 1024.0;
		index++;
	}

	snprintf(string, stringSize, kFormats[index], size);

	return string;
}


int64
parse_size(const char* sizeString)
{
	int64 parsedSize = -1;
	char* end;
	parsedSize = strtoll(sizeString, &end, 0);
	if (end != sizeString && parsedSize > 0) {
		int64 rawSize = parsedSize;
		switch (tolower(*end)) {
			case 't':
				parsedSize *= 1024;
			case 'g':
				parsedSize *= 1024;
			case 'm':
				parsedSize *= 1024;
			case 'k':
				parsedSize *= 1024;
				end++;
				break;
			case '\0':
				break;
			default:
				parsedSize = -1;
				break;
		}

		// Check for overflow
		if (parsedSize > 0 && rawSize > parsedSize)
			parsedSize = -1;
	}

	return parsedSize;
}


}	// namespace BPrivate

diff --git a/src/tools/bfs_tools/Jamfile b/src/tools/bfs_tools/Jamfile
new file mode 100644
index 0000000..c35cae4 100644
--- /dev/null
+++ b/src/tools/bfs_tools/Jamfile
@@ -1,0 +1,42 @@
SubDir HAIKU_TOP src tools bfs_tools ;

UsePrivateBuildHeaders libroot shared kernel storage support ;

SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin bfs_tools ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin bfs_tools lib ] ;

USES_BE_API on <build>bfsinfo = true ;
USES_BE_API on <build>bfswhich = true ;
USES_BE_API on <build>recover = true ;

BFS_TOOLS_SOURCES =
	bfs.cpp
	Bitmap.cpp
	BPlusTree.cpp
	Disk.cpp
	dump.cpp
	Hashtable.cpp
	Inode.cpp
;

BuildPlatformMain <build>bfswhich :
	bfswhich.cpp
	$(BFS_TOOLS_SOURCES)
	:
	$(HOST_LIBBE) $(HOST_LIBSUPC++)
;

BuildPlatformMain <build>bfsinfo :
	bfsinfo.cpp
	$(BFS_TOOLS_SOURCES)
	:
	$(HOST_LIBBE) $(HOST_LIBSUPC++) libshared_build.a
;

BuildPlatformMain <build>recover :
	recover.cpp
	$(BFS_TOOLS_SOURCES)
	:
	$(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) libshared_build.a
;

diff --git a/headers/build/private/shared/StringForSize.h b/headers/build/private/shared/StringForSize.h
new file mode 100644
index 0000000..f6ccab5 100644
--- /dev/null
+++ b/headers/build/private/shared/StringForSize.h
@@ -1,0 +1,1 @@
#include <../private/shared/StringForSize.h>
diff --git a/src/bin/bfs_tools/lib/Disk.cpp b/src/bin/bfs_tools/lib/Disk.cpp
index d0793ea..6f40fdc 100644
--- a/src/bin/bfs_tools/lib/Disk.cpp
+++ b/src/bin/bfs_tools/lib/Disk.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright (c) 2001-2008 pinc Software. All Rights Reserved.
 * Copyright (c) 2001-2025 pinc Software. All Rights Reserved.
 * Released under the terms of the MIT license.
 */

@@ -8,7 +8,6 @@
#include "Disk.h"
#include "dump.h"

#include <Drivers.h>
#include <File.h>
#include <Entry.h>
#include <List.h>
@@ -20,6 +19,12 @@
#include <unistd.h>
#include <ctype.h>

#ifdef __HAIKU__
#	include <Drivers.h>
#else
#	include <sys/ioctl.h>
#	include <linux/fs.h>
#endif

#define MIN_BLOCK_SIZE_INODES 50
#define MAX_BLOCK_SIZE_INODES 500
@@ -106,6 +111,7 @@
	fPath.SetTo(deviceName);

	if (entry.IsDirectory()) {
#ifdef __HAIKU__
		dev_t on = dev_for_path(deviceName);
		fs_info info;
		if (fs_stat_dev(on, &info) != B_OK)
@@ -113,6 +119,7 @@

		fPath.SetTo(info.device_name);
		deviceName = fPath.Path();
#endif
	}

	if (deviceName == NULL) {
@@ -136,6 +143,7 @@
		return;
	}

#ifdef __HAIKU__
	partition_info partitionInfo;
	device_geometry geometry;
	if (ioctl(device, B_GET_PARTITION_INFO, &partitionInfo,
@@ -151,6 +159,13 @@
		fprintf(stderr,"Disk: Could not get partition info.\n  Use file size as partition size\n");
		fFile.GetSize(&fSize);
	}
#else
	if (ioctl(device, BLKGETSIZE64, &fSize) == -1) {
		struct stat st;
		if (fstat(device, &st) != -1)
			fSize = st.st_size;
	}
#endif
	close(device);

	if (fSize == 0LL) {
diff --git a/src/bin/bfs_tools/lib/Inode.cpp b/src/bin/bfs_tools/lib/Inode.cpp
index 5cd5cd7..df2aec5 100644
--- a/src/bin/bfs_tools/lib/Inode.cpp
+++ b/src/bin/bfs_tools/lib/Inode.cpp
@@ -174,6 +174,7 @@
/*static*/ bool
Inode::_LowMemory()
{
#ifdef __HAIKU__
	static bigtime_t lastChecked;
	static int32 percentUsed;

@@ -184,6 +185,9 @@
	}

	return percentUsed > 75;
#else
	return false;
#endif
}


diff --git a/src/bin/bfs_tools/lib/bfs.h b/src/bin/bfs_tools/lib/bfs.h
index 4d4a5e6..abf460f 100644
--- a/src/bin/bfs_tools/lib/bfs.h
+++ b/src/bin/bfs_tools/lib/bfs.h
@@ -1,9 +1,9 @@
/* bfs - BFS definitions and helper functions
 *
 * Initial version by Axel Dörfler, axeld@pinc-software.de
 * Parts of this code is based on work previously done by Marcus Overhagen
 *
 * Copyright 2001-2008 pinc Software. All Rights Reserved.
 * Copyright 2001-2025 pinc Software. All Rights Reserved.
 * This file may be used under the terms of the MIT License.
 */
#ifndef BFS_H
@@ -11,10 +11,6 @@


#include <SupportDefs.h>

#if !defined(BEOS_VERSION_DANO) && !defined(__HAIKU__)

#	define B_BAD_DATA B_ERROR
#endif


// File types as used in BFS and stored in its inodes
diff --git a/src/bin/bfs_tools/lib/dump.cpp b/src/bin/bfs_tools/lib/dump.cpp
index d289050..578c7d9 100644
--- a/src/bin/bfs_tools/lib/dump.cpp
+++ b/src/bin/bfs_tools/lib/dump.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright 2001-2010, pinc Software. All Rights Reserved.
 * Copyright 2001-2025, pinc Software. All Rights Reserved.
 * Released under the terms of the MIT license.
 */

@@ -14,6 +14,7 @@

#include <stdio.h>
#include <string.h>
#include <time.h>

#define Print printf

diff --git a/src/build/libbe/storage/Statable.cpp b/src/build/libbe/storage/Statable.cpp
index 2f1d978..baa141f 100644
--- a/src/build/libbe/storage/Statable.cpp
+++ b/src/build/libbe/storage/Statable.cpp
@@ -219,6 +219,21 @@
	return set_stat(statData, B_STAT_MODIFICATION_TIME);
}


status_t
BStatable::GetCreationTime(time_t *ctime) const
{
	return GetModificationTime(ctime);
}


status_t
BStatable::SetCreationTime(time_t ctime)
{
	return B_ERROR;
}


/*!	\brief Returns the time the node was accessed.
	Not used.
	\see GetModificationTime()