We help IT Professionals succeed at work.

Opening big files (over 2-3 GB) and seeking after 2GB limit

pdraganov
pdraganov asked
on
Which function should I use to open big files (up to 4GB - the limit of FAT32)?
I use standard reset(INT21 AH=3D) and receive DOS ERROR 05 - access denied.
Comment
Watch Question

MathiasIT Specialist

Commented:
That's a good question, because you have to handle big files under DOS. Only Win9x and higher can handle those files correctly. You will get DOS error code 5 if you want to accesss a file if it is already open or you want to write to a read-only file. If you really want to use such files, use a TStream object instead. Streams are without any restrictions. I cannot say, but I think it is also under Pascal (I'm using a special Stream object, which I got from a friend).

Bye, TDS.

Author

Commented:
TStream has virtual methods only and TDOSStream uses the same INT 21 (AH=3D, AL=0 - Read only) AL=1 - Write only and AL=2 - Read/Write in its Init method) as in standerd reset procedure.
When I receive error 5 my file isn't open nor read-only. I read the help for this error but it seems that this error is returned by Windows (I use 98 SE) if the file is too big. Is there any function in Delphi to open such file?

Commented:
I don't think that you will be able to access these files properly from within the 16-bit DOS subsystem; one of your many problems will be that the Longint type does not exist as unsigned variable. If you are in the need of really big files, using a native windows app on a NTFS drive woulkd be the best choice (practically unlimited size).

Author

Commented:
Windows Media 8 encoding utility runs under MS-DOS prompt. Also Ulead Video Studio and Adobe Premiere and many more video editing programs can handle files up to 4GB. All they work under Win98 and FAT32. I have a program, HEdit, for editing files, but it doesn't open files bigger than 2GB. Virtual Dub has a Hex View, which I can use to view files bigger than 2GB. This means that there are 2 methods for file handling - old and new (extended). Is there any way to use the new method from Delphi, if it is impossible from DOS (INT 21)?

Commented:
Windows Media 8 etc. are Win32 console applications, e.g. normal Win32 programs but with console I/O instead of a GUI. They are not using DOS but are regular Win32 applications!

All 32-Bit versions of Delphi, that is, Delphi 2 and newer, can generate these console applications also by adding the compiler switch "{$APPTYPE CONSOLE}" at the very beginning of the DPR file. With these you can use the full Win32 API and therefore also read and write files exaclty the same as Win32 GUI applications.
MathiasIT Specialist

Commented:
pdraganov: you have mentioned the 4GB and 2GB barrier. You can see which program was compiled in Pascal -> HEDIT. As AvonWyss said there is no long variable in Pascal which can handle 4GB, only 2GB. Switch over to another language like c and the type "unsigned long" or "long long". You can also write your own file handling routines which use "real" as type. I don't know if it works but you have a bigger number and I think also a bigger filesize you can handle.
Correct me if i'm wrong.

Bye, TDS.

Commented:
COMP would be better than real, since it actually is a signed 64-bit integer and thus does not suffer the problems with unsignificant bits that Real, Single, Double, and Extended have. However, since it's not a native X86 integer, it has some quirks and restrictions; it is handled like a floathing point number. I would really encourage the use of another platform (both compiler and OS) for this.

Author

Commented:
I can use longint to handle up to 4GB if I discard overflow - negative numbers will be above 2GB.
If I write my own routines for file handling I have to write FAT32 handling like DISKEDIT from Norton Utilities, which works in pure DOS mode. I viewed RTL of Delphi 4 routines and found that they use CreateFileA routine from kernel32.dll. Borland Pascal 7.0 has Windows compiler but it uses only kernel, not kernel32. I will try Delphi 4.

Commented:
Yes, use Delphi 4 - and thus create Win32 applications. That's what I was suggesting from the very start anyways. ;-)
Commented:
Since you didn't come back, I guess that my comment are solving your question.

Author

Commented:
Sorry for my late response. I had problems with my installation CD for Delphi 4 (damaged) and I downloaded Delphi 6 Personal. Next experts-exchange site was broken.
Thank you for your advice, AvonWyss. I had only to change assign with assignfile, and close with closefile.

Author

Commented:
Sorry for my late response. I had problems with my installation CD for Delphi 4 (damaged) and I downloaded Delphi 6 Personal. Next experts-exchange site was broken.
Thank you for your advice, AvonWyss. I had only to change assign with assignfile, and close with closefile.

Author

Commented:
Sorry for my late response. I had problems with my installation CD for Delphi 4 (damaged) and I downloaded Delphi 6 Personal. Next experts-exchange site was broken.
Thank you for your advice, AvonWyss. I had only to change assign with assignfile, and close with closefile.

Author

Commented:
Sorry for my late response. I had problems with my installation CD for Delphi 4 (damaged) and I downloaded Delphi 6 Personal. Next experts-exchange site was broken.
Thank you for your advice, AvonWyss. I had only to change assign with assignfile, and close with closefile.

Author

Commented:
Sorry for my late response. I had problems with my installation CD for Delphi 4 (damaged) and I downloaded Delphi 6 Personal. Next experts-exchange site was broken.
Thank you for your advice, AvonWyss. I had only to change assign with assignfile, and close with closefile.

Author

Commented:
There is a problem accepting answers with Netscape 4.78. This is the reason for repeated messages. The last one I made with Internet Explorer.