hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/sbin/sh
 
#RESULT_FILE="/data/udisk_capacity.txt"
#LOG_FILE="/data/udisk.log"
#source send_cmd_pipe.sh
 
#while true; do
    for nr in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
   udisk="/dev/block/sd$nr"
        part=$udisk
    
        #echo "searching disk ..." >> LOG_FILE
            while true; do
                if [ -b "$udisk" ]; then
                    busybox sleep 1
                    if [ -b "$udisk" ]; then
                        echo "udisk insert"
                        break;
                    fi
                else
                    busybox sleep 1
                fi
            done
            
            if [ ! -d "/tmp/udisk" ]; then
                busybox mkdir -p /tmp/udisk
            fi
            
            #echo "mounting disk ..." >> LOG_FILE
            busybox mount -t vfat $udisk /tmp/udisk
            if [ $? -ne 0 ]; then
       for num in 1 2 3 4 5 6;do
           udiskp=$udisk"$num"
                    busybox mount -t vfat $udiskp /tmp/udisk
                    if [ $? -ne 0 ]; then
                       echo "udisk mount failed" >> LOG_FILE
                       #SEND_CMD_PIPE_FAIL $3
                       #busybox sleep 3
                       # goto for nr in ...
                       # detect next plugin, the devno will changed
                       #continue 2
                    else
                       part=$udiskp
              break
                    fi
       done
       else
       break
            fi
    
       if [ $part = $udiskp ];then
       break
            fi
        done
    
        capacity=`busybox df | busybox grep /tmp/udisk | busybox awk '{printf $2}'`
        #echo "$part: $capacity" >> LOG_FILE
 
        busybox umount /tmp/udisk
        #SEND_CMD_PIPE_OK_EX $3 $capacity
 
        echo $capacity > /data/udisk_capacity.txt
        break
    
#        while true; do
#            if [ -b "$udisk" ]; then
#                echo "please remove udisk"
#                busybox sleep 1
#            else
#                echo "udisk removed"
#                break
#            fi
#        done
#done