How to open file as PAGINGFILE earlier opened and closed as noraml file

Hi, All!

I need to open file as PAGING file, which was earlier opened and closed as normal file. IoCreateFile returns SHARING_VIOLATION.

I quess that FSD doesn’t delete FCB because of remaining references to it from other parts like(Cache/ VMM). My question is, how too force FSD/Cache/VMM to forget FCB’s(or something like) for files that have been already closed.

Is there a paging file already opened on that volume?

IIRC, the file system allows only one file per volume to be opened as a paging file.

Regards,
Razvan

I just checked FASTFAT source and it looks like you cannot open as a paging file a file which was earlier opened as a normal file.

Look for the following comment in FatCommonCreate:

//
// If there is already an Fcb for a paging file open and
// it was not already opened as a paging file, we cannot
// continue as it is too difficult to move a live Fcb to
// non-paged pool.
//

Regards,
Razvan

I understand the question, and I believe it is a dead end for you, and
Rzavan has given some good reason. So, what I’m wondering, why do you think
you need to open as paging file - what are you really trying to achieve
here - the group might be able to point you in a much better direction.

wrote in message news:xxxxx@ntfsd…
> Hi, All!
>
> I need to open file as PAGING file, which was earlier opened and closed as
> normal file. IoCreateFile returns SHARING_VIOLATION.
>
> I quess that FSD doesn’t delete FCB because of remaining references to it
> from other parts like(Cache/ VMM). My question is, how too force
> FSD/Cache/VMM to forget FCB’s(or something like) for files that have been
> already closed.
>
>

One part of my programs interacts with user and after that creates ordinary file, adds data and close it. After that this part of program saves file allocation in some place, it will be used later in boot time and problem is how to protect this file to be not moved by defragmenters. My approach was is to open that file as PAGEFILE and hold it open. But when i try to open this file which previously closed, sometimes on NTFS i bacome SHARING_VIOLATION, but sometimes it opens. So as I understand some part of code sometimes still holds the reference to FILEOBJECT. So, question is how to force filesystem and other parts(CC, VMM) to forget about closed files.

Or,perhaps, somebody know another approach how to protect the file from moving by defragmenters.

Thanks

> Or,perhaps, somebody know another approach how to protect

the file from moving by defragmenters.

One approach would be to filter FSCTL_MOVE_FILE for the file of interest and deny it. I don’t know what side effects (if any) that would have on defragmenters.

Regards,
Razvan

> Or,perhaps, somebody know another approach how to

protect the file from moving by defragmenters.
A method I know was used, not being ideal though, is to mark your file
clusters
as “bad” (which survives until reformatting or “Scan for and attempt
recovery of
bad clusters”) and replace writes/reads by direct disk operations
[relatively easy
even if you have more than one run in retrieval pointers].

So you firts opena file “as is”, get its runs through retrieval ptrs, close
it,
“spoil” the clusters in these runs and live happily ever after with physical
writes/reads.

“Ever after” if (a) noone interfered in-between, (b) no reformats, (c) no
recovery scans.

----- Original Message -----
From:
To: “Windows File Systems Devs Interest List”
Sent: Wednesday, February 11, 2009 10:26 AM
Subject: RE:[ntfsd] How to open file as PAGINGFILE earlier opened and closed
as noraml file

> One part of my programs interacts with user and after that creates
> ordinary file, adds data and close it. After that this part of program
> saves file allocation in some place, it will be used later in boot time
> and problem is how to protect this file to be not moved by defragmenters.
> My approach was is to open that file as PAGEFILE and hold it open. But
> when i try to open this file which previously closed, sometimes on NTFS i
> bacome SHARING_VIOLATION, but sometimes it opens. So as I understand some
> part of code sometimes still holds the reference to FILEOBJECT. So,
> question is how to force filesystem and other parts(CC, VMM) to forget
> about closed files.
>
> Or,perhaps, somebody know another approach how to protect the file from
> moving by defragmenters.
>
> Thanks
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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

One part of code creates file as normal file and saves there data. Then it takes file allocation on the volume and saves it in some place. After that file is closed. Saved file allocation later will be used for read that data in boot time.

So, My goal is open that file as PAGEFILE(after it was closed) and doing it protect this file from potential DEFRAGMENTATION, that could have place .

Ok, I get you suggestions. Thank you very much… But just for education, could you tell me, is it possible to force FSD to erase internal structure like FCB when file is closed. For example,

  1. open file with NO_BUFFERING(it allows not to have problems with open References from Cache and VMM)
  2. write data to it
  3. close file
  4. do something to force FSD to check that all references to FCB are gone and allows FSD to erace internal file structures like (FCB,CCB)
  5. open the same file as PAGING_FILE.

The question is, when and how FSD decides to erace all file relative structes. And how to force it.

Thank you

— On Fri, 2/13/09, xxxxx@rambler.ru wrote:
> for education, could you tell me, is it possible to force
> FSD to erase internal structure like FCB when file is
> closed.
>
> The question is, when and how FSD decides to erace all
> file relative structes. And how to force it.

The short answer: NO.

How the FSD handles its FCBs is entirely its own business and trying to force its behaviour to match your expectations is futile. Unless you control the source code for the file system, you should try seeing it as a black box (and keeping this in mind when you design your solution).

Regards,
Razvan

This is my (feeble) understanding. First, not it’s not “possible to force
FSD to erase internal structure like FCB”. Second, FSD will tear down “FCB”
some time after it first becomes possible to tear down “FCB”.

wrote in message news:xxxxx@ntfsd…
> Ok, I get you suggestions. Thank you very much… But just for education,
> could you tell me, is it possible to force FSD to erase internal structure
> like FCB when file is closed. For example,
>
> 1) open file with NO_BUFFERING(it allows not to have problems with open
> References from Cache and VMM)
> 2) write data to it
> 3) close file
> 4) do something to force FSD to check that all references to FCB are gone
> and allows FSD to erace internal file structures like (FCB,CCB)
> 5) open the same file as PAGING_FILE.
>
> The question is, when and how FSD decides to erace all file relative
> structes. And how to force it.
>
> Thank you
>

> This is my (feeble) understanding. First, not it’s not "possible to force

FSD to erase internal structure like FCB".

CcPurgeCacheSection can probably help.


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

I need to have file allocation the same when it was after file was created, data added and file closed by some part of my program. I can make sure it only by openinng that file as PAGEFILE from the kernel so the defrag api will skip it during defragmentation.

In all these posts have you provided any details about what that ‘fixed’
file will contain? You have managed to get caught in a dead end alley,
surrounded by 100 story buildings on each side and in front. It almost
looks like you have seen descriptions of how some secure boot software used
to work in the days of MS-DOS and are attempting to use the same techniques
with Windows on NTFS partitions. Write down a sequence point list from
where the file is created through where it is used to where it can be
deleted. Re-order that list several times until you can’t find any sequence
point that must proceed a point previously listed. Think about the ‘file’
as being just a file and not a ‘fixed’ sequence of sectors on a hard drive
at each point. Then think about how you can make that ‘file’ available at
each sequence point.

Also consider that opening that ‘file’ as a paging file will not solve your
‘problem’ is a defragmenter decides to relocate that file even when it is
open. Some defrag programs run in native mode to optimize page files. A
service that loads before your service could relocate that file, though a
boot start driver can protect it from everything except a disk optimizer run
from another bootable partition. I have used multiple boot volumes of the
same OS to make recovery easier and doing an optimization on the other
volume since no files will be in use.

wrote in message news:xxxxx@ntfsd…
>I need to have file allocation the same when it was after file was created,
>data added and file closed by some part of my program. I can make sure it
>only by openinng that file as PAGEFILE from the kernel so the defrag api
>will skip it during defragmentation.
>

As max says it might *help*, but it won’t *solve* everything.

Also, you have to make the right guess as to which locks to hold while you
are calling it. And don’t mind if it fails.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> This is my (feeble) understanding. First, not it’s not “possible to force
> FSD to erase internal structure like FCB”.

CcPurgeCacheSection can probably help.


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

Thank you guys for your answers!

First my idea was to use FlushFile for the current file, which use (CcPurgeCacheSection…) but it didn’t help me. Yes, i understand that there are native defragmentor which start at boot time, and potentially could use their FSD implementations to move file. As i know there is not any good solution to protect the file from moving.

I want just protect from non advanced defrag utils, like windows own. I’m not interesting how to protect file from moving in all cases, i’m interesting how to open file as paging file which was earlier opened and closed as ordinary file.

The one idea is to open it as NO_BUFFERING file which stops caching and when i close that file i want to know is it possible to force fsd to forget internal structures which are not more referenced by other winodws components? Like FCB in fastfat, f.e.

xxxxx@rambler.ru wrote:

Thank you guys for your answers!

First my idea was to use FlushFile for the current file, which use (CcPurgeCacheSection…) but it didn’t help me. Yes, i understand that there are native defragmentor which start at boot time, and potentially could use their FSD implementations to move file. As i know there is not any good solution to protect the file from moving.

I want just protect from non advanced defrag utils, like windows own. I’m not interesting how to protect file from moving in all cases, i’m interesting how to open file as paging file which was earlier opened and closed as ordinary file.

The one idea is to open it as NO_BUFFERING file which stops caching and when i close that file i want to know is it possible to force fsd to forget internal structures which are not more referenced by other winodws components? Like FCB in fastfat, f.e.

Please, re-read David’s response. Ignoring the possibility that your
‘file’ can be relocated at boot time is just asking for trouble - when
it happens, and it will, what will be the failure mode? Normally the
failure mode would be volume-level corruption - do you really want to
generate a volume level corruptor? I’m unfamiliar with where you’re
going here, but I could also move your file, then have an unprivileged
user use the same sectors you were using, and write to them…

Generally a better approach is to re-open the file at boot time, mark it
deny defrag (FSCTL_MARK_HANDLE), query its extents, and operate on
those. Note that pagefiles do not come into play in this sequence.

To go back to specifics:

  1. If you’re on NTFS, it can handle any number of pagefiles per volume.
  2. NTFS is designed to allow a file to be closed as a regular file and
    opened as a pagefile and vice-versa. It has explicit code to enable
    this. Are you sure that the reason your pagefile open is failing is due
    to stale structures after a previous non-pagefile close? If so, which
    Windows build are you using?
  3. A better way to prevent an object from moving is FSCTL_MARK_HANDLE,
    as mentioned above. This is far less restrictive on the rest of the
    system; for example, a user could then open your file and query its
    attributes, etc.
  • M


This posting is provided “AS IS” with no warranties, and confers no rights