Пишу драйвер виртуального диска, который монтируется с файла с поддрержкой шифрования.
при записи/чтении обрабатываю IRP_MJ_READ/....WRITE. в файл пишу с помощью KeWriteFile.
Проблкма в следующем. После запроса на запись, данные шифруются и кидаются не на диск, как мне бы хотелось, а в кеш. После попытки читания, ОС. подставляет пользователю данные из кеша, обходя при этом мой обработич IRP_WRITE, т.е. пользователь получает на разшифрованные, а зашифрованные данные.
Как решить эту проблему??
A>Проблкма в следующем. После запроса на запись, данные шифруются и кидаются не на диск, как мне бы хотелось, а в кеш.
firstly, pay attention: there are 2 caches: for
disk level and for
file level. Sure, there is only one cache (Cc) for all OS, but let's think about it like about separate entities.
So, you should have cached data for your virtual disk (and file system layer with 3d cache above) and you should have your encrypted file that only your driver normally use — with separate cache structures handled by real FSD.
in this situation it's OK by OS to satisfy your internal ZwReadFile(encrypted file-continer handle,...) from cache — you'll get back your encrypted data, as expected.
To don't allow use your container to someone else (Ex: don't allow to open its second instance in the FAR and fall into the real cache problems), you might just open it exclusively — internally from your virtual disk driver. Or invent FS filter... there are a lot of products with disk/volume/FS filters bunch of drivers, but I don't think it is what you are looking for.
in short, everything as Alter_ said, exactly.
but if you want to solve your problem easy way, I give you another hints
Hint 1:
to pass data to disk directly through file handle you might use (FILE_NO_INTERMEDIATE_BUFFERING | FILE_SYNCHRONOUS_IO_NONALERT) flags, if you prefer ZwCreateFile. FILE_WRITE_THROUGH sometimes is also useful.
Hint 2:
just do encryption/decryption in separate buffers, not in-place:
— allocate another buffer/MDL
— copy original data being processed
— process it (encrypt/decrypt)
— pass down (call XxRead/WriteFile, for ex)
— do cleanup of previously allocated buffers
A>Как решить эту проблему??
check ideas above
find available sources of virtual disks over internet
do the search by this forum, if google doesn't help
... << RSDN@Home 1.1.4 beta 7 rev. 447>>