Linked file was : Writning to a file 
Author Message
 Linked file was : Writning to a file

Hi there,

I was thinking about the problem, when I got an idea of how to solve it
maybe. But unfortunately I don't have the knowledge to do it all by myself.
My idea is something like this:

A file is in fact nothing more than a linked list of sectors. If I'm able to
read a distinct sector then I can also write my data to an emtpy sector and
modify the "pointers" of an existing sector to the new sector. The new
sector will point then to the rest of the file. This way I can add data to a
file without handling all the data from the list. Only three sectors have to
be modified. This is especially usefull when operating with large files. The
bad thing is that you will get defragmented files, but this will not be a
big problem as I can write a small app that defragments it or use an
existing defrag app.

I know that I can use int 25 and int 26, but what are the details?? Or are
there more alternatives which I don't know of?

Please help, Darius Blaszijk


Quote:

> >Thanks for the rapid and good reply I got on my previous question. Now
I'm
> >stuck again on something different.
> >I have an untyped file where I want to add data to at the end and even
> >better anywhere in the middle. How do I do that. Obviously append doesn't
> >work, as it only applies to text files. Should I then use the blockread
and
> >blockwrite functions to copy the file and then slip in the data I want? I
> >hope that there are more convenient and quicker methods.

> If you want to add to the end you can use FileSize to get the
> size and then seek and write the records.  If you want to add in
> the middle then what you describe is probably best.



Sat, 06 Sep 2003 08:16:57 GMT  
 Linked file was : Writning to a file
No, a file is not a "linked list of sectors".  In Pascal, a file is a stream of
characters, with an "EOF" flag at the end.  It is implemented (underline that!)
in some operating systems as a linked list of sectors, but that is outside the
scope of the language.

Bob Schor
Pascal Enthusiast

Quote:

> Hi there,

> I was thinking about the problem, when I got an idea of how to solve it
> maybe. But unfortunately I don't have the knowledge to do it all by myself.
> My idea is something like this:

> A file is in fact nothing more than a linked list of sectors. If I'm able to
> read a distinct sector then I can also write my data to an emtpy sector and
> modify the "pointers" of an existing sector to the new sector. The new
> sector will point then to the rest of the file. This way I can add data to a
> file without handling all the data from the list. Only three sectors have to
> be modified. This is especially usefull when operating with large files. The
> bad thing is that you will get defragmented files, but this will not be a
> big problem as I can write a small app that defragments it or use an
> existing defrag app.

> I know that I can use int 25 and int 26, but what are the details?? Or are
> there more alternatives which I don't know of?

> Please help, Darius Blaszijk




> > >Thanks for the rapid and good reply I got on my previous question. Now
> I'm
> > >stuck again on something different.
> > >I have an untyped file where I want to add data to at the end and even
> > >better anywhere in the middle. How do I do that. Obviously append doesn't
> > >work, as it only applies to text files. Should I then use the blockread
> and
> > >blockwrite functions to copy the file and then slip in the data I want? I
> > >hope that there are more convenient and quicker methods.

> > If you want to add to the end you can use FileSize to get the
> > size and then seek and write the records.  If you want to add in
> > the middle then what you describe is probably best.



Sun, 07 Sep 2003 06:25:30 GMT  
 Linked file was : Writning to a file
hi darius,



Quote:
> Hi there,

> I was thinking about the problem, when I got an idea of how to solve
it
> maybe. But unfortunately I don't have the knowledge to do it all by
myself.
> My idea is something like this:

> A file is in fact nothing more than a linked list of sectors. If I'm
able to
> read a distinct sector then I can also write my data to an emtpy
sector and
> modify the "pointers" of an existing sector to the new sector. The new
> sector will point then to the rest of the file. This way I can add
data to a
> file without handling all the data from the list. Only three sectors
have to
> be modified. This is especially usefull when operating with large
files. The
> bad thing is that you will get defragmented files, but this will not
be a
> big problem as I can write a small app that defragments it or use an
> existing defrag app.

> I know that I can use int 25 and int 26, but what are the details?? Or
are
> there more alternatives which I don't know of?

> Please help, Darius Blaszijk

[...]

it's not as easy - or better you never should try to do so. this should
be done by your os. many system won't even allow a normal application to
access the disk directly. think of the fats and eg. a multitasking os
accessing changing files, while you are handling the fat .... your disk
will be corrupted.

here is my idea .. this should work with most os.

create a big file to store your data in. it is then the job of your
application to
organize the structure of the file.

within your file you can go to any location (fileseek) and read and
write data whereever you want to.

if your file is getting to small you can add new space by writing at end
of file.

see fileseek, filepos and filesize for positioning,
and blockread / blockwrite for transferring data.

good luck!

greetings
jochen



Sun, 07 Sep 2003 05:23:33 GMT  
 Linked file was : Writning to a file


20 Mar 2001 17:25:30 :-

Quote:
>No, a file is not a "linked list of sectors".  In Pascal, a file is a stream of
>characters, with an "EOF" flag at the end.  It is implemented (underline that!)
>in some operating systems as a linked list of sectors, but that is outside the
>scope of the language.

>Bob Schor
>Pascal Enthusiast

This here is a Borland Pascal newsgroup, though you may be reading in
c.l.p.misc.

Borland's Pascals are DOS-based products (Borland's Mac Pascal must be
pretty dead now, and would better use c.l.p.mac); looking back in
thread, the original interest does appear to be BP/TP.

(Follow-up therefore set; the originator ought not to have cross-
posted.)

DOS uses FAT-12 and FAT-16, in which patching into a file by editing the
FAT with Int25/26 is certainly possible.  Of course, it's extremely
dangerous, both because of the possibility of error and that of other
processes also accessing the file system.  The method should only be
considered by those with sufficient proven skill and wisdom to realise
that it really ought not to be done that way.

The best solution is probably to increase the amount of internal
structure in the file, so that the logical order of data is decoupled
from the physical order; then the new data can be added in the first
available hole or at the end, and when data is removed the gap does not
have to be closed up.

There could be a gain of efficiency, however, if the file is structured
so that pseudo-records are a multiple of the sector size, 512 bytes, or
maybe the cluster size.

--

 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.



Sun, 07 Sep 2003 21:50:46 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Linked file was : Writning to a file

2. Losing File Handles - But I am not using Files

3. Dynamic link between Pascal .so file and executable file sourced in gcc

4. BGI file linked in EXE file?

5. help for including units in main file (i am using BP7)

6. I am missing something and I can't run my PAS files

7. Executing DOS batch files (or any other program files) and deleting files with PASCAL

8. Writting and Reading a linked list from/to a file

9. Read a file to link list in pascal

10. c++ dos v3 linking multiple files

11. Linking an object file/Linken einer Objektdatei

12. Link 2 exe and/or com files

 

 
Powered by phpBB® Forum Software