Obtain the name of the disk unit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtain the name of the disk unit

Gisela Decuzzi
Hi, I need to do a validation and check if the image is running in an usb with a spefic name.
I found how to determine the execution path: FileSystem disk workingDirectory, but I wolud like to obtain the disk name and didn't find a message for that.
Does anybody know how to do this?
Reply | Threaded
Open this post in threaded view
|

Re: Obtain the name of the disk unit

Ben Coman
Gisela Decuzzi wrote:
> Hi, I need to do a validation and check if the image is running in an
> usb with a spefic name.
> I found how to determine the execution path: FileSystem disk
> workingDirectory, but I wolud like to obtain the disk name and didn't
> find a message for that.
> Does anybody know how to do this?
Not that I can help :)
but what operating system?
Can you give one example of a disk name you would expect to get?

cheers, Ben

Reply | Threaded
Open this post in threaded view
|

Re: Obtain the name of the disk unit

Nicolai Hess
2013/12/2 <[hidden email]>
Gisela Decuzzi wrote:
Hi, I need to do a validation and check if the image is running in an usb with a spefic name.
I found how to determine the execution path: FileSystem disk workingDirectory, but I wolud like to obtain the disk name and didn't find a message for that.
Does anybody know how to do this?
Not that I can help :)
but what operating system?
Can you give one example of a disk name you would expect to get?

cheers, Ben


I am pretty sure that it is not possible. Getting the volume label is platform dependent.
And I can not find any reference on this in the fileplugin.
On windows you would need to call GetVolumeInformation().


A quick solution for win32 with help from NativeBoosts FFI:

NBWin32Shell class >>getVolumeLabel: aPath buffer: aBuffer size: anInteger

<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
     ^ self nbCall: #( bool GetVolumeInformationA (
    String aPath,
    char* aBuffer,
    int anInteger,
    0,
    0,
    0,
    nil,
    0))
    module: #Kernel32

For example use that:
|diskpath buffer label root |
diskpath:= FileSystem disk workingDirectory path.
root := diskpath segments first, diskpath delimiter asString.
buffer := String new:255.
label:=(NBWin32Shell getVolumeLabel: root buffer: buffer size: (buffer size)) ifTrue:[buffer allButLast] ifFalse:[''].
label

A note on GetVolumeInformation, if you want to retrieve the label of the current working
directory, you'll have to add a trailing delimiter (c:\ works, c: only works if it isn't the
root of the current working directory!)

best regards
Nicolai