Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-09

cluster size info for win9x/go32

9 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lee, John

Anyone know where one can get diskcluster size info? Can't seem to find it in win32 library... Need the info for win9x and dos? And also how to access this info via an fpc program? TIA for help.

Unknown author
Anyone know where one can get diskcluster size info? Can't seem to find

it

in win32 library... Need the info for win9x and dos? And also how to

access

this info via an fpc program? TIA for help.

Don't know if this procedure will function under win9x, but with DOS it used to work fine.

Jim

(See attached file: DriveInfo.Pas)

Ralf Quint
you wrote 12 lines
> Anyone know where one can get diskcluster size info? Can't seem to find it > in win32 library... Need the info for win9x and dos? And also how to access > this info via an fpc program? TIA for help. Don't know if this procedure will function under win9x, but with DOS it used to work fine. Jim (See attached file: DriveInfo.Pas)

Well, the attached program will only work on drives/partitions up to 2GB in size. If the drive/partition is bigger (FAT32 partition), it will always return the maximum of 2GB-32K. For FAT32, use INT 21h/AX=7303h instead.

Ralf

Marco van de Voort
to Ralf Quint
From my Edos. Uses Dos and Go32 probably :
FUNCTION ClusterSize(Drv:LONGINT):LONGINT;
TYPE FreeRecord=RECORD
                  SizRec        : WORD; { Size of this record}
                  StrucVersion  : WORD; { Structure version}
                  SecPerClus    : CARDINAL;
                  BytePerSec    : CARDINAL;
                  AvailClus     : CARDINAL;
                  TotClus       : CARDINAL;
                  PhysSectAvail : CARDINAL;
                  PhysSectTot   : CARDINAL;
                  AllocAvail    : CARDINAL;
                  AllocTot      : CARDINAL;
                  Res1,
                  Res2          : CARDINAL;
                 END;
CONST SecBuf=20;
VAR R : Registers;
    O : LONGINT;
    S : ARRAY[0..5] OF CHAR;
    S2 : String;
    ClusRec : FreeRecord;
BEGIN
 IF LfnSupport THEN
  BEGIN
    IF Drv=0 THEN
     BEGIN
      GetDir(Drv,S2);
      Drv:=ORD(S2[1])-64;
     END;
    S:='C:\'#0;
    S[0]:=CHR(Drv+64);
    CopyToDos(S,8);
    R.AX:=$7303;
    R.CX:=SIZEOF(FreeRecord);
    R.esi:=tb_offset;
    R.ds:=tb_segment;
    R.edi:=tb_offset+SecBuf;
    R.es:=tb_segment;
    MsDos(R);
    seg_move(dosmemselector,transfer_buffer+SecBuf,get_ds,longint(@ClusRec),SIZEOF(FreeRecord));
    O:=ClusRec.BytePerSec*ClusRec.SecPerClus;
    if (R.flags and carryflag)  0 then
     doserror:=R.ax
   else
     doserror:=0;
  END
  ELSE
   BEGIN
    R.AX:=$3600;
    R.DX:=Drv;
    MsDos(R);
    IF R.AX=$FFFF THEN
     O:=0
    ELSE
     O:=R.AX
   END;
  IF IsCdRom(Drv) THEN         {Exception, cdroms are always 2048
anyway}
   O:=2048;
  ClusterSize:=O;
END;

Marco van de Voort ( or )

Lee, John

Marco's version works fine for fat32 and fat16...

Only 2 issues/problems:
1)it needs go32 (uses it to copy data) so can't be used in a fpc win32 program. Looks as if there ought to be a variant using only the dos unit, to extend it for fat32, using INT 21h/AX=7303h... Apparently this works for fat16 too ... if someone knows the algorithm, I'll try it...

2) doesn't pick up correct cluster size of a networked drive under win9x. This may be a windoze/win9x problem tho... Anyone know whether there is a fix for this?

FUNCTION ClusterSize(Drv:LONGINT):LONGINT;

...snip...

Kuba Ober

Guys, please look at http://msdn.microsoft.com/library/default.asp first.

For GO32 you need to refer to underlying OS anyway, and this is always DOS, so call basic int21h functions.
But, it GO32 works in a DOS box under win95osr2 or later, or if it is a pure win32 app call fat32 api functions, for example

Int 21h Function 440Dh Minor Code 60h (FAT32)
Returns the device parameters for the specified block device. mov bx, Drive ;See below
mov ch, DeviceCat ;See below
mov cl, 60h ;Get device parameters
mov dx, seg DriveDP ;See below
mov ds, dx
mov dx, offset DriveDP ;ds:dx points to a device parameters structure mov ax, 440Dh ;IOCTL for block device
int 21h

jc error_handler ;carry set means error

It returns EA_DEVICEPARAMETERS structure, which contains FAT32 version of BPB structure, which contains A_BF_BPB_BytesPerSector DW ? ;and A_BF_BPB_SectorsPerCluster DB ?
Multiplying those two gives bytes-per-cluster info. Please look at
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/fat32_7jxs.htm for details.

Cheerz,
Kuba

Ralf Quint
John Lee wrote 11 lines
Marco's version works fine for fat32 and fat16... Only 2 issues/problems: 1)it needs go32 (uses it to copy data) so can't be used in a fpc win32 program. Looks as if there ought to be a variant using only the dos unit, to extend it for fat32, using INT 21h/AX=7303h... Apparently this works for fat16 too ... if someone knows the algorithm, I'll try it... 2) doesn't pick up correct cluster size of a networked drive under win9x. This may be a windoze/win9x problem tho... Anyone know whether there is a fix for this?

For networked drives (or drives using a similar filesystem approach like CD-ROMs), there is no cluster size information, as the originating file system just might not have such structures. So the redirector doesn't provide this information.

Ralf

Jonas Maebe
1)it needs go32 (uses it to copy data) so can't be used in a fpc win32 program. Looks as if there ought to be a variant using only the dos unit, to extend it for fat32, using INT 21h/AX=7303h... Apparently this works for fat16 too ... if someone knows the algorithm, I'll try it...

You simply need two completely different procedures to do this under Dos and Win32. Under Win32, you don't communicate anymore with the OS using interrupts (so calling int 21h will probably just crash a win32 program). You already have the Dos version, the windows versio probably needs some function from the windows unit to get the information about a drive. Which one you need can probably be found on msdn.microsoft.com

Jonas

Kuba Ober
to Jonas Maebe
You simply need two completely different procedures to do this under Dos and Win32. Under Win32, you don't communicate anymore with the OS using interrupts (so calling int 21h will probably just crash a win32 program).

Wrong ;-). There are some INT21 procedures which are accessible both in real and protected mode. FAT32 functions are example of these. Kuba