我可以一次将整个 NTFS 目录树读入 RAM 吗? [英] Can I read whole NTFS directory tree into RAM at once?

查看:54
本文介绍了我可以一次将整个 NTFS 目录树读入 RAM 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道读取目录的唯一方法是递归地下降到每个目录,但是如果我想快速在整个磁盘上的任何位置找到文件,这太慢了.

Only way I know of reading directories is to recursively descend into each directory but that's too slow if I want to find file anywhere on the whole disk quickly.

Windows 程序Everything Search"http://www.voidtools.com/ 可以做到这一点比我假设的递归下降速度更快(它在不到 10 秒的时间内读取了 4TB 硬盘上近 20 亿个文件的文件名).

There's windows program "Everything Search" http://www.voidtools.com/ that does that faster than I assume is possible by recursive descent (it reads filenames of almost 2bln files on 4TB HDD in less than 10 seconds).

我知道我可以提前建立索引,但是否可以通过在一次操作中将磁盘的整个目录树读入内存并在那里解析来完成?

I know I could build index ahead of time but can it be done just by reading whole directory tree of a disk into ram in one operation and parsed there?

编辑

由于事实证明我的问题令人困惑,因此我想这样做:

Since my question proved to be confusing here's what I want to do:

https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

// For Directory::GetFiles and Directory::GetDirectories 
// For File::Exists, Directory::Exists 
using namespace System;
using namespace System::IO;
using namespace System::Collections;

// Insert logic for processing found files here. 
void ProcessFile( String^ path )
{
   Console::WriteLine( "Processed file '{0}'.", path );
}


// Process all files in the directory passed in, recurse on any directories  
// that are found, and process the files they contain. 
void ProcessDirectory( String^ targetDirectory )
{

   // Process the list of files found in the directory. 
   array<String^>^fileEntries = Directory::GetFiles( targetDirectory );
   IEnumerator^ files = fileEntries->GetEnumerator();
   while ( files->MoveNext() )
   {
      String^ fileName = safe_cast<String^>(files->Current);
      ProcessFile( fileName );
   }


   // Recurse into subdirectories of this directory. 
   array<String^>^subdirectoryEntries = Directory::GetDirectories( targetDirectory );
   IEnumerator^ dirs = subdirectoryEntries->GetEnumerator();
   while ( dirs->MoveNext() )
   {
      String^ subdirectory = safe_cast<String^>(dirs->Current);
      ProcessDirectory( subdirectory );
   }
}

int main( int argc, char *argv[] )
{
   for ( int i = 1; i < argc; i++ )
   {
      String^ path = gcnew String(argv[ i ]);
      if ( File::Exists( path ) )
      {

         // This path is a file
         ProcessFile( path );
      }
      else 
      if ( Directory::Exists( path ) )
      {

         // This path is a directory
         ProcessDirectory( path );
      }
      else
      {
         Console::WriteLine( "{0} is not a valid file or directory.", path );
      }

   }
}

我想获得相同的信息,但不想多次调用 Directory::GetDirectories.我正在寻找的解决方案无论如何都不像这段代码.这段代码只是说明我想要读取磁盘的哪些信息(目录中所有文件的名称),而不是我想要的方式(我不想要递归和与目录一样多的系统调用).

I want to get same information but without calling Directory::GetDirectories multiple times. Solution I'm looking for doesn't look anyway like this code. This code is just illustration of what information I want read of the disk (names of all files in directories) not how I'd like to do it (I don't want recursion and as many system calls as there are directories).

EDIT 2(对于认为这个问题过于宽泛的人):

EDIT 2 (For the people that consider this question too broad):

我问的是如何在 Windows 或 Linux 操作系统上执行此操作.我会接受任何语言的答案,因为我最感兴趣的是我需要进行哪些系统调用(以及如何解析这些调用的结果)以将整个驱动器的 NTFS 目录树放入 RAM 中,系统调用少于一个驱动器上的每个目录.

I'm asking how to do that either on Windows or Linux operating systems. I'll accept answer in any language because I'm most interested what system calls I need to make (and how to parse the results of those calls) to get NTFS directory tree of a whole drive into RAM with fewer system calls than one per each directory on the drive.

我也会接受将我指向 Windows 或 Linux 库的答案.

I'll also accept the answer that points me to Windows or Linux library that does exactly that.

推荐答案

如果您有足够的 RAM,请继续执行.但是我建议您分块加载磁盘而不是整个磁盘,这也将提高您的时间效率.

if you have sufficient amount of RAM then go ahead and do it. But I recommend you to load disk in parts instead of whole disk that will also improve your time efficiency.

这篇关于我可以一次将整个 NTFS 目录树读入 RAM 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆