Write File to specific physical disk sector

Hi, is there any way that I can control on which physical sector of the hard drive that a file will be written to? My target is that I want to write a file to hard disk starting at physical sector 0x230 for example. Is this possible? How to implement this at file system filter levle or at disk class level? Thanks.

At disk level ofcourse. You can’t really manipulate this stuff in the file
system stack.

Regards,
Ayush Gupta
AI Consulting

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-402153-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Saturday, February 20, 2010 1:38 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Write File to specific physical disk sector

Hi, is there any way that I can control on which physical sector of the
hard drive that a file will be written to? My target is that I want to
write a file to hard disk starting at physical sector 0x230 for
example. Is this possible? How to implement this at file system filter
levle or at disk class level? 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

But how I can do this at disk level? Say I want to create a 1MB file, file.bin, on the hard drive. And I want to create the file at sector 0x230 of partition 1. How to do this?

How can I make sure that the data starting at sector 0x230 is the data of file.bin?

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-402159-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Friday, February 19, 2010 1:38 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Write File to specific physical disk sector

But how I can do this at disk level? Say I want to create a 1MB file,
file.bin, on the hard drive. And I want to create the file at sector 0x230
of
partition 1. How to do this?

How can I make sure that the data starting at sector 0x230 is the data of
file.bin?

I am not really sure I want to hear the answer to this, but *why* do you
think you want to do that? I’m pretty sure you have concocted an unworkable
solution to a problem that probably has a solution. If you share the
original problem, I suspect we can steer you toward an effective solution.
But what you’ve asked is very likely not to be it. The partition table
defines which partitions owns which blocks.

Phil

Uh, really silly question, but suppose sector 0x230 belongs to the $MFT
table? Can one spell crash? Even then suppose it’s buried somewhere in a
fragmented free chain and you decide to go stomping all over it and the rest
of your sectors in that 1MB blob you THINK might be free? How do you know
that sector and all the other sectors have not been “occupied” and managed
by the system?

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Friday, February 19, 2010 2:38 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Write File to specific physical disk sector

But how I can do this at disk level? Say I want to create a 1MB file,
file.bin, on the hard drive. And I want to create the file at sector 0x230
of partition 1. How to do this?

How can I make sure that the data starting at sector 0x230 is the data of
file.bin?


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

__________ Information from ESET Smart Security, version of virus signature
database 4881 (20100219) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature
database 4881 (20100219) __________

The message was checked by ESET Smart Security.

http://www.eset.com

This is not really my thing, though I would concur with Phil about the issue of why this is necessary in the first place; however, if you want to do this, it would seem prudent to at least start with the user mode defragmentation api’s. If nothing else, it will be a lot easier to experiment an no matter how you end up implementing this, you’re going to have to deal with the case of block already being in use.

Good luck,

mm

I do not believe you can tell a file system where to create a file, but you can find out where the file was created on disk. Anytime I have needed to know the physical location of a file, I’ve created it and then queried the FS as to where the file is and how it is laid out on disk (to guarantee that it is contiguous).

–Mark Cariddi
OSR, Open Systems Resources, Inc

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Friday, February 19, 2010 3:08 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Write File to specific physical disk sector

Hi, is there any way that I can control on which physical sector of the hard drive that a file will be written to? My target is that I want to write a file to hard disk starting at physical sector 0x230 for example. Is this possible? How to implement this at file system filter levle or at disk class level? 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

Thanks everyone for your opinions. OK. Here is my condition why I want to do
this. I have a disk class upper filter. I want to make my filter compatible
with Microsoft DriveExtender on Windows Home Server. My disk filter will
create a 3MB file on each of the hard drives. And the file is stored
continuously on the hard drive, say starting from sector 0x230. Then when I
try to add a hard drive to the server storage pool VDS (Virtual Disk
Service) will try to format the drive by IOCTL_DISK_DELETE_DRIVE_LAYOUT,
IOCTL_DISK_CREATE_DISK, IOCTL_DISK_SET_DRIVE_LAYOUT_EX. But the point is I
still need the 3MB data on the drive even it is not backed by the file after
the VDS formatting. So my filter will protect the 3MB data by return
STATUS_ACCESS_DENIED when anyone wants to write to this area on the drive.
But this will make VDS (or NTFS and cache manager) not happy because I got
several “Windows - Delayed Write Failed” errors. That is why I hope I can
recreate the original file and make it link with my data on the drive. Other
than this I don’t know if there is other ways to keep my private data on the
drive.

And thank you everyone who can give me a hint.

Think about how the various file systems actually work. Volumes are
basically just a number of sectors numbered from zero to N - 1. The FSD
then adds its control information such as FATs, boot sectors, directories,
etc. as it needs. The FSD believes it owns all the sectors in that volume.
Microsoft has BitLocker that encrypts various drives. It uses a special
partition to contain the boot files since Bitlocker won’t be loaded until
those files, including the OS itself, are present. Maybe that is a better
solution than trying to hide something in the midst of sectors you don’t
control. Many OEMs put special partitions on the drives for recovery and
diagnostics.

“Michael Zhu” wrote in message
news:xxxxx@ntfsd…
Thanks everyone for your opinions. OK. Here is my condition why I want to do
this. I have a disk class upper filter. I want to make my filter compatible
with Microsoft DriveExtender on Windows Home Server. My disk filter will
create a 3MB file on each of the hard drives. And the file is stored
continuously on the hard drive, say starting from sector 0x230. Then when I
try to add a hard drive to the server storage pool VDS (Virtual Disk
Service) will try to format the drive by IOCTL_DISK_DELETE_DRIVE_LAYOUT,
IOCTL_DISK_CREATE_DISK, IOCTL_DISK_SET_DRIVE_LAYOUT_EX. But the point is I
still need the 3MB data on the drive even it is not backed by the file after
the VDS formatting. So my filter will protect the 3MB data by return
STATUS_ACCESS_DENIED when anyone wants to write to this area on the drive.
But this will make VDS (or NTFS and cache manager) not happy because I got
several “Windows - Delayed Write Failed” errors. That is why I hope I can
recreate the original file and make it link with my data on the drive. Other
than this I don’t know if there is other ways to keep my private data on the
drive.

And thank you everyone who can give me a hint.

Write anywhere, then try FSCTL_MOVE_FILE.


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

wrote in message news:xxxxx@ntfsd…
> Hi, is there any way that I can control on which physical sector of the hard drive that a file will be written to? My target is that I want to write a file to hard disk starting at physical sector 0x230 for example. Is this possible? How to implement this at file system filter levle or at disk class level? Thanks.
>

>IOCTL_DISK_SET_DRIVE_LAYOUT_EX. But the point is I still need the 3MB data on the drive even

it is not backed by the file after the VDS formatting.

Why? the user explicitly wanted to wipe off the whole disk.


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

Yes. Under my condition VDS tried to add a blank drive to the storage pool.
Actually my disk filter is for full disk encryption. That 3MB private area
on the drive contains some sensitive information used to do
encryption/decryption. That is why I have to keep it even VDS wants to
format the drive.

On Mon, Feb 22, 2010 at 2:07 AM, Maxim S. Shatskih
wrote:

> >IOCTL_DISK_SET_DRIVE_LAYOUT_EX. But the point is I still need the 3MB data
> on the drive even
> >it is not backed by the file after the VDS formatting.
>
> Why? the user explicitly wanted to wipe off the whole disk.
>
> –
> 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
> (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
>

Yes. This is what I am trying to implement right now. I hope I can move my
private 3MB data to somewhere out of the VDS created partition. Then it will
not impact the work of DriveExtender. Still have some problem right now to
make everyone (VDS, NTFS, cache manager) happy.

On Mon, Feb 22, 2010 at 12:35 AM, David Craig wrote:

> Think about how the various file systems actually work. Volumes are
> basically just a number of sectors numbered from zero to N - 1. The FSD
> then adds its control information such as FATs, boot sectors, directories,
> etc. as it needs. The FSD believes it owns all the sectors in that volume.
> Microsoft has BitLocker that encrypts various drives. It uses a special
> partition to contain the boot files since Bitlocker won’t be loaded until
> those files, including the OS itself, are present. Maybe that is a better
> solution than trying to hide something in the midst of sectors you don’t
> control. Many OEMs put special partitions on the drives for recovery and
> diagnostics.
>
> “Michael Zhu” wrote in message
> news:xxxxx@ntfsd…
>
> Thanks everyone for your opinions. OK. Here is my condition why I want to
> do this. I have a disk class upper filter. I want to make my filter
> compatible with Microsoft DriveExtender on Windows Home Server. My disk
> filter will create a 3MB file on each of the hard drives. And the file is
> stored continuously on the hard drive, say starting from sector 0x230. Then
> when I try to add a hard drive to the server storage pool VDS (Virtual Disk
> Service) will try to format the drive by IOCTL_DISK_DELETE_DRIVE_LAYOUT,
> IOCTL_DISK_CREATE_DISK, IOCTL_DISK_SET_DRIVE_LAYOUT_EX. But the point is I
> still need the 3MB data on the drive even it is not backed by the file after
> the VDS formatting. So my filter will protect the 3MB data by return
> STATUS_ACCESS_DENIED when anyone wants to write to this area on the drive.
> But this will make VDS (or NTFS and cache manager) not happy because I got
> several “Windows - Delayed Write Failed” errors. That is why I hope I can
> recreate the original file and make it link with my data on the drive. Other
> than this I don’t know if there is other ways to keep my private data on the
> drive.
>
> And thank you everyone who can give me a hint.
>
> —
> 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
>

Hi Max,

You mentioned FSCTL_MOVE_FILE. I also thought about this. Look at the
following MOVE_FILE_DATA structure.

typedef struct {
HANDLE FileHandle;
LARGE_INTEGER StartingVcn;
LARGE_INTEGER StartingLcn;
ULONG ClusterCount;
} MOVE_FILE_DATA, *PMOVE_FILE_DATA;
If I want to move the file, how to prepare the StartingVcn, StartingLcn and
ClusterCount? What is the real relations between these 3 parameters and the
absolute sector number on the drive? Thanks.

On Mon, Feb 22, 2010 at 2:04 AM, Maxim S. Shatskih
wrote:

> Write anywhere, then try FSCTL_MOVE_FILE.
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> wrote in message news:xxxxx@ntfsd…
> > Hi, is there any way that I can control on which physical sector of the
> hard drive that a file will be written to? My target is that I want to write
> a file to hard disk starting at physical sector 0x230 for example. Is this
> possible? How to implement this at file system filter levle or at disk class
> level? 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
>

>full disk encryption. That 3MB private area on the drive contains some sensitive information used to

do encryption/decryption.

Create a separate partition for this.


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

Thanks Max. That is what I am trying to do right now.

Can you give me some hint on the question about FSCTL_MOVE_FILE? I really
don’t know how to prepare those parameters if I want to move a file. Thanks.

On Mon, Feb 22, 2010 at 8:49 AM, Maxim S. Shatskih
wrote:

> >full disk encryption. That 3MB private area on the drive contains some
> sensitive information used to
> >do encryption/decryption.
>
> Create a separate partition for this.
>
> –
> 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
> (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
>

Sorry for stepping into somebody else thread.

> @Mark: Anytime I have needed to know the physical location of a file, I’ve created it and then queried the FS as to where the file is and how it is laid out on disk (to guarantee that it is contiguous).

Are you able to get the physical location (not the LCN) on the disk? If yes than would you please share how? Thanks.

See http://www.wd-3.com/archive/luserland.htm

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@yahoo.com” wrote in message
news:xxxxx@ntfsd:

> Sorry for stepping into somebody else thread.
>
>
> >> @Mark: Anytime I have needed to know the physical location of a file, I’ve created it and then queried the FS as to where the file is and how it is laid out on disk (to guarantee that it is contiguous).
>
>
> Are you able to get the physical location (not the LCN) on the disk? If yes than would you please share how? Thanks.

Information from ESET Smart Security, version of virus
signature database 4893 (20100224)


The message was checked by ESET Smart Security.

http://www.eset.com

Thanks Don. I was aware of this link (from one of your old posts on the list). But this has some limitations/assumptions like it works only for simple volume etc. I was curious if there was any other way to make this work on complex volumes too.

the method we use only works on simple volumes.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Wednesday, February 24, 2010 6:42 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Write File to specific physical disk sector

Thanks Don. I was aware of this link (from one of your old posts on the list). But this has some limitations/assumptions like it works only for simple volume etc. I was curious if there was any other way to make this work on complex volumes too.


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