Forum > Linux
How to eject/safetly remove an USB Drive ?
nhatdung:
i can find them all in /etc/mtab
but how to eject/safetly remove ?
TurboRascal:
You mean how to unmount a drive from your program? For that you should use API calls...
nhatdung:
yes that's what i mean. But what API should i use %)
TurboRascal:
umount call. In C it's like this:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#include <sys/mount.h> int umount(const char *target);
(this is from the umount(2) manpage)
Unfortunately, I've never did it from Pascal, so I cannot help you much. You could check the FPC documentation, also someone with some experience in this might help better...
You should also beware it is quite likely for the unmounting to fail, either if the volume requires root privileges to unmount, or there are open files on it (quite often). There isn't much you can do about it from your program if it happens, but handle the error gracefully and report it to the user...
Leledumbo:
--- Quote ---umount call. In C it's like this:
--- End quote ---
If the C signature is like that, then it's probably like this in Pascal:
--- Code: ---uses
ctypes;
function umount(const target: PChar): cint: cdecl; external;
--- End code ---
hoping it resides in the kernel libs (which I assume so).
Navigation
[0] Message Index
[#] Next page