diff --git a/headers/build/private/shared/StringForSize.h b/headers/build/private/shared/StringForSize.h new file mode 100644 index 0000000000..f6ccab54ea --- /dev/null +++ b/headers/build/private/shared/StringForSize.h @@ -0,0 +1 @@ +#include <../private/shared/StringForSize.h> diff --git a/src/bin/bfs_tools/bfswhich.cpp b/src/bin/bfs_tools/bfswhich.cpp index 2829154c21..3a27ef0efa 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 @@ scanNode(Disk& disk, Inode* inode, const char* name, 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 @@ scanNodes(Disk& disk, Directory* directory, const char* directoryName, 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 @@ scanNodes(Disk& disk, Directory* directory, const char* directoryName, 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 @@ scanNodes(Disk& disk, const block_run& checkForRun, bool scanAll) delete indices; } - printf(" %7Ld nodes found.\n", gCount); + printf(" %7" B_PRIdOFF " nodes found.\n", gCount); } @@ -217,7 +217,7 @@ testBitmap(Disk& disk, const block_run& run) 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 @@ main(int argc, char** argv) 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/lib/Disk.cpp b/src/bin/bfs_tools/lib/Disk.cpp index d0793eabd0..6f40fdcff5 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 #include #include #include @@ -20,6 +19,12 @@ #include #include +#ifdef __HAIKU__ +# include +#else +# include +# include +#endif #define MIN_BLOCK_SIZE_INODES 50 #define MAX_BLOCK_SIZE_INODES 500 @@ -106,6 +111,7 @@ Disk::Disk(const char *deviceName, bool rawMode, off_t start, off_t stop) 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 @@ Disk::Disk(const char *deviceName, bool rawMode, off_t start, off_t stop) fPath.SetTo(info.device_name); deviceName = fPath.Path(); +#endif } if (deviceName == NULL) { @@ -136,6 +143,7 @@ Disk::Disk(const char *deviceName, bool rawMode, off_t start, off_t stop) return; } +#ifdef __HAIKU__ partition_info partitionInfo; device_geometry geometry; if (ioctl(device, B_GET_PARTITION_INFO, &partitionInfo, @@ -151,6 +159,13 @@ Disk::Disk(const char *deviceName, bool rawMode, off_t start, off_t stop) 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 5cd5cd7462..df2aec542c 100644 --- a/src/bin/bfs_tools/lib/Inode.cpp +++ b/src/bin/bfs_tools/lib/Inode.cpp @@ -174,6 +174,7 @@ Inode::CopyBuffer() /*static*/ bool Inode::_LowMemory() { +#ifdef __HAIKU__ static bigtime_t lastChecked; static int32 percentUsed; @@ -184,6 +185,9 @@ Inode::_LowMemory() } 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 4d4a5e652f..abf460f5bb 100644 --- a/src/bin/bfs_tools/lib/bfs.h +++ b/src/bin/bfs_tools/lib/bfs.h @@ -3,7 +3,7 @@ * 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 @@ -12,10 +12,6 @@ #include -#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 // (coincidentally the same as in Haiku's sys/stat.h) diff --git a/src/bin/bfs_tools/lib/dump.cpp b/src/bin/bfs_tools/lib/dump.cpp index d289050c4a..578c7d917f 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 #include +#include #define Print printf diff --git a/src/bin/bfs_tools/recover.cpp b/src/bin/bfs_tools/recover.cpp index 8f5e63086f..e12c14c8d4 100644 --- a/src/bin/bfs_tools/recover.cpp +++ b/src/bin/bfs_tools/recover.cpp @@ -804,6 +804,7 @@ main(int argc, char **argv) return -1; } +#ifdef __HAIKU__ if (argv[1] != NULL) { dev_t device = dev_for_path(argv[1]); fs_info info; @@ -824,6 +825,7 @@ main(int argc, char **argv) } } } +#endif bool recreatedSuperBlock = false; diff --git a/src/build/libbe/storage/Statable.cpp b/src/build/libbe/storage/Statable.cpp index 2f1d978ad7..baa141f0b5 100644 --- a/src/build/libbe/storage/Statable.cpp +++ b/src/build/libbe/storage/Statable.cpp @@ -219,6 +219,21 @@ BStatable::SetModificationTime(time_t mtime) 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() diff --git a/src/build/libshared/Jamfile b/src/build/libshared/Jamfile index f641868c13..f85bb9a407 100644 --- a/src/build/libshared/Jamfile +++ b/src/build/libshared/Jamfile @@ -12,6 +12,7 @@ BuildPlatformStaticLibraryPIC libshared_build.a : 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 0000000000..8d5c3e26b1 --- /dev/null +++ b/src/build/libshared/StringForSize.cpp @@ -0,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 +#include +#include + + +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/Jamfile b/src/tools/Jamfile index 6a27516f3b..61f1b6d65e 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -91,6 +91,7 @@ SEARCH on [ FGristFiles 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/tools/bfs_tools/Jamfile b/src/tools/bfs_tools/Jamfile new file mode 100644 index 0000000000..c35cae451d --- /dev/null +++ b/src/tools/bfs_tools/Jamfile @@ -0,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 bfsinfo = true ; +USES_BE_API on bfswhich = true ; +USES_BE_API on recover = true ; + +BFS_TOOLS_SOURCES = + bfs.cpp + Bitmap.cpp + BPlusTree.cpp + Disk.cpp + dump.cpp + Hashtable.cpp + Inode.cpp +; + +BuildPlatformMain bfswhich : + bfswhich.cpp + $(BFS_TOOLS_SOURCES) + : + $(HOST_LIBBE) $(HOST_LIBSUPC++) +; + +BuildPlatformMain bfsinfo : + bfsinfo.cpp + $(BFS_TOOLS_SOURCES) + : + $(HOST_LIBBE) $(HOST_LIBSUPC++) libshared_build.a +; + +BuildPlatformMain recover : + recover.cpp + $(BFS_TOOLS_SOURCES) + : + $(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) libshared_build.a +; +