Get drive free space

Anything QL Software or Programming Related.
User avatar
Andrew
Aurora
Posts: 795
Joined: Tue Jul 17, 2018 9:10 pm

Get drive free space

Post by Andrew »

Is there a function/a way to read the free space available on a drive?
Except Turbo Toolkit's DEVICE_SPACE function?
I do not want to load all Turbo Toolkit for the use of a single function.


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Get drive free space

Post by dilwyn »

Easiest way without an extension is to send DIR output to a file, then read back the first line, something like "123/234 Sectors" and slice that up into the used and available sectors, a bit like DMEDIUM_FREE in SBASIC. You need to know how many bytes per sector of course.

If using one of the compilers, you could send DIR output to a pipe instead of a file, that's how my Q-Trans retrieves the info IIRC.


User avatar
Andrew
Aurora
Posts: 795
Joined: Tue Jul 17, 2018 9:10 pm

Re: Get drive free space

Post by Andrew »

Dir output to a file - doesn't work. I mean, I want to check if I have space to write a 1k file. If I don't have space for that than I might don't have enough space for a dir file.
Dir output to a pipe - this might work, except that I have no way of knowing how many bytes per sector there are.


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Get drive free space

Post by dilwyn »

Andrew wrote:Dir output to a file - doesn't work. I mean, I want to check if I have space to write a 1k file. If I don't have space for that than I might don't have enough space for a dir file.
Dir output to a pipe - this might work, except that I have no way of knowing how many bytes per sector there are.

Code: Select all

This is how the QDOS/SMS manual describes IOF.MINF (FS.MDINF in QDOS terminology) trap #2, d0=$45 call:
Trap #3 D0=$45       IOF.MINF
Get information about medium
Call parameters Return parameters
D1              D1.L Empty / Good sectors
D2              D2 Preserved
D3.W Timeout    D3.L Preserved
                D4+ All preserved
A0 Channel ID   A0 Preserved
A1 Pointer to 10 byte buffer A1
A2              A2 Preserved
A3              A3 Preserved
                A4+ All preserved
Error returns:
NC Not complete
ICHN Channel not open
The name of the medium, its capacity, and the available space may be obtained for a file or directory that is
open. The medium name is 10 bytes long and left justified. Any remaining bytes are filled with the space
character ($20).
The number of empty sectors is in the most significant word (MSW) of D1, the total available on the medium
is in the least significant word (LSW). A sector is 512 bytes.
Sending DIR output to file on the same medium of course defeats the object, use pipe or ramdisk.

Don't know if QL hard disks are always 512 bytes per sector, floppy disks can vary by density.

You could probably open a direct sector channel to test the density if you know it's supported on the system.

A better way is probably to error trap the write output so that if the drive runs out of space, at least your program can report it and close and finish tidily. This runs the risk that it needs more lines of BASIC (more memory) than just using the toolkit in the first place.

If the Turbo Toolkit function does what you want, you could probably use the DEA software to extract the keyword as assembler source and amend it to do what you want. Instructions on using DEA to do this at https://quanta.org.uk/wp-content/upload ... INE-35.pdf. Or you could look at the SMSQ/E sources to see how DMEDIUM_FREE and the other DMEDIUM_xxxx extensions work.


User avatar
Andrew
Aurora
Posts: 795
Joined: Tue Jul 17, 2018 9:10 pm

Re: Get drive free space

Post by Andrew »

Thank you DIlwyn! The info is great!


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Get drive free space

Post by mk79 »

Just a short note, for your purpose minf is okay, but if somebody really wants to get the free disc space you need iof.xinf as 65535 sectors doesn't cut it with big drives. And also it's true to better just trap the error. There are other possible errors that need to be trapped anyway.


User avatar
NormanDunbar
Forum Moderator
Posts: 2274
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Get drive free space

Post by NormanDunbar »

Dilwyn wrote:Don't know if QL hard disks are always 512 bytes per sector, floppy disks can vary by density.
DS/DD and DS/HD are 512 bytes per sector. (See http://qdosmsq.dunbar-it.co.uk/doku.php ... sq:fs:dsdd and http://qdosmsq.dunbar-it.co.uk/doku.php ... sq:fs:dsdd)
DS/ED are 2,048 bytes per sector. (See http://qdosmsq.dunbar-it.co.uk/doku.php ... sq:fs:dsed)

If that helps?


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Get drive free space

Post by dilwyn »

mk79 wrote:Just a short note, for your purpose minf is okay, but if somebody really wants to get the free disc space you need iof.xinf as 65535 sectors doesn't cut it with big drives. And also it's true to better just trap the error. There are other possible errors that need to be trapped anyway.
Here's the notes on that trap call, flagged as a DD2 (level 2 filing system) one:

Code: Select all

Trap #3 D0=$4F IOF.XINF [DD2]
Get extended information
Call parameters Return parameters
D1 0            D1 Preserved
D2              D2 Preserved
D3.W Timeout    D3 Preserved
A0 Channel ID   A0 Preserved
A1 Pointer to info buffer A1 Preserved
Error returns:
Any I/O sub system errors
This call fetches extended filing system information in a block 64 bytes long.
IOI_NAME $00 String Up to 20 character medium name (null filled)
IOI_DNAM $16 String Up to 4 character long device name (e.g. Win)
IOI_DNUM $1C Byte Drive number
IOI_RDON $1D Byte Non zero if read only
IOI_ALLC $1E Word Allocation unit size (in bytes)
IOI_TOTL $20 Long Total medium size (in allocation units)
IOI_FREE $24 Long Free space on medium (in allocation units)
IOI_HDRL $28 Long File header length (per file storage overhead)
IOI_FTYP $2C Byte Format type (1=qdos, 2=msdos etc)
IOI_STYP $2D Byte Format sub-type
IOI_DENS $2E Byte Density
IOI_MTYP $2F Byte Medium type (ram=0, flp=1, hd=2, cd=3)
IOI_REMV $30 Byte Set if removable
IOI_XXXX $31 $0F Bytes Set to -1
The number of allocation units required to store a file may be calculated as:
(file + header length + alloc unit size - 1) / (alloc unit size)
This trap is supported on Level 2 device drivers.
It should be called to find out whether the current device is Level 2 or not and to check which operations are
supported.
If this trap succeeds, all other filing system traps will be available.


User avatar
Andrew
Aurora
Posts: 795
Joined: Tue Jul 17, 2018 9:10 pm

Re: Get drive free space

Post by Andrew »

dilwyn wrote:If the Turbo Toolkit function does what you want, you could probably use the DEA software to extract the keyword as assembler source and amend it to do what you want. Instructions on using DEA to do this at https://quanta.org.uk/wp-content/upload ... INE-35.pdf. Or you could look at the SMSQ/E sources to see how DMEDIUM_FREE and the other DMEDIUM_xxxx extensions work.
I used DEA and extracted DEVICE_SPACE from Turbo toolkit - and that worked just fine
Next I tried to copile it using C1Assembler - and failed. The compiled code is not working.
This was my first ever attempt to compile asm code in the last 30 years.
Can someone take a look at the code and try to compile it? I am not sure if I blundered something or the code extracted by DEA is not working on it's own.
Attachments
Device_Space_ASM.zip
(1.47 KiB) Downloaded 90 times


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: Get drive free space

Post by EmmBee »

Andrew wrote:Is there a function/a way to read the free space available on a drive?
Except Turbo Toolkit's DEVICE_SPACE function?
I do not want to load all Turbo Toolkit for the use of a single function.
Hi,

Using DEVICE_SPACE, a channel has to be already open for creation for it to return the correct result.

So ... n = FOP_NEW("mdv1_my_file") : space = DEVICE_SPACE(#n)

I am suspecting you are really needing to use the function DEVICE_STATUS, where the file is not open yet.

Thus ... space = DEVICE_STATUS("mdv1_my_file")

should return the same result as DEVICE_SPACE, except the file does not have to be opened.

It could be this difference is the reason why your assembled code is not working right.

EmmBee


Post Reply