summaryrefslogtreecommitdiff
path: root/rc/bin/usbeject
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
commit2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch)
treef6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/usbeject
parente463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff)
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/usbeject')
-rwxr-xr-xrc/bin/usbeject41
1 files changed, 41 insertions, 0 deletions
diff --git a/rc/bin/usbeject b/rc/bin/usbeject
new file mode 100755
index 000000000..cae9d0394
--- /dev/null
+++ b/rc/bin/usbeject
@@ -0,0 +1,41 @@
+#!/bin/rc
+# usbeject - unmount usb disks given as arguments
+# unmount all of them if no arguments given
+rfork e
+disk = ()
+mtpt = /n/usb
+
+test -e /dev/fs/ctl || bind -b '#k' /dev >[2]/dev/null
+
+test -e /dev/usb || bind -a '#u' /dev || {
+ echo $0: no '#u/usb' >[1=2]
+ exit nousb
+}
+test -e /dev/usbdctl || mount -a /srv/usb /dev || {
+ echo $0: cannot mount /srv/usb >[1=2]
+ exit nousbd
+}
+
+disks=()
+mtpt=()
+switch ($#*) {
+case 0
+ disks=`{ls -pd /n/sdU*}
+case *
+ disks=()
+ for (a) {
+ if(~ $a sd??)
+ disk=`{ls -pd /n/^$*^*}
+ if not
+ disk=$a
+ disks=($disks $disk)
+ }
+}
+if (~ $disks '''sdU*''')
+ exit ''
+for (disk in $disks) {
+ unmount /n/$disk >[2]/dev/null && echo $disk unmounted
+ if (test -e /dev/fs/ctl)
+ echo del $disk^parts/^'*' >/dev/fs/ctl >[2]/dev/null
+}
+exit ''