Link to home
Start Free TrialLog in
Avatar of robowe
robowe

asked on

How to read FAT table in memory?

I am using Turbo C 3.0 and want to read the FAT table
(File Allocation Table) from disk sectors into memory.
The size of FAT16 is sizeof(int)*0xFFFF = 128k
The absread() works fine, but....

This does't work:
unsigned int fat_table[0xFFFE];
unsigned int huge fat_table[0xFFFE];

because compilers max datasize is 64k
If I use (integer) the size is two times 64k=128k

This does't work either:
unsigned int far *fat_ptr;
fat_ptr=(unsigned int far *) calloc(0xFFFE,2);
fat_ptr=(unsigned int far *) malloc(2L*65535L);

But this work!
unsigned int far *fat_ptr;
fat_ptr=(unsigned int far *) calloc(0x6FFE,2);

How to do YOU read fat_table into memory?
Do I have to do XMS or EMS calls?
ASKER CERTIFIED SOLUTION
Avatar of AVaulin
AVaulin
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cph
cph

Are you sure that you need to read all the FAT conentens at once?
'cos I did a program which dealt with the FAT and at the beginning I thought I got to have everything. The solution I found was to treat it by pack of 512 bytes.
If you want, my program is available at:
      http://www.mygale.org/03/cph

Its name is Safer...

Enjoy,
      CpH
Avatar of robowe

ASKER

Yes!, Option/Compiler/Code generation must be set either for:
Model=Compact (64k for code, 1MB for static data)
Model=Large (1MB code, 1MB for static data)
Model=Huge (1MB code, static data >64k)

But the problem was when i was using the debug option
in Turbo-C. Here I have to change the Option/Debugger
Program Heap Size = 300K Bytes

This should work:
unsigned int huge *fat_ptr;
fat_ptr=(unsigned int huge *) malloc( (long)0xFFFF*2L);

 huge (type modifier)
 ----------------------------
 Similar to far type modifier

 Syntax:  <type> huge <pointer-definition> ;

 The huge modifier is similar to the far
 modifier except for two additional features.

 * Its segment is normalized during pointer
   arithmetic so that pointer comparisons are
   accurate.

 * Huge pointers can be incremented without
   suffering from segment wraparound.
Avatar of robowe

ASKER

Yes!, Option/Compiler/Code generation must be set either for:
Model=Compact (64k for code, 1MB for static data)
Model=Large (1MB code, 1MB for static data)
Model=Huge (1MB code, static data >64k)

But the problem was when i was using the debug option
in Turbo-C. Here I have to change the Option/Debugger
Program Heap Size = 300K Bytes

This should work:
unsigned int huge *fat_ptr;
fat_ptr=(unsigned int huge *) malloc( (long)0xFFFF*2L);

 huge (type modifier)
 ----------------------------
 Similar to far type modifier

 Syntax:  <type> huge <pointer-definition> ;

 The huge modifier is similar to the far
 modifier except for two additional features.

 * Its segment is normalized during pointer
   arithmetic so that pointer comparisons are
   accurate.

 * Huge pointers can be incremented without
   suffering from segment wraparound.