Evoluator

Helloo,

I have a fundemental question about file streams.

The question is the following:

Given a files is already on the HDD, and a file stream is used to write data on the stream.

Would the following code change the value of the file on the exact location in the HDD or would it change the value of the file but on a different location of the HDD

Code Block

Dim Stream As New FileStream("C:\Test.txt", ReadWrite)

Stream.Position = 5

Stream.Write(Buffer1,0,10)

Stream.Close()

So the question could be rephrased like this; Does the code above change the value of 5th-15th byte of the file "C:\Test.txt" on the exact physical position on the HDD with the value in the Buffer1 array

Thanks for your help




Re: Visual Basic Express Edition How do file streams work?

ReneeC

We began this conversation at one time. Please forget "physical" and think "logical" you care about where the data is in relation to other data in the file. That is the "logical" location, not the "physical" which often means the very same thing.

Consider disk defragmentation. Data is moved all around physically but maintains the same relationship to itself logically. Unless you are agent dealing with the structure of the disk, you don't care about physical, you care about logical.

The answer to your question is sort of yes. Sort of yes because these things are all zero based.

Take care Evoluator.






Re: Visual Basic Express Edition How do file streams work?

Evoluator

You see ReneeC, my problem is not about the logical part of it, I really don't care about the logical!
The only thing which matters to me is the Physical position of the data that I write on the HDD.

Well this is what made me think; If the amount of data is 512 bytes and the cluster size is say 1024, when the 512 bytes long data is written at the beggining of the cluster (Stream position 0) the data should have the exact physical addrss, other wise the logical managment of the file would be impossible!

What I like to know is the following; If I open a FileStream and write data in blocks half the size of the cluster would I be able to write the data on the exact physical position or would it be recordede somwhere else (I emphesize, I don't care about the logical part of it, Just physical)

Thanks ReneeC





Re: Visual Basic Express Edition How do file streams work?

ReneeC

"The only thing which matters to me is the Physical position of the data that I write on the HDD. "

You've never said why

Are you aware that if there is a badblock the block is remapped transparently Logiclly it's the same physically is not.

So why do you care about a physical location on a disk The whole idea of coding today is not to care.






Re: Visual Basic Express Edition How do file streams work?

Evoluator

Dear ReneeC

AS I have mentioned before, I am immensly interested in cryptograph.Hence therefore, I am writting a Extreamly secure file shredder which is exceptionally user friendly, while it allows advanced features to be implemented. Moreover, this application is going to be published under GNU license agreement.

All I need is a way to over write on the previous physical position of the file, so when the file is deleted, there is no physical trace from it. It is also impoortant to mention that the data which would be written on the previous physical position of the file should be determined using advanced wipe algorithms. But my problem in this respect is writtin data on the exactly the same position at which the file was previously wirtten.

If i could sort this problem out, I have sorted the file shredder part of the program! Then I could move on to the cryptography of files which the software automatically erases after encrypting, so that the files are not recoverable by any means.

This software is intended for use for large companies with sensitive data to protect.

This is the macro picture of the problem. Smile






Re: Visual Basic Express Edition How do file streams work?

ReneeC

Let me put it as supportively as I can. This is a BAD Design unless you map the file at run time and even then, remember there are dynamic disk defragmenters that follow right along behind you.

I believe this has the potential to make your life pretty painful. I would absolutely recommend against physical concerns of the disk. If you run this thing with dynamic decompression and the file is remapped you could also be deleting the contents of newly moved files now occupying the space of the old file. I urge you not to pursue this.






Re: Visual Basic Express Edition How do file streams work?

Evoluator

I argu other wise.

If the file is locked completely so that no other oporations could move the file, then I would condifently be able to over wirte data on the locations that is required.

But you are missing the point, I really don't want to learn about the difficulties lying in front of me, but rather ways of solving the problem.

I just need a code which would over write on the location of the parts of the hard drive where the file was recorded. So without deleting the file I like to write the data that is required on the file (I mean the physical location of the file) then when competed deleted the file.


Could this be possible at all





Re: Visual Basic Express Edition How do file streams work?

js06

I don't know much about this subject, but i was under the impression that when you delete a file it is never actually removed but rather marked as deleted so that it can be rewritten. Basically i thought that you can't really delete but rather rewrite. Not that you can't remove the information but that windows handles it this way unless you were to format. And i have never heard of anything that formats portions of a partition, only the whole thing.

I thought that you would have to either rewrite all the "free" space on the disk (which would include the areas of the disk with files marked as deleted) which seems ridiculous or locate the file and just simply rewrite the file with useless data.

Which seems like you should be able to do if these are company documents and not application files.

Like i said i don't know much about the subject i was just under the impression this is how it worked.

So if i am way off here then disregard.






Re: Visual Basic Express Edition How do file streams work?

ReneeC

Jeff,

We're a little ahead of you on this and we're in agreement. All along I've recommended reading the file and overwriting the data. That's clean. Repeat as many times as you like. This is a logical operation. No telling how many times a file is moved in derfragmentation. That data is still on the disk.

Evoluator, This is the solution I've recommended all along. How many times has a file been copied You don't know.

How many times has it been moved through drefragmentation. You don't know.

All you can do is to read the file and write over it. That's all you can do,. What you are asking about here is correct. There is no problem with it. But what you are doing here is logical and not physical.






Re: Visual Basic Express Edition How do file streams work?

jgalley

If one were to:

Dim myFS As FileStream = New FileStream("C:\foo.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None)

That would lock the file and allow you to rewrite the bytes to 0s then write again to 1s. It is my interpretation that the locked file and supporting disk clusters would not be moved by the OS underneath you.





Re: Visual Basic Express Edition How do file streams work?

ReneeC

Right. I have no issue with that at all. But all of that treatment is Logical I/O and not I/O to specific physical blocks.

This file could have been moved ten times. When moved, the data is copied. You can't guaratee that the data is not out there in unallocated space. That's all I've been trying to say. He's been saying "physical" which implies specific physical locations on the disk. What's true is that this writes to logical locations which may or may not relate to the original physical blocks the data was written to.






Re: Visual Basic Express Edition How do file streams work?

Evoluator

Well then I would have my answer if the OS would not move the file arround!





Re: Visual Basic Express Edition How do file streams work?

ReneeC

Ah but if cows could fly !!!!!

I've been trying to tell you this for months. This would be a great algorithm if you can get people to run Windows 3.1.

And then there's shadow copying that Vista does. But people like myself also run DiskKeeper which defragments files on the fly, hense moves files around. "Physical" went out in the seventies.






Re: Visual Basic Express Edition How do file streams work?

Evoluator

But ReeneC,

You know Windows is the most unstable oporating system. The problem is that it trys to do too many things and therefore it fails. My only problem is this: If a deframentor softwares could determine the physical location of the file why couldn't I

I like to keep full control when I program, I don'y want the OS doing it for me, this is the problem.






Re: Visual Basic Express Edition How do file streams work?

ReneeC

"You know Windows is the most unstable oporating system."

I don't know this at all. From my perspective, I would say, "Windows is the ONLY pc operating system." My othre question is, why do people perceive this OS as unstable. I've been running Vista for a year. I have never had a crash or a hang. That doesn't mean I don't have to reboot...but when I do, it's my doing.

"If a deframentor softwares could determine the physical location of the file why couldn't I "

There is a little bit of "chicken" and "egg" here. Defragmentation is not concernd with where your files are physically only that there is no to no defragmentation. But there are lots of reason that I keep explaining to you that we don't use phyical anymore.

One reason is because of bad block re-vectoring. When there is media deterioration blocks are revectored and data is recovered in the new block if possible AND the block is made to look logically contiguous with the other blocks BUT it is not physically contiguous at all.

The point is... we do not want software that has to track physical locations. We have been working to get away from that because that isn't what application programming is about.