[udev] mount hdd storage to /media/hdd using udev.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-core / udev / udev-182 / autoumount.py
diff --git a/meta-openvuplus/recipes-core/udev/udev-182/autoumount.py b/meta-openvuplus/recipes-core/udev/udev-182/autoumount.py
new file mode 100755 (executable)
index 0000000..87e4e21
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+import os
+import sys
+
+def getMountPoint(devName):
+       mounts = file('/proc/mounts').read().split('\n')
+       for x in mounts:
+               if not x.startswith('/'):
+                       continue
+
+               devpath, mountpoint  = x.split()[:2]
+               if devpath == devName:
+                       return mountpoint
+
+       return None
+
+def autoumount():
+       kernel = sys.argv[1]
+       dev_kernel = os.path.join("/dev/", kernel)
+
+       mountPoint = getMountPoint(dev_kernel)
+       if mountPoint is None:
+               mountPoint = os.path.join("/media/", kernel)
+
+       if os.system("umount %s" % mountPoint):
+               os.system("umount %s" % os.path.join("/dev/", kernel))
+
+       try:
+               os.rmdir(mountPoint)
+       except:
+               pass
+
+if __name__=="__main__":
+       autoumount()
+