12-14-2009 01:37 PM
Folks,
I need to allow the user to unmount a flash drive by clicking on a button on LabVIEW user interface (after having copied some log files to it). I tried to do it by making a system call to a script that contained a line "umount /media/flash", where "flash" is the name of the flash drive that I can detect programmatically (it can be anything, depending on how the user named his flash drive). The problem is that calling umount like this requires root access; without it the OS responds with
/media/flash is not in the fstab (and you are not root)
Is there a way to do it from LabVIEW with or without a system call, but definitely without root access? If not, then is there a means to tell the OS to flush any buffers associated with the "copy" command, so that all the files are on the flash before he pulls it out?
The instrument runs openSUSE 11.1 with Gnome. The user does not have access to the desktop or command line - just to the LabVIEW front panel.
Thanks,
Sergey
12-14-2009 01:51 PM
Hmm, just from a Linux perspective, what about giving no password sudo access to the umount command for the user running the LabVIEW process? Then add sudo to your umount command in your script.
Not sure if there are ways directly from LabVIEW to do that.
12-14-2009 01:54 PM
Sergey,
You should be able to add an entry to the /etc/fstab file for the flash drive and then add the users option (instead of defaults). This will allow normal users to call mount and umount on /mnt/flash. For more information, search online for "linux umount normal user." There are many examples, but most of them pertain to CD-ROM drives. It would not be too much to modify them for the flash drive instead.
You can then just call umount /mnt/flash in LabVIEW.
Randy Hoskin
LabVIEW for Linux
National Instruments
12-14-2009 01:56 PM
You might look into how the desktop environment does this for an answer. In general that's something that requires root access, but obviously for some devices and for the desktop use case it makes sense to allow a non-admin user to do that. I think they use some combination of HAL and DBus, but I'm not sure how to write a script that interacts with it. I'm pretty sure it can be done somehow, though.
For flushing to disk, look into the "sync" command. I think it will do what you want.
12-14-2009 01:58 PM
There are ways to allow non-root users to mount/umount filesystems, but to my knowledge they all require some initial setup by the root user. You could allow sudo access for umount, or add a line to your /etc/fstab file like this suggests:
http://www.losurs.org/docs/tips/sysadmin/user-mountable
Lastly if you can't do any pre-setup as root, you could always just run the "sync" command to flush everything to disk and hope that when they pull the drive everything is OK.
--
Shawn
12-14-2009 01:58 PM
Ah yes, then there is this. I guess it shows that it has been too long since I've used Linux as my main machine.
12-14-2009 02:25 PM
I think that modifying the /etc/fstab file requires that I know the name of the user's flash drive in advance. If that's the case, I cannot use it. I'll try the "sync" command. Giving "no-password sudo access to the umount command only" sounds like a good solution too. Any suggestions on how to do it?
There is one more suggestion that I came across: using "gnome-umount" command. I'll try it too.
Thanks,
Sergey
12-14-2009 02:33 PM
I think you would add something like the following to your /etc/sudoers file. Insert the username that you are giving the privileges to and confirm where umount is located.
username ALL = NOPASSWD: /sbin/umount
12-14-2009 09:02 PM
Here's the answer that worked for me: calling System Exec with the command
gnome-umount -p "My Flash Drive"
where My Flash Drive is the name of the memory stick as seen in the /media folder. This name may contain spaces, in which case quote marks are required.
-- Sergey