Hello,
the following function, (maoslib-64bit, macOSFolderitemExtension) works OK when compiling in 32-bit, but it crashes in 64-bit: see below <<< crash here >>>, where OSError is supposed to return as 0 (zero).
I hope declare-expert people may find the stumbling block in order to fix it.
Help greatly appreciated. Thanks.
Sierra, Xojo 2017 2.1
[code]Public Function DeviceName(extends f as FolderItem) as String
//# DeviceName returns the BSD name of the volume containing f as found in the directory /dev. Only local volumes have such names.
#if TargetMacOS
soft declare function PBHGetVolParmsSync lib CarbonLib (ByRef paramBlock as HIOParam) as Short
dim paramBlock as HIOParam
paramBlock.ioVRefNum = f.MacVRefNum
//the following line is a trick to work around the inability to assign a pointer to a structure
//to a field of type Ptr.
dim infoBuffer as new MemoryBlock(GetVolParmsInfoBuffer.Size)
paramBlock.ioBuffer = infoBuffer
paramBlock.ioReqCount = infoBuffer.Size
dim OSError as integer = PBHGetVolParmsSync(paramBlock)//<<< crash here >>>//commenting these four lines, compilation proceeds OK
if OSError <> 0 then
return ""
end if
dim infoBufferPtr as GetVolParmsInfoBuffer = paramBlock.ioBuffer.GetVolParmsInfoBuffer(0)
if infoBufferPtr.vMServerAddr = 0 then
if infoBufferPtr.vMDeviceID <> nil then
dim s as MemoryBlock = infoBufferPtr.vMDeviceID
dim BSDName as String = s.CString(0)
return DefineEncoding(BSDName, Encodings.SystemDefault)
else
return ""
end if
else
// vMServerAddr <> 0 means it's a network device, which apparently won't have a BSD name.
return ""
end if
Volume(0).name (or f.name) and BSDName (above in the function) are different things. In 32-bit, BSDName results as something like disk2xx; in 64-bit, if I comment the OSError lines, it returns “”.
Yes, also the code above (32-bit) gives disk1 for volume(0), disk2xx for an external USB drive (xx stand for letters I don’t remember right now), and so on. But in 64-bit… crash.
Well, this should not that hard to get the name with a few declares. There should ne no need for a plugin at all.
As workaround you can use also a shell call, e.g.
$ /usr/sbin/diskutil list / | head -1
/dev/disk2 (internal, virtual):
Excellent!
Since I’ll actually parse external devices only, I added a pushbutton with a selectFolder dialog in order to pass the selected volume to your code (after putting it in a method and adding a parameter f as folderitem).
Then, since the original code needs only the last part of the deviceName, I just spitted it:
…
dim path as String = f.nativePath//f.shellpath
…
dim s() as String = splitB(DefineEncoding(statfsResult.StringValue(154, 90), Encodings.UTF8), “/”)
TextArea1.AppendText “f_mntfromname: “”” + s(s.Ubound) + “”"" + EndOfLine