views:

135

answers:

2

I will write some thing in a file/memory just before system shutdown or a service shutdown. In the next restart of system, Is it possible to access same file or same memory on the disk, before filesystem loads? Actual requirement is like this, we have a driver that sits between volume level drivers and filesystem driver...in that part of the driver code, I want to access some memory or file.

Thanks & Regards,
calvin

+2  A: 

The logical thing here is to read/write this into the registry if it is not too big. Is there a reason you do not want to use the registry?

If you need to access large data and you are writing a volume or device filter and cannot rely on ZwOpen/Read/Write/Close functions in the kernel an approach would be to create the file in user mode, get its device name and cluster chain and store them in the registry. On the next boot, you can get the device and clusters from registry, and do direct I/O on them.

KIV
yes, data is lot bigger than 12mb(reg can hold only 12, i think), moreover no customer accepts to use their entire registry.
calvin
Then create a 12mb file, get cluster chain and use it.
KIV
Thanks for the answer, i will try out, any sample pseudo code would help much better...
calvin
In both user or kernel mode (wherever you prefer) you can initialize the data store like this:1. Create a file on the boot disk FS2. Resize it to 12MB (fill 12Mb zeroes or use API to set file size)3. Using FSCTL_GET_RETRIEVAL_POINTERS get the allocation information 4. Store this allocation information in RegistryYou can use the data store like this:1. Read the allocation information from Registry2. Create simple read/write functions that write on the physical disk, using the cluster information from the registryI hope this helps
KIV
A: 

Since you want to access this before the filesystem loads, my first thought is to allocate and use a block of storage space on the hard drive outside of the filesystem. You can create a hidden mini-partition on the drive and use low-level I/O commands to read and write your data.

This is a common task in the world of embedded systems, and we often implement it by adding some sort of non-volatile memory device into the system (flash, battery-backed DRAM, etc) and reading and writing to that device. Since you likely don't have the same level of control over the available hardware as embedded developers do, the closest analogue I can think of would be to reserve a chunk of space on a physical disk that you can read from without having to mount as a filesystem. A dedicated mini-partition might work the best because if you know the size of it, you can treat it as one big raw-access buffer and can avoid having to hassle with filenames, filesystems, etc.

bta