简体   繁体   English

获取有关硬盘扇区中原始数据的更改的通知-文件更改通知

[英]Get notified about the change in raw data in hard disk sector - File change notification

I'm trying to make a software that backups my entire hard drive. 我正在尝试制作一个备份整个硬盘的软件。

I've managed to write a code for reading the raw data from hard disk sectors. 我设法编写了一个代码,用于从硬盘扇区读取原始数据。 However, i want to have incremental backups. 但是,我想进行增量备份。 For that i need to know the changed made to OS settings, file changes, everything. 为此,我需要知道对OS设置所做的更改,文件更改以及所有内容。

My question is - 我的问题是-

Using FileSystemWatcher and Inotify , will i be able to know every change made to every sector in the hard drive ? 使用FileSystemWatcherInotify ,我是否能够知道对硬盘驱动器中每个扇区进行的所有更改? (OS settings etc) (操作系统设置等)

I'm coding it in C++ for linux and windows. 我正在用C ++为Linux和Windows编写代码。

(Saw this question on Stackoverflow which gave me some idea) (在Stackoverflow上看到了这个问题,这给了我一些想法)

Inotify is to detect changes while your program is running, I'm guessing that FilySystemWatches is similar. Inotify是在程序运行时检测更改,我猜FilySystemWatches是类似的。

One way to solve this is to have a checksum on each sector or multiple of sectors, and when making a backup you compare the checksums to the list you have and only backup blocks that have been changed. 解决此问题的一种方法是在每个扇区或多个扇区上具有校验和,并且在进行备份时,将校验和与您拥有的列表进行比较,并且仅将已更改的备份块进行比较。

The MS Windows FileSystemWatcher mechanism is more limited than Linux's Inotify , but both probably will do what you need. 与Windows 的Inotify相比 ,MS Windows FileSystemWatcher机制受到更多限制,但是两者都可以满足您的需求。 The Linux mechanism provides (optional) notification for file reads, which causes the "access timestamp" to be updated. Linux机制为文件读取提供(可选)通知,这将导致“访问时间戳”被更新。

However, the weakness from your application's perspective is that all file modifications made from system boot up to your program getting loaded (and unload to shutdown) will not be monitored. 但是,从应用程序的角度来看,缺点是从系统启动到加载程序(从卸载到关机)的所有文件修改都不会受到监视。 Your application might need to look through file modification timestamps of many files to identify changed files, depending on the level of monitoring you are targeting. 您的应用程序可能需要查看许多文件的文件修改时间戳,以识别更改的文件,具体取决于您要监视的监视级别。

Both architectures maintain a timestamp for each file tracking when the file was last accessed. 两种架构都为上次访问文件的时间跟踪每个文件保留一个时间戳。 If that being updated is a trigger for a backup notification, the Windows mechanism lacking such notification will cause mismatched behavior on the platforms. 如果该更新是触发备份通知的触发器,则缺少此类通知的Windows机制将导致平台上的行为不匹配。 Windows' mechanism can also drop notifications due to buffer size limitations. Windows的机制也可能由于缓冲区大小限制而删除通知。 Here is a real gem from the documentation : 这是文档中的一个真正的宝石:

Note that a FileSystemWatcher does not raise an Error event when an event is missed or when the buffer size is exceeded, due to dependencies with the Windows operating system. 请注意,由于Windows操作系统的依赖性,当缺少事件或超出缓冲区大小时, FileSystemWatcher不会引发Error事件。 To keep from missing events, follow these guidelines: 为了避免丢失事件,请遵循以下准则:

  • Increasing the buffer size with the InternalBufferSize property can prevent missing file system change events. 使用InternalBufferSize属性增加缓冲区大小可以防止丢失文件系统更改事件。

  • Avoid watching files with long file names. 避免观看带有长文件名的文件。 Consider renaming using shorter names. 考虑使用短名称重命名。

  • Keep your event handling code as short as possible. 保持事件处理代码尽可能短。

At least you can control two out of three of these.... 至少您可以控制其中三分之二...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM