2009年8月31日 星期一

the auto-mounting mechanism of storage devices (ex: USB storages) on the Android platform

Implement the auto-mounting mechanism of storage devices (ex: USB storages) on the Android platform:

1. Implement a daemon to listen the uevents of storage devices (via netlink).
2. Use the uevent to know the information for creating the corresponding device nodes under /dev.
The following is one example of uevent for the usb storage:

add@/devices/pci0000:00/0000:00:1d.7/usb1/1-6
add@/devices/pci0000:00/0000:00:1d.7/usb1/1-6/1-6:1.0
add@/class/scsi_host/host8
add@/class/usb_endpoint/usbdev1.9_ep81
add@/class/usb_endpoint/usbdev1.9_ep02
add@/class/usb_endpoint/usbdev1.9_ep83
add@/class/usb_device/usbdev1.9
add@/class/usb_endpoint/usbdev1.9_ep00
add@/devices/pci0000:00/0000:00:1d.7/usb1/1-6/1-6:1.0/host8/target8:0:0/8:0:0:0
add@/class/scsi_disk/8:0:0:0
change@/devices/pci0000:00/0000:00:1d.7/usb1/1-6/1-6:1.0/host8/target8:0:0/8:0:0:0
add@/block/sdd
add@/block/sdd/sdd1
add@/class/bdi/8:48
add@/class/scsi_device/8:0:0:0
add@/class/bsg/8:0:0:0

3. Use the tool "disktype"to know the filesystem of the partitions on the storage device.

sudo /usr/bin/disktype /dev/sdd1
--- /dev/sdd1
Block device, size 125.0 MiB (131046400 bytes)
Windows NTLDR boot loader
NTFS file system
Volume size 125.0 MiB (131045888 bytes, 255949 sectors)

sudo /usr/bin/disktype /dev/sdd1 | grep "file system" | cut -d'f' -f1
NTFS

4. Mount the partitions on the specific directories under “/sdcard”. But we must check if the mount point is available first:

disk_partition=/dev/sdd1
mount_point=/sdcard/sdd1
if ! mountpoint -q $mount_point;then echo "The $mount_point is available. Mount $disk_partition on the $mount_point"; fi



5. Broadcast the mounted event to let applications on Android platform know.

#/system/bin/busybox rm /etc/vold.conf
#/system/bin/busybox touch /etc/vold.conf
# /system/bin/busybox mknod /dev/mmcblk0p1 b 179 1
# /system/bin/busybox mkdir /sdcard/sd
# /system/bin/busybox mount /dev/mmcblk0p1 /sdcard/sd
# /system/bin/busybox chmod 777 /sdcard
# /system/bin/setprop EXTERNAL_STORAGE_STATE mounted
# /system/bin/busybox sh /system/bin/am broadcast -a android.intent.action.MEDIA_MOUNTED --ez read-only false -d file:///sdcard
Broadcasting: Intent { action=android.intent.action.MEDIA_MOUNTED data=file:///sdcard (has extras) }
#
# /system/bin/busybox mknod /dev/sda1 b 8 1
# /system/bin/busybox mkdir /sdcard/usb
# /system/bin/busybox chmod 777 /sdcard
# /system/bin/ntfs-3g /dev/sda1 /sdcard/usb
# /system/bin/setprop EXTERNAL_STORAGE_STATE mounted
# /system/bin/busybox sh /system/bin/am broadcast -a android.intent.action.MEDIA_MOUNTED --ez read-only false -d file:///sdcard
Broadcasting: Intent { action=android.intent.action.MEDIA_MOUNTED data=file:///sdcard (has extras) }

3 則留言:

匿名 提到...

Good post and this enter helped me alot in my college assignement. Say thank you you as your information.

匿名 提到...

art naked news [url=http://portal.prmag.com/_Lindsay-Lohan-nude-in-movie-34I-Know-Who-Killed-Me34/video/1218215/16633.html] naked video clips[/url] .

匿名 提到...

google law firm