473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File I/o questions

Neo
I am writing an encryption program. I am using fopen , fgetc and fput c to
open, read a block of data and write a block of encrypted.

Thus all the blocks are overwritten with the encrypted.
I use win 2000 / Xp and file sys FAT and NTFS.
My program will add a 512 byte header to the beginning.. so the end file
will be (original size + 512) rounded to the nearest 128 bit multiple

My question are :

*Is it guaranteed that the functions mentioned above will over write the
same sectors in the hard disk, and not wrie to a new block and change the
allocaton table?
*Also are there any other functions i can use to perform direct changes to
blocks of a file diretly onto the hard disk.?

*Are there any tools on the net that will tell me the exact ?
Jan 29 '06 #1
4 1970
Neo schrieb:
I am writing an encryption program. I am using fopen , fgetc and fput c to
open, read a block of data and write a block of encrypted.

Thus all the blocks are overwritten with the encrypted.
I use win 2000 / Xp and file sys FAT and NTFS.
My program will add a 512 byte header to the beginning.. so the end file
will be (original size + 512) rounded to the nearest 128 bit multiple

My question are :

*Is it guaranteed that the functions mentioned above will over write the
same sectors in the hard disk, and not wrie to a new block and change the
allocaton table?
No. C++ does not know anything about sectors or hard disks, so C++ does
not guarantee something like that. You should ask in a Newsgroup about
your OS (Windows).

(And I think it is not guaranteed by Windows either.)

*Also are there any other functions i can use to perform direct changes to
blocks of a file diretly onto the hard disk.?


There may be platform specific functions, known to the people in the
right newsgroups.

--
Thomas
Jan 29 '06 #2
"Neo" writes:
I am writing an encryption program. I am using fopen , fgetc and fput c to
open, read a block of data and write a block of encrypted.

Thus all the blocks are overwritten with the encrypted.
I use win 2000 / Xp and file sys FAT and NTFS.
My program will add a 512 byte header to the beginning.. so the end file
will be (original size + 512) rounded to the nearest 128 bit multiple

My question are :

*Is it guaranteed that the functions mentioned above will over write the
same sectors in the hard disk, and not wrie to a new block and change the
allocaton table?
*Also are there any other functions i can use to perform direct changes to
blocks of a file diretly onto the hard disk.?

*Are there any tools on the net that will tell me the exact ?


You alluded to what is basically C code in a C++ group. I would open the
file for input and output in binary mode and use istream::read() to capture
the data. Immediately write all zeros to the entire file using
ostream::write().. Then compute your results and store them in the same
file. If the system crashes while your program is running, there is still
no problem. This is not a place to save a few milliseconds. I can't
foresee any problems in the world of actual computers as opposed to some
gedanken experiment.

I assume you are using C code for I/O because it is easier to comprehend.
Bite the bullet and learn iostreams, it's worth the effort.
Jan 29 '06 #3
Neo
"osmium" <r1********@comcast.net> wrote in
news:44***********@individual.net:
"Neo" writes:
I am writing an encryption program. I am using fopen , fgetc and fput
I assume you are using C code for I/O because it is easier to
comprehend. Bite the bullet and learn iostreams, it's worth the
effort.


Oh i know them alright :)... my basic question is will the same sectors in
the HD be used.. becoz i dont wnt the encrypted stuff elsewhere on
unallocated space.. i want the same sectors to be used for the encrypted
file.
Jan 29 '06 #4
Neo wrote:
I am writing an encryption program. I am using fopen , fgetc and fput c to
open, read a block of data and write a block of encrypted.

Thus all the blocks are overwritten with the encrypted.
What if there is power shortage when you are in the middle
of doing that? Your file is screwed.
I use win 2000 / Xp and file sys FAT and NTFS.
My program will add a 512 byte header to the beginning.. so the end file
will be (original size + 512) rounded to the nearest 128 bit multiple

My question are :

*Is it guaranteed that the functions mentioned above will over write the
same sectors in the hard disk, and not wrie to a new block and change the
allocaton table?
The answer is easily 'no'. Imagine an original file that has
a size of exactly n*sector_size. If you extend it by 512 bytes
it will occupy at least (n+1) sectors. Therefore you have a
guarantee that a new block will be written and hence the sectors
will not be the same.
*Also are there any other functions i can use to perform direct changes to
blocks of a file diretly onto the hard disk.?
Possibly, but not in C++ as the standard defines it.
*Are there any tools on the net that will tell me the exact ?


Possibly, but this is beyond the scope of this newsgroup.

- J.
Jan 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
5
by: Jim Holder | last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The tcpdump make couldn't find ioccom.h and sockio.h. When a header file is missing, how do you find it? Thanks.
29
by: Tola | last post by:
In my case of study, my teacher gave me a project, after I analysed the problem I found that I had to used open the file on the other machine? Please help? Thank you in advance. Tola CHROUK
4
by: Grant Austin | last post by:
Hello, This might be a tad off topic. The c-programming groups I found appear to be unused... The problem is simple... I need to create a listing file from an assembler source file. The...
1
by: Tomas Vera | last post by:
Hello All, I have some questions about how the file upload process works in a web app. Background: The user is filling out a tech support request form. On the form is a file upload control so...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
1
by: mb | last post by:
Hi, I picked up this JavaScript code (quiz code) at: http://javascript.internet.com/miscellaneous/multiple-choice-quiz.html and modified it (and may have deleted some line I shouldn't have) so...
2
by: TPK | last post by:
I have an HTML document with Javascript where I have a portion of the page contents, a series of questions, being pulled from a XML file. When the page dynamically builds all the questions and...
2
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
6
by: portCo | last post by:
Hello there, I am creating a vb application which is some like like a questionare. Application read a text file which contains many questions and display one question and the input is needed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.