This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thecrimulo's profile picture

New Disk API function

Started by thecrimulo, 04 January 2017 - 01:01 PM
thecrimulo #1
Posted 04 January 2017 - 02:01 PM
Hi there,
I request a new Disk API function that returns the device type inserted on a side, either "computer", "floppy" or "disc".
Lupus590 #2
Posted 04 January 2017 - 03:21 PM
Can kind of be implemented by the user by having a type file at the root of the disk/disk-like-device's filesystem which identifies the device type.

A device without this file will have to be identified by the user, although computers/turtles could be programmed to make their own on startup.

You might be able to do something fancy with the varying storage capacities of different devices.

Also, why would you need this? I can't see any need to know what's in the drive while it's in the drive. A turtle can identify it for you if you really need to.
Edited on 04 January 2017 - 02:24 PM
thecrimulo #3
Posted 04 January 2017 - 05:03 PM
I am making a Virtual Filesystem adaptation with devices, partitions and such. There is a file that can specify it but not every device is going to have them. That's why I wanted it in a function (and Turtles don't help because in some servers it is not allowed)
Dog #4
Posted 04 January 2017 - 05:55 PM
As Lupus590 suggested, you can probably use the different storage sizes to determine what storage medium you are examining. The downside is that I believe those values can be changed in the config, so they wouldn't be guaranteed to be the same on every server you play on.
thecrimulo #5
Posted 04 January 2017 - 07:05 PM
I've researched for the capacity of computers, pocket computers (1,000,000) and floppys (125,000), here is a function outline that differences them by size:


function disk.getDevice(side)
	if disk.hasData(side) then
		local sMountPath = disk.getMountPath(side)
		local nFreeSpace = fs.getFreeSpace(sMountPath)
		if nFreeSpace <= 125000 then return "floppy"
		elseif nFreeSpace > 125000 then return "computer"
		end return nFreeSpace
	else return nil end
end

Anything beyond 125,000 is considered computer because of that it is configurable and it might be less or more than 1,000,000.

However, it would be fine to have a function that just detects it, instead of the size trick, so its always exact.
TheRockettek #6
Posted 04 January 2017 - 08:25 PM
floppy space is configurable too ya know :P/>
houseofkraft #7
Posted 04 January 2017 - 08:26 PM
All you need to do is check what type the peripheral side is. The code below might work


function disk.getDevice(side)
     if peripheral.getType(side) == "computer" then
       return "computer"
     elseif peripheral.getType(side) == "disk" then
       return "floppy"
     else
       return "unknown"
     end
end
Lupus590 #8
Posted 04 January 2017 - 08:32 PM
All you need to do is check what type the peripheral side is. The code below might work
the computer is in the disk drive so your code will always think it is a floppy even though the disk drive contains a computer
thecrimulo #9
Posted 04 January 2017 - 10:04 PM
floppy space is configurable too ya know :P/>

One more reason to need the function