1. FAT32 HELP!

Hi Folks,

I'm hoping someone can point me in the right direction for obtaining
extended free space on FAT32 drives while in DOS.  I tried using the
following function (INT21, #7303), which works great in a dos box, but not
in real mode.  Is this impossible, or what?

Any help would be greatly appreciated!

Best Regards,

Wes Hamilton, Technical Specialist
Western Mass Regional Library, Hatfield, MA

----------------------------------------------------------
(this is part of J. Craig Gilbert's diskutil.e, modified):
----------------------------------------------------------

global function disk_free_space(integer letter)
  atom bytes_per_sector, sectors_per_cluster, free_clusters, total_clusters
  atom free_space, total_space
  atom NameBuffer, ResultBuffer

  if not drive_exist(letter) then
     return -1
  end if

  NameBuffer = allocate_low(4)
  if not NameBuffer then
    return -1
  end if
  poke(NameBuffer,letter & ":\\" & 0)

  ResultBuffer = allocate_low(44)
  if not ResultBuffer then
    free_low(NameBuffer)
    return -1
  end if

  mregs = repeat(0,10)
  mregs[REG_AX] = #7303
  mregs[REG_CX] = 44
  mregs[REG_DS] = floor(NameBuffer/16)
  mregs[REG_DX] = remainder(NameBuffer,16)
  mregs[REG_ES] = floor(ResultBuffer/16)
  mregs[REG_DI] = remainder(ResultBuffer,16)

  mregs = dos_interrupt(#21,mregs)
  free_low(NameBuffer)
  if and_bits(mregs[REG_FLAGS],1) then   <-------THIS IS WHERE IT FAILS!
    free_low(ResultBuffer)
    return -1
  end if

  bytes_per_sector = peek4u(ResultBuffer + 8)
  sectors_per_cluster = peek4u(ResultBuffer + 4)
  free_clusters = peek4u(ResultBuffer + 12)
  total_clusters = peek4u(ResultBuffer + 16)
  free_space = bytes_per_sector * sectors_per_cluster * free_clusters
  total_space = bytes_per_sector * sectors_per_cluster * total_clusters

  free_low(ResultBuffer)

  return {free_space, total_space}
end function

new topic     » topic index » view message » categorize

2. Re: FAT32 HELP!

Wes
   If you look in the archive you will find a program by Jacques Deschenes
   for CDAUDIO control. In his program is an include file called RMCALL.E
   used for calling real mode from protected mode. Using this may allow
   you to use the interrupt.
Bernie

new topic     » goto parent     » topic index » view message » categorize

3. Re: FAT32 HELP!

Wes Hamilton wrote:
> I'm hoping someone can point me in the right direction for obtaining
> extended free space on FAT32 drives while in DOS.  I tried using the

Hi, Wes.
If it is only the free space you need, this DOS 2+ interrupt routine
should work most anywhere.  It is limited to reporting a maximum of
about 2G but then so is the Win95 interrupt.

Cheers,
-- Nick


--<WARNING: This code works on my computer but no guarantees>--

include machine.e

--disk_free() returns {free space, total space} where drive_num = 0 for
-- default drive, 1 for A:, 2 for B: 3 for C: and so on -- Nick Metcalfe
--Notes: don't use for CD-ROMS.  The reported total and free space are
-- limited to 2G - 32k even if there's more.
function disk_free(integer drive_num)
  sequence mregs
  mregs = repeat(0,10)
  mregs[REG_AX] = #3600
  mregs[REG_DX] = drive_num * 256
  mregs = dos_interrupt(#21,mregs)
  --check for invalid drive number
  if mregs[REG_AX] = #FFFF then
    return -1
  end if
  --return {free space, total space}
  return{mregs[REG_AX] * mregs[REG_BX] * mregs[REG_CX], mregs[REG_AX] *
mregs[REG_CX] * mregs[REG_DX]}
end function

printf(1, "%dk free of %dk total\n", disk_free(3) / 1024)

new topic     » goto parent     » topic index » view message » categorize

4. Re: FAT32 HELP!

Hi Nick

Thanks, I've had to resort to #36 as a backup; the whole point of using
#7303 was to get the extended free space as I am working with 25GB drives.
I know there must be a way, since the 'dir' command reports the correct
info...

Best Regards,
Wes

---------------------------
Nick Wrote:
>>Hi, Wes.
>>If it is only the free space you need, this DOS 2+ interrupt routine
>>should work most anywhere.  It is limited to reporting a maximum of
>>about 2G but then so is the Win95 interrupt.

new topic     » goto parent     » topic index » view message » categorize

5. Re: FAT32 HELP!

Wes Hamilton wrote:
> I know there must be a way, since the 'dir' command reports the correct
> info...

Hi Wes,
Is parsing the output of the dir command going too far?

Cheers,
-- Nick

new topic     » goto parent     » topic index » view message » categorize

6. Re: FAT32 HELP!

That was my next step, until I found that you can't redirect the standard
error in dos, so any drive with no files will happily present a FILE NOT
FOUND even though I'm redirecting output :)

Bill didn't make it easy...

-----Original Message-----
From: Euphoria Programming for MS-DOS
[mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Nick Metcalfe
Sent: Wednesday, August 18, 1999 1:15 PM
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Re: FAT32 HELP!


Wes Hamilton wrote:
> I know there must be a way, since the 'dir' command reports the correct
> info...

Hi Wes,
Is parsing the output of the dir command going too far?

Cheers,
-- Nick

new topic     » goto parent     » topic index » view message » categorize

7. Re: FAT32 HELP!

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

The latest:
>Hi Wes,
>Is parsing the output of the dir command going too far=3F
>
>Cheers,
>-- Nick

Then Wes:
>That was my next step, until I found that you can't redirect the
>standard
>error in dos, so any drive with no files will happily present a FILE
>NOT
>FOUND even though I'm redirecting output :)
>
>Bill didn't make it easy...
>

Hmm.  Looks like I need to update the diskutil file.  I've been doing
some sniffing around, and thus far come up with diddly/squat as far
as a *nice* routine is concerned.

However, the redirected dir parsing should work fine if you first
write a dummy file to ensure that you get no FILE NOT FOUND error.

I guess it would simplify parsing as well since you know, in that
case, what file name to run a dir for, so you'll only get one
return, with no dir dot and dir dot dot stuff in the way either.
A zero byte dummy file, deleted immediately afterward, should do
the trick.

If for some reason you can't write a dummy file (no write
permissions, whatever), then I dunno.  I'll keep looking.

I'm still puzzled about why the carry flag test bombed.  If the
version of DOS you're running supports FAT32 (as I assume it
does) then the durn thing should work.  Even if it did not
support FAT32, it should have returned CF clear/AL 00h, according
to Ralf Browns famous List.

Possibly relevant note: According to the aforementioned List
with regard to INT21/AX=3D7303h:
    "This function reportedly returns a maximum of 2GB
     free space even on an FAT32 partition larger than
     2GB under some versions of Win95, apparently by
     limiting the number of reported free clusters to
     no more than 64K."

So even if you get #7303 to work, you may still need the
dir parsing trick to get reliable info.

Back to looking,
Craig
------------------------------------------
Logic, like whiskey, loses its beneficial
effect when taken in too large quantities.
--Lord Dunsany

-------Phoenix-Boundary-07081998---

new topic     » goto parent     » topic index » view message » categorize

8. Re: FAT32 HELP!

Wes
    I think you will find that you can not access some functions
    from within the DPMI which Euphoria is running in.
    In my previous post, I mention an include file that can be used to go
    go around this restriction. It was used to call CDAUDIO functions
    that were not accessable inside the DPMI. Did You get a chance to
    take a look at it ?
Bernie

new topic     » goto parent     » topic index » view message » categorize

9. Re: FAT32 HELP!

Hi Bernie,

Yep I had a chance to check it out, some pretty interesting stuff!  Trouble
is, creating the actual asm code to feed rmcall.e is way beyond me at this
point, so I wasn't able to see if that was the problem or not.

It seems [REG_AX] is 57h after the call, which according to HelpPC indicates
a 'bad parameter'.  But as it works in a dos window, I think the problem is
DPMI related as you suggest, or #7303 is just unavailable in Win'9x dos.

Wes

-----Original Message-----
From: Euphoria Programming for MS-DOS
[mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Bernie Ryan
Sent: Wednesday, August 18, 1999 9:05 PM
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Re: FAT32 HELP!


Wes
    I think you will find that you can not access some functions
    from within the DPMI which Euphoria is running in.
    In my previous post, I mention an include file that can be used to go
    go around this restriction. It was used to call CDAUDIO functions
    that were not accessable inside the DPMI. Did You get a chance to
    take a look at it ?
Bernie

new topic     » goto parent     » topic index » view message » categorize

10. Re: FAT32 HELP!

On Wed, 18 Aug 1999 00:56:28 -0400, Wes Hamilton <whamilton at WMRLS.ORG>
wrote:

  WES your function works !


>Hi Folks,
>
>I'm hoping someone can point me in the right direction for obtaining
>extended free space on FAT32 drives while in DOS.  I tried using the
>following function (INT21, #7303), which works great in a dos box, but not
>in real mode.  Is this impossible, or what?

 JUST CHANGE THE PARAMETER "letter" TO A SEQUENCE AND THEN CALL IT

 WITH Disk_free_space("C")


>global function disk_free_space(integer letter) <<-------------<<

Bernie

new topic     » goto parent     » topic index » view message » categorize

11. Re: FAT32 HELP!

Bernie,

I made the correction you suggested, but I'm afraid that didn't do it.  If I
follow your directions explicitly, I get a type check on the call to
drive_exist, so I changed letter to letter[1].

Did you actually get it working in DOS?  Here's my code, so you can see if I
messed anything up :)
Wes

----------------------------------------------------------------------------
global function disk_free_space_ex(sequence letter)
  atom bytes_per_sector, sectors_per_cluster, free_clusters, total_clusters
  atom free_space, total_space
  atom NameBuffer, ResultBuffer

  if not drive_exist(letter[1]) then
     return -1
  end if

  NameBuffer = allocate_low(4)
  if not NameBuffer then
    return -1
  end if
  poke(NameBuffer,letter & ":\\" & 0)  <----also tried {letter[1], 0} and
                                            {letter[1] - 'A', 0} for kicks;
nope.
  ResultBuffer = allocate_low(44)
  if not ResultBuffer then
    free_low(NameBuffer)
    return -1
  end if

  mregs = repeat(0,10)
  mregs[REG_AX] = #7303
  mregs[REG_CX] = 44
  mregs[REG_DS] = floor(NameBuffer/16)
  mregs[REG_DX] = remainder(NameBuffer,16)
  mregs[REG_ES] = floor(ResultBuffer/16)
  mregs[REG_DI] = remainder(ResultBuffer,16)

  mregs = dos_interrupt(#21,mregs)
  free_low(NameBuffer)
  if and_bits(mregs[REG_FLAGS],1) then  <---works fine in W'9x, bombs in
W'98 DOS (REG_AX=57h)
    free_low(ResultBuffer)
    return -1
  end if

  bytes_per_sector = peek4u(ResultBuffer + 8)
  sectors_per_cluster = peek4u(ResultBuffer + 4)
  free_clusters = peek4u(ResultBuffer + 12)
  total_clusters = peek4u(ResultBuffer + 16)
  free_space = bytes_per_sector * sectors_per_cluster * free_clusters
  total_space = bytes_per_sector * sectors_per_cluster * total_clusters

  free_low(ResultBuffer)

  return {free_space, total_space}
end function
----------------------------------------------------------------------------
------

-----Original Message-----
From: Euphoria Programming for MS-DOS
[mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Bernie Ryan
Sent: Thursday, August 19, 1999 2:55 PM
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Re: FAT32 HELP!


On Wed, 18 Aug 1999 00:56:28 -0400, Wes Hamilton <whamilton at WMRLS.ORG>
wrote:

  WES your function works !


>Hi Folks,
>
>I'm hoping someone can point me in the right direction for obtaining
>extended free space on FAT32 drives while in DOS.  I tried using the
>following function (INT21, #7303), which works great in a dos box, but not
>in real mode.  Is this impossible, or what?

 JUST CHANGE THE PARAMETER "letter" TO A SEQUENCE AND THEN CALL IT

 WITH Disk_free_space("C")


>global function disk_free_space(integer letter) <<-------------<<

Bernie

new topic     » goto parent     » topic index » view message » categorize

12. Re: FAT32 HELP!

WES

  RUN THIS PROGRAM BY IT SELF

  DON'T ADD ANYTHING

  This works in WIN95 SR2 FAT32

Bernie
___________________________________________________________________________

include machine.e

sequence mregs
mregs = repeat(0, 10)

global function disk_free_space_ex(sequence letter)
  atom bytes_per_sector, sectors_per_cluster, free_clusters, total_clusters
  atom free_space, total_space
  atom NameBuffer, ResultBuffer

--  if not drive_exist(letter[1]) then -- commented out because I
--     return -1                       -- don't know what routine
--  end if                             -- your using here bernie

  NameBuffer = allocate_low(4)
  if not NameBuffer then
    return -1
  end if
  poke(NameBuffer,letter & ":\\" & 0)

  ResultBuffer = allocate_low(44)
  if not ResultBuffer then
    free_low(NameBuffer)
    return -1
  end if

  mregs = repeat(0,10)
  mregs[REG_AX] = #7303
  mregs[REG_CX] = 44
  mregs[REG_DS] = floor(NameBuffer/16)
  mregs[REG_DX] = remainder(NameBuffer,16)
  mregs[REG_ES] = floor(ResultBuffer/16)
  mregs[REG_DI] = remainder(ResultBuffer,16)

  mregs = dos_interrupt(#21,mregs)
  free_low(NameBuffer)
  if and_bits(mregs[REG_FLAGS],1) then
    free_low(ResultBuffer)
    return -1
  end if

  bytes_per_sector = peek4u(ResultBuffer + 8)
  sectors_per_cluster = peek4u(ResultBuffer + 4)
  free_clusters = peek4u(ResultBuffer + 12)
  total_clusters = peek4u(ResultBuffer + 16)
  free_space = bytes_per_sector * sectors_per_cluster * free_clusters
  total_space = bytes_per_sector * sectors_per_cluster * total_clusters

  free_low(ResultBuffer)

  return {free_space, total_space}
end function

? disk_free_space_ex("C")   -- calling this

----------------------------------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

13. Re: FAT32 HELP!

Bernie Wrote:
>>WES
>>  RUN THIS PROGRAM BY IT SELF
>>  DON'T ADD ANYTHING
>>  This works in WIN95 SR2 FAT32

That it does, as well as in WIN98.  Unfortunately, my original routine did
as well.  Perhaps I'm not being clear as to what I'm trying to do:

(1) in windows, run the following program (don't add anything)
    output is {xxxxxxx,xxxxxxx}

(2) restart your computer
    press F8 to boot in command mode
    run the following program (don't add anything)
    output is -1

If you get anything else, then I'm going to be really confused.  But in all
seriousness, I really appreciate all your help on this (and that of everyone
else who replied).  I'll be busy tonight working on the 'dir' parse kludge
in case I can't ever get a work-around on this...

Wes
_________________________________________________________________________

include machine.e

sequence mregs
mregs = repeat(0, 10)

global function disk_free_space_ex(sequence letter)
  atom bytes_per_sector, sectors_per_cluster, free_clusters, total_clusters
  atom free_space, total_space
  atom NameBuffer, ResultBuffer

--  if not drive_exist(letter[1]) then -- commented out because I
--     return -1                       -- don't know what routine
--  end if                             -- your using here bernie

  NameBuffer = allocate_low(4)
  if not NameBuffer then
    return -1
  end if
  poke(NameBuffer,letter & ":\\" & 0)

  ResultBuffer = allocate_low(44)
  if not ResultBuffer then
    free_low(NameBuffer)
    return -1
  end if

  mregs = repeat(0,10)
  mregs[REG_AX] = #7303
  mregs[REG_CX] = 44
  mregs[REG_DS] = floor(NameBuffer/16)
  mregs[REG_DX] = remainder(NameBuffer,16)
  mregs[REG_ES] = floor(ResultBuffer/16)
  mregs[REG_DI] = remainder(ResultBuffer,16)

  mregs = dos_interrupt(#21,mregs)
  free_low(NameBuffer)
  if and_bits(mregs[REG_FLAGS],1) then
    free_low(ResultBuffer)
    return -1
  end if

  bytes_per_sector = peek4u(ResultBuffer + 8)
  sectors_per_cluster = peek4u(ResultBuffer + 4)
  free_clusters = peek4u(ResultBuffer + 12)
  total_clusters = peek4u(ResultBuffer + 16)
  free_space = bytes_per_sector * sectors_per_cluster * free_clusters
  total_space = bytes_per_sector * sectors_per_cluster * total_clusters

  free_low(ResultBuffer)

  return {free_space, total_space}
end function

? disk_free_space_ex("C")   -- calling this

----------------------------------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

14. Re: FAT32 HELP!

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

Hi Wes Hamilton, you wrote on 8/19/99 6:24:15 PM:
><SNIPPED>...I'll be busy tonight working on the 'dir' parse
>kludge
>in case I can't ever get a work-around on this...
>
>Wes
><CODE SNIPPED>

Good luck with the 'dir' method.  I don't have a solution yet
either (though not for lack of hair pulling), but I do have a
little more info and some questions.

I got tired of finding zip for information on the 'net, so I
ran command.com through a dissassembler and found that there is
indeed a call to int #21/ax=3D#7303 inside there.  That seems
to indicate that you were correct in your choice of function,
but also that Bernie was correct about it needing a real mode
execution.

However, it may not require all the machine code Jacques used,
at least not for this one task.  I found some interrupts which
claim to be for exactly that purpose (simulating real mode ints),
and that brings me to my questions.

As part of the process, the interrupts require that ES:EDI
be loaded with the address of a call structure. So,

1) Am I correct in assuming that Euphoria uses EDI (by way
of regs[REG_DI]) automatically, since it's in protected mode=3F

2) I first set ES to be the segment of the call structure
address--floor(addressVar/16)--but the code bombed, so I
am wondering if the segment should have been the current code
or data segment.  That doesn't make sense to me, since the
address was allocated low, but I dunno . . .

Also, one of the interrupts I am trying is a CauseWay interrupt,
int #31/ax=3DFF01 I think.  So far all it has produced are some
impressively solid system lock-ups.  Is there something
inherently unstable about using a CauseWay interrupt from
within Euphoria or (more likely) am I just mangling the
application somehow=3F

Any help would be appreciated since, in addition to helping
Wes, I've got to figure this out at some point in order to
update diskutil.e.

I realize that it would help if I could offer some source code.
Unfortunately, I left it at work; this is because I am an idiot.
I'm in a twelve step program for that, but I keep forgetting
to go to the meetings, getting lost on the way, etc . . .

If this proves to be insufficient info for anybody to offer any
help with, I'll post some code so maybe somebody can spot
what I'm screwing up.  By the way, Wes, what I'm trying to
do is set up a routine for calling real mode interrupts so
that in your code (or anyone's) you can do this:

          regs =3D dosInterruptReal32(#21,regs)
or
          regs =3D dosInterruptReal16(#21,regs)

and go about your business normally.

I'll be gone for a few days, so I'll be delayed responding to
any posts directed toward me; talk to you guys later.
(first real vacation in six years, WAHOOOOOOO!)

Craig
-------------------------------------------------
I understand mathematics, I just can't do proofs.
--Anonymous

-------Phoenix-Boundary-07081998---

new topic     » goto parent     » topic index » view message » categorize

15. Re: FAT32 HELP!

Wes:
   It doesn't work using DOS COMMAND PROMPT MODE,
   Yet it works in SAFE MODE DOS COMMAND PROMPT.
   I think the causeway extender may operate different depending if
   virtual drivers are loaded. The reason I say this is that DOS can still
   use the Directory command.
Bernie

new topic     » goto parent     » topic index » view message » categorize

16. Re: FAT32 HELP!

Hey Bernie,
If you are trying to get the free space for a given drive below is what MSDN
says about the subject.

*************  MSDN snippet  ****************************

Int 21h Function 7303h Get_ExtFreeSpace (FAT32)
[Windows 95 only.]

Returns the total disk space and the free disk space.

mov  dx, seg Buffer
mov  es, dx
mov  di, offset Buffer    ;See below
mov  es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel
mov  cx, BufferSize       ;See below

mov  dx, seg DriveName    ;See below
mov  ds, dx
mov  dx, offset DriveName ;See below

mov  ax, 7303h            ;Get_ExtFreeSpace
int  21h

jc  error_handler         ;carry set means error

Parameters
Buffer
The address of the buffer at ES:DI that will receive the disk space
information.
BufferSize
The size (in bytes) of the buffer.
DriveName
The address of a null terminated string at DS:DX. In real mode, this must be
in standard form ("C:\"). In Windows, either the standard name or a
universal naming convention form ("\\Server\Share") is acceptable.
Return Values
Clears the carry flag and returns the total disk space and the free disk
space of the specified drive, in the form of an ExtGetDskFreSpcStruc (FAT32)
structure, to a buffer at ES:DI. It is recommended to initialize the buffer
to the level value the application expects to receive.

Remarks
When calling this function with DeviceIoControl, the dwloControlCode
parameter must be set to VWIN32_DIOC_DOS_IOCTL (defined as 6 in VWIN32.H).
For more information on this, see Using VWIN32 to Carry Out MS-DOS
Functions.

*************  End MSDN snippet  ****************************

Thanks,
JKinsey

-----Original Message-----
From: Euphoria Programming for MS-DOS
[mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Bernie Ryan
Sent: Friday, August 20, 1999 9:46 AM
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Re: FAT32 HELP!


Wes:
   It doesn't work using DOS COMMAND PROMPT MODE,
   Yet it works in SAFE MODE DOS COMMAND PROMPT.
   I think the causeway extender may operate different depending if
   virtual drivers are loaded. The reason I say this is that DOS can still
   use the Directory command.
Bernie

new topic     » goto parent     » topic index » view message » categorize

17. Re: FAT32 HELP!

Thanks John
 We are aware of how to use that function. If you will read
 previous messages you will find that the problem is that if you are using
 Euphoria to call this function and you reboot win95 into the DOS PROMPT
 MODE ( using F8 ) Then Euphoria will not be able to use this function.
Bernie

new topic     » goto parent     » topic index » view message » categorize

18. Re: FAT32 HELP!

Sorry to beat a dead horse about this, but I was wondering if anyone has
made any further progress or has additional input...

The following code is an attempt to call INT21h, 7303h in real mode using
JD's Rmcall.e (part of CDAUDIO in the archive) as Bernie suggested.
Unfortunately, I found that I get the same results as my previous code using
Euphoria's dos_interrupt (it works in protected mode windows, but fails when
booted to command mode).  ALSO NOTE: it seems this code works but causes
windows to crash on shutdown with a message about a protection violation.

So my conclusion would be that INT21h, 7303h is just not available in real
mode, yet John Kinsey sent in info from MSDN (reposted below) that would
indicate it does!  Also in the MSDN doc is the following instruction (I
assume to initialize the result buffer, as is recommended in the same
section):

mov  es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel

Could this be the problem?  And if so, how would one go about reproducing
this statement for my purposes?  I would imagine if someone out there has a
copy of MASM and can get this call to work, the assembled code could be
pasted into my routine and I would be very happy :)

Thanks,
Wes

include machine.e
include Rmcall.e   --from JD's cdaudio to execute code in real mode

global function disk_free_space_ex(integer letter)
  atom bytes_per_sector, sectors_per_cluster, free_clusters, total_clusters
  atom free_space, total_space
  atom NameBuffer, ResultBuffer

  atom CodePtr
  sequence Code
  x_regs xr

  --if not drive_exist(letter) then
  --  return -1
  --end if

  NameBuffer = allocate_low(4)
  if not NameBuffer then
    return -1
  end if

  ResultBuffer = allocate_low(44)
  if not ResultBuffer then
    free_low(NameBuffer)
    return -1
  end if

  Code = {-- code to execute in real mode.
          #CD,#21,        -- int 21
          #CB,            -- retf
          0               -- for a total of 4 bytes
         }

  CodePtr = allocate_low(length(Code))
  if not CodePtr then
    free_low(NameBuffer)
    free_low(ResultBuffer)
    return -1
  end if

  poke(CodePtr,Code)
  poke(NameBuffer, letter & ":\\" & 0)

  xr = repeat(0,NBR_REGS)
    xr[iR_EAX] = #7303
    xr[iR_ECX] = 44
    xr[iR_DS] = floor(NameBuffer/16)
    xr[iR_EDX] = remainder(NameBuffer,16)
    xr[iR_ES] = floor(ResultBuffer/16)
    xr[iR_EDI] = remainder(ResultBuffer,16)
  xr = CallRealMode(CodePtr,xr,0)
  free_low(CodePtr)
  free_low(NameBuffer)

  if and_bits(xr[iFLAGS],1) then
    free_low(ResultBuffer)
    return -1
  end if

  bytes_per_sector = peek4u(ResultBuffer + 8)
  sectors_per_cluster = peek4u(ResultBuffer + 4)
  free_clusters = peek4u(ResultBuffer + 12)
  total_clusters = peek4u(ResultBuffer + 16)
  free_space = bytes_per_sector * sectors_per_cluster * free_clusters
  total_space = bytes_per_sector * sectors_per_cluster * total_clusters

  free_low(ResultBuffer)

  return {free_space, total_space}
end function

? disk_free_space_ex('C')
------------------------------------------------------------------------


John Kinsey Wrote on August 20, 1999:
---->
Hey Bernie,
If you are trying to get the free space for a given drive below is what MSDN
says about the subject.

*************  MSDN snippet  ****************************

Int 21h Function 7303h Get_ExtFreeSpace (FAT32)
[Windows 95 only.]

Returns the total disk space and the free disk space.

mov  dx, seg Buffer
mov  es, dx
mov  di, offset Buffer    ;See below
mov  es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel
mov  cx, BufferSize       ;See below

mov  dx, seg DriveName    ;See below
mov  ds, dx
mov  dx, offset DriveName ;See below

mov  ax, 7303h            ;Get_ExtFreeSpace
int  21h

jc  error_handler         ;carry set means error

Parameters
Buffer
The address of the buffer at ES:DI that will receive the disk space
information.
BufferSize
The size (in bytes) of the buffer.
DriveName
The address of a null terminated string at DS:DX. In real mode, this must be
in standard form ("C:\"). In Windows, either the standard name or a
universal naming convention form ("\\Server\Share") is acceptable.
Return Values
Clears the carry flag and returns the total disk space and the free disk
space of the specified drive, in the form of an ExtGetDskFreSpcStruc (FAT32)
structure, to a buffer at ES:DI. It is recommended to initialize the buffer
to the level value the application expects to receive.

Remarks
When calling this function with DeviceIoControl, the dwloControlCode
parameter must be set to VWIN32_DIOC_DOS_IOCTL (defined as 6 in VWIN32.H).
For more information on this, see Using VWIN32 to Carry Out MS-DOS
Functions.

*************  End MSDN snippet  ****************************

Thanks,
JKinsey
<-----

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu