Get list of drives? And.....

Archives Forums/Linux Discussion/Get list of drives? And.....

Garrett(Posted 2006) [#1]
Ok, I'm totally lost on this one :-(

How would I go about getting a list of the drives through BlitzMax? And.. How
can I determine which of those drives currently has the active directory?

I've posted this in both the OS X section and Linux Section because the program
I am working on is for both of these.

Thanks for any help,
-Garrett


Robert(Posted 2006) [#2]
Hello,

You could find the list of mounted filesystems by reading the contents of the "/proc/mounts" file. This is a file containing lines of text with fields separated by spaces.

The first field is the physical device which has been 'mounted' (so that its contents are accessible through some pathname). The second field is the location in the filesystem where the contents of the device can be accessed.

Below are the current contents of my /proc/mounts file with a CD inserted in the drive.

rootfs / rootfs rw 0 0
none /sys sysfs rw 0 0
none /proc proc rw,nodiratime 0 0
udev /dev tmpfs rw 0 0
/dev/hda3 / ext3 rw,data=ordered 0 0
/dev/hda3 /dev/.static/dev ext3 rw,data=ordered 0 0
tmpfs /var/run tmpfs rw 0 0
tmpfs /var/lock tmpfs rw 0 0
usbfs /proc/bus/usb usbfs rw 0 0
tmpfs /lib/modules/2.6.15-26-386/volatile tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
tmpfs /var/run tmpfs rw 0 0
tmpfs /var/lock tmpfs rw 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/hdc /media/cdrom0 iso9660 ro,nosuid,nodev,noexec 0 0

For example, my main hard drive is the device called '/dev/hda3' and to browse the contents of my hard drive, I would navigate to '/'. My CDROM is the device called '/dev/hdc' and to browse its contents I would navigate to '/media/cdrom0'

To find out which drive contains the active directory, you would need to retrieve the current dir ( I presume BlitzMAX already provides a command for this? ) and find out which mount point the active directory starts with.

eg. If the current directory was "/media/cdrom0/something" then scanning through the list would find that it was part of the '/media/cdrom0' filesystem. In the case that you get multiple patches (eg. here both '/' and '/media/cdrom0' would match), pick the longest match.

Regards,
Robert.


Garrett(Posted 2006) [#3]
Thanks Robert. I was of course trying to find a way within BlitzMax itself, but
seems I'll have to poll an external app to do so. I also found that "df" will
give info about the drives connected too. So one or the other should get me
where I need to go :-)

Thanks,
-Garrett


Brucey(Posted 2006) [#4]
I've started on (yet another) wee module, called "Volumes" which would be a cross-platform-get-volume-information module.
It is designed to work via the platform APIs, rather than hacking together some parser to read cli output :-)

I slapped together the linux code last night and it seems to work a treat. Well, it tells me what stuff is mounted - including the ipod. Just need to get the disk size/free stuff now and that'll be the linux end sorted.
I have the other two sets of API and just need to code them (Mac-side I'll have to guess as to code correctness until I get my powerbook back)..

Max rocks for mod-building :-)

PS. if you didn't know already, there's a whole forum *just* for Macs ;-)

Edit:
...and it now works on Windows...

Example :
SuperStrict

Framework bah.volumes
Import brl.standardio

Local list:TList = ListVolumes()

If list Then
	Print "Volumes :"

	For Local v:TVolume = EachIn list
	
		If v.available Then
			Print "~t" + v.volumeName + "  -  " + v.volumeDevice + "  -  " + ((v.volumeFree / 1024) / 1024) + "mb"
		End If
	
	Next
End If

produces (on windows) :
Volumes :
	Local Disk  -  C:\  -  1813mb
	CHIPPIE  -  I:\  -  298mb
	stuff  -  P:\  -  49924mb

(stuff is a mounted network share)


Brucey(Posted 2006) [#5]
Here's the linux ouput of the above code :
Volumes :
	/  -  /dev/sda1  -  4195mb
	/proc  -  proc  -  0mb
	/sys  -  sysfs  -  0mb
	/dev/pts  -  devpts  -  0mb
	/dev/shm  -  tmpfs  -  93mb
	/proc/bus/usb  -  usbfs  -  0mb
	/lib/modules/2.6.12-10-386/volatile  -  tmpfs  -  81mb
	/dev  -  tmpfs  -  0mb
	/media/ipod  -  /dev/sdb1  -  298mb

Seems to work pretty well so far...


Garrett(Posted 2006) [#6]
Either I'm getting so old that I'm now getting forgetful, or my reply to your
initial reply has disappeared :-(

I thought I said something like "I really look forward to your module for this"

-Garrett


Garrett(Posted 2006) [#7]
Anyway, for now I'm using 'df' on OS X since all OS X machines will give the same
results and df on OS X is easy enough to parse.

But for Linux, 'df' is not the same on each and every distro out there, so 'df' is
going to be unreliable for Linux.

What will likely work for all Linux distros is 'mount' But mount is not quite as easy
to parse out, but at least it's not impossible.

-Garrett


Brucey(Posted 2006) [#8]
Either I'm getting so old that I'm now getting forgetful, or my reply to your
initial reply has disappeared

Looks like a whole pile of posts got lost somewhere, given the amount "where is my post?" posts...

I've actually had a look at various df sources to see what they are doing under the hood so that I can access the same core API that they do.

Just the Mac code left to do now...


Garrett(Posted 2006) [#9]
That'll be sweet, as I really hate having to poll external apps for info like this,
no less, I've not been able to get that freeprocess to work on OS X, so I've
been redirecting the df and mount output to files and then reading them in.

-Garrett