shrink and expand

hello everyone,

I hav an activity monitor FS minifilter. I was wondering, if there is any
way to capture the volume ‘shirnk’ or ‘expand’ events in the said
minifilter? I understand that, I am too high in the stack for this, and non
of the filter manager apis seem to help, still I thought I would ask…

thanks

B

FSCTL_SHRINK/EXPAND_VOLUME


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Bedanto” wrote in message news:xxxxx@ntfsd…
hello everyone,

I hav an activity monitor FS minifilter. I was wondering, if there is any way to capture the volume ‘shirnk’ or ‘expand’ events in the said minifilter? I understand that, I am too high in the stack for this, and non of the filter manager apis seem to help, still I thought I would ask…

thanks

B

Thanks maxim! This really will help my cause.

BTW I understand that these work only for VISTA+

So there won’t be a legit way to handle products like partition magic and
acronis (XP style using the disk management IOCTLS) would there?

With all your experience in FS and volume stack it would be really helpful
if you can throw some pointers. At this point to me it looks like we can’t
even do it at the volume level, we will have to go to the disk filter.

Any pointers will be really really helpful.

thanks
B

On Fri, Mar 11, 2011 at 9:59 PM, Maxim S. Shatskih
wrote:

> FSCTL_SHRINK/EXPAND_VOLUME
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> “Bedanto” wrote in message news:xxxxx@ntfsd…
> hello everyone,
>
> I hav an activity monitor FS minifilter. I was wondering, if there is any
> way to capture the volume ‘shirnk’ or ‘expand’ events in the said
> minifilter? I understand that, I am too high in the stack for this, and non
> of the filter manager apis seem to help, still I thought I would ask…
>
> thanks
>
> B
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

>So there won’t be a legit way to handle products like partition magic and acronis (XP style using the

disk management IOCTLS) would there?

I think no, they all use undocumented stuff.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks Max!

There seem to be several posts on the internet about how inadequate the
vista shrink operation is.
http://www.howtogeek.com/howto/windows-vista/working-around-windows-vistas-shrink-volume-inadequacy-problems/
The root cause of the problem seems to be that the MFTMirror resides in
those areas of the disk.

MSDN says:
http://msdn.microsoft.com/en-us/library/aa964912(v=vs.85).aspx

To complete a shrink operation, you must:

  1. Call *CreateFile*http:
    to open a handle to the volume.
    2. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of the
    SHRINK_VOLUME_INFORMATIONhttp:
    structure to ShrinkPrepare. Set the NewNumberOfSectors member of the
    same structure to zero. If this call succeeds, the filesystem will not
    allocate clusters beyond the end of the new volume length.
    3. Call FSCTL_MOVE_FILEhttp:
    on all files beyond the new number of sectors and move them within the
    valid range. You are responsible for moving any files that are affected by
    the shrink operation.
    4. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of the
    SHRINK_VOLUME_INFORMATIONhttp:
    structure to ShrinkCommit. Set the NewNumberOfSectors member of the
    same structure to zero. If all files beyond the end of the new volume size
    have not been moved, the call fails with STATUS_ALREADY_COMMITTED
    (ERROR_ACCESS_DENIED). Otherwise, the filesystem has now been shrunk.
    5. Call IOCTL_DISK_GROW_PARTITIONhttp:.
    Set the BytesToGrow member of the
    DISK_GROW_PARTITIONhttp:
    structure to the negative number that represents the number of bytes to
    remove.

    I was hoping NTFS to handle step two better and move it’s meta data around,
    which doesn’t seem to be the case.
    Step 3 will never work for system files maintained by the OS.

    SO what is the point of giving useless half baked APIS to the end user, if
    they cant use it?

    B

    On Sun, Mar 13, 2011 at 11:02 PM, Maxim S. Shatskih
    wrote:

    > >So there won’t be a legit way to handle products like partition magic and
    > acronis (XP style using the
    > >disk management IOCTLS) would there?
    >
    > I think no, they all use undocumented stuff.
    >
    > –
    > Maxim S. Shatskih
    > Windows DDK MVP
    > xxxxx@storagecraft.com
    > http://www.storagecraft.com
    >
    >
    > —
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars visit:
    > http://www.osr.com/seminars
    >
    > To unsubscribe, visit the List Server section of OSR Online at
    > http://www.osronline.com/page.cfm?name=ListServer
    ></http:></http:></http:></http:></http:></http:>

All,

continuing on this discussion…

I want to use the FSCTL Max pointed out FSCTL_SHRINK/EXPAND_VOLUME.

Lets assume I have a meta data file open (just like the meta data maager
example in WDK), what is the right thing to do on receivng
FSCTL_SHRINK/EXPAND_VOLUME? I am supposed to close all handles and release
the context till thie FSCTL complets?

If so, assuming mine is a tracking driver which tracks sme data continously
in it’s meta data files, I wil be missing the IO in this interval. I am okay
with that if the SHRINK/EXPAND suceeds. But if it fails, iteans nothng
happend on the volume and I stopped my work too. This seems to be a
preemptive solution to me.

Is there a better way of handling this? Can I wait till the FSCTL completion
comes back with success and then stop the IO operation in the completion
routine?

thanks

ap

On Tue, Mar 15, 2011 at 12:27 PM, Bedanto wrote:

> Thanks Max!
>
> There seem to be several posts on the internet about how inadequate the
> vista shrink operation is.
>
> http://www.howtogeek.com/howto/windows-vista/working-around-windows-vistas-shrink-volume-inadequacy-problems/
> The root cause of the problem seems to be that the MFTMirror resides in
> those areas of the disk.
>
> MSDN says:
> http://msdn.microsoft.com/en-us/library/aa964912(v=vs.85).aspx
>
> To complete a shrink operation, you must:
>
> 1. Call CreateFilehttp:
> to open a handle to the volume.
> 2. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of
> the SHRINK_VOLUME_INFORMATIONhttp:
> structure to ShrinkPrepare. Set the NewNumberOfSectors member of the
> same structure to zero. If this call succeeds, the filesystem will not
> allocate clusters beyond the end of the new volume length.
> 3. Call FSCTL_MOVE_FILEhttp:
> on all files beyond the new number of sectors and move them within the
> valid range. You are responsible for moving any files that are affected by
> the shrink operation.
> 4. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of
> the SHRINK_VOLUME_INFORMATIONhttp:
> structure to ShrinkCommit. Set the NewNumberOfSectors member of the
> same structure to zero. If all files beyond the end of the new volume size
> have not been moved, the call fails with STATUS_ALREADY_COMMITTED
> (ERROR_ACCESS_DENIED). Otherwise, the filesystem has now been shrunk.
> 5. Call IOCTL_DISK_GROW_PARTITIONhttp:.
> Set the BytesToGrow member of the DISK_GROW_PARTITIONhttp:
> structure to the negative number that represents the number of bytes
> to remove.
>
>
> I was hoping NTFS to handle step two better and move it’s meta data around,
> which doesn’t seem to be the case.
> Step 3 will never work for system files maintained by the OS.
>
> SO what is the point of giving useless half baked APIS to the end user, if
> they cant use it?
>
> B
>
>
>
>
> On Sun, Mar 13, 2011 at 11:02 PM, Maxim S. Shatskih <
> xxxxx@storagecraft.com> wrote:
>
>> >So there won’t be a legit way to handle products like partition magic and
>> acronis (XP style using the
>> >disk management IOCTLS) would there?
>>
>> I think no, they all use undocumented stuff.
>>
>> –
>> Maxim S. Shatskih
>> Windows DDK MVP
>> xxxxx@storagecraft.com
>> http://www.storagecraft.com
>>
>>
>> —
>> NTFSD is sponsored by OSR
>>
>> For our schedule of debugging and file system seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTFSD is sponsored by OSR For our schedule of debugging and file system
> seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</http:></http:></http:></http:></http:></http:>