bfs_tools: Replaced S_* macros with internal BFS_S_* macros
* This makes the BFS tools implementation independent from the actual values of these macros to ease porting. Change-Id: Id7aa8d38c2574875999362a147701f00ec8fab26 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10147 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* BPlusTree - BFS B+Tree implementation
|
||||
**
|
||||
** Copyright 2001-2002 pinc Software. All Rights Reserved.
|
||||
** Copyright 2001-2025 pinc Software. All Rights Reserved.
|
||||
** Released under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
@@ -179,18 +179,19 @@ status_t BPlusTree::SetTo(BPositionIO *stream,bool allowDuplicates)
|
||||
|
||||
if (DataStream *dataStream = dynamic_cast<DataStream *>(stream))
|
||||
{
|
||||
uint32 toMode[] = {S_STR_INDEX, S_INT_INDEX, S_UINT_INDEX, S_LONG_LONG_INDEX,
|
||||
S_ULONG_LONG_INDEX, S_FLOAT_INDEX, S_DOUBLE_INDEX};
|
||||
uint32 mode = dataStream->Mode() & (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX | S_LONG_LONG_INDEX
|
||||
| S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX);
|
||||
uint32 toMode[] = {BFS_S_STR_INDEX, BFS_S_INT_INDEX, BFS_S_UINT_INDEX,
|
||||
BFS_S_LONG_LONG_INDEX, BFS_S_ULONG_LONG_INDEX, BFS_S_FLOAT_INDEX, BFS_S_DOUBLE_INDEX};
|
||||
uint32 mode = dataStream->Mode() & (BFS_S_STR_INDEX | BFS_S_INT_INDEX | BFS_S_UINT_INDEX
|
||||
| BFS_S_LONG_LONG_INDEX | BFS_S_ULONG_LONG_INDEX | BFS_S_FLOAT_INDEX
|
||||
| BFS_S_DOUBLE_INDEX);
|
||||
|
||||
if (header.data_type > BPLUSTREE_DOUBLE_TYPE
|
||||
|| (dataStream->Mode() & S_INDEX_DIR) && toMode[header.data_type] != mode
|
||||
|| (dataStream->Mode() & BFS_S_INDEX_DIR) && toMode[header.data_type] != mode
|
||||
|| !dataStream->IsDirectory())
|
||||
return fStatus = B_BAD_TYPE;
|
||||
|
||||
// although it's in stat.h, the S_ALLOW_DUPS flag is obviously unused
|
||||
fAllowDuplicates = (dataStream->Mode() & (S_INDEX_DIR | 0777)) == S_INDEX_DIR;
|
||||
fAllowDuplicates = (dataStream->Mode() & (BFS_S_INDEX_DIR | 0777)) == BFS_S_INDEX_DIR;
|
||||
|
||||
//printf("allows duplicates? %s\n",fAllowDuplicates ? "yes" : "no");
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ void
|
||||
Disk::SaveInode(bfs_inode *inode, bool *indices, bfs_inode *indexDir,
|
||||
bool *root, bfs_inode *rootDir)
|
||||
{
|
||||
if ((inode->mode & S_INDEX_DIR) == 0) {
|
||||
if ((inode->mode & BFS_S_INDEX_DIR) == 0) {
|
||||
*root = true;
|
||||
printf("\troot node found!\n");
|
||||
if (inode->inode_num.allocation_group != 8
|
||||
@@ -619,7 +619,7 @@ Disk::SaveInode(bfs_inode *inode, bool *indices, bfs_inode *indexDir,
|
||||
}
|
||||
if (rootDir)
|
||||
memcpy(rootDir, inode, sizeof(bfs_inode));
|
||||
} else if (inode->mode & S_INDEX_DIR) {
|
||||
} else if (inode->mode & BFS_S_INDEX_DIR) {
|
||||
*indices = true;
|
||||
printf("\tindices node found!\n");
|
||||
if (indexDir)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2008 pinc Software. All Rights Reserved.
|
||||
* Copyright 2001-2025 pinc Software. All Rights Reserved.
|
||||
* Released under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
@@ -548,19 +548,19 @@ Inode *
|
||||
Inode::Factory(Disk *disk, bfs_inode *inode, bool ownBuffer)
|
||||
{
|
||||
// attributes (of a file)
|
||||
if ((inode->mode & (S_ATTR | S_ATTR_DIR)) == S_ATTR)
|
||||
if ((inode->mode & (BFS_S_ATTR | BFS_S_ATTR_DIR)) == BFS_S_ATTR)
|
||||
return new Attribute(disk, inode, ownBuffer);
|
||||
|
||||
// directories, attribute directories, indices
|
||||
if (S_ISDIR(inode->mode) || inode->mode & S_ATTR_DIR)
|
||||
if (BFS_S_ISDIR(inode->mode) || inode->mode & BFS_S_ATTR_DIR)
|
||||
return new Directory(disk, inode, ownBuffer);
|
||||
|
||||
// regular files
|
||||
if (S_ISREG(inode->mode))
|
||||
if (BFS_S_ISREG(inode->mode))
|
||||
return new File(disk, inode, ownBuffer);
|
||||
|
||||
// symlinks (short and link in data-stream)
|
||||
if (S_ISLNK(inode->mode))
|
||||
if (BFS_S_ISLNK(inode->mode))
|
||||
return new Symlink(disk, inode, ownBuffer);
|
||||
|
||||
return NULL;
|
||||
@@ -614,7 +614,7 @@ Inode::EmptyInode(Disk *disk, const char *name, int32 mode)
|
||||
inode->magic1 = INODE_MAGIC1;
|
||||
inode->inode_size = disk->BlockSize();
|
||||
inode->mode = mode;
|
||||
inode->flags = INODE_IN_USE | (mode & S_IFDIR ? INODE_LOGGED : 0);
|
||||
inode->flags = INODE_IN_USE | (mode & BFS_S_IFDIR ? INODE_LOGGED : 0);
|
||||
|
||||
if (name) {
|
||||
small_data *data = inode->small_data_start;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2008, pinc Software. All Rights Reserved.
|
||||
* Copyright 2001-2025, pinc Software. All Rights Reserved.
|
||||
* Released under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef INODE_H
|
||||
@@ -23,14 +23,14 @@ class Inode {
|
||||
status_t SetTo(bfs_inode *inode);
|
||||
virtual status_t InitCheck() const;
|
||||
|
||||
bool IsFile() const { return S_ISREG(fInode->mode); }
|
||||
bool IsDirectory() const { return S_ISDIR(fInode->mode); }
|
||||
bool IsSymlink() const { return S_ISLNK(fInode->mode); }
|
||||
bool IsIndex() const { return S_ISINDEX(fInode->mode); }
|
||||
bool IsFile() const { return BFS_S_ISREG(fInode->mode); }
|
||||
bool IsDirectory() const { return BFS_S_ISDIR(fInode->mode); }
|
||||
bool IsSymlink() const { return BFS_S_ISLNK(fInode->mode); }
|
||||
bool IsIndex() const { return BFS_S_ISINDEX(fInode->mode); }
|
||||
bool IsAttribute() const
|
||||
{ return (fInode->mode & S_ATTR) != 0; }
|
||||
{ return (fInode->mode & BFS_S_ATTR) != 0; }
|
||||
bool IsAttributeDirectory() const
|
||||
{ return (fInode->mode & S_ATTR_DIR) != 0; }
|
||||
{ return (fInode->mode & BFS_S_ATTR_DIR) != 0; }
|
||||
bool IsRoot() const { return BlockRun() == fDisk->Root(); }
|
||||
|
||||
int32 Mode() const { return fInode->mode; }
|
||||
|
||||
@@ -17,6 +17,31 @@
|
||||
#endif
|
||||
|
||||
|
||||
// File types as used in BFS and stored in its inodes
|
||||
// (coincidentally the same as in Haiku's sys/stat.h)
|
||||
#define BFS_S_ATTR_DIR 01000000000 /* attribute directory */
|
||||
#define BFS_S_ATTR 02000000000 /* attribute */
|
||||
#define BFS_S_INDEX_DIR 04000000000 /* index (or index directory) */
|
||||
#define BFS_S_STR_INDEX 00100000000 /* string index */
|
||||
#define BFS_S_INT_INDEX 00200000000 /* int32 index */
|
||||
#define BFS_S_UINT_INDEX 00400000000 /* uint32 index */
|
||||
#define BFS_S_LONG_LONG_INDEX 00010000000 /* int64 index */
|
||||
#define BFS_S_ULONG_LONG_INDEX 00020000000 /* uint64 index */
|
||||
#define BFS_S_FLOAT_INDEX 00040000000 /* float index */
|
||||
#define BFS_S_DOUBLE_INDEX 00001000000 /* double index */
|
||||
|
||||
/* standard file types */
|
||||
#define BFS_S_IFMT 00000170000 /* type of file */
|
||||
#define BFS_S_IFLNK 00000120000 /* symbolic link */
|
||||
#define BFS_S_IFREG 00000100000 /* regular */
|
||||
#define BFS_S_IFDIR 00000040000 /* directory */
|
||||
|
||||
#define BFS_S_ISREG(mode) (((mode) & BFS_S_IFMT) == BFS_S_IFREG)
|
||||
#define BFS_S_ISLNK(mode) (((mode) & BFS_S_IFMT) == BFS_S_IFLNK)
|
||||
#define BFS_S_ISDIR(mode) (((mode) & BFS_S_IFMT) == BFS_S_IFDIR)
|
||||
#define BFS_S_ISINDEX(mode) (((mode) & BFS_S_INDEX_DIR) == BFS_S_INDEX_DIR)
|
||||
|
||||
|
||||
struct __attribute__((packed)) block_run {
|
||||
int32 allocation_group;
|
||||
uint16 start;
|
||||
|
||||
@@ -150,7 +150,7 @@ dump_inode(const Inode *nameNode, const bfs_inode *inode, bool showOffsets)
|
||||
Print(" inode_size = %" B_PRId32 "\n",inode->inode_size);
|
||||
Print(" etc = %#08" B_PRIx32 "\n",inode->etc);
|
||||
Print(" short_symlink = %s\n",
|
||||
S_ISLNK(inode->mode) && (inode->flags & INODE_LONG_SYMLINK) == 0
|
||||
BFS_S_ISLNK(inode->mode) && (inode->flags & INODE_LONG_SYMLINK) == 0
|
||||
? inode->short_symlink : "-");
|
||||
|
||||
dump_data_stream(inode, &inode->data, showOffsets);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -339,7 +339,7 @@ getNameIndex(Disk &disk)
|
||||
|
||||
if (!node || !node->IsIndex() || node->Name() == NULL)
|
||||
continue;
|
||||
if (!strcmp(node->Name(), "name") && node->Mode() & S_STR_INDEX)
|
||||
if (!strcmp(node->Name(), "name") && node->Mode() & BFS_S_STR_INDEX)
|
||||
return dynamic_cast<Directory *>(node);
|
||||
}
|
||||
|
||||
@@ -374,9 +374,9 @@ checkDirectoryContents(Disk& disk, Directory *dir)
|
||||
|
||||
missing->SetParent(dir->BlockRun());
|
||||
}
|
||||
// if (node->Mode() & S_INDEX_DIR)
|
||||
// if (node->Mode() & BFS_S_INDEX_DIR)
|
||||
// {
|
||||
// if (node->Mode() & S_STR_INDEX)
|
||||
// if (node->Mode() & BFS_S_STR_INDEX)
|
||||
// printf("index directory (%ld, %d): \"%s\" is missing (%ld, %d, %d)\n",node->BlockRun().allocation_group,node->BlockRun().start,name,run.allocation_group,run.start,run.length);
|
||||
// else
|
||||
// printf("index directory (%ld, %d): key is missing (%ld, %d, %d)\n",node->BlockRun().allocation_group,node->BlockRun().start,run.allocation_group,run.start,run.length);
|
||||
@@ -459,10 +459,10 @@ checkStructure(Disk &disk)
|
||||
Inode *parentNode = parentGetter.Node();
|
||||
|
||||
Directory *dir = dynamic_cast<Directory *>(parentNode);
|
||||
if (dir || (parentNode && (node->Mode() & S_ATTR_DIR))) {
|
||||
if (dir || (parentNode && (node->Mode() & BFS_S_ATTR_DIR))) {
|
||||
// entry has a valid parent directory, so it's assumed to be a valid entry
|
||||
disk.BlockBitmap()->BackupSet(node, true);
|
||||
} else if (node->Mode() & S_ATTR) {
|
||||
} else if (node->Mode() & BFS_S_ATTR) {
|
||||
if (gVerbose) {
|
||||
printf("attribute \"%s\" at %" B_PRId32 ",%d misses its parent.\n",
|
||||
node->Name(), node->BlockRun().allocation_group,
|
||||
@@ -500,7 +500,7 @@ checkStructure(Disk &disk)
|
||||
|
||||
Inode *nameNode = (Inode *)gMissingEmpty.Remove(&run);
|
||||
if (nameNode != NULL) {
|
||||
nameNode->SetMode(S_IFDIR);
|
||||
nameNode->SetMode(BFS_S_IFDIR);
|
||||
if (gVerbose)
|
||||
printf("found missing name!\n");
|
||||
} else {
|
||||
@@ -509,7 +509,7 @@ checkStructure(Disk &disk)
|
||||
<< ":" << (int32)run.start;
|
||||
|
||||
nameNode = Inode::EmptyInode(&disk, parentName.String(),
|
||||
S_IFDIR);
|
||||
BFS_S_IFDIR);
|
||||
if (nameNode) {
|
||||
nameNode->SetBlockRun(run);
|
||||
nameNode->SetParent(disk.Root());
|
||||
@@ -580,14 +580,14 @@ checkStructure(Disk &disk)
|
||||
if ((dir = (Directory *)gMissing.Get(run)) != NULL) {
|
||||
if (gVerbose)
|
||||
puts("\tfound in missing");
|
||||
dir->SetMode(dir->Mode() | S_ATTR_DIR);
|
||||
dir->SetMode(dir->Mode() | BFS_S_ATTR_DIR);
|
||||
dir->SetParent(node->BlockRun());
|
||||
} else {
|
||||
if (gVerbose)
|
||||
puts("\tcreate new!");
|
||||
|
||||
Inode *empty = Inode::EmptyInode(&disk, NULL,
|
||||
S_IFDIR | S_ATTR_DIR);
|
||||
BFS_S_IFDIR | BFS_S_ATTR_DIR);
|
||||
if (empty) {
|
||||
empty->SetBlockRun(run);
|
||||
empty->SetParent(node->BlockRun());
|
||||
|
||||
Reference in New Issue
Block a user