File: _common

package info (click to toggle)
partclone 0.3.23%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,152 kB
  • sloc: ansic: 112,812; sh: 4,756; xml: 2,410; makefile: 502; perl: 106; asm: 35; sed: 16
file content (175 lines) | stat: -rwxr-xr-x 3,062 bytes parent folder | download
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash

break_debug=0
logfile="$$_test.log"
img="$$_floppy.img"
raw="$$_floppy.raw"
raw_restore="$$_floppy_restore.raw"
dd_bs=1024
normal_size=$((256*1*256))
floppy_size=1024
current_dir=`pwd`
ptldir="../src"

ptlinfo=$ptldir/partclone.info
ptlchkimg=$ptldir/partclone.chkimg
ptlrestore=$ptldir/partclone.restore

mkfs_option_for_ext2='-F'
mkfs_option_for_ext3='-F'
mkfs_option_for_ext4='-F'
mkfs_option_for_reiserfs='-q'
mkfs_option_for_reiser4='-f -y'
mkfs_option_for_ntfs='-f -F'
mkfs_option_for_jfs='-q'
mkfs_option_for_xfs='-f'
mkfs_option_for_btrfs='-f'
mkfs_option_for_fat12='-F 12'
mkfs_option_for_fat16='-F 16'
mkfs_option_for_fat32='-F 32'
mkfs_option_for_f2fs='-f'
mkfs_option_for_nilfs2='-f'
#mkfs_option_for_minix='-3'

## file system
# mountable for writing file system
mountable_fs="ext2 ext3 ext4 vfat exfat minix jfs xfs reiserfs ntfs btrfs hfsplus f2fs nilfs2"

# vmfs file system can't format, can mount read-only
# ufs mkfs.ufs can't format special file as partition
extra_fs="vmfs ufs"

# foramtable file system reiser4 can't mount, ufs read-only
formatable_fs="$mountable_fs reiser4"

_check_root(){
    if [[ $UID -ne 0 ]]; then
	echo "$0 must be run as root"
	exit 1
    fi
}

_check_return_code(){
    if [ $? != 0 ]; then
	echo "return code fail"
	exit
    fi
}

_ptlbreak(){
    if [[ $break_debug -ne 0 && $- = *"i"* ]];then

	echo "continue test process(Y/n)? default yes"
	read con
	if [ "$con" == "n" ];then
	    exit 1
	fi
    fi

}
_test_size(){
    fs=$1
    case "$fs" in
	fat12)
	    normal_size=$((1024*8))
	;;
	fat16)
	    normal_size=$((1024*32))
	;;
	fat32|fat|vfat)
	    normal_size=$((1024*128))
	;;
	f2fs)
	    normal_size=$((1024*128))
	;;
	xfs)
	    normal_size=$((1024*384))
	;;
    esac

    echo $normal_size
}


_findmkfs(){
    fs=$1
    case "$fs" in
	fat12|fat16|fat32|fat|vfat)
	    fs="vfat"
	;;
    esac

    locate_path=$(type -P locate)
    if [ -n $locate_path ]; then
        mkfs_path=$($locate_path mkfs.$fs|grep sbin| sort -n -r |head -n 1)
    fi
    if [ -z $mkfs_path ]; then
        mkfs_path=$(which mkfs.$fs)
    fi
    if [ -z $mkfs_path ]; then
	echo  >&2 "can't find mkfs.$fs"
	exit 1
    fi
    echo $mkfs_path

}

_ptlname(){
    fs=$1
    case "$fs" in
	ext2|ext3|ext4|extfs)
	    ptl="$ptldir/partclone.extfs"
	;;
	fat16|fat12|fat32|fat|vfat)
	    ptl="$ptldir/partclone.fat"
	;;
	hfsplus)
	    ptl="$ptldir/partclone.hfsp"
	;;
	*)
	    ptl="$ptldir/partclone.$fs"
    esac

    if [ ! -f $ptl ]; then
	echo >&2 "can't find $ptl"
	exit 1
    fi
    echo "$ptl"
}

_convert_to_bytes(){
    str=$1
    case $str in
	*KB)
	    bytes=$((${str%KB}*1000))
	;;
	*K)
	    bytes=$((${str%K}*1024))
	;;
	*MB)
	    bytes=$((${str%MB}*1000*1000))
	;;
	*M)
	    bytes=$((${str%M}*1024*1024))
	;;
	*GB)
	    bytes=$((${str%GB}*1000*1000*1000))
	;;
	*G)
	    bytes=$((${str%G}*1024*1024*1024))
	;;
	*TB)
	    bytes=$((${str%TB}*1000*1000*1000*1000))
	;;
	*T)
	    bytes=$((${str%T}*1024*1024*1024*1024))
	;;
	*B)
	    bytes=$((${str%B}))
	;;
	*)
	    bytes=$((str))
	;;
    esac
    echo $bytes
}