Solved

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

Posted on 2004-08-28
6
286 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 150 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

777 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