Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C file stream fns (fwrite etc) - do the files move about on disk?

Posted on 2004-08-28
6
Medium Priority
?
305 Views
Last Modified: 2010-04-15
Hi all,

if i have a file on the disk and I open it up for writing, if I make some changes to the data, but don't alter the size of the file, does it stay in the same place on the disk? what if the file is fragmented across the disk, does this affect things at all?

thanks for any info.

=me=
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11923121
If you just write without appending, the file will stay in the same place (sector), but if you or anybody make a defrag the obviously file will be physically moved.
if you append some data, then is it high probable that this data will not be stored physically continuous.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11923139
That depends completely upon the implementation of the underlying filesystem.
0
 
LVL 2
ID: 11923467
cheers jaime, sorry should have mentioned I'm talking about FAT, FAT32 and NTFS (I'm assuming they'll be fairly similar in approach).

=me=
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 total points
ID: 11923564
talking about FAT/FAT32/NTFS with DOS/Windows I think my comment is still valid. File sectors are not reorganized until an explicit defrag option. Also, files with "system" attribute won't be moved even by defrag.
0
 
LVL 22

Expert Comment

by:grg99
ID: 11925228
Why exactly do you want to know if files move around?  The whole point of having a file system is you don't have to worry about where the file is physically stored.

As others have noted, in general files stay put.  But you can't depend on this, it's a undefined aspect of most file systems. There are plenty of things that could trigger a file move:

(1)  If you have any automatically scheduled "defrag" sessions, of course that can move files.

(2)  If the OS thinks that one of the file blocks may be going bad, it might mark that sector bad in the FAT and relocate the file.

(3)  If some program requests a bunch of contiguous space for a file, the OS may move files to accomplish this.

(4)  If the file is on a compressed volume, just changing the data in a block can make the data too large to fit in the old block, requiring the file system to reallocate the blocks.

(5)  There's no telling what various background "helper" and real-time virus checkers may be doing.

0
 
LVL 2
ID: 11935825
thanks for the input guys. The points go to jaime (thanks - it's as I figured, I just wanted to hear it from someone else!)

To clarify, what I'm doing is making a prog that wipes files from the disk so that there are no magnetic 'traces' left behind 9there are various commercial apps that do this). I had the idea after reading about 'Spin Rite' by Steve Gibson (great guy, check out his site, lots of interesting projects - www.grc.com ) and its use of 'magnetodynamics' ( www.grc.com/srphysics.htm ). Basicly different patterns of data on disks can be strong or weak because the magnetic pulses interfere with one another. My prog writes very 'strong' signals to the portion of the disk where an unwanted file exists so that there are no 'traces' left behind. Anyway, this rather requires me to be writing in the same place as the files! Hence my question. Hope that explains things!

=me=
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question