Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
166 user(s) are online (136 user(s) are browsing Forums)

Members: 0
Guests: 166

more...

Headlines

 
  Register To Post  

How find free disk space? (SOLVED)
Home away from home
Home away from home


See User information
Can anyone give me any hints on how I can make a program to find out free disk space (and perhaps total disk size)?


Edited by ChrisH on 2011/8/28 21:59:31
Author of the PortablE programming language.
Go to top
Re: How find free disk space?
Just can't stay away
Just can't stay away


See User information
@ChrisH

struct InfoData *data=0;
BPTR lo=0;

data=IDOS->AllocDosObject(DOS_INFODATA,TAG_DONE);
if (
data!=0)
{
 
lo=IDOS->Lock("<volume_name>",ACCESS_READ);
 if (
lo!=0)
 {
  if (
IDOS->Info(lo,data))
  {
   
// data->id_NumBlocksUsed /* Number of block in use */
   // data->id_NumBlocks /* Number of blocks on disk */
   // data->id_BytesPerBlock
  
}
  
IDOS->UnLock(lo);
 }
 
IDOS->FreeDosObject(DOS_INFODATA,data);
}


Rock lobster bit me - so I'm here forever
X1000 + AmigaOS 4.1 FE
"Anyone can build a fast CPU. The trick is to build a fast system." - Seymour Cray
Go to top
Re: How find free disk space?
Home away from home
Home away from home


See User information
@TSK
Thanks, that's a lot easier than I was expecting. I should have remembered the AmigaDos "Info" command, and then looked to see if it has a direct function call equivalent (which seems to happen for quite a few commands).

Author of the PortablE programming language.
Go to top
Re: How find free disk space?
Home away from home
Home away from home


See User information
@TSK
I've converted your code into PortablE, in case anyone is interested:
MODULE 'dos'

PROC main()
    
DEF data:PTR TO infodatalock:BPTR
    lock 
:= NIL
    
    
IF lock := Lock('your_volume_name:'ACCESS_READ)
        IF 
data := AllocDosObject(DOS_INFODATANILA)
            IF 
Info(lockdata)
                Print(
'size = \\d MB\\n'data.numblocks !!BIGVALUE data.bytesperblock 1024 1024 !!VALUE)
                Print(
'free = \\d MB\\n', (data.numblocks data.numblocksused) !!BIGVALUE data.bytesperblock 1024 1024 !!VALUE)
            ENDIF
            
FreeDosObject(DOS_INFODATAdata)
        ENDIF
        
UnLock(lock)
    ENDIF
ENDPROC


The BIGVALUE & VALUE casts are there so that it can handle sizes above 2GB.

BTW, I find this code rather nicer to read than the C equivalent, but maybe that's just me

EDIT: Added a missing FreeDosObject() call.


Edited by ChrisH on 2011/8/29 14:05:04
Author of the PortablE programming language.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project