Announcement

Collapse
No announcement yet.

how to get the volume size from a driveletter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to get the volume size from a driveletter

    Hi everybody,

    I'm trying to create some code that will give me the size of the volume if i feed it the driveletter of that volume. I already use the interrupt 21 function 360 approach elsewhere in my code (a bit like the "diskfree" approach in the pb35.inc stuff, in dosunit.bas i believe) to get the free space on a volume, i was hoping for a similar sort of thing but can't find anything.
    As a sidenote, the int 21 function 360 approach doesn't return values higher than 2Gb as free space (the old dos fat16 limit), which is not a problem for the code that i use it for, but that would be a problem for the new bit of code i need: the volume size should be returned correctly for fat16 and fat32 drives of any size.
    Any suggestions would be much appreciated, thanks.
    Regards,
    Tom
    [URL=http://www.DiyDataRecovery.nl]

  • #2
    I think I'd SHELL to a 32-bit Windows program which CAN get those oversize values, passing the drive letter on the command line and returning the size as a display integer ("FORMAT$(value)" in PB/Win-speak).

    Can return to a file or maybe an environment variable.

    It's a thought.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Apparently DX will give you the total space on the volume:

      AH = 36h
      DL = drive number (00h = default, 01h = A:, etc)

      Return:
      AX = FFFFh if invalid drive else
      AX = sectors per cluster
      BX = number of free clusters
      CX = bytes per sector
      DX = total clusters on drive

      Notes: Free space on drive in bytes is AX * BX * CX. Total space on drive in bytes is AX * CX * DX.

      Taken from Ralph Brown's interrupt list. This function is also limited to 2 GB.

      Georg

      Comment


      • #4
        I'm just cutting and pasting old code I have, I can't guarantee any of it works, especially in a 32 bit environment.
        Looks like the SHELL thing is what I did too but here's some code I had stored.


        Code:
        Type DiskInfo
        InfoLevel As Word
        SerialNum As Dword
        VolLabel As String*11
        SysType As String*8
        End Type
        
        Dim MyDisk As DiskInfo
        
        MyDisk.InfoLevel = 0000 'just has to be 0.
        MyDisk.SerialNum = 
        VolLabel = "A vol label" 'sets volume label. fill with 
        '"NO NAME " for no name.
        'First get SysType, then use it to set.
        
        !PUSH DS
        !MOV AH, &h69 ;function number
        !MOV AL, &h00 ;00=Get number, 01=set number
        !MOV BL, &h00 ;00=default drive. 1=A, 2=B, 3=C, etc.)
        !MOV BH, &h00 ;this has to be 0.
        !MOV DX, VARPTR(MyDisk)
        !MOV DS, VARSEG(MyDisk)
        !INT &h21 ;call DOS
        !POP DS
        Code:
        Sub GetMegsFree(Megs) PUBLIC
        Dim St$(999)
        TempFile$="TEMP.$$$"
        Shell("DIR > "+TempFile$)
        F=FreeFile
        Open TempFile$ For Input As #F
        Do Until Eof(F)
            Incr Adder%,1
            Line Input #F,St$(Adder%)
        Loop
        Kill TempFile$
        H$=LTrim$(Remove$(Mid$(St$(Adder%),20,20),"bytes"))
        Erase St$
        H$=Remove$(H$,",")
        Megs=(Val(H$)\1024000)
        End Sub
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          1. Type PB/DOS code
          2. Find a friend with either PB/CC or PB/WIN to compile the windows program
          Code:
          'Freespace.bas
          #COMPILE EXE
          #COMPILER  PBCC PBWIN
          #DIM ALL
          #IF %DEF(%PB_CC32)
            #IF NOT (%PB_REVISION AND &h0500)    ' #CONSOLE OFF new in PB/CC 5?
               #CONSOLE OFF
            #ENDIF
          #ENDIF
          
          FUNCTION PBMAIN () AS LONG
               
               LOCAL dr AS STRING, ds AS QUAD, S AS STRING, hFile AS LONG
               
               dr = COMMAND$
               ds = DISKSIZE(dr)
               hFile = FREFILE
               OPEN "~ds" FOR OUTPUT AS hFile
               PRINT #hFile, FORMAT$(ds)
               CLOSE hFile
          
          END FUNCTION
          
          #IF 0
            PB DOS CODE.
          FUNCTION GetDisksize (Dr) AS QUAD
               
           LOCAL h AS INTEGER, buff AS STRING
             SHELL "Freespace.exe " & dr
             h = FREEFILE
             OPEN "~ds" FOR INPUT AS h
             LINE INPUT #h, buff
             CLOSE h
             FUNCTION =  VAL (buff)
               
          END FUNCTION
          
          
              LOCAL Z AS QUAD
              Z = GetDiskSize ("D")
          
          #ENDIF
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Thanks for the replies sofar.
            I can't shell because i run the whole thing in true dos, not a windows cmd console or dos box, but reel FreeDOS. Also, using the shell command in DOS uses up a huge chunk of code memory that i need for other stuff (adding the shell command to the code makes the executable substantially larger and reduces free memory quite a bit), so that's a no go too.
            The AH=36 approach i've tried but that doesn't work because of the 2GB limit. Also, i need the volume's size, not the amount of free space.
            It seems i won't be able to implement anything anytime soon so i'll find a way around this for now. Thanks anyway.
            [URL=http://www.DiyDataRecovery.nl]

            Comment


            • #7
              can't shell because i run the whole thing in true dos, not a windows cmd console or dos box, but reel FreeDOS.
              I can't speak to the vagaries of non-Microsoft "MS-DOS" but I guarantee you this is doable with "reel" MS-DOS.

              Also, using the shell command in DOS uses up a huge chunk of code memory that i need for other stuff (adding the shell command to the code makes the executable substantially larger and reduces free memory quite a bit), so that's a no go too.
              Someone here offers a product which compacts memory on SHELLs. However, I can't speak to the vagaries of non-Microsoft "MS-DOS".

              However, in this case SHELL adds next to nothing to your program's memory needs, since the SHELL'ed 32-bit program does not run in the same 16-bit address space as your MS-Program.

              But if it does, you can....
              Code:
              SHELL  "[b]START /W [/b] [i]programname[/i] [params]"
              ... and for sure this will not run in your 16-bit space.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Tom,

                The short answer ( as near as I can figure ) is that you should ask this
                question in a FreeDOS forum. They would be most familiar with the OS
                and know how to get the right answer. And this is the sort of question
                that has come up before so you should find an answer quickly.

                Most people here were going under the assumption that you were running
                under Windows and could run a Windows program. This is NOT possible
                when running under DOS alone. Even running some sort of Windows
                emulator would be way overkill for the problem.

                Comment


                • #9
                  I thought "real" MS-Dos could not even recognize disk > 2 Gb, meaning a FreeDOS forum is the probably the ONLY place you could get the info you seek.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  mma[email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    @Michael: that would be open to debate. MS-DOS 7 (the DOS under win9x) does partitions larger than 2Gb, but you could argue that it isn't real dos. True enough, all the older MS versions (up until 6.22) don't do > 2Gb, so i gues you're right. FreeDOS however does partitions larger than 2Gb, so detection should be possible, but as far as i can see unlikely. I'll have a look at the FreeDOS forums though, thanks for that pointer.
                    To clarify: for this app i'm not running windows at all so the whole shell thing is not possible/desired.
                    Thanks.
                    [URL=http://www.DiyDataRecovery.nl]

                    Comment


                    • #11
                      Code:
                         FREE SPACE ON DRIVES
                      
                         A      No disk 
                         B      756 Kb
                         C      1,500,000,0000 bytes
                         J     > 2,000,000,000 bytes
                         ...
                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Try
                        Int 21h Func 7303h (Get Extended Free Space) and
                        Int 12h Func 7302h (Get extended DPB).

                        For more details you can try googling for "int 21h fat32".

                        ViH

                        Comment

                        Working...
                        X