1#! /bin/sh 2 3DISK_FIND_TABLE=/tmp/find_disk_abcxzy 4download_state="$(/bin/config get green_download_enable)" 5download_start() { 6 sleep 2 7 green_download=`ps -w| grep -v grep |grep -c green_download.sh` 8 download_entry=`ps -w| grep -v grep |grep -c greendownload` 9 [ "x$green_download" != "x0" ] && return 10 [ "x$download_entry" != "x0" ] && return 11 [ "x$download_state" == "x1" ] && echo "hotplug starting green_download ........" > /dev/console && /usr/sbin/green_download.sh start 12} 13 14# $---> sda1 15print_log() 16{ 17 if [ `length $1` != '4' ];then 18 return 19 fi 20 21 sata_disk_name=`/bin/config get sata_diskname` 22 23 device_name=`cat $DISK_FIND_TABLE | grep $1 | awk -F* '{print $2}'` 24 volume_name=`cat $DISK_FIND_TABLE | grep $1 | awk -F* '{{{i=NF-3; a="*";while(i!=0) {printf $(NF-i); if(i!=1) printf a; i--}}}}'` 25 26 if [ "x$sata_disk_name" = "x$1" ]; then 27 logger "[External disk attached] The External disk attached $device_name($volume_name) is attached to the router" 28 return 29 else 30 logger "[USB device attached] The USB storage device $device_name($volume_name) is attached to the router" 31 return 32 fi 33 34 volume_name=`/usr/sbin/vol_id -L /dev/$1` 35 if [ ! -n "$volume_name" ]; then 36 volume_name=$1 37 fi 38 logger "[USB device attached] The USB storage device $1($volume_name) is attached to the router" 39} 40 41if [ $# -eq 0 ];then 42 echo "Must run with devicename." 43 exit 1 44fi 45mkdir /mnt/$1 46 47fs_type=$(vol_id /dev/$1 | grep ID_FS_TYPE | awk -F= '{print $2}') 48if [ "x$fs_type" = "x" ]; then 49 fs_type=$(parted -s /dev/$1 print | sed -n '/Number/{n;p}' | awk '{print $5}') 50fi 51echo This partition type is $fs_type ! 52partition_tb=$(parted -s /dev/`echo $1 | sed 's/[0-9]//g'` print | grep "Partition Table" | awk '{print $3}') 53if [ "x$(parted -s /dev/`echo $1 | sed 's/[0-9]//g'` print noshare | grep $1)" = "x" -o "x$partition_tb" = "xloop" ]; then 54 case "$fs_type" in 55 "ntfs") 56 mount -t ufsd -o nls=utf8,rw,nodev,noexec,noatime,uid=0,gid=0,fmask=0,dmask=0 --force /dev/$1 /mnt/$1 57 ;; 58 "ext4") 59 mount -t ext4 -o nodev,noexec,noatime,barrier=0,data=writeback /dev/$1 /mnt/$1 60 ;; 61 "ext3") 62 mount -t ext3 -o nodev,noexec,noatime,barrier=0,data=writeback /dev/$1 /mnt/$1 63 if [ $? -ne 0 ];then 64 mount -t ext4 -o nodev,noexec,noatime,barrier=0,data=writeback /dev/$1 /mnt/$1 65 fi 66 ;; 67 "ext2") 68 mount -t ext2 -o nodev,noexec,noatime /dev/$1 /mnt/$1 69 ;; 70 "xfs") 71 mount -t xfs /dev/$1 /mnt/$1 72 chmod -R 777 /mnt/$1 73 ;; 74 "hfs") 75 mount -t hfs -o nodev,noexec,noatime /dev/$1 /mnt/$1 76 ;; 77 "hfsplus") 78 mount -t hfsplus -o nodev,noexec,noatime --force /dev/$1 /mnt/$1 79 chmod -R 777 /mnt/$1 80 ;; 81 "vfat") 82 mount -o usefree,utf8=yes,fmask=0000,dmask=0000 /dev/$1 /mnt/$1 83 ;; 84 *) 85 if [ "x$fs_type" = "x" ];then 86 rmdir /mnt/$1 87 return 88 fi 89 mount /dev/$1 /mnt/$1 90 if [ $? -ne 0 ];then 91 rmdir /mnt/$1 92 else 93 echo "mount /mnt/$1 success" 94 fi 95 return 96 ;; 97 esac 98fi 99 100diskname=$(echo $1 | sed 's/[0-9].*//') 101lastpartition=$(cat /proc/partitions | grep $diskname | awk '{print $4}' | tail -1) 102echo "disk name is $diskname last partition is $lastpartition" 103 104if [ $1 = $lastpartition ]; then 105 echo noop > /sys/block/$diskname/queue/scheduler 106 echo 1024 > /sys/block/$diskname/queue/nr_requests 107 108 /usr/sbin/detectSATA start 109 if [ "x$(pidof update_smb)" != "x" ]; then 110 echo "update_smb is running, sleep 2" > /dev/console 111 sleep 2 112 fi 113 update_smb $diskname 114 /usr/sbin/update_afp $diskname 115 #/usr/sbin/usb_cfg approve $1 116 /sbin/cmdftp restart 117 /sbin/cmddlna restart & 118 #if download is ennable start download 119 download_start 120fi 121 122print_log $1 123rm /tmp/umount_result 124 125