Platforms to show: All Mac Windows Linux Cross-Platform

Back to FolderItem class.

FolderItem.EjectVolumeMBS(force as boolean, byref dissenterPID as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacClassic Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
This routine ejects the volume specified by folderitem.
Example
dim disk as FolderItem

dim c as Integer = VolumeCount-1
for i as Integer = 0 to c
dim v as FolderItem = volume(i)
if v.Name = "testvolume" then
disk = v
exit
end if
next

if disk = nil then
MsgBox "Please change the name in this code."
else
dim pid as Integer
dim e as Integer = disk.EjectVolumeMBS(false, pid)

if e=0 then
msgBox "Volume unmounted."
else

if pid=0 then
msgBox "Failed to unmount with error: "+str(e)
else
dim name as string
dim p as new ProcessMBS // from Util plugin
p.GetFirstProcess

do
if p.ProcessID = pid then
name = p.Name
end if
loop until not p.GetNextProcess

if len(name)>0 then
msgBox "Failed to unmount with error: "+str(e)
else
MsgBox "Failed to unmount."+EndOfLine+EndOfLine+"The application "+name+" is still using this volume."+EndOfLine+"Error: "+str(e)
end if

end if
end if
end if

If the volume cannot be ejected the pid of the process which denied the unmount will be returned in the dissenter parameter. This routine returns after the eject is complete. Ejecting a volume will result in the unmounting of other volumes on the same device.

force: Specify true if you want the volume forcibly unmounted. Force unmounting a volume will very likely result in data loss since the volume will be ejected even if there are open files on it. This option should be reserved for situations such as the backing store for a volume is gone (so the data is lost regardless).
dissenterPID: Optionally, pid of the process which denied the unmount if the unmount is denied.

Returns a Mac OS error code. 0 means no error and -1 is a plugin error if the function can't be called. -47 is returned if the disc is in use.

PS: Seems like on my tests the pid is not set by Apple.

Blog Entries

The items on this page are in the following plugins: MBS MacClassic Plugin.


The biggest plugin in space...