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

江枫思渺然 提交于 2019-12-13 19:53:58

问题


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.

My question is -

Using FileSystemWatcher and Inotify, will i be able to know every change made to every sector in the hard drive ? (OS settings etc)

I'm coding it in C++ for linux and windows.

(Saw this question on Stackoverflow which gave me some idea)


回答1:


Inotify is to detect changes while your program is running, I'm guessing that FilySystemWatches is similar.

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.




回答2:


The MS Windows FileSystemWatcher mechanism is more limited than Linux's Inotify, but both probably will do what you need. The Linux mechanism provides (optional) notification for file reads, which causes the "access timestamp" to be updated.

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' mechanism can also drop notifications due to buffer size limitations. 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. To keep from missing events, follow these guidelines:

  • Increasing the buffer size with the InternalBufferSize property can prevent missing file system change events.

  • 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....



来源:https://stackoverflow.com/questions/12816003/get-notified-about-the-change-in-raw-data-in-hard-disk-sector-file-change-noti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!