How to eject/safetly remove an USB Drive ? lazarus / 32-Linux ---------------------------------------------------------------------- nhatdung · 2011-03-31 16:59 i can find them all in /etc/mtab but how to eject/safetly remove ? ---------------------------------------------------------------------- TurboRascal · 2011-03-31 19:54 You mean how to unmount a drive from your program? For that you should use API calls... ---------------------------------------------------------------------- nhatdung · 2011-04-01 02:49 yes that's what i mean. But what API should i use ---------------------------------------------------------------------- TurboRascal · 2011-04-01 20:18 umount call. In C it's like this: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include         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 · 2011-04-01 22:38 Quoteumount call. In C it's like this:If the C signature is like that, then it's probably like this in Pascal: Code: [Select]uses   ctypes; function umount(const target: PChar): cint: cdecl; external; hoping it resides in the kernel libs (which I assume so). ---------------------------------------------------------------------- TurboRascal · 2011-04-01 23:49 It should be there, this is a kernel syscall... ---------------------------------------------------------------------- nhatdung · 2011-04-02 13:55 there is no mount/umount command in freepascal. i use tprocess and it work fine  thanks! ---------------------------------------------------------------------- ik · 2011-04-02 14:39 I think that you can use syscall for that, something like: Code: [Select]fpsyscall(syscall_nr_umount, '/mnt/dok'); Or something like that (I have not tried it myself). ---------------------------------------------------------------------- nhatdung · 2011-04-05 07:24 i haven't try my self but use tprocess call umount work very good btw : where is "fpsyscall" function ? ---------------------------------------------------------------------- TurboRascal · 2011-04-07 22:30 Quote from: nhatdung on April 02, 2011, 03:55:23 pmthere is no mount/umount command in freepascal. i use tprocess and it work fine  thanks! So you called the umount binary file from your program? Not too bad a solution since every linux system must have that... ---------------------------------------------------------------------- rajivsoft · 2011-04-08 07:39 Instead of TProcess you can try to use what i know works on Mac OS X Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ... Unix, ......fpSystem('diskutil umount /Volumes/volume_name');instead of /Volumes/volume_name put your mount path to usb ---------------------------------------------------------------------- ik · 2011-04-08 09:36 Quote from: rajivsoft on April 08, 2011, 09:39:37 amInstead of TProcess you can try to use what i know works on Mac OS X Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ... Unix, ......fpSystem('diskutil umount /Volumes/volume_name');instead of /Volumes/volume_name put your mount path to usb But then you must place the full path of the program. I offered to use SysCalls that uses the system in code to umount the device itself. So even if a unix/linux does not have umount command for any reason, the program should it. ---------------------------------------------------------------------- nhatdung · 2011-04-09 09:01 sorry but i can't find function fpsyscall/syscall in Lazarus. Can u tell me what unit to use ? ---------------------------------------------------------------------- fabienwang · 2011-04-09 09:03 I think it's fpSystem() in Unix unit. ---------------------------------------------------------------------- nhatdung · 2011-04-09 10:06 fpSystem only take 1 argument ---------------------------------------------------------------------- fabienwang · 2011-04-09 15:18 Yes and you just have to put the full command with arguments to it