本文整理汇总了C++中Directory::InitCheck方法的典型用法代码示例。如果您正苦于以下问题:C++ Directory::InitCheck方法的具体用法?C++ Directory::InitCheck怎么用?C++ Directory::InitCheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Directory
的用法示例。
在下文中一共展示了Directory::InitCheck方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: files
void
collectFiles(Disk &disk)
{
Directory *root = (Directory *)Inode::Factory(&disk,disk.Root());
puts("Collecting files (this will take some time)...");
if (root == NULL || root->InitCheck() < B_OK)
{
fprintf(stderr," Could not open root directory!\n");
return;
}
collectFiles(disk,root);
printf(" %7Ld files found.\n",gCount);
delete root;
}
示例2: strerror
int
checkIndex(Disk &disk,char *attribute,block_run &run,bool collect)
{
Directory *index = (Directory *)Inode::Factory(&disk,run);
status_t status;
if (index == NULL || (status = index->InitCheck()) < B_OK)
{
fprintf(stderr," Could not get index directory for \"%s\": %s!\n",attribute,index ? strerror(status) : "not found/corrupted");
return -1;
}
printf("\nCheck \"%s\" index's on-disk structure...\n",attribute);
//dump_inode(index->InodeBuffer());
BPlusTree *tree;
if (index->GetTree(&tree) < B_OK || tree->Validate(true) < B_OK)
{
fprintf(stderr," B+Tree of index \"%s\" seems to be corrupt!\n",attribute);
//return -1;
}
if (collect && (!gDoNotCheckIndex || !gDoNotCheckForFiles))
collectFiles(disk);
if (!gDoNotCheckIndex)
{
printf("Check for non-existing files in index \"%s\"...\n",attribute);
checkIndexForNonExistingFiles(disk,*tree);
}
if (!gDoNotCheckForFiles)
{
printf("Check for files not in index \"%s\" (this may take even more time)...\n",attribute);
checkFiles(disk,*tree,attribute);
}
return 0;
}
示例3: disk
int
main(int argc,char **argv)
{
puts("Copyright (c) 2001-2008 pinc Software.");
char *toolName = argv[0];
if (argc < 2 || !strcmp(argv[1],"--help"))
{
printUsage(toolName);
return -1;
}
while (*++argv)
{
char *arg = *argv;
if (*arg == '-')
{
while (*++arg && isalpha(*arg))
{
switch (*arg)
{
case 'i':
gDoNotCheckIndex = true;
break;
case 'f':
gDoNotCheckForFiles = true;
break;
case 'a':
gCheckAll = true;
break;
}
}
}
else
break;
}
char *attribute = argv[0];
if (!gCheckAll && attribute == NULL)
{
printUsage(toolName);
return -1;
}
dev_t device = dev_for_path(".");
if (device < B_OK)
{
fprintf(stderr,"Could not find device for current location: %s\n",strerror(device));
return -1;
}
fs_info info;
if (fs_stat_dev(device,&info) < B_OK)
{
fprintf(stderr,"Could not get stats for device: %s\n",strerror(errno));
return -1;
}
Disk disk(info.device_name);
status_t status;
if ((status = disk.InitCheck()) < B_OK)
{
fprintf(stderr,"Could not open device or file \"%s\": %s\n",info.device_name,strerror(status));
return -1;
}
if (disk.ValidateSuperBlock() < B_OK)
{
fprintf(stderr,"The disk's superblock is corrupt!\n");
return -1;
}
Directory *indices = (Directory *)Inode::Factory(&disk,disk.Indices());
if (indices == NULL || (status = indices->InitCheck()) < B_OK)
{
fprintf(stderr," Could not get indices directory: %s!\n",indices ? strerror(status) : "not found/corrupted");
delete indices;
return -1;
}
BPlusTree *tree;
if (indices->GetTree(&tree) < B_OK || tree->Validate() < B_OK)
{
fprintf(stderr," Indices B+Tree seems to be corrupt!\n");
delete indices;
return -1;
}
block_run run;
if (gCheckAll)
{
putchar('\n');
collectFiles(disk);
char name[B_FILE_NAME_LENGTH];
while (indices->GetNextEntry(name,&run) >= B_OK)
checkIndex(disk,name,run,false);
}
else if (indices->FindEntry(attribute,&run) == B_OK)
checkIndex(disk,attribute,run,true);
//.........这里部分代码省略.........
示例4: if
void
checkFiles(Disk &disk,BPlusTree &tree,char *attribute)
{
block_run *runs = (block_run *)malloc(gCount * sizeof(block_run));
if (runs == NULL)
{
fprintf(stderr," Not enough memory!\n");
return;
}
// copy hashtable to array
block_run *run = NULL;
int32 index = 0;
gHashtable.Rewind();
while (gHashtable.GetNextEntry((void **)&run) == B_OK)
{
runs[index++] = *run;
}
// sort array to speed up disk access
qsort(runs,index,sizeof(block_run),(int (*)(const void *,const void *))compareBlockRuns);
bool sizeIndex = !strcmp(attribute,"size");
bool nameIndex = !strcmp(attribute,"name");
bool modifiedIndex = !strcmp(attribute,"last_modified");
char key[B_FILE_NAME_LENGTH];
uint16 keyLength = 0;
Inode *inode = NULL;
for (int32 i = 0;i < index;i++)
{
if (i % 50 == 0)
printf(" %7ld%s1A\n",i,gEscape);
delete inode;
inode = Inode::Factory(&disk,runs[i]);
if (inode == NULL || inode->InitCheck() < B_OK)
{
fprintf(stderr," inode at (%ld, %d) is corrupt!\n",runs[i].allocation_group,runs[i].start);
delete inode;
continue;
}
// check indices not based on standard attributes
if (sizeIndex)
{
if (inode->IsDirectory())
continue;
memcpy(key,&inode->InodeBuffer()->data.size,sizeof(off_t));
keyLength = sizeof(off_t);
}
else if (nameIndex)
{
strcpy(key,inode->Name());
keyLength = strlen(key);
}
else if (modifiedIndex)
{
if (inode->IsDirectory())
continue;
memcpy(key,&inode->InodeBuffer()->last_modified_time,sizeof(off_t));
keyLength = sizeof(off_t);
}
else // iterate through all attributes to find the right one (damn slow, sorry...)
{
inode->RewindAttributes();
char name[B_FILE_NAME_LENGTH];
uint32 type;
void *data;
size_t length;
bool found = false;
while (inode->GetNextAttribute(name,&type,&data,&length) == B_OK)
{
if (!strcmp(name,attribute))
{
strncpy(key,(char *)data,B_FILE_NAME_LENGTH - 1);
key[B_FILE_NAME_LENGTH - 1] = '\0';
keyLength = length > B_FILE_NAME_LENGTH ? B_FILE_NAME_LENGTH : length;
found = true;
break;
}
}
if (!found)
continue;
}
off_t value;
if (tree.Find((uint8 *)key,keyLength,&value) < B_OK)
{
if (*inode->Name())
fprintf(stderr," inode at (%ld, %d) name \"%s\" is not in index!\n",runs[i].allocation_group,runs[i].start,inode->Name());
else
{
// inode is obviously deleted!
block_run parent = inode->Parent();
Directory *directory = (Directory *)Inode::Factory(&disk,parent);
if (directory != NULL && directory->InitCheck() == B_OK)
//.........这里部分代码省略.........