Recent

Author Topic: [SOLVED] USB Drive  (Read 11824 times)

nhatdung

  • New Member
  • *
  • Posts: 37
[SOLVED] USB Drive
« on: April 05, 2011, 09:23:43 am »
Hi!
I'm currently porting my application to MacOS. I got two issue :
+ How to detect all usb drive ?
+ How to eject/safetly remove an USB Drive ?

 %)
« Last Edit: April 05, 2011, 08:27:52 pm by nhatdung »

rajivsoft

  • New Member
  • *
  • Posts: 48
Re: USB Drive ?
« Reply #1 on: April 05, 2011, 10:10:13 am »
you can call shell commands like 'ls /Volumes/' to see what is mounted on the system and 'umount /Volumes/desired_usb_name' to unmount ;)

for see ls output you must use TProcess and it's output property
Code: Pascal  [Select][+][-]
  1. var
  2.   ls_process: TProcess;
  3.   AStringList: TStringList;  
  4. begin
  5.       ls_process := TProcess.Create(nil);
  6.       ls_process.CommandLine := 'ls /Volumes/';
  7.       ls_process.Options := ls_process.Options + [poUsePipes, poWaitOnExit];
  8.       ls_process.Execute;  
  9.  
  10.       AStringList := TStringList.Create;
  11.       AStringList.LoadFromStream(ls_process.Output);
  12. ...

for umount you can use a simple
Code: Pascal  [Select][+][-]
  1. Shell('mount /Volumes/' + desired_usb_name);

nhatdung

  • New Member
  • *
  • Posts: 37
Re: USB Drive ?
« Reply #2 on: April 05, 2011, 12:15:42 pm »
hi!
ls /Volumes/ seem work! It show me all USB drive include hdd drive. How to get exactly usb drive ?
I can't umount any drive use the command :
umount /Volumes/[drive name]
it show me Operation not permitted
BTW: How about umount drive with name have space on it (eg: "NO NAME") ?

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: USB Drive ?
« Reply #3 on: April 05, 2011, 12:44:05 pm »
Un-mounting tipically needs root privileges, unless the current user mounted the volume (which seems likely for connecting USB devices).

For spaces in names, you can probalby escape them with a "\", so something like this might work?

Code: [Select]
umount /Volumes/name\ with\ spaces

Bart

rajivsoft

  • New Member
  • *
  • Posts: 48
Re: USB Drive ?
« Reply #4 on: April 05, 2011, 12:53:32 pm »
hi!
ls /Volumes/ seem work! It show me all USB drive include hdd drive. How to get exactly usb drive ?
Try to use mount command to se what is mounted (i think usb drive mustn't have 'local' value in parenthesis, or something other different from hdd)
Quote
I can't umount any drive use the command :
umount /Volumes/[drive name]
it show me Operation not permitted
try umount /Volumes/drive name/ (slash at the end)
for me it works with a bash script that mount a specific folder of another mac on the network, then copy some files and at the end unmount the folder with umount...

btw http://ss64.com/osx/mount.html
« Last Edit: April 05, 2011, 01:00:31 pm by rajivsoft »

nhatdung

  • New Member
  • *
  • Posts: 37
Re: USB Drive ?
« Reply #5 on: April 05, 2011, 06:04:17 pm »
Un-mounting tipically needs root privileges, unless the current user mounted the volume (which seems likely for connecting USB devices).

For spaces in names, you can probalby escape them with a "\", so something like this might work?

Code: [Select]
umount /Volumes/name\ with\ spaces

Bart

I simply input a USB stick (4gb) and open terminal, trying to eject it but always got Operation not permitted (see attach file)
And it seem like all have 'local' :(
« Last Edit: April 05, 2011, 06:19:50 pm by nhatdung »

rajivsoft

  • New Member
  • *
  • Posts: 48
Re: USB Drive ?
« Reply #6 on: April 05, 2011, 06:22:48 pm »
I simply input a USB stick (4gb) and open terminal, trying to eject it but always got Operation not permitted (see attach file)
And it seem like all have 'local' :(
Try diskutil umount /Volumes/volume_name

edit: but it has nosuid, now you can use mount to acquire all strings and then loop and seek with AnsiPos for it's presence, when it returns true that is your USB ;)
« Last Edit: April 05, 2011, 06:25:52 pm by rajivsoft »

nhatdung

  • New Member
  • *
  • Posts: 37
Re: USB Drive ?
« Reply #7 on: April 05, 2011, 06:25:22 pm »
waoooooooo, work perfect! Thanks you! ;D

nhatdung

  • New Member
  • *
  • Posts: 37
Re: USB Drive ?
« Reply #8 on: April 05, 2011, 07:51:52 pm »
One more question:  how to shell open an url ?
« Last Edit: April 05, 2011, 07:55:36 pm by nhatdung »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: USB Drive ?
« Reply #9 on: April 05, 2011, 08:02:46 pm »
Quote
One more question:  how to shell open an url ?
Err... LCLIntf.OpenURL?

nhatdung

  • New Member
  • *
  • Posts: 37
Re: USB Drive ?
« Reply #10 on: April 05, 2011, 08:09:59 pm »
perfect  :)

 

TinyPortal © 2005-2018