Am I right in thinking that it’s not possible to rename an ADS to the
primary stream of the same file?
e.g. if I rename:
\Device\HarddiskVolume1\myfile.txt:myads
to:
\Device\HarddiskVolume1\myfile.txt
I seem to be hitting a STATUS_INVALID_PARAMETER.
I’m just looking for a quick way to replace the data in the primary stream
with that in an ADS. I was hoping to avoid doing a data transfer between the
two streams.
Thanks,
Ged.
Just to follow up on this for future ref as I got it to work once I
understood the docs a little better.
The first point to note is this:
“The new name for the stream must begin with a colon (:)”
When building up the FILE_RENAME_INFORMATION struct, the FileName param
should only contain the ADS name including the colon and not the full file
path including the colon and ADS name.
The next point is this:
" If ReplaceIfExists is set to TRUE, the rename operation will succeed only
if a stream with the same name exists and is a zero-length data stream"
Therefore if the primary stream has any data in it, it needs it’s file
position and EOF to be set to zero before you attempt the rename.
Finally, (and taking the first point into consideration), as this is the
primary stream which we’re trying to rename to, the FileName param should
just be a : with no proceeding ADS name. The FS obviously doesn’t like this,
so FileName needs to contain ‘::$DATA’
A a good use case for this is when modifying data in a file (e.g.
encrypting). You read the data from the primary stream, do whatever mods you
need on the data and write it out to a temp stream in the same file. (If it
fails you haven’t damaged the original data). Renaming back to the primary
stream avoids having to transfer the data from the temp stream back to the
primary. When working with large files, the saving is considerable.
Ged.
-----Original Message-----
From: Ged Murphy [mailto:xxxxx@gmail.com]
Sent: 28 August 2014 18:01
To: ‘Windows File Systems Devs Interest List’
Subject: Rename ADS to Primary
Am I right in thinking that it’s not possible to rename an ADS to the
primary stream of the same file?
e.g. if I rename:
\Device\HarddiskVolume1\myfile.txt:myads
to:
\Device\HarddiskVolume1\myfile.txt
I seem to be hitting a STATUS_INVALID_PARAMETER.
I’m just looking for a quick way to replace the data in the primary stream
with that in an ADS. I was hoping to avoid doing a data transfer between the
two streams.
Thanks,
Ged.